Functional Weave
Code in Rust

charts.bar-chart@1.0.0

vectors.json

9,793 bytes · view raw

[
  {"name": "grouped: two series side by side in each category", "args": [{"width": 300, "height": 200, "categories": ["Q1", "Q2"], "series": [{"name": "A", "values": [10, 20]}, {"name": "B", "values": [30, 40]}], "mode": "grouped"}], "expect": {"width": 300, "height": 200, "plot": {"x": 31, "y": 34, "width": 249, "height": 136}, "xAxis": {"orient": "bottom", "position": 170, "line": {"x1": 31, "y1": 170, "x2": 280, "y2": 170}, "ticks": [{"position": 93.25, "label": "Q1", "tick": {"x1": 93.25, "y1": 170, "x2": 93.25, "y2": 176}, "labelX": 93.25, "labelY": 179, "anchor": "middle", "baseline": "hanging"}, {"position": 217.75, "label": "Q2", "tick": {"x1": 217.75, "y1": 170, "x2": 217.75, "y2": 176}, "labelX": 217.75, "labelY": 179, "anchor": "middle", "baseline": "hanging"}]}, "yAxis": {"orient": "left", "position": 31, "line": {"x1": 31, "y1": 170, "x2": 31, "y2": 34}, "ticks": [{"position": 170, "label": "0", "tick": {"x1": 31, "y1": 170, "x2": 25, "y2": 170}, "labelX": 22, "labelY": 170, "anchor": "end", "baseline": "middle"}, {"position": 102, "label": "20", "tick": {"x1": 31, "y1": 102, "x2": 25, "y2": 102}, "labelX": 22, "labelY": 102, "anchor": "end", "baseline": "middle"}, {"position": 34, "label": "40", "tick": {"x1": 31, "y1": 34, "x2": 25, "y2": 34}, "labelX": 22, "labelY": 34, "anchor": "end", "baseline": "middle"}]}, "gridLines": [{"x1": 31, "y1": 170, "x2": 280, "y2": 170}, {"x1": 31, "y1": 102, "x2": 280, "y2": 102}, {"x1": 31, "y1": 34, "x2": 280, "y2": 34}], "bars": [{"series": "A", "category": "Q1", "value": 10, "color": "#e69f00", "rect": {"x": 43.45, "y": 136, "width": 48.52, "height": 34}}, {"series": "A", "category": "Q2", "value": 20, "color": "#e69f00", "rect": {"x": 167.95, "y": 102, "width": 48.52, "height": 68}}, {"series": "B", "category": "Q1", "value": 30, "color": "#56b4e9", "rect": {"x": 94.53, "y": 68, "width": 48.52, "height": 102}}, {"series": "B", "category": "Q2", "value": 40, "color": "#56b4e9", "rect": {"x": 219.03, "y": 34, "width": 48.52, "height": 136}}], "colors": ["#e69f00", "#56b4e9"], "legend": [{"label": "A", "row": 0, "x": 8, "y": 8, "width": 21, "textX": 22}, {"label": "B", "row": 0, "x": 45, "y": 8, "width": 21, "textX": 59}]}},
  {"name": "stacked: positives stack up from zero and a negative hangs below it", "args": [{"width": 300, "height": 200, "categories": ["x", "y"], "series": [{"name": "A", "values": [10, 20]}, {"name": "B", "values": [30, -10]}], "mode": "stacked"}], "expect": {"width": 300, "height": 200, "plot": {"x": 38, "y": 34, "width": 242, "height": 136}, "xAxis": {"orient": "bottom", "position": 170, "line": {"x1": 38, "y1": 170, "x2": 280, "y2": 170}, "ticks": [{"position": 98.5, "label": "x", "tick": {"x1": 98.5, "y1": 170, "x2": 98.5, "y2": 176}, "labelX": 98.5, "labelY": 179, "anchor": "middle", "baseline": "hanging"}, {"position": 219.5, "label": "y", "tick": {"x1": 219.5, "y1": 170, "x2": 219.5, "y2": 176}, "labelX": 219.5, "labelY": 179, "anchor": "middle", "baseline": "hanging"}]}, "yAxis": {"orient": "left", "position": 38, "line": {"x1": 38, "y1": 170, "x2": 38, "y2": 34}, "ticks": [{"position": 170, "label": "-20", "tick": {"x1": 38, "y1": 170, "x2": 32, "y2": 170}, "labelX": 29, "labelY": 170, "anchor": "end", "baseline": "middle"}, {"position": 124.67, "label": "0", "tick": {"x1": 38, "y1": 124.67, "x2": 32, "y2": 124.67}, "labelX": 29, "labelY": 124.67, "anchor": "end", "baseline": "middle"}, {"position": 79.33, "label": "20", "tick": {"x1": 38, "y1": 79.33, "x2": 32, "y2": 79.33}, "labelX": 29, "labelY": 79.33, "anchor": "end", "baseline": "middle"}, {"position": 34, "label": "40", "tick": {"x1": 38, "y1": 34, "x2": 32, "y2": 34}, "labelX": 29, "labelY": 34, "anchor": "end", "baseline": "middle"}]}, "gridLines": [{"x1": 38, "y1": 170, "x2": 280, "y2": 170}, {"x1": 38, "y1": 124.67, "x2": 280, "y2": 124.67}, {"x1": 38, "y1": 79.33, "x2": 280, "y2": 79.33}, {"x1": 38, "y1": 34, "x2": 280, "y2": 34}], "bars": [{"series": "A", "category": "x", "value": 10, "color": "#e69f00", "rect": {"x": 50.1, "y": 102, "width": 96.8, "height": 22.67}}, {"series": "A", "category": "y", "value": 20, "color": "#e69f00", "rect": {"x": 171.1, "y": 79.33, "width": 96.8, "height": 45.34}}, {"series": "B", "category": "x", "value": 30, "color": "#56b4e9", "rect": {"x": 50.1, "y": 34, "width": 96.8, "height": 68}}, {"series": "B", "category": "y", "value": -10, "color": "#56b4e9", "rect": {"x": 171.1, "y": 124.67, "width": 96.8, "height": 22.66}}], "colors": ["#e69f00", "#56b4e9"], "legend": [{"label": "A", "row": 0, "x": 8, "y": 8, "width": 21, "textX": 22}, {"label": "B", "row": 0, "x": 45, "y": 8, "width": 21, "textX": 59}]}},
  {"name": "one series: full-width bands, no legend; widths are differences of rounded edges (37.87, 37.86)", "args": [{"width": 200, "height": 150, "categories": ["a", "b", "c"], "series": [{"name": "S", "values": [5, -5, 10]}], "mode": "grouped"}], "expect": {"width": 200, "height": 150, "plot": {"x": 38, "y": 12, "width": 142, "height": 108}, "xAxis": {"orient": "bottom", "position": 120, "line": {"x1": 38, "y1": 120, "x2": 180, "y2": 120}, "ticks": [{"position": 61.67, "label": "a", "tick": {"x1": 61.67, "y1": 120, "x2": 61.67, "y2": 126}, "labelX": 61.67, "labelY": 129, "anchor": "middle", "baseline": "hanging"}, {"position": 109, "label": "b", "tick": {"x1": 109, "y1": 120, "x2": 109, "y2": 126}, "labelX": 109, "labelY": 129, "anchor": "middle", "baseline": "hanging"}, {"position": 156.33, "label": "c", "tick": {"x1": 156.33, "y1": 120, "x2": 156.33, "y2": 126}, "labelX": 156.33, "labelY": 129, "anchor": "middle", "baseline": "hanging"}]}, "yAxis": {"orient": "left", "position": 38, "line": {"x1": 38, "y1": 120, "x2": 38, "y2": 12}, "ticks": [{"position": 120, "label": "-10", "tick": {"x1": 38, "y1": 120, "x2": 32, "y2": 120}, "labelX": 29, "labelY": 120, "anchor": "end", "baseline": "middle"}, {"position": 66, "label": "0", "tick": {"x1": 38, "y1": 66, "x2": 32, "y2": 66}, "labelX": 29, "labelY": 66, "anchor": "end", "baseline": "middle"}, {"position": 12, "label": "10", "tick": {"x1": 38, "y1": 12, "x2": 32, "y2": 12}, "labelX": 29, "labelY": 12, "anchor": "end", "baseline": "middle"}]}, "gridLines": [{"x1": 38, "y1": 120, "x2": 180, "y2": 120}, {"x1": 38, "y1": 66, "x2": 180, "y2": 66}, {"x1": 38, "y1": 12, "x2": 180, "y2": 12}], "bars": [{"series": "S", "category": "a", "value": 5, "color": "#e69f00", "rect": {"x": 42.73, "y": 39, "width": 37.87, "height": 27}}, {"series": "S", "category": "b", "value": -5, "color": "#e69f00", "rect": {"x": 90.07, "y": 66, "width": 37.86, "height": 27}}, {"series": "S", "category": "c", "value": 10, "color": "#e69f00", "rect": {"x": 137.4, "y": 12, "width": 37.87, "height": 54}}], "colors": ["#e69f00"], "legend": []}},
  {"name": "all zero: the y axis still has a height, 0 to 1", "args": [{"width": 200, "height": 150, "categories": ["a"], "series": [{"name": "S", "values": [0]}], "mode": "grouped"}], "expect": {"width": 200, "height": 150, "plot": {"x": 38, "y": 12, "width": 142, "height": 108}, "xAxis": {"orient": "bottom", "position": 120, "line": {"x1": 38, "y1": 120, "x2": 180, "y2": 120}, "ticks": [{"position": 109, "label": "a", "tick": {"x1": 109, "y1": 120, "x2": 109, "y2": 126}, "labelX": 109, "labelY": 129, "anchor": "middle", "baseline": "hanging"}]}, "yAxis": {"orient": "left", "position": 38, "line": {"x1": 38, "y1": 120, "x2": 38, "y2": 12}, "ticks": [{"position": 120, "label": "0.0", "tick": {"x1": 38, "y1": 120, "x2": 32, "y2": 120}, "labelX": 29, "labelY": 120, "anchor": "end", "baseline": "middle"}, {"position": 66, "label": "0.5", "tick": {"x1": 38, "y1": 66, "x2": 32, "y2": 66}, "labelX": 29, "labelY": 66, "anchor": "end", "baseline": "middle"}, {"position": 12, "label": "1.0", "tick": {"x1": 38, "y1": 12, "x2": 32, "y2": 12}, "labelX": 29, "labelY": 12, "anchor": "end", "baseline": "middle"}]}, "gridLines": [{"x1": 38, "y1": 120, "x2": 180, "y2": 120}, {"x1": 38, "y1": 66, "x2": 180, "y2": 66}, {"x1": 38, "y1": 12, "x2": 180, "y2": 12}], "bars": [{"series": "S", "category": "a", "value": 0, "color": "#e69f00", "rect": {"x": 52.2, "y": 120, "width": 113.6, "height": 0}}], "colors": ["#e69f00"], "legend": []}},
  {"name": "no categories is an error", "args": [{"width": 300, "height": 200, "categories": [], "series": [{"name": "A", "values": []}], "mode": "grouped"}], "expectError": "a bar chart needs at least one category"},
  {"name": "no series is an error", "args": [{"width": 300, "height": 200, "categories": ["a"], "series": [], "mode": "grouped"}], "expectError": "a bar chart needs at least one series"},
  {"name": "a series of the wrong length is an error", "args": [{"width": 300, "height": 200, "categories": ["a", "b"], "series": [{"name": "A", "values": [1]}], "mode": "grouped"}], "expectError": "series \"A\" has 1 values but there are 2 categories"},
  {"name": "a repeated category is an error", "args": [{"width": 300, "height": 200, "categories": ["a", "a"], "series": [{"name": "A", "values": [1, 2]}], "mode": "grouped"}], "expectError": "domain has a repeated value"},
  {"name": "two series with one name is an error", "args": [{"width": 300, "height": 200, "categories": ["a"], "series": [{"name": "A", "values": [1]}, {"name": "A", "values": [2]}], "mode": "grouped"}], "expectError": "domain has a repeated value"},
  {"name": "an unknown mode is an error", "args": [{"width": 300, "height": 200, "categories": ["a"], "series": [{"name": "A", "values": [1]}], "mode": "overlapped"}], "expectError": "mode must be grouped or stacked"},
  {"name": "a chart too small for its margins is an error", "args": [{"width": 40, "height": 40, "categories": ["a"], "series": [{"name": "A", "values": [1]}], "mode": "grouped"}], "expectError": "margins leave no room to plot"}
]