vccs 1.0.0-beta.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/es/cartesian/bar/components/BarRectangles.mjs +1 -1
- package/dist/es/cartesian/brush/Brush.mjs +4 -0
- package/dist/es/cartesian/funnel/Funnel.mjs +1 -1
- package/dist/es/cartesian/scatter/Scatter.mjs +1 -1
- package/dist/es/chart/CellGridLayer.mjs +1 -1
- package/dist/es/chart/JourneySankey.mjs +1 -1
- package/dist/es/chart/Sankey.mjs +2 -2
- package/dist/es/chart/Sparkline.mjs +1 -1
- package/dist/es/chart/SunburstChart.mjs +1 -1
- package/dist/es/chart/Treemap.mjs +1 -1
- package/dist/es/events/sync.mjs +1 -2
- package/dist/es/events/usePointEvents.mjs +1 -1
- package/dist/es/model/tooltip.mjs +3 -5
- package/dist/es/polar/pie/Pie.mjs +1 -1
- package/dist/es/polar/radial-bar/RadialBar.mjs +1 -1
- package/dist/model/tooltip.d.ts +4 -18
- package/package.json +6 -2
- package/usage/catalog.json +235 -0
- package/usage/guides/charts/area-chart.md +56 -0
- package/usage/guides/charts/bar-chart.md +60 -0
- package/usage/guides/charts/bar-list.md +46 -0
- package/usage/guides/charts/calendar-heatmap.md +55 -0
- package/usage/guides/charts/cohort-chart.md +47 -0
- package/usage/guides/charts/composed-chart.md +70 -0
- package/usage/guides/charts/funnel-chart.md +58 -0
- package/usage/guides/charts/heatmap.md +51 -0
- package/usage/guides/charts/journey-sankey.md +49 -0
- package/usage/guides/charts/line-chart.md +60 -0
- package/usage/guides/charts/pie-chart.md +59 -0
- package/usage/guides/charts/radar-chart.md +69 -0
- package/usage/guides/charts/radial-bar-chart.md +54 -0
- package/usage/guides/charts/sankey.md +59 -0
- package/usage/guides/charts/scatter-chart.md +62 -0
- package/usage/guides/charts/sparkline.md +51 -0
- package/usage/guides/charts/sunburst-chart.md +66 -0
- package/usage/guides/charts/tracker.md +49 -0
- package/usage/guides/charts/treemap.md +68 -0
- package/usage/guides/core/installation.md +68 -0
- package/usage/guides/core/ssr-testing.md +50 -0
- package/usage/guides/core/typed-rows.md +47 -0
- package/usage/guides/core/vue-api.md +72 -0
- package/usage/vccs-usage.mjs +191 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# ScatterChart
|
|
2
|
+
|
|
3
|
+
Use `ScatterChart` to show relationships or distributions across numeric variables, optionally with bubble size. Use `LineChart` for an ordered trend and `BarChart` for category comparisons.
|
|
4
|
+
|
|
5
|
+
## Data shape
|
|
6
|
+
|
|
7
|
+
- Give each `Scatter` its own `data` array when the series contain different points.
|
|
8
|
+
- `XAxis data-key` and `YAxis data-key` select the numeric coordinates from each flat row.
|
|
9
|
+
- Set `type="number"` on both axes for numeric positioning.
|
|
10
|
+
- Add `ZAxis data-key` only when a third numeric field should control point size.
|
|
11
|
+
|
|
12
|
+
## Minimal example
|
|
13
|
+
|
|
14
|
+
```vue
|
|
15
|
+
<script setup lang="ts">
|
|
16
|
+
import { CartesianGrid, Scatter, ScatterChart, Tooltip, XAxis, YAxis, ZAxis } from 'vccs'
|
|
17
|
+
|
|
18
|
+
const data = [
|
|
19
|
+
{ hours: 2, score: 62, students: 12 },
|
|
20
|
+
{ hours: 4, score: 70, students: 18 },
|
|
21
|
+
{ hours: 6, score: 79, students: 16 },
|
|
22
|
+
{ hours: 8, score: 85, students: 22 },
|
|
23
|
+
]
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<template>
|
|
27
|
+
<ScatterChart :height="300">
|
|
28
|
+
<CartesianGrid />
|
|
29
|
+
<XAxis
|
|
30
|
+
data-key="hours"
|
|
31
|
+
type="number"
|
|
32
|
+
/>
|
|
33
|
+
<YAxis
|
|
34
|
+
data-key="score"
|
|
35
|
+
type="number"
|
|
36
|
+
/>
|
|
37
|
+
<ZAxis
|
|
38
|
+
data-key="students"
|
|
39
|
+
:range="[60, 400]"
|
|
40
|
+
/>
|
|
41
|
+
<Tooltip :cursor="false" />
|
|
42
|
+
<Scatter
|
|
43
|
+
name="Classes"
|
|
44
|
+
:data="data"
|
|
45
|
+
fill="#f97316"
|
|
46
|
+
/>
|
|
47
|
+
</ScatterChart>
|
|
48
|
+
</template>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Animation is enabled by default; retrieve `ssr-testing` before taking screenshots or asserting exact geometry.
|
|
52
|
+
|
|
53
|
+
## Chart-specific rules
|
|
54
|
+
|
|
55
|
+
- Put `data` on each `Scatter` for multiple series; set `name` and add `Legend` to distinguish them.
|
|
56
|
+
- `ZAxis range` sets the minimum and maximum dot size; omit `ZAxis` for uniform points.
|
|
57
|
+
- The tooltip shows one point at a time rather than all series at a category.
|
|
58
|
+
- Retrieve `composed-chart` when scatter points must share axes with bars, areas, or lines.
|
|
59
|
+
|
|
60
|
+
## Related guides
|
|
61
|
+
|
|
62
|
+
`installation`, `vue-api`, `typed-rows`, `ssr-testing`, `line-chart`, `composed-chart`.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Sparkline
|
|
2
|
+
|
|
3
|
+
Use `Sparkline` for a tiny trend inside a KPI tile, table row, or dense dashboard. Use `LineChart` when axes, multiple series, or a larger analytical view matter.
|
|
4
|
+
|
|
5
|
+
## Data shape
|
|
6
|
+
|
|
7
|
+
- `data` is an ordered array of numbers or object rows.
|
|
8
|
+
- Object rows use `data-key="value"` by default; choose another numeric field with `data-key`.
|
|
9
|
+
- Use `null` for a missing point that should remain a gap.
|
|
10
|
+
- Set `name-key` to a date or another stable identifier when points must keep their identity across updates.
|
|
11
|
+
|
|
12
|
+
## Minimal example
|
|
13
|
+
|
|
14
|
+
```vue
|
|
15
|
+
<script setup lang="ts">
|
|
16
|
+
import { Sparkline, Tooltip } from 'vccs'
|
|
17
|
+
|
|
18
|
+
const data = [
|
|
19
|
+
{ day: 'Mon', value: 820 },
|
|
20
|
+
{ day: 'Tue', value: 932 },
|
|
21
|
+
{ day: 'Wed', value: 901 },
|
|
22
|
+
{ day: 'Thu', value: 934 },
|
|
23
|
+
{ day: 'Fri', value: 1090 },
|
|
24
|
+
{ day: 'Sat', value: 1180 },
|
|
25
|
+
]
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<template>
|
|
29
|
+
<Sparkline
|
|
30
|
+
:data="data"
|
|
31
|
+
name-key="day"
|
|
32
|
+
type="area"
|
|
33
|
+
color="#f97316"
|
|
34
|
+
:height="40"
|
|
35
|
+
>
|
|
36
|
+
<Tooltip :cursor="false" />
|
|
37
|
+
</Sparkline>
|
|
38
|
+
</template>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Chart-specific rules
|
|
42
|
+
|
|
43
|
+
- Use `type="line"`, `type="area"`, or `type="bar"`; `gap` and `radius` apply only to bars.
|
|
44
|
+
- Give multiple sparklines the same `min` and `max` when their shapes must be comparable.
|
|
45
|
+
- Use `name-key` for a moving time window; without it, points match by array position.
|
|
46
|
+
- Place `Tooltip` in the default slot, or bind `v-model:active-index` to show the hovered point in your own markup.
|
|
47
|
+
- The component fills its container width and defaults to 32px tall unless you set `height` or `aspect`.
|
|
48
|
+
|
|
49
|
+
## Related guides
|
|
50
|
+
|
|
51
|
+
`installation`, `vue-api`, `typed-rows`, `ssr-testing`, `line-chart`, `area-chart`.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# SunburstChart
|
|
2
|
+
|
|
3
|
+
Use `SunburstChart` for two or three levels of a part-to-whole hierarchy as concentric rings. Use `PieChart` for one flat level and `Treemap` when many leaves need more readable areas and labels.
|
|
4
|
+
|
|
5
|
+
## Data shape
|
|
6
|
+
|
|
7
|
+
- `data` is one root object, not an array. The root is not drawn; its `children` form the inner ring.
|
|
8
|
+
- Each node has a `name` by default and may have nested `children`.
|
|
9
|
+
- Leaves need a numeric `value`; `data-key` and `name-key` select different fields.
|
|
10
|
+
- Parent values are the sum of their children. A node may also provide `fill`.
|
|
11
|
+
|
|
12
|
+
## Minimal example
|
|
13
|
+
|
|
14
|
+
```vue
|
|
15
|
+
<script setup lang="ts">
|
|
16
|
+
import { SunburstChart, Tooltip } from 'vccs'
|
|
17
|
+
|
|
18
|
+
const data = {
|
|
19
|
+
name: 'Traffic',
|
|
20
|
+
children: [
|
|
21
|
+
{
|
|
22
|
+
name: 'Search',
|
|
23
|
+
fill: '#f97316',
|
|
24
|
+
children: [
|
|
25
|
+
{ name: 'Google', value: 420 },
|
|
26
|
+
{ name: 'Bing', value: 90 },
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'Social',
|
|
31
|
+
fill: '#14b8a6',
|
|
32
|
+
children: [
|
|
33
|
+
{ name: 'LinkedIn', value: 150 },
|
|
34
|
+
{ name: 'Mastodon', value: 80 },
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
{ name: 'Direct', value: 160, fill: '#f59e0b' },
|
|
38
|
+
],
|
|
39
|
+
}
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<template>
|
|
43
|
+
<SunburstChart
|
|
44
|
+
:data="data"
|
|
45
|
+
:height="320"
|
|
46
|
+
:inner-radius="40"
|
|
47
|
+
title="Traffic by source"
|
|
48
|
+
>
|
|
49
|
+
<Tooltip :cursor="false" />
|
|
50
|
+
</SunburstChart>
|
|
51
|
+
</template>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Animation is enabled by default; retrieve `ssr-testing` before taking screenshots or asserting exact geometry.
|
|
55
|
+
|
|
56
|
+
## Chart-specific rules
|
|
57
|
+
|
|
58
|
+
- Give the root at least one child; a root without `children` renders no sectors.
|
|
59
|
+
- Set `fill` on a top-level group to color its branch. A child's own `fill` overrides its branch color.
|
|
60
|
+
- Use `inner-radius` for the center hole and `outer-radius` when the automatic radius does not fit your layout.
|
|
61
|
+
- Use `ring-padding` to separate rings and `padding` to separate sectors by angle.
|
|
62
|
+
- Customize sectors with the `#content` slot, not a function-valued `content` prop.
|
|
63
|
+
|
|
64
|
+
## Related guides
|
|
65
|
+
|
|
66
|
+
`installation`, `vue-api`, `ssr-testing`, `treemap`, `pie-chart`.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Tracker
|
|
2
|
+
|
|
3
|
+
Use `Tracker` for an ordered sequence of discrete statuses, such as daily service health or build results. Use `Sparkline` for a numeric trend and `Heatmap` for a two-dimensional value matrix.
|
|
4
|
+
|
|
5
|
+
## Data shape
|
|
6
|
+
|
|
7
|
+
- `data` contains one row per bar, ordered oldest first.
|
|
8
|
+
- `data-key` selects the status and defaults to `status`.
|
|
9
|
+
- `name-key` selects the label and bar identity; it defaults to `date`.
|
|
10
|
+
- Built-in statuses are `up`, `degraded`, `down`, and `maintenance`; custom status strings need their own colors and labels.
|
|
11
|
+
|
|
12
|
+
## Minimal example
|
|
13
|
+
|
|
14
|
+
```vue
|
|
15
|
+
<script setup lang="ts">
|
|
16
|
+
import { Tooltip, Tracker } from 'vccs'
|
|
17
|
+
|
|
18
|
+
const data = [
|
|
19
|
+
{ date: '2026-08-01', status: 'up' },
|
|
20
|
+
{ date: '2026-08-02', status: 'up' },
|
|
21
|
+
{ date: '2026-08-03', status: 'degraded' },
|
|
22
|
+
{ date: '2026-08-04', status: 'up' },
|
|
23
|
+
{ date: '2026-08-05', status: 'down' },
|
|
24
|
+
{ date: '2026-08-06', status: 'up' },
|
|
25
|
+
{ date: '2026-08-07', status: 'maintenance' },
|
|
26
|
+
]
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<template>
|
|
30
|
+
<Tracker
|
|
31
|
+
:data="data"
|
|
32
|
+
:height="32"
|
|
33
|
+
>
|
|
34
|
+
<Tooltip :cursor="false" />
|
|
35
|
+
</Tracker>
|
|
36
|
+
</template>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Chart-specific rules
|
|
40
|
+
|
|
41
|
+
- Keep input rows oldest first; the component does not sort them into time order.
|
|
42
|
+
- Use a stable `name-key` so bars keep their identity when a moving window drops one row and appends another.
|
|
43
|
+
- For custom statuses, set both `status-colors` and `status-labels`; unknown statuses otherwise use the muted color and their raw text.
|
|
44
|
+
- Place `Tooltip` in the default slot. Cell events receive the original input row.
|
|
45
|
+
- Use the `#cell` slot to replace a bar; its slot cell wraps the domain row rather than being the row itself.
|
|
46
|
+
|
|
47
|
+
## Related guides
|
|
48
|
+
|
|
49
|
+
`installation`, `vue-api`, `typed-rows`, `ssr-testing`, `sparkline`, `heatmap`, `calendar-heatmap`.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Treemap
|
|
2
|
+
|
|
3
|
+
Use `Treemap` to compare hierarchical part-to-whole values as rectangles, especially when there are many leaves. Use `PieChart` for a short flat list of proportions and `SunburstChart` when radial rings communicate the hierarchy better.
|
|
4
|
+
|
|
5
|
+
## Data shape
|
|
6
|
+
|
|
7
|
+
- `data` is an array of top-level nodes, not a single root object.
|
|
8
|
+
- Each node has a `name` by default and may have a `children` array.
|
|
9
|
+
- Leaves need a positive numeric `value`; `data-key` and `name-key` select different fields.
|
|
10
|
+
- Parent values are derived by summing their descendants, so do not add totals to parent rows.
|
|
11
|
+
|
|
12
|
+
## Minimal example
|
|
13
|
+
|
|
14
|
+
```vue
|
|
15
|
+
<script setup lang="ts">
|
|
16
|
+
import { Tooltip, Treemap } from 'vccs'
|
|
17
|
+
|
|
18
|
+
const data = [
|
|
19
|
+
{
|
|
20
|
+
name: 'Search',
|
|
21
|
+
children: [
|
|
22
|
+
{ name: 'Google', value: 420 },
|
|
23
|
+
{ name: 'Bing', value: 90 },
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'Social',
|
|
28
|
+
children: [
|
|
29
|
+
{ name: 'LinkedIn', value: 150 },
|
|
30
|
+
{ name: 'Mastodon', value: 80 },
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'Direct',
|
|
35
|
+
children: [
|
|
36
|
+
{ name: 'Bookmarks', value: 160 },
|
|
37
|
+
{ name: 'Newsletter', value: 110 },
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
const colors = ['#f97316', '#14b8a6', '#f59e0b', '#06b6d4']
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<template>
|
|
46
|
+
<Treemap
|
|
47
|
+
:data="data"
|
|
48
|
+
:height="320"
|
|
49
|
+
data-key="value"
|
|
50
|
+
:colors="colors"
|
|
51
|
+
>
|
|
52
|
+
<Tooltip :cursor="false" />
|
|
53
|
+
</Treemap>
|
|
54
|
+
</template>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Animation is enabled by default; retrieve `ssr-testing` before taking screenshots or asserting exact geometry.
|
|
58
|
+
|
|
59
|
+
## Chart-specific rules
|
|
60
|
+
|
|
61
|
+
- The default `type="flat"` displays leaves. Their `colors` entry comes from their top-level group.
|
|
62
|
+
- Set `type="nest"` for drill-down. Clicking a group shows its children and a breadcrumb trail for going back.
|
|
63
|
+
- Use `stroke` to change the rectangle border color.
|
|
64
|
+
- Customize rectangles and labels with the `#content` slot, not a function-valued `content` prop.
|
|
65
|
+
|
|
66
|
+
## Related guides
|
|
67
|
+
|
|
68
|
+
`installation`, `vue-api`, `ssr-testing`, `sunburst-chart`, `pie-chart`.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Installation and registration
|
|
2
|
+
|
|
3
|
+
vccs requires Vue `^3.5`, the `motion-v` `^2.4` peer, and an ESM bundler. The Nuxt module requires Nuxt 4; the Vite resolver requires `unplugin-vue-components` in the application's dev dependencies.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add vccs motion-v
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Install `motion-v` explicitly because not every package manager installs peers automatically.
|
|
12
|
+
|
|
13
|
+
## Explicit imports in Vite
|
|
14
|
+
|
|
15
|
+
Import components from `vccs` and compose them in the template. Retrieve the chart guide before choosing its children.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { Bar, BarChart, Tooltip, XAxis, YAxis } from 'vccs'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Do not deep-import source files, runtime prop definitions, or internal helpers. The only public subpaths are `vccs/nuxt` and `vccs/resolver`.
|
|
22
|
+
|
|
23
|
+
## Auto-imports in Vite
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
pnpm add -D unplugin-vue-components
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import vue from '@vitejs/plugin-vue'
|
|
31
|
+
import { defineConfig } from 'vite'
|
|
32
|
+
import Components from 'unplugin-vue-components/vite'
|
|
33
|
+
import { VccsResolver } from 'vccs/resolver'
|
|
34
|
+
|
|
35
|
+
export default defineConfig({
|
|
36
|
+
plugins: [
|
|
37
|
+
vue(),
|
|
38
|
+
Components({ resolvers: [VccsResolver()] }),
|
|
39
|
+
],
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The resolver imports a component only when the template uses it. Keep explicit imports for types and `defineChartComponents`.
|
|
44
|
+
|
|
45
|
+
## Nuxt 4
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
export default defineNuxtConfig({
|
|
49
|
+
modules: ['vccs/nuxt'],
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The module registers every public component and composable. Import types and `defineChartComponents` from `vccs`.
|
|
54
|
+
|
|
55
|
+
When another UI library also registers `Tooltip`, `Legend`, or `Label`, add a prefix:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
export default defineNuxtConfig({
|
|
59
|
+
modules: ['vccs/nuxt'],
|
|
60
|
+
vccs: { prefix: 'V' },
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
This registers names such as `VBarChart` and `VLine`. Nuxt 3 is unsupported by the module; do not hide its build error with `transpile` or `ClientOnly` workarounds.
|
|
65
|
+
|
|
66
|
+
## Related guides
|
|
67
|
+
|
|
68
|
+
`vue-api`, `typed-rows`, `ssr-testing`.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# SSR and deterministic testing
|
|
2
|
+
|
|
3
|
+
Server-rendered charts normally preserve their entrance start, then animate after hydration when they enter the viewport. Do not mistake that intended entrance state for missing SVG or a hydration failure.
|
|
4
|
+
|
|
5
|
+
## Complete server HTML
|
|
6
|
+
|
|
7
|
+
For a complete chart without client JavaScript, provide numeric `width` and `height` and disable animation on the chart root:
|
|
8
|
+
|
|
9
|
+
```vue
|
|
10
|
+
<AreaChart
|
|
11
|
+
:data="data"
|
|
12
|
+
:width="900"
|
|
13
|
+
:height="250"
|
|
14
|
+
:is-animation-active="false"
|
|
15
|
+
>
|
|
16
|
+
<Area data-key="desktop" />
|
|
17
|
+
</AreaChart>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Disabling animation alone does not reveal an unmeasured responsive chart. With only `height`, the server reserves a box using an initial width and the browser measures the real width later.
|
|
21
|
+
|
|
22
|
+
Do not add `ClientOnly` to solve chart SSR. Use it only when the data itself exists exclusively in the browser.
|
|
23
|
+
|
|
24
|
+
## Nuxt
|
|
25
|
+
|
|
26
|
+
Retrieve `installation` and register `vccs/nuxt` under Nuxt 4. The module handles component and composable registration; fixed-size SSR needs no client-only wrapper.
|
|
27
|
+
|
|
28
|
+
## Deterministic tests and screenshots
|
|
29
|
+
|
|
30
|
+
Set `is-animation-active` to `false` on the chart root, or on an individual series when only that series must be still:
|
|
31
|
+
|
|
32
|
+
```vue
|
|
33
|
+
<BarChart
|
|
34
|
+
:data="rows"
|
|
35
|
+
:height="300"
|
|
36
|
+
:is-animation-active="false"
|
|
37
|
+
>
|
|
38
|
+
<Bar data-key="desktop" />
|
|
39
|
+
</BarChart>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The chart value supplies defaults to its items; an explicit series value overrides it. Disable animation before exact geometry assertions, screenshots, or pixel-exact SSR comparisons.
|
|
43
|
+
|
|
44
|
+
In component tests, measure the container deliberately and assert library behavior through public classes such as `.v-charts-surface` and item attributes such as `data-v-charts-item-index`. Do not depend on generated SVG ids.
|
|
45
|
+
|
|
46
|
+
Charts follow the operating system's reduced-motion setting, but tests must not depend on the host setting: disable animation explicitly.
|
|
47
|
+
|
|
48
|
+
## Related guides
|
|
49
|
+
|
|
50
|
+
`installation`, `vue-api`, `typed-rows`.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Typed chart rows
|
|
2
|
+
|
|
3
|
+
A child component cannot infer the row type from its chart root's `data`. Create row-typed component aliases once when wrong `data-key` values or untyped tooltip rows should become compile-time errors.
|
|
4
|
+
|
|
5
|
+
## Minimal example
|
|
6
|
+
|
|
7
|
+
```vue
|
|
8
|
+
<script setup lang="ts">
|
|
9
|
+
import { Area, AreaChart, Tooltip, XAxis, defineChartComponents } from 'vccs'
|
|
10
|
+
|
|
11
|
+
interface Visit {
|
|
12
|
+
date: string
|
|
13
|
+
desktop: number
|
|
14
|
+
mobile: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
defineProps<{ visits: Visit[] }>()
|
|
18
|
+
|
|
19
|
+
const Chart = defineChartComponents<Visit>()({ AreaChart, Area, XAxis, Tooltip })
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<template>
|
|
23
|
+
<Chart.AreaChart
|
|
24
|
+
:data="visits"
|
|
25
|
+
:height="300"
|
|
26
|
+
>
|
|
27
|
+
<Chart.XAxis data-key="date" />
|
|
28
|
+
<Chart.Area data-key="desktop" />
|
|
29
|
+
<Chart.Area data-key="mobile" />
|
|
30
|
+
<Chart.Tooltip />
|
|
31
|
+
</Chart.AreaChart>
|
|
32
|
+
</template>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`Chart.Area data-key="tablet"` now fails typechecking because `tablet` is not a key of `Visit`. Tooltip content created through `Chart.Tooltip` receives payload entries whose `payload` is `Visit`.
|
|
36
|
+
|
|
37
|
+
## Rules
|
|
38
|
+
|
|
39
|
+
- Select every component used with that row type in one `defineChartComponents<Row>()({ ... })` call; use the resulting aliases in the template.
|
|
40
|
+
- The runtime component references are unchanged. This helper narrows declarations, not behavior.
|
|
41
|
+
- Only selected components are referenced by the consumer bundle.
|
|
42
|
+
- Standalone charts can infer rows from `data`; use their retrieved guide's generic pattern when explicit aliases are unnecessary.
|
|
43
|
+
- Import reusable model and payload types such as `BrushStartEndIndex`, `TooltipActiveIndex`, `TooltipPayloadEntry`, and `TooltipPayload` from `vccs`. Runtime `*VueProps` objects and internal context helpers are not public.
|
|
44
|
+
|
|
45
|
+
## Related guides
|
|
46
|
+
|
|
47
|
+
`installation`, `vue-api`, `ssr-testing`.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Vue API rules
|
|
2
|
+
|
|
3
|
+
vccs keeps Recharts component names but uses Vue rendering and reactivity contracts. Apply these rules only after retrieving the chart guide; supported slots and models are component-specific.
|
|
4
|
+
|
|
5
|
+
## Slots replace render props
|
|
6
|
+
|
|
7
|
+
Use named slots for custom shapes, dots, labels, ticks, tooltip content, and cursors. A function passed to a prop such as `dot` or `content` is not a Vue render contract.
|
|
8
|
+
|
|
9
|
+
```vue
|
|
10
|
+
<Tooltip>
|
|
11
|
+
<template #content="{ active, payload, label }">
|
|
12
|
+
<div v-if="active">
|
|
13
|
+
<strong>{{ label }}</strong>
|
|
14
|
+
<div>{{ payload?.[0]?.name }}: {{ payload?.[0]?.value }}</div>
|
|
15
|
+
</div>
|
|
16
|
+
</template>
|
|
17
|
+
</Tooltip>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Do not spread tooltip slot props with `v-bind="tooltipProps"`; the project's ESLint auto-fix removes that spread. Destructure the slot instead. Each tooltip payload entry exposes the original row as `payload`.
|
|
21
|
+
|
|
22
|
+
Common slot payloads:
|
|
23
|
+
|
|
24
|
+
- Tooltip `content`: `{ active, payload, label, coordinate, accessibilityLayer }`. Payload entries carry `name`, `value`, `color`, `unit`, `dataKey`, and the original row as `payload`.
|
|
25
|
+
- Line, Area, and Scatter `dot` / `activeDot`: `{ cx, cy, index, value, payload }` plus the series' presentation attributes. Render SVG at `cx` and `cy`.
|
|
26
|
+
|
|
27
|
+
## Templates and events
|
|
28
|
+
|
|
29
|
+
- Write `class`, not `className`.
|
|
30
|
+
- Write SVG attributes in kebab-case, such as `stroke-width` and `stroke-dasharray`.
|
|
31
|
+
- Use Vue events such as `@click`, not callback props such as `:on-click`.
|
|
32
|
+
- Item event callbacks receive `(item, index, event)`.
|
|
33
|
+
|
|
34
|
+
## Models
|
|
35
|
+
|
|
36
|
+
- `v-model:active-index` is `number | null`; `null` means no active item. Never substitute `-1`.
|
|
37
|
+
- `v-model:range` on `Brush` is `BrushStartEndIndex | null`; `null` selects all rows and replaces separate start/end models.
|
|
38
|
+
- `v-model:hidden` on `Legend` controls hidden series keys.
|
|
39
|
+
- A supplied model value is controlled state. An omitted model lets the component keep local state.
|
|
40
|
+
|
|
41
|
+
Only bind a model documented by the retrieved chart guide. Do not infer that every chart root supports every model.
|
|
42
|
+
|
|
43
|
+
## Responsive size
|
|
44
|
+
|
|
45
|
+
Charts are responsive by default. Set a numeric `height` and let the chart fill its container's width; pass numeric `width` and `height` for a fixed box.
|
|
46
|
+
|
|
47
|
+
```vue
|
|
48
|
+
<LineChart
|
|
49
|
+
:data="rows"
|
|
50
|
+
:height="300"
|
|
51
|
+
>
|
|
52
|
+
<!-- axes and series -->
|
|
53
|
+
</LineChart>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Do not add `ResponsiveContainer`; it is deprecated and scheduled for removal in 2.0.
|
|
57
|
+
|
|
58
|
+
## Data keys and missing values
|
|
59
|
+
|
|
60
|
+
`data-key` accepts a field name, numeric index, or accessor function. Set `name` or `name-key` when an accessor function's series needs a readable label. `NaN` and `Infinity` are missing values, not finite coordinates.
|
|
61
|
+
|
|
62
|
+
Retrieve `typed-rows` when wrong keys should become compile-time errors.
|
|
63
|
+
|
|
64
|
+
## Theme and selectors
|
|
65
|
+
|
|
66
|
+
A series without an explicit color uses `--v-charts-series-1` through `--v-charts-series-8`. Override those variables to theme a dashboard instead of repeating colors on every series.
|
|
67
|
+
|
|
68
|
+
Library classes use the `v-charts-` prefix. Item marks expose `data-v-charts-item-index`; use these hooks for CSS and tests rather than Recharts class names.
|
|
69
|
+
|
|
70
|
+
## Related guides
|
|
71
|
+
|
|
72
|
+
`installation`, `typed-rows`, `ssr-testing`.
|