Functional Weave
Code in Rust

charts.stack@1.0.0

vectors.json

2,566 bytes · view raw

[
  {"name": "zero: each series sits on the one before it", "args": [[[10, 20], [5, 5], [1, 2]], "zero"], "expect": [[{"y0": 0, "y1": 10}, {"y0": 0, "y1": 20}], [{"y0": 10, "y1": 15}, {"y0": 20, "y1": 25}], [{"y0": 15, "y1": 16}, {"y0": 25, "y1": 27}]]},
  {"name": "zero: a negative value pulls its band below the running top, as d3's stackOffsetNone", "args": [[[10], [-4], [3]], "zero"], "expect": [[{"y0": 0, "y1": 10}], [{"y0": 10, "y1": 6}], [{"y0": 6, "y1": 9}]]},
  {"name": "zero: binary noise is rounded away (0.1 + 0.2 is 0.30000000000000004)", "args": [[[0.1], [0.2], [0.3]], "zero"], "expect": [[{"y0": 0, "y1": 0.1}], [{"y0": 0.1, "y1": 0.3}], [{"y0": 0.3, "y1": 0.6}]]},
  {"name": "expand: each position scaled to a total of 1", "args": [[[1, 3], [1, 1], [2, 0]], "expand"], "expect": [[{"y0": 0, "y1": 0.25}, {"y0": 0, "y1": 0.75}], [{"y0": 0.25, "y1": 0.5}, {"y0": 0.75, "y1": 1}], [{"y0": 0.5, "y1": 1}, {"y0": 1, "y1": 1}]]},
  {"name": "expand: thirds round to 6 places and the top is exactly 1", "args": [[[1], [1], [1]], "expand"], "expect": [[{"y0": 0, "y1": 0.333333}], [{"y0": 0.333333, "y1": 0.666667}], [{"y0": 0.666667, "y1": 1}]]},
  {"name": "expand: a position whose values are all zero stays at zero", "args": [[[0, 2], [0, 2]], "expand"], "expect": [[{"y0": 0, "y1": 0}, {"y0": 0, "y1": 0.5}], [{"y0": 0, "y1": 0}, {"y0": 0.5, "y1": 1}]]},
  {"name": "diverging: positives stack up from zero, negatives down from zero", "args": [[[10, -5], [-3, 4], [2, -1]], "diverging"], "expect": [[{"y0": 0, "y1": 10}, {"y0": -5, "y1": 0}], [{"y0": -3, "y1": 0}, {"y0": 0, "y1": 4}], [{"y0": 10, "y1": 12}, {"y0": -6, "y1": -5}]]},
  {"name": "diverging: a zero value is an empty band at zero", "args": [[[5], [0], [2]], "diverging"], "expect": [[{"y0": 0, "y1": 5}], [{"y0": 0, "y1": 0}], [{"y0": 5, "y1": 7}]]},
  {"name": "a single series", "args": [[[1, 2, 3]], "zero"], "expect": [[{"y0": 0, "y1": 1}, {"y0": 0, "y1": 2}, {"y0": 0, "y1": 3}]]},
  {"name": "no series", "args": [[], "zero"], "expect": []},
  {"name": "series with no positions", "args": [[[], []], "diverging"], "expect": [[], []]},
  {"name": "series of different lengths are an error", "args": [[[1, 2], [1]], "zero"], "expectError": "every series must have the same number of values"},
  {"name": "expand with a negative value is an error", "args": [[[1], [-1]], "expand"], "expectError": "expand needs values of zero or more"},
  {"name": "an unknown offset is an error", "args": [[[1]], "silhouette"], "expectError": "stack offset must be zero, expand or diverging"}
]