blockcharts 0.0.2 → 0.0.3
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 +118 -17
- package/package.json +43 -6
- package/release/bc.d.ts +35 -2
- package/release/blocks/guide.axis.js +1 -1
- package/release/blocks/guide.grid.js +1 -1
- package/release/blocks/guide.kpi.js +1 -1
- package/release/blocks/guide.legend.js +1 -1
- package/release/blocks/interaction.animate.js +1 -1
- package/release/blocks/interaction.brush.js +1 -1
- package/release/blocks/interaction.click.js +3 -0
- package/release/blocks/interaction.crosshair.js +1 -1
- package/release/blocks/interaction.legend-filter.js +1 -1
- package/release/blocks/interaction.tooltip.js +2 -2
- package/release/blocks/interaction.zoom-controls.js +1 -1
- package/release/blocks/interaction.zoom.js +1 -1
- package/release/blocks/lib.columns.js +1 -1
- package/release/blocks/lib.curve.js +1 -1
- package/release/blocks/lib.pointer.js +2 -2
- package/release/blocks/lib.stats.js +1 -1
- package/release/blocks/lib.ticks.js +1 -1
- package/release/blocks/lib.view.js +1 -1
- package/release/blocks/mark.arc.js +1 -1
- package/release/blocks/mark.area.js +1 -1
- package/release/blocks/mark.boxplot.js +1 -1
- package/release/blocks/mark.candlestick.js +1 -1
- package/release/blocks/mark.line.js +1 -1
- package/release/blocks/mark.point.js +1 -1
- package/release/blocks/mark.polygon.js +1 -1
- package/release/blocks/mark.rect.js +1 -1
- package/release/blocks/mark.rule.js +1 -1
- package/release/blocks/mark.sankey.js +1 -1
- package/release/blocks/mark.text.js +1 -1
- package/release/blocks/mark.violin.js +1 -1
- package/release/blocks/renderer.canvas.js +1 -1
- package/release/blocks/renderer.svg.js +1 -1
- package/release/blocks/scale.band.js +1 -1
- package/release/blocks/scale.color.js +1 -1
- package/release/blocks/scale.linear.js +1 -1
- package/release/blocks/scale.log.js +1 -1
- package/release/blocks/scale.sequential.js +1 -1
- package/release/blocks/scale.size.js +1 -1
- package/release/blocks/scale.time.js +1 -1
- package/release/blocks/transform.aggregate.js +1 -1
- package/release/blocks/transform.bin.js +1 -1
- package/release/blocks/transform.calculate.js +1 -1
- package/release/blocks/transform.calendar.js +1 -1
- package/release/blocks/transform.contour.js +1 -1
- package/release/blocks/transform.decimate.js +1 -1
- package/release/blocks/transform.density.js +1 -1
- package/release/blocks/transform.filter.js +1 -1
- package/release/blocks/transform.fold.js +1 -1
- package/release/blocks/transform.funnel.js +1 -1
- package/release/blocks/transform.hexbin.js +1 -1
- package/release/blocks/transform.highlight.js +1 -1
- package/release/blocks/transform.marimekko.js +1 -1
- package/release/blocks/transform.quartiles.js +1 -1
- package/release/blocks/transform.sankey.js +1 -1
- package/release/blocks/transform.sort.js +1 -1
- package/release/blocks/transform.stack.js +1 -1
- package/release/blocks/transform.treemap.js +1 -1
- package/release/blocks/transform.waterfall.js +1 -1
- package/release/blocks/transform.window.js +1 -1
- package/release/core.js +3 -3
- package/release/frameworks/controller.d.mts +51 -0
- package/release/frameworks/controller.mjs +181 -0
- package/release/frameworks/element.d.mts +32 -0
- package/release/frameworks/element.mjs +95 -0
- package/release/frameworks/react.d.mts +10 -0
- package/release/frameworks/react.mjs +30 -0
- package/release/frameworks/svelte.d.mts +9 -0
- package/release/frameworks/svelte.mjs +17 -0
- package/release/frameworks/vue.d.mts +40 -0
- package/release/frameworks/vue.mjs +44 -0
- package/release/kits/basic.js +8 -5
- package/release/kits/basic.mjs +8 -5
- package/release/kits/composition.js +8 -5
- package/release/kits/composition.mjs +8 -5
- package/release/kits/dashboard.js +8 -5
- package/release/kits/dashboard.mjs +8 -5
- package/release/kits/full.js +8 -5
- package/release/kits/full.mjs +8 -5
- package/release/kits/timeseries.js +8 -5
- package/release/kits/timeseries.mjs +8 -5
- package/release/loader.js +1 -1
- package/release/manifest.json +227 -122
- package/release/schema/chart.schema.json +4155 -0
- package/release/schema/page.schema.json +4547 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/*! blockcharts 0.0.3 | MIT License */
|
|
2
|
+
// <block-chart>: a chart as a custom element, for any framework that sets properties on elements (Angular, Vue, Svelte,
|
|
3
|
+
// Solid, Lit) and for plain pages. Importing this file defines it; the runtime is the kit the page loaded.
|
|
4
|
+
// el.spec = {...}; el.data = rows; or <block-chart spec='{"data": "sales", ...}'></block-chart>
|
|
5
|
+
// el.addEventListener('bc-click', (e) => e.detail.values) with { "type": "click" } among the spec's interactions
|
|
6
|
+
// Properties set together are drawn once. Taken out of the page, the chart goes; put back, it is drawn again. No shadow
|
|
7
|
+
// DOM: the chart takes the page's styles (--bc-* variables, .bc-* classes) as any chart does.
|
|
8
|
+
import { Controller } from './controller.mjs';
|
|
9
|
+
// a server has no HTMLElement: the class is defined there too, and never used
|
|
10
|
+
const Base = (typeof HTMLElement === 'function' ? HTMLElement : class {
|
|
11
|
+
});
|
|
12
|
+
export class BlockChartElement extends Base {
|
|
13
|
+
static get observedAttributes() {
|
|
14
|
+
return ['spec'];
|
|
15
|
+
}
|
|
16
|
+
constructor() {
|
|
17
|
+
super();
|
|
18
|
+
this.specValue = undefined;
|
|
19
|
+
this.dataValue = undefined;
|
|
20
|
+
this.controller = null;
|
|
21
|
+
this.queued = false;
|
|
22
|
+
// a framework may set spec or data before this file defined the element: they are own properties then, hiding the
|
|
23
|
+
// setters below, and are taken over
|
|
24
|
+
for (const key of ['spec', 'data']) {
|
|
25
|
+
if (Object.prototype.hasOwnProperty.call(this, key)) {
|
|
26
|
+
const value = this[key];
|
|
27
|
+
delete this[key];
|
|
28
|
+
this[key] = value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** The chart spec. Without `data`, it names a dataset given to BC.data. */
|
|
33
|
+
get spec() {
|
|
34
|
+
return this.specValue;
|
|
35
|
+
}
|
|
36
|
+
set spec(value) {
|
|
37
|
+
this.specValue = value;
|
|
38
|
+
this.schedule();
|
|
39
|
+
}
|
|
40
|
+
/** The chart's own data: rows, { columns } or an encoded dataset. */
|
|
41
|
+
get data() {
|
|
42
|
+
return this.dataValue;
|
|
43
|
+
}
|
|
44
|
+
set data(value) {
|
|
45
|
+
this.dataValue = value;
|
|
46
|
+
this.schedule();
|
|
47
|
+
}
|
|
48
|
+
/** The chart as drawn now (setView, getView, diagnostics), null when there is none. */
|
|
49
|
+
get chart() {
|
|
50
|
+
return this.controller ? this.controller.handle : null;
|
|
51
|
+
}
|
|
52
|
+
attributeChangedCallback(name, _old, value) {
|
|
53
|
+
if (name !== 'spec' || value === null)
|
|
54
|
+
return;
|
|
55
|
+
try {
|
|
56
|
+
this.spec = JSON.parse(value);
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
console.error('[blockcharts] <block-chart spec> is not valid JSON:', e);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
connectedCallback() {
|
|
63
|
+
// a custom element is inline by default, and an inline element has no width to lay the chart out at
|
|
64
|
+
if (!this.style.display)
|
|
65
|
+
this.style.display = 'block';
|
|
66
|
+
this.schedule();
|
|
67
|
+
}
|
|
68
|
+
disconnectedCallback() {
|
|
69
|
+
if (this.controller)
|
|
70
|
+
this.controller.destroy();
|
|
71
|
+
this.controller = null;
|
|
72
|
+
}
|
|
73
|
+
/** Draw once after the properties set in this turn, if the element is on the page and has a spec. */
|
|
74
|
+
schedule() {
|
|
75
|
+
if (this.queued)
|
|
76
|
+
return;
|
|
77
|
+
this.queued = true;
|
|
78
|
+
queueMicrotask(() => {
|
|
79
|
+
this.queued = false;
|
|
80
|
+
if (!this.isConnected || !this.specValue)
|
|
81
|
+
return;
|
|
82
|
+
if (!this.controller)
|
|
83
|
+
this.controller = new Controller(this);
|
|
84
|
+
this.controller.set({ spec: this.specValue, data: this.dataValue });
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** Defines the element under `name` (default "block-chart"), unless that name is taken; importing this file already did. */
|
|
89
|
+
export function defineBlockChart(name = 'block-chart') {
|
|
90
|
+
const registry = globalThis.customElements;
|
|
91
|
+
if (registry && !registry.get(name))
|
|
92
|
+
registry.define(name, class extends BlockChartElement {
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
defineBlockChart();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference path="../bc.d.ts" />
|
|
2
|
+
import type { CSSProperties, ForwardRefExoticComponent, RefAttributes } from 'react';
|
|
3
|
+
import type { BlockChartHandle, ChartProps } from './controller.mjs';
|
|
4
|
+
export type { BlockChartHandle, ChartProps, WrapperSpec } from './controller.mjs';
|
|
5
|
+
export interface BlockChartProps extends ChartProps {
|
|
6
|
+
id?: string;
|
|
7
|
+
className?: string;
|
|
8
|
+
style?: CSSProperties;
|
|
9
|
+
}
|
|
10
|
+
export declare const BlockChart: ForwardRefExoticComponent<BlockChartProps & RefAttributes<BlockChartHandle>>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*! blockcharts 0.0.3 | MIT License */
|
|
2
|
+
// <BlockChart spec={spec} data={rows} onClick={(d) => ...} />: a chart as a React component (React 18 and 19). The chart is
|
|
3
|
+
// drawn after mount, so a server renders an empty <div>; the runtime is the kit the app imported (import
|
|
4
|
+
// "blockcharts/kits/basic.mjs"). The ref is a BlockChartHandle: the chart's view (setView, getView) and the chart itself.
|
|
5
|
+
import { createElement, forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
|
|
6
|
+
import { Controller, handleOf } from './controller.mjs';
|
|
7
|
+
export const BlockChart = forwardRef(function BlockChart(props, ref) {
|
|
8
|
+
const host = useRef(null);
|
|
9
|
+
const controller = useRef(null);
|
|
10
|
+
const latest = useRef(props);
|
|
11
|
+
latest.current = props;
|
|
12
|
+
useImperativeHandle(ref, () => handleOf(() => (controller.current ? controller.current.handle : null)), []);
|
|
13
|
+
// mounted once (twice in StrictMode, which unmounts in between); every render after hands it the props, and the
|
|
14
|
+
// controller draws again only when the spec or the data changed
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const c = new Controller(host.current);
|
|
17
|
+
controller.current = c;
|
|
18
|
+
c.set(latest.current);
|
|
19
|
+
return () => {
|
|
20
|
+
c.destroy();
|
|
21
|
+
if (controller.current === c)
|
|
22
|
+
controller.current = null;
|
|
23
|
+
};
|
|
24
|
+
}, []);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (controller.current)
|
|
27
|
+
controller.current.set(props);
|
|
28
|
+
});
|
|
29
|
+
return createElement('div', { ref: host, id: props.id, className: props.className, style: props.style });
|
|
30
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference path="../bc.d.ts" />
|
|
2
|
+
import type { ChartProps } from './controller.mjs';
|
|
3
|
+
export type { ChartProps, WrapperSpec } from './controller.mjs';
|
|
4
|
+
/** What Svelte expects of an action (svelte/action's ActionReturn), written out so the action needs nothing of Svelte's. */
|
|
5
|
+
export interface BlockChartAction {
|
|
6
|
+
update(props: ChartProps): void;
|
|
7
|
+
destroy(): void;
|
|
8
|
+
}
|
|
9
|
+
export declare function blockchart(node: HTMLElement, props: ChartProps): BlockChartAction;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*! blockcharts 0.0.3 | MIT License */
|
|
2
|
+
// <div use:blockchart={{ spec, data, onClick }}></div>: a chart as a Svelte action (Svelte 4 and 5). Plain JavaScript, so
|
|
3
|
+
// nothing has to compile it; the runtime is the kit the app imported (import "blockcharts/kits/basic.mjs"). An action runs
|
|
4
|
+
// in the browser only, so a server renders the empty element.
|
|
5
|
+
import { Controller } from './controller.mjs';
|
|
6
|
+
export function blockchart(node, props) {
|
|
7
|
+
const controller = new Controller(node);
|
|
8
|
+
controller.set(props);
|
|
9
|
+
return {
|
|
10
|
+
update(next) {
|
|
11
|
+
controller.set(next);
|
|
12
|
+
},
|
|
13
|
+
destroy() {
|
|
14
|
+
controller.destroy();
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/// <reference path="../bc.d.ts" />
|
|
2
|
+
import type { PropType } from 'vue';
|
|
3
|
+
import type { ChartProps, WrapperSpec } from './controller.mjs';
|
|
4
|
+
export type { BlockChartHandle, ChartProps, WrapperSpec } from './controller.mjs';
|
|
5
|
+
export declare const BlockChart: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
6
|
+
spec: {
|
|
7
|
+
type: PropType<WrapperSpec>;
|
|
8
|
+
required: true;
|
|
9
|
+
};
|
|
10
|
+
data: {
|
|
11
|
+
type: PropType<BC.DatasetInput>;
|
|
12
|
+
required: false;
|
|
13
|
+
default: undefined;
|
|
14
|
+
};
|
|
15
|
+
onClick: {
|
|
16
|
+
type: PropType<NonNullable<ChartProps['onClick']>>;
|
|
17
|
+
required: false;
|
|
18
|
+
default: undefined;
|
|
19
|
+
};
|
|
20
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
23
|
+
spec: {
|
|
24
|
+
type: PropType<WrapperSpec>;
|
|
25
|
+
required: true;
|
|
26
|
+
};
|
|
27
|
+
data: {
|
|
28
|
+
type: PropType<BC.DatasetInput>;
|
|
29
|
+
required: false;
|
|
30
|
+
default: undefined;
|
|
31
|
+
};
|
|
32
|
+
onClick: {
|
|
33
|
+
type: PropType<NonNullable<ChartProps['onClick']>>;
|
|
34
|
+
required: false;
|
|
35
|
+
default: undefined;
|
|
36
|
+
};
|
|
37
|
+
}>> & Readonly<{}>, {
|
|
38
|
+
data: BC.DatasetInput;
|
|
39
|
+
onClick: (detail: BC.ClickDetail, event: CustomEvent<BC.ClickDetail>) => void;
|
|
40
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*! blockcharts 0.0.3 | MIT License */
|
|
2
|
+
// <BlockChart :spec="spec" :data="rows" @click="(d) => ..." />: a chart as a Vue 3 component. The chart is drawn after
|
|
3
|
+
// mount, so a server renders an empty <div>; the runtime is the kit the app imported (import "blockcharts/kits/basic.mjs").
|
|
4
|
+
// @click is a click on the data (interaction.click), with the row; the component's ref exposes the chart's view.
|
|
5
|
+
import { defineComponent, h, onBeforeUnmount, onMounted, ref, toRaw, watch } from 'vue';
|
|
6
|
+
import { Controller, handleOf } from './controller.mjs';
|
|
7
|
+
export const BlockChart = defineComponent({
|
|
8
|
+
name: 'BlockChart',
|
|
9
|
+
props: {
|
|
10
|
+
spec: { type: Object, required: true },
|
|
11
|
+
data: { type: [Array, Object], required: false, default: undefined },
|
|
12
|
+
// a prop, not an emit: @click binds to it, and whether it is there is whether the chart takes clicks
|
|
13
|
+
onClick: { type: Function, required: false, default: undefined },
|
|
14
|
+
},
|
|
15
|
+
setup(props, { expose }) {
|
|
16
|
+
const host = ref(null);
|
|
17
|
+
let controller = null;
|
|
18
|
+
const current = () => ({
|
|
19
|
+
// the raw objects: the chart reads them often, and through a reactive proxy every read is slower
|
|
20
|
+
spec: toRaw(props.spec),
|
|
21
|
+
data: props.data === undefined ? undefined : toRaw(props.data),
|
|
22
|
+
onClick: props.onClick,
|
|
23
|
+
});
|
|
24
|
+
expose(handleOf(() => (controller ? controller.handle : null)));
|
|
25
|
+
onMounted(() => {
|
|
26
|
+
controller = new Controller(host.value);
|
|
27
|
+
controller.set(current());
|
|
28
|
+
});
|
|
29
|
+
const again = () => {
|
|
30
|
+
if (controller)
|
|
31
|
+
controller.set(current());
|
|
32
|
+
};
|
|
33
|
+
// a spec changed in place (a reactive object) or replaced, data replaced, a listener added: drawn again if it differs
|
|
34
|
+
watch(() => props.spec, again, { deep: true });
|
|
35
|
+
watch(() => props.data, again);
|
|
36
|
+
watch(() => props.onClick, again);
|
|
37
|
+
onBeforeUnmount(() => {
|
|
38
|
+
if (controller)
|
|
39
|
+
controller.destroy();
|
|
40
|
+
controller = null;
|
|
41
|
+
});
|
|
42
|
+
return () => h('div', { ref: host });
|
|
43
|
+
},
|
|
44
|
+
});
|