-
-
Notifications
You must be signed in to change notification settings - Fork 36
Closed
Description
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
- Passing additional props to scales (ex.
scaleBand().padding(0.4)maybe as<BarChart bandPadding={0.4}> - Pass
$$restPropsto underlyingChartsuch as<BarChart {data} x="date" y="value"> - Provide a default slot implementation that includes axis, tooltip, etc
- Should we support SVG only, or support Canvas when available (ex. Geo)
- SVG only ATM, as going full Canvas (axis, etc) would require more component support that is available (focusing on marks first, so it would be blended at first now)
- Not exposing a ton of props. LayerChart's primary goal is composition / composability, and should leverage components directly instead of props with indirection
- Exposing
propsto target internal components, but recommend overriding slots (named or default) as use cases become more complicated
- Exposing
- Simplified gradients
- Expose
marksslot for easy styling with<LinearGradient let:url>component
- Expose
- Do not set explicit
0min domain if data includes negative values- Handled via
yBaseline
- Handled via
- Turn off Axis (sparkline, etc)
- Turn off Tooltip
- Support opt-in animations/tweening
- Smartly show
<Rule={x}>unlessxDomaindoes not include0in min/max range (same fory)- Does this work for all use cases?
- Turn off bottom rule if
xDomainincludes negative values - Disable tooltips/highlight? (ex.
<AreaChart tooltip={false}>) - Opt into adding a
<Legend>(ex.<Chart legend={....}>)
Initial charts to support
- BarChart
- default scales:
scaleBand/scaleLinear - tooltip:
bandorbisect-x/bisect-y - vertical and horizontal orientation
- examples
- vertical
- horizontal
- series (overlap)
- series (diverging)
- series (stack)
- series (group)
- series (group and stack)
- labels
- sparkbar
- canvas
- default scales:
- LineChart
- default scales:
scaleTimeorscaleLinear/scaleLinear - tooltip:
bisect-x - examples
- series
- series (highlight on hover)
- labels
- gradient (encoding)
- gradient (threshold)
- radial (radar)
- radial (series)
- sparkline
- canvas
- default scales:
- AreaChart
- default scales:
scaleTimeorscaleLinear/scaleLinear - tooltip:
bisect-x - examples
- gradient
- threshold gradient
- series
- series (highlight on hover)
- series (stack)
- labels
- radial
- sparkline
- canvas
- tween
- default scales:
- ScatterChart
- default scales:
scaleLinear - tooltip:
voronoiorquadtree - examples
- series
- radius
- canvas
- default scales:
- PieChart
- Other integrations
- Legend
- Brush
- TransformContext
- More?
- Threshold
- Hierarchy
- Force
- Geo
Related: #68
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels