This idea has been in my head for some time, but I figure it's time to formally write it down, as it would simplify the "basic" use cases (especially for exploration or quick visualizations) and enable additional use cases similar to the newly released shadcn/ui Charts. While I was initially adverse to the idea, I think creating BarChart, AreaChart, LineChart, etc will provide a lot of value, including:
- Quick exploration (
<BarChart {data} />) if you align with conventions
- Good initial defaults for common chart types (setting up scales, tooltip modes, and even axis, legends, etc)
- Provide convenient ways to remove abstractions as you want (override accessors, slots, styling, etc)
- Reduce imports (
d3-scale, many LayerChart components, ...)
The general idea is
<script>
import { BarChart, ... } from 'layerchart';
</script>
<BarChart {data} x="date" y="value">
...
</BarChart>
is a streamlined instance of
<script>
import { Chart, ... } from 'layerchart';
import { scaleBand, scaleLinear } from 'd3-scale';
</script>
<Chart
{data}
x="date"
xScale={scaleBand()}
y="value"
yScale={scaleLinear()}
yDomain={[0, null]}
padding={{ left: 16, bottom: 24 }}
tooltip={{ mode: 'band' }}
>
...
</Chart>
Possibly also provide a default slot impl, so
<script>
import { BarChart } from 'layerchart';
</script>
<BarChart {data} x="date" y="value" />
is a streamlined instance of
<script>
import { Chart, Svg, Axis, Bars, Highlight, Tooltip, TooltipItem } from 'layerchart';
import { scaleBand, scaleLinear } from 'd3-scale';
</script>
<Chart
{data}
x="date"
xScale={scaleBand()}
y="value"
yScale={scaleLinear()}
yDomain={[0, null]}
padding={{ left: 16, bottom: 24 }}
tooltip={{ mode: 'band' }}
>
<Svg>
<Axis placement="left" grid rule />
<Axis placement="bottom" rule />
<Bars radius={4} strokeWidth={1} class="fill-primary" />
<Highlight area />
</Svg>
<Tooltip header={(data) => format(data.date, "eee, MMMM do")} let:data>
<TooltipItem label="value" value={data.value} />
</Tooltip>
</Chart>
Items to consider
Initial charts to support
Related: #68
This idea has been in my head for some time, but I figure it's time to formally write it down, as it would simplify the "basic" use cases (especially for exploration or quick visualizations) and enable additional use cases similar to the newly released shadcn/ui Charts. While I was initially adverse to the idea, I think creating
BarChart,AreaChart,LineChart, etc will provide a lot of value, including:<BarChart {data} />) if you align with conventionsd3-scale, many LayerChart components, ...)The general idea is
is a streamlined instance of
Possibly also provide a default slot impl, so
is a streamlined instance of
Items to consider
scaleBand().padding(0.4)maybe as<BarChart bandPadding={0.4}>$$restPropsto underlyingChartsuch as<BarChart {data} x="date" y="value">propsto target internal components, but recommend overriding slots (named or default) as use cases become more complicatedmarksslot for easy styling with<LinearGradient let:url>component0min domain if data includes negative valuesyBaseline<Rule={x}>unlessxDomaindoes not include0in min/max range (same fory)xDomainincludes negative values<AreaChart tooltip={false}>)<Legend>(ex.<Chart legend={....}>)Initial charts to support
scaleBand/scaleLinearbandorbisect-x/bisect-yscaleTimeorscaleLinear/scaleLinearbisect-xscaleTimeorscaleLinear/scaleLinearbisect-xscaleLinearvoronoiorquadtreemanual(path)Related: #68