yuankunzhang / charming

A visualization library for Rust
Apache License 2.0
1.85k stars 73 forks source link

Klick builder pattern #30

Closed qknight closed 9 months ago

qknight commented 1 year ago

Adding item_style support in SankeyNode using builder pattern:

let mut labels: Vec<SankeyNode> = vec![];

let label = "foo";
let my_style = ItemStyle::new().color("red").border_color("black");
let sn = SankeyNode::new(label).item_style(my_style);

labels.push(sn);

This way one can override the echarts sankey colors for nodes and organize the coloring!

let chart = Chart::new().series(
    Sankey::new()
        .layout_iterations(0u64)
        .links(sankey_links)
        .data(labels)
);

Note, this includes https://github.com/yuankunzhang/charming/pull/29

This is similar to:

let one = "green";
let two = "#DE3163";
let three = "orange";

option = 
{
  "series": [
    {
      "type": "sankey",

      "layoutIterations": 0,
      lineStyle: {
        color: 'source',
        curveness: 0.4
      },
      "links": [ 
        {
          "source": "Nutzung 2.179",
          "target": "Emission 2.179",
          "value": 2178.4796516480023
        }
      ],
      "data": [
        {
          "name": "Nutzung 2.179",
          itemStyle: {
            color: two,
            borderColor: 'black'
          },
                  },
        {
          "name": "Emission 2.179",
          itemStyle: {
            color: two,
            borderColor: 'black'
          }
        }
      ]
    }
  ]
};

https://echarts.apache.org/examples/en/editor.html?c=sankey-simple&lang=ts&version=5.4.4-dev.20231111&decal=1

qknight commented 10 months ago

@ yuankunzhang is there anything I can do to make this being merged?