Skip to content

Serde support#46

Merged
rtbo merged 21 commits into
mainfrom
serde2
Jun 28, 2026
Merged

Serde support#46
rtbo merged 21 commits into
mainfrom
serde2

Conversation

@rtbo

@rtbo rtbo commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Custom support for serialization and deserialization.
This is not a simple #[derive(Serialize, Deserialize)]. It is a hand crafted implementation to fit the plotive-js typescript definitions.
Therefore any figure written in JSON, YML or Javascript that follows those definitions can be parsed. non-provided fields will keep the default assignment. Ticks, strokes, colors etc. can either be deserialized from string, object or arrays per the typescript definitions.
Similarily, a figure can be automatically serialized into something that looks hand-written (all defaults props are ignored, those that can be simplified are etc.)

For example the minimal example serializes in YML as

title: Minimal Figure
plot:
  series:
    type: line
    x: x
    y: y

whereas implementation with #[derive(Serialize, Deserialize)] would look like the following which would also be required for deserialization:

plots:
  Plot:
    series:
      - Line: 
          x_data:
            SrcRef: x
          y_data:
            SrcRef: y
          name: null
          x_axis:
            Idx: 0
          y_axis:
            Idx: 0
          stroke:
            color: Auto
            width: 1.5
            pattern: Solid
            opacity: null
          marker: null
          interpolation: Linear
    x_axes:
      - id: null
        title: null
        side: Main
        scale: Auto
        ticks: null
        minor_ticks: null
        grid: null
        minor_grid: null
    y_axes:
      - id: null
        title: null
        side: Main
        scale: Auto
        ticks: null
        minor_ticks: null
        grid: null
        minor_grid: null
    x_axis_set: false
    y_axis_set: false
    title: null
    fill: null
    border:
      Box:
        color:
          Theme: Foreground
        width: 1.0
        pattern: Solid
        opacity: null
    insets: Auto
    legend: null
    colorbar: null
    annotations: []
title:
  text: Minimal Figure
  props:
    font_size: 20.0
    font:
      families:
        - SansSerif
      weight: 400
      width: Normal
      style: Normal
    fill:
      Theme: Foreground
    outline: null
    underline: false
    strikeout: false
  spans: []
size:
  w: 800.0
  h: 600.0
legend: null
fill:
  Solid:
    color:
      Theme: Background
    opacity: null
padding:
  Even: 20.0

@rtbo rtbo merged commit ea129bb into main Jun 28, 2026
2 checks passed
@rtbo rtbo deleted the serde2 branch June 28, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant