`BarChart` to support stacked bars
rolyp opened this issue · comments
It should be relatively easy to adapt BarChartRecord
(let’s call it Bar
or StackedBar
) to take a list of (categorical value, numerical value) pairs, rather than a single numerical value, in such a way that the current bar chart examples are supported as a special case.
Conceivably we could represent BarChart
as a dictionary of Bar
(or StackedBar
, which could itself be a dictionary of numerical values), since categorical values are currently represented as strings, but for that we would probably want #954, and anyway we might want to use something other than strings to represent categorical data at some point.
-
Selectable
type synonym -
BubbleChartRecord
->Bubble
-
BarChartRecord
->StackedBar
- Turn
y
field of typeNumber
into list of(String, Number)
pairs - Fix up
bar-chart-line-chart.fld
- Generalise
BarChart.js
to extracty
data by extracting first element from list of(String, Number)
pairs - Fix bar selection
- Generalise
BarChart.js
to support multipley
data values (but validate on singleton stack only initially)- Scan-like operation on bars in stack to accumulate
y
offset
- Scan-like operation on bars in stack to accumulate
- New example to exercise generalisation, based on new
non-renewables
dataset- Copy bar chart code from
bar-chart-line-chart.fld
tostacked-bar-chart.fld
and add toICFP2024.purs
- Switch to
non-renewables.fld
- Plot year rather than country on x-axis (say 2014-2017); plot country on y-axis (
BRA
only, initially) - Plot multiple countries on y-axis
- Clean up code a bit
- Copy bar chart code from
- Fix
BarChart.js
code for non-singleton stacks- Exception in
Sel_isNone
(brokenx
field, missingsel
field) -
y_max
as sum of bar segments not just first -
y
calculation to useprev.height
- Exception in
- Fix stack segment selection
- Restore previous behaviour where data binding for each
rect
carries index of bar - Extend with index of bar segment
- Restore previous behaviour where data binding for each
- Experiment with passing
d
(data) to handler rather than accessing via__data__
❌ not straightforward - Better heuristic for
tickEvery
- Colour scheme
- Highlighting problem with overlaid borders
- Maybe distinguish colour scheme from line chart (for sake of
bar-chart-line-chart
example) - Selection border stroke to emulate line chart
Couple of mini-problems to fix:
- Caption truncated
- Selection of bottom segment of bar is borked