Interest in a Simplified Charts Wrapper component, prior to PR.
As I have worked through my first chart with LayerChart as well as the rewrite for version 2, I have had to piece together a lot of the implementation. I realize docs are lagging behind implementations and thought I would help if you have some interest. In the process of writing some of that up, I had another idea for a wrapper component for simple charts.
- Simple Charts wrapper. Instead of Picking each simple chart (LineChart, ArcChart, etc), what about
<SimpleChart chartType="line" {data} ... />
thats looks something like... (untested)
<script lang="ts">
import { onMount } from "svelte";
import type { Component } from "svelte";
let { chartType, data, ...rest } = $props();
chartType = chartType.toLowerCase();
let component: Component | null = $state(null);
const simpleCharts = ["arc", "area", "bar", "line", "pie", "scatter"];
onMount(async () => {
if (simpleCharts.includes(chartType)) {
component = (await import(`./${chartType}Chart.svelte`)).default;
}
});
</script>
{#if component}
<component {data} {...rest} ></component>
{:else}
<p>Unknown chart type: {chartType}</p>
{/if}
It think it would call attention to choice when using <Chart /> vs an Simplifed chart like <LineChart /> distinction especially in the docs.
Components
- Charts
- Chart
- SimpleChart
- ArcChart
- AreaChart
- BarChart
- LineChart
- PieChart
- ScatterChart
If this is something you're interested in let me know and I'll submit a PR.
This is interesting, and there is a cross roads with Chart and simple charts like LineChart, etc.
This unified SimpleChart sounds similar to the AutoChart idea (but with manual declaration). AutoChart was also an idea before the simplified charts existed.
I would like to investigate consolidating more of the functionality within the simplified charts into Chart and even if at some point the simplified charts could be fully consolidated. Seeing how ObservablePlot / SveltePlot are able to accomplish much of this and remain (fairly) concise gives me a lot of ideas.
What do you think about looking at it the other way and seeing how Chart can be updated to provide much of the same capability as the simplified charts (making these simple charts thinner and thinner possibly to the point of become unneeded)?
I think you could go either way. Like everything there are positives and negatives.
Here are a few thoughts.
- I don't have any familiarity with any of the other charting packages you mentioned.
- Unified Chart/Simple Charts would be nice to have one path which you never have to abandon and rewrite.
- Originally I wrote my PSA chart via Chart, but left it for a Simple Chart when I wanted built in benefits they provide.
- I can imagine the other direction where someone underestimates complexity, starts with a simple chart and then needs to rewrite in Chart for broader control.
- Simple Chart become a much easier path for people to choose when/if all supported types are available.
- I do worry a little about complexity if both are combined within the same component because I think with boils down to two quite different implementation that would be tough to explain clearly. Maybe I'm wrong, and it's all in the implementation.
- I think that keeping them separate does promote clarity. However currently it it confusing which charts are actually Simple Charts (ie my original idea for a wrapper SimpleChart). If there was a SimpleChart wrapper component then all the Simple Charts types just become another primitive and docs get a lot clearer (at least to me).