swiftplot 0.1.1 → 0.3.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 +71 -47
- package/dist/chart.d.ts +4 -0
- package/dist/chart.js +171 -86
- package/dist/charts/build.d.ts +52 -0
- package/dist/charts/build.js +63 -0
- package/dist/charts/candlestick.d.ts +8 -0
- package/dist/charts/candlestick.js +105 -0
- package/dist/charts/combo.d.ts +8 -0
- package/dist/charts/combo.js +50 -0
- package/dist/charts/controller.d.ts +2 -2
- package/dist/charts/controller.js +2 -2
- package/dist/charts/defaults.d.ts +10 -2
- package/dist/charts/defaults.js +67 -6
- package/dist/charts/distribution.d.ts +15 -0
- package/dist/charts/distribution.js +178 -0
- package/dist/charts/fields.d.ts +33 -3
- package/dist/charts/fields.js +150 -66
- package/dist/charts/flow.d.ts +15 -0
- package/dist/charts/flow.js +189 -0
- package/dist/charts/heatmap.d.ts +9 -0
- package/dist/charts/heatmap.js +104 -0
- package/dist/charts/index.d.ts +8 -1
- package/dist/charts/index.js +7 -0
- package/dist/charts/parts.d.ts +23 -0
- package/dist/charts/parts.js +66 -0
- package/dist/charts/radar.d.ts +7 -0
- package/dist/charts/radar.js +77 -0
- package/dist/charts/types.d.ts +562 -23
- package/dist/charts/xy.d.ts +35 -25
- package/dist/charts/xy.js +327 -126
- package/dist/features/animate.d.ts +10 -1
- package/dist/features/animate.js +3 -3
- package/dist/features/brush.d.ts +3 -1
- package/dist/features/brush.js +2 -1
- package/dist/features/legend.d.ts +1 -3
- package/dist/features/legend.js +4 -5
- package/dist/features/tooltip.d.ts +10 -2
- package/dist/features/tooltip.js +12 -10
- package/dist/features/zoom.d.ts +1 -0
- package/dist/features/zoom.js +22 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/marks/arcs.d.ts +10 -4
- package/dist/marks/arcs.js +2 -1
- package/dist/marks/area.d.ts +9 -8
- package/dist/marks/area.js +2 -2
- package/dist/marks/bar.d.ts +18 -10
- package/dist/marks/bar.js +5 -5
- package/dist/marks/box.d.ts +7 -1
- package/dist/marks/box.js +2 -8
- package/dist/marks/candlestick.d.ts +22 -0
- package/dist/marks/candlestick.js +133 -0
- package/dist/marks/common.d.ts +18 -0
- package/dist/marks/common.js +14 -0
- package/dist/marks/dots.d.ts +6 -5
- package/dist/marks/dots.js +3 -1
- package/dist/marks/errorBars.d.ts +9 -4
- package/dist/marks/errorBars.js +21 -1
- package/dist/marks/funnel.d.ts +8 -3
- package/dist/marks/funnel.js +2 -1
- package/dist/marks/heatmap.d.ts +8 -7
- package/dist/marks/line.d.ts +8 -6
- package/dist/marks/radar.d.ts +9 -2
- package/dist/marks/radar.js +9 -2
- package/dist/marks/radialBars.d.ts +12 -5
- package/dist/marks/rule.d.ts +19 -0
- package/dist/marks/rule.js +4 -1
- package/dist/marks/sankey.d.ts +14 -2
- package/dist/marks/sankey.js +4 -1
- package/dist/marks/sunburst.d.ts +5 -0
- package/dist/marks/sunburst.js +2 -1
- package/dist/marks/ticks.d.ts +4 -1
- package/dist/marks/tree.d.ts +14 -6
- package/dist/marks/tree.js +6 -3
- package/dist/marks/treemap.d.ts +5 -0
- package/dist/marks/treemap.js +7 -2
- package/dist/paint.d.ts +6 -1
- package/dist/paint.js +6 -1
- package/dist/scale.d.ts +1 -1
- package/dist/scale.js +4 -3
- package/dist/scales/band.d.ts +3 -0
- package/dist/scales/band.js +5 -1
- package/dist/scales/bare.d.ts +4 -1
- package/dist/scales/bare.js +4 -1
- package/dist/scales/color.d.ts +2 -0
- package/dist/scales/log.d.ts +8 -1
- package/dist/scales/log.js +3 -2
- package/dist/scales/time.d.ts +7 -0
- package/dist/scales/time.js +3 -1
- package/dist/text.d.ts +8 -0
- package/dist/text.js +33 -0
- package/dist/transforms.d.ts +11 -7
- package/dist/transforms.js +8 -7
- package/dist/types.d.ts +44 -13
- package/package.json +2 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Options } from '../types.js';
|
|
2
|
+
import type { FunnelProps, PieProps, RadialBarProps } from './types.js';
|
|
3
|
+
export declare const pieChart: (<D extends import("./types.js").Input | undefined = undefined>(el: HTMLElement, props: PieProps<D>) => [D] extends [readonly never[] | undefined] ? Omit<import("./controller.js").EasyChart<never>, "update"> & {
|
|
4
|
+
update<D_1 extends import("./types.js").Input | undefined = undefined>(props: Partial<PieProps<D_1>> & {
|
|
5
|
+
data?: D_1 | null | undefined;
|
|
6
|
+
}): void;
|
|
7
|
+
} : import("./controller.js").EasyChart<PieProps<D>>) & {
|
|
8
|
+
spec: <D extends import("./types.js").Input | undefined = undefined>(props: PieProps<D>) => Options;
|
|
9
|
+
};
|
|
10
|
+
export declare const funnelChart: (<D extends import("./types.js").Input | undefined = undefined>(el: HTMLElement, props: FunnelProps<D>) => [D] extends [readonly never[] | undefined] ? Omit<import("./controller.js").EasyChart<never>, "update"> & {
|
|
11
|
+
update<D_1 extends import("./types.js").Input | undefined = undefined>(props: Partial<FunnelProps<D_1>> & {
|
|
12
|
+
data?: D_1 | null | undefined;
|
|
13
|
+
}): void;
|
|
14
|
+
} : import("./controller.js").EasyChart<FunnelProps<D>>) & {
|
|
15
|
+
spec: <D extends import("./types.js").Input | undefined = undefined>(props: FunnelProps<D>) => Options;
|
|
16
|
+
};
|
|
17
|
+
export declare const radialBarChart: (<D extends import("./types.js").Input | undefined = undefined>(el: HTMLElement, props: RadialBarProps<D>) => [D] extends [readonly never[] | undefined] ? Omit<import("./controller.js").EasyChart<never>, "update"> & {
|
|
18
|
+
update<D_1 extends import("./types.js").Input | undefined = undefined>(props: Partial<RadialBarProps<D_1>> & {
|
|
19
|
+
data?: D_1 | null | undefined;
|
|
20
|
+
}): void;
|
|
21
|
+
} : import("./controller.js").EasyChart<RadialBarProps<D>>) & {
|
|
22
|
+
spec: <D extends import("./types.js").Input | undefined = undefined>(props: RadialBarProps<D>) => Options;
|
|
23
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { arcs } from '../marks/arcs.js';
|
|
2
|
+
import { funnel } from '../marks/funnel.js';
|
|
3
|
+
import { radialBars } from '../marks/radialBars.js';
|
|
4
|
+
import { defined, easyChart, featuresOf, given, install, noAxes, sizeOf } from './build.js';
|
|
5
|
+
import { colorsFor, formatNumber, namesOf } from './defaults.js';
|
|
6
|
+
import { reader } from './fields.js';
|
|
7
|
+
function pick(s, p, name) {
|
|
8
|
+
const { kinds, check, sole, read, numeric } = reader(s, name);
|
|
9
|
+
if (!s.length)
|
|
10
|
+
return undefined;
|
|
11
|
+
const given = s.shape === 'numbers' ? { value: 'value' } : s.shape === 'pairs' ? { label: 'x', value: 'y' } : p;
|
|
12
|
+
const pool = check([
|
|
13
|
+
['label', given.label],
|
|
14
|
+
['value', given.value],
|
|
15
|
+
], ['value']);
|
|
16
|
+
const label = given.label ?? pool.find(f => kinds.get(f) === 'text');
|
|
17
|
+
const value = sole('value', given.value, pool);
|
|
18
|
+
const { values } = numeric(value, 'value');
|
|
19
|
+
const named = label === undefined ? undefined : read(label, 'the accessor label', 'label');
|
|
20
|
+
const nameOf = named && namesOf(named.kind, named.categories, [named.values], true);
|
|
21
|
+
return {
|
|
22
|
+
label: typeof value === 'string' ? value : 'value',
|
|
23
|
+
values,
|
|
24
|
+
...(named && { labels: Array.from(named.values, v => (Number.isFinite(v) ? nameOf(v) : '')) }),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function reject(p, name) {
|
|
28
|
+
if (given(p, 'x') || given(p, 'y'))
|
|
29
|
+
throw new Error(`${name}: use label and value, not x and y`);
|
|
30
|
+
noAxes(p, name);
|
|
31
|
+
}
|
|
32
|
+
function parts(kind, frame, draw) {
|
|
33
|
+
const name = `${kind}Chart`;
|
|
34
|
+
return (p, { source: s, theme, memo }) => {
|
|
35
|
+
if (s.length)
|
|
36
|
+
reject(p, name);
|
|
37
|
+
const picked = memo('fields', [s, p.label, p.value], () => pick(s, p, name));
|
|
38
|
+
const features = featuresOf({ ...p, zoom: false }, picked?.labels?.length ?? 0);
|
|
39
|
+
const ref = memo('tooltip', [], () => ({}));
|
|
40
|
+
ref.current = picked;
|
|
41
|
+
return {
|
|
42
|
+
options: {
|
|
43
|
+
...sizeOf(p),
|
|
44
|
+
theme,
|
|
45
|
+
frame,
|
|
46
|
+
marks: picked
|
|
47
|
+
? [
|
|
48
|
+
draw(defined({ key: kind, ...picked, colors: colorsFor(theme, p.colors, picked.values.length) }), p),
|
|
49
|
+
]
|
|
50
|
+
: [],
|
|
51
|
+
},
|
|
52
|
+
features,
|
|
53
|
+
use: () => {
|
|
54
|
+
ref.current = picked;
|
|
55
|
+
return install(features, {
|
|
56
|
+
mode: 'nearest',
|
|
57
|
+
text: (label, _x, _y, row) => `${label || ref.current.label}: ${formatNumber(ref.current.values[row])}`,
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const shown = (text) => (text === false ? undefined : true);
|
|
64
|
+
export const pieChart = easyChart(parts('pie', 'polar', (part, p) => arcs(defined({ ...part, inner: p.inner, text: shown(p.text), sweep: p.sweep }))));
|
|
65
|
+
export const funnelChart = easyChart(parts('funnel', 'blank', (part, p) => funnel(defined({ ...part, text: shown(p.text), fill: p.fill }))));
|
|
66
|
+
export const radialBarChart = easyChart(parts('radialBar', 'polar', (part, p) => radialBars(defined({ ...part, max: p.max, sweep: p.sweep, inner: p.inner }))));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const radarChart: (<D extends import("./types.js").Input | undefined = undefined>(el: HTMLElement, props: import("./types.js").RadarProps<D>) => [D] extends [readonly never[] | undefined] ? Omit<import("./controller.js").EasyChart<never>, "update"> & {
|
|
2
|
+
update<D_1 extends import("./types.js").Input | undefined = undefined>(props: Partial<import("./types.js").RadarProps<D_1>> & {
|
|
3
|
+
data?: D_1 | null | undefined;
|
|
4
|
+
}): void;
|
|
5
|
+
} : import("./controller.js").EasyChart<import("./types.js").RadarProps<D>>) & {
|
|
6
|
+
spec: <D extends import("./types.js").Input | undefined = undefined>(props: import("./types.js").RadarProps<D>) => import("../types.js").Options;
|
|
7
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { radar } from '../marks/radar.js';
|
|
2
|
+
import { defined, easyChart, featuresOf, given, install, noAxes, sizeOf } from './build.js';
|
|
3
|
+
import { colorsFor, formatNumber, namesOf } from './defaults.js';
|
|
4
|
+
import { list, reader } from './fields.js';
|
|
5
|
+
const NAME = 'radarChart';
|
|
6
|
+
function pick(s, props) {
|
|
7
|
+
const { kinds, check, noNumbers, read, numeric } = reader(s, NAME);
|
|
8
|
+
if (!s.length)
|
|
9
|
+
return { axes: [], shapes: [] };
|
|
10
|
+
const p = s.shape === 'numbers' ? { y: 'value' } : s.shape === 'pairs' ? { x: 'x', y: 'y' } : props;
|
|
11
|
+
const named = list(p.y ?? undefined);
|
|
12
|
+
const pool = check([['x', p.x], ...named.map(f => ['y', f])], ['y']);
|
|
13
|
+
const x = p.x ?? pool.find(f => kinds.get(f) === 'text');
|
|
14
|
+
const ys = named.length ? named : pool.filter(f => kinds.get(f) === 'number');
|
|
15
|
+
if (!ys.length)
|
|
16
|
+
noNumbers('y');
|
|
17
|
+
const spokes = x === undefined ? undefined : read(x, 'the accessor x', 'x');
|
|
18
|
+
const nameOf = spokes && namesOf(spokes.kind, spokes.categories, [spokes.values], true);
|
|
19
|
+
const ids = new Set(ys);
|
|
20
|
+
const seen = new Set();
|
|
21
|
+
const idOf = (f, label) => {
|
|
22
|
+
let id = label;
|
|
23
|
+
if (typeof f !== 'string' || seen.has(f))
|
|
24
|
+
for (let n = 2; ids.has(id); n++)
|
|
25
|
+
id = `${label} (${n})`;
|
|
26
|
+
ids.add(id);
|
|
27
|
+
seen.add(f);
|
|
28
|
+
return id;
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
axes: Array.from({ length: s.length }, (_, i) => nameOf && Number.isFinite(spokes.values[i]) ? nameOf(spokes.values[i]) : ''),
|
|
32
|
+
shapes: ys.map((f, i) => {
|
|
33
|
+
const label = typeof f === 'string' ? f : `y${i + 1}`;
|
|
34
|
+
return { id: idOf(f, label), label, values: numeric(f, 'y', `${i + 1}`).values };
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const build = (p, { source: s, theme, memo }) => {
|
|
39
|
+
if (s.length) {
|
|
40
|
+
if (given(p, 'label') || given(p, 'value'))
|
|
41
|
+
throw new Error(`${NAME}: use x and y, not label and value`);
|
|
42
|
+
noAxes(p, NAME);
|
|
43
|
+
}
|
|
44
|
+
const picked = memo('fields', [s, p.x, ...list(p.y ?? undefined)], () => pick(s, p));
|
|
45
|
+
const { axes, shapes } = picked;
|
|
46
|
+
const colors = colorsFor(theme, p.colors, shapes.length);
|
|
47
|
+
const marks = memo('marks', [picked, p.max, p.fill, ...colors], () => {
|
|
48
|
+
if (!shapes.length)
|
|
49
|
+
return [];
|
|
50
|
+
const series = shapes.map(({ id, ...r }, i) => ({
|
|
51
|
+
...r,
|
|
52
|
+
key: `shape:${id}`,
|
|
53
|
+
group: id,
|
|
54
|
+
color: colors[i],
|
|
55
|
+
}));
|
|
56
|
+
const [grid, ...rest] = radar(defined({ axes, series, max: p.max, fill: p.fill }));
|
|
57
|
+
return [{ ...grid, key: 'radar-grid' }, ...rest];
|
|
58
|
+
});
|
|
59
|
+
const features = featuresOf({ ...p, zoom: false }, shapes.length);
|
|
60
|
+
const ref = memo('tooltip', [], () => ({}));
|
|
61
|
+
ref.current = picked;
|
|
62
|
+
return {
|
|
63
|
+
options: { ...sizeOf(p), theme, frame: 'polar', marks },
|
|
64
|
+
features,
|
|
65
|
+
use: () => {
|
|
66
|
+
ref.current = picked;
|
|
67
|
+
return install(features, {
|
|
68
|
+
mode: 'nearest',
|
|
69
|
+
text: (label, _x, v, row) => {
|
|
70
|
+
const spoke = ref.current.axes[row];
|
|
71
|
+
return `${spoke ? `${spoke} · ` : ''}${label}: ${Number.isFinite(v) ? formatNumber(v) : '–'}`;
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
export const radarChart = easyChart(build);
|