blockcharts 0.0.1 → 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.
Files changed (87) hide show
  1. package/README.md +274 -171
  2. package/package.json +43 -6
  3. package/release/bc.d.ts +35 -2
  4. package/release/blocks/guide.axis.js +2 -2
  5. package/release/blocks/guide.grid.js +2 -2
  6. package/release/blocks/guide.kpi.js +2 -2
  7. package/release/blocks/guide.legend.js +2 -2
  8. package/release/blocks/interaction.animate.js +2 -2
  9. package/release/blocks/interaction.brush.js +2 -2
  10. package/release/blocks/interaction.click.js +3 -0
  11. package/release/blocks/interaction.crosshair.js +2 -2
  12. package/release/blocks/interaction.legend-filter.js +2 -2
  13. package/release/blocks/interaction.tooltip.js +2 -2
  14. package/release/blocks/interaction.zoom-controls.js +2 -2
  15. package/release/blocks/interaction.zoom.js +2 -2
  16. package/release/blocks/lib.columns.js +2 -2
  17. package/release/blocks/lib.curve.js +2 -2
  18. package/release/blocks/lib.pointer.js +2 -2
  19. package/release/blocks/lib.stats.js +2 -2
  20. package/release/blocks/lib.ticks.js +2 -2
  21. package/release/blocks/lib.view.js +2 -2
  22. package/release/blocks/mark.arc.js +2 -2
  23. package/release/blocks/mark.area.js +2 -2
  24. package/release/blocks/mark.boxplot.js +2 -2
  25. package/release/blocks/mark.candlestick.js +2 -2
  26. package/release/blocks/mark.line.js +2 -2
  27. package/release/blocks/mark.point.js +2 -2
  28. package/release/blocks/mark.polygon.js +2 -2
  29. package/release/blocks/mark.rect.js +2 -2
  30. package/release/blocks/mark.rule.js +2 -2
  31. package/release/blocks/mark.sankey.js +2 -2
  32. package/release/blocks/mark.text.js +2 -2
  33. package/release/blocks/mark.violin.js +2 -2
  34. package/release/blocks/renderer.canvas.js +2 -2
  35. package/release/blocks/renderer.svg.js +2 -2
  36. package/release/blocks/scale.band.js +2 -2
  37. package/release/blocks/scale.color.js +2 -2
  38. package/release/blocks/scale.linear.js +2 -2
  39. package/release/blocks/scale.log.js +2 -2
  40. package/release/blocks/scale.sequential.js +2 -2
  41. package/release/blocks/scale.size.js +2 -2
  42. package/release/blocks/scale.time.js +2 -2
  43. package/release/blocks/transform.aggregate.js +2 -2
  44. package/release/blocks/transform.bin.js +2 -2
  45. package/release/blocks/transform.calculate.js +2 -2
  46. package/release/blocks/transform.calendar.js +2 -2
  47. package/release/blocks/transform.contour.js +2 -2
  48. package/release/blocks/transform.decimate.js +2 -2
  49. package/release/blocks/transform.density.js +2 -2
  50. package/release/blocks/transform.filter.js +2 -2
  51. package/release/blocks/transform.fold.js +2 -2
  52. package/release/blocks/transform.funnel.js +2 -2
  53. package/release/blocks/transform.hexbin.js +2 -2
  54. package/release/blocks/transform.highlight.js +2 -2
  55. package/release/blocks/transform.marimekko.js +2 -2
  56. package/release/blocks/transform.quartiles.js +2 -2
  57. package/release/blocks/transform.sankey.js +2 -2
  58. package/release/blocks/transform.sort.js +2 -2
  59. package/release/blocks/transform.stack.js +2 -2
  60. package/release/blocks/transform.treemap.js +2 -2
  61. package/release/blocks/transform.waterfall.js +2 -2
  62. package/release/blocks/transform.window.js +2 -2
  63. package/release/core.js +3 -3
  64. package/release/frameworks/controller.d.mts +51 -0
  65. package/release/frameworks/controller.mjs +181 -0
  66. package/release/frameworks/element.d.mts +32 -0
  67. package/release/frameworks/element.mjs +95 -0
  68. package/release/frameworks/react.d.mts +10 -0
  69. package/release/frameworks/react.mjs +30 -0
  70. package/release/frameworks/svelte.d.mts +9 -0
  71. package/release/frameworks/svelte.mjs +17 -0
  72. package/release/frameworks/vue.d.mts +40 -0
  73. package/release/frameworks/vue.mjs +44 -0
  74. package/release/kits/basic.js +25 -22
  75. package/release/kits/basic.mjs +25 -22
  76. package/release/kits/composition.js +39 -36
  77. package/release/kits/composition.mjs +39 -36
  78. package/release/kits/dashboard.js +37 -34
  79. package/release/kits/dashboard.mjs +37 -34
  80. package/release/kits/full.js +64 -61
  81. package/release/kits/full.mjs +64 -61
  82. package/release/kits/timeseries.js +35 -32
  83. package/release/kits/timeseries.mjs +35 -32
  84. package/release/loader.js +2 -2
  85. package/release/manifest.json +326 -221
  86. package/release/schema/chart.schema.json +4155 -0
  87. package/release/schema/page.schema.json +4547 -0
@@ -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
+ });