Closed leomorpho closed 1 month ago
Hey @leomorpho, thanks for checking out LayerChart. It looks like you pulled part of createStackData()
from utils/stack. Was there something it was lacking (I didn't spot any differences after a quick glance)
Regardless, nothing jumps out at me that could be simplified ATM, but I would like to improve grouped
/stacked
at some point, especially regarding tooltip/data. See https://github.com/techniq/layerchart/issues/21 and https://github.com/techniq/layerchart/issues/98.
I would also like grouped scales to be more integrated to <Chart>
, which are really just derived scales (x1Scale derives from xScale and uses it's bandwidth instead of the chart's width). Had a chat about adding something in LayerCake, but wasn't worth it at that point (needed more investigation).
However it might be improved, I want to make sure it supports switching between grouped only, stacked only, and group and stacked, such as this example.
Speaking of examples, it would be good to add a diverging bar chart example to the docs., similar to what you have (and both stacked and simpler single bar examples), similar to these:
Sorry for the delay, but take a look at the new BarChart
with series
support. This can not be accomplished with:
<div class="h-[300px] p-4 border rounded">
<BarChart
data={wideData}
x="year"
series={[
{
key: "apples",
value: (d) => -d.apples,
color: "hsl(var(--color-danger))",
},
{
key: "bananas",
color: "hsl(var(--color-warning))",
},
{
key: "cherries",
color: "hsl(var(--color-success))",
},
{
key: "grapes",
color: "hsl(var(--color-info))",
},
]}
seriesLayout="stackDiverging"
props={{
xAxis: { format: "none" },
yAxis: { format: "metric" },
}}
/>
</div>
I was trying to create a stacked bar chart with both positive and negative values (on opposite sides of the x-axis) and ended up doing the following, which works, but makes me wonder if perhaps I am missing something and it could have been done more easily?
In any case, perhaps this code can be useful to someone else...