@fusion.dev/helix-plot 0.245.0 → 0.246.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.
@@ -96,6 +96,14 @@ export interface PlotDriver<F> {
96
96
  draw(field: F, colors: PlotColors, font: string): void;
97
97
  /** Marks the reading at `index` as the one the keys rest on, or none with `-1`. */
98
98
  focus(index: number): void;
99
+ /**
100
+ * Draws one frame of the readings moving to new ones: the chart's `shown`
101
+ * field, between its readings before and after a change, in the colors and
102
+ * the font the last `draw` was given. **The view holds still**, framed as
103
+ * `draw` framed the new readings, so nothing but the readings moves. A
104
+ * driver with none is drawn each frame by `draw`.
105
+ */
106
+ move?(field: F, colors: PlotColors, font: string): void;
99
107
  /**
100
108
  * Calls `hover` with the index of the reading a mouse or a pen rests on in
101
109
  * the drawing, and with `-1` when it rests on none. Returns what stops
@@ -83,6 +83,19 @@ export const connectPlot = (frame, driver, options) => {
83
83
  });
84
84
  }
85
85
  let connected = true;
86
+ let look;
87
+ const moveTo = (field) => {
88
+ const shown = chart.shown;
89
+ if (!look || shown === undefined || shown === field) {
90
+ return;
91
+ }
92
+ if (driver.move) {
93
+ driver.move(shown, look.colors, look.font);
94
+ }
95
+ else {
96
+ driver.draw(shown, look.colors, look.font);
97
+ }
98
+ };
86
99
  const draw = () => {
87
100
  const field = chart.field;
88
101
  if (!connected || !field) {
@@ -90,6 +103,7 @@ export const connectPlot = (frame, driver, options) => {
90
103
  }
91
104
  const colors = plotColorsFrom(frame, options.groupsOf(field), options.extraOf?.(field));
92
105
  if (!colors || options.readings(field) === 0) {
106
+ look = undefined;
93
107
  chart.rendererDrawn?.(false);
94
108
  return;
95
109
  }
@@ -97,15 +111,32 @@ export const connectPlot = (frame, driver, options) => {
97
111
  .fontFamily.split(',')[0]
98
112
  ?.trim()
99
113
  .replace(/^["']|["']$/g, '') ?? '';
100
- driver.draw(field, colors, font || 'sans-serif');
114
+ look = { colors, font: font || 'sans-serif' };
115
+ driver.draw(field, look.colors, look.font);
116
+ moveTo(field);
101
117
  driver.focus(chart.active ?? -1);
102
118
  chart.rendererDrawn?.(true);
103
119
  };
104
120
  const handleChange = (event) => {
105
121
  const { kind } = event.detail;
122
+ const field = chart.field;
106
123
  if (kind === 'data') {
107
124
  draw();
108
125
  }
126
+ else if (kind === 'move') {
127
+ if (!look || !field) {
128
+ draw();
129
+ return;
130
+ }
131
+ const shown = chart.shown ?? field;
132
+ if (driver.move) {
133
+ driver.move(shown, look.colors, look.font);
134
+ }
135
+ else {
136
+ driver.draw(shown, look.colors, look.font);
137
+ }
138
+ driver.focus(chart.active ?? -1);
139
+ }
109
140
  else {
110
141
  driver.focus(chart.active ?? -1);
111
142
  }
@@ -14,6 +14,11 @@ export interface BarCell {
14
14
  /** The tone its cell names, which colors its own bar. */
15
15
  tone?: string | undefined;
16
16
  value?: number | undefined;
17
+ /** On a move frame, the series whose color it moves from and how far it has come, from 0 to 1. */
18
+ wore?: {
19
+ depth: number;
20
+ share: number;
21
+ } | undefined;
17
22
  }
18
23
  /**
19
24
  * What a Spatial Bar Chart publishes for a renderer to draw: every place on
@@ -10,6 +10,8 @@ export interface TreemapBlock {
10
10
  };
11
11
  group: string;
12
12
  groupIndex: number;
13
+ /** How much of its height it stands at, from 0 to 1, while it grows in or shrinks away. Whole where absent. */
14
+ grown?: number | undefined;
13
15
  height?: number | undefined;
14
16
  label: string;
15
17
  row: number;
@@ -25,8 +25,11 @@ export interface ThreeBarDriverOptions {
25
25
  * the blocks below it, on a grid of categories across and series in depth, in a box with a grid on its floor and two of
26
26
  * its walls, lit from above. Each series takes a series color from the theme,
27
27
  * and a bar whose cell names a tone takes that tone's. Under the chart's
28
- * `emphasis="muted"`, every other bar is the neutral ink. The chart's own
29
- * drawing alone draws a row, the glow, a toned bar's value, and the growth.
28
+ * `emphasis="muted"`, every other bar is the neutral ink. **The bars grow
29
+ * in and move to new readings as the chart's own drawing does**: the chart
30
+ * works out each frame, and the driver draws it with the view held still.
31
+ * The chart's own drawing alone draws a row, the glow, and a toned bar's
32
+ * value.
30
33
  *
31
34
  * **Dragging turns the box, and the wheel and a pinch bring it nearer.**
32
35
  * Shift with an arrow on the chart turns it a step. It never turns by itself.
@@ -38,62 +38,75 @@ export const threeBarDriver = (container, options = {}) => {
38
38
  geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
39
39
  return geometry;
40
40
  };
41
+ const build = (next, colors, font, framed) => {
42
+ field = next;
43
+ const [ex, ey, ez] = next.axes.extent ?? [1, 1, 1];
44
+ const spacing = Math.min((2 * HALF * ex) / Math.max(next.categories.length, 1), (2 * HALF * ez) / Math.max(next.lanes, 1));
45
+ const width = spacing * FOOTPRINT;
46
+ const page = new Color(colors.page);
47
+ const { emphasis, muted, through } = colors.look;
48
+ const solids = [];
49
+ const lines = [];
50
+ drawnCells = [];
51
+ tops = new Map();
52
+ const seriesColor = (cell) => {
53
+ const of = (depth) => new Color(colors.groups[depth % colors.groups.length] ?? colors.ink);
54
+ return cell.wore ? of(cell.wore.depth).lerp(of(cell.depth), cell.wore.share) : of(cell.depth);
55
+ };
56
+ next.cells.forEach((cell, index) => {
57
+ if (cell.value === undefined || (next.stacked && cell.value === 0)) {
58
+ return;
59
+ }
60
+ const toned = cell.tone ? colors.extra[`tone-${cell.tone}`] : undefined;
61
+ const tone = toned
62
+ ? new Color(toned)
63
+ : muted
64
+ ? new Color(colors.ground).lerp(new Color(colors.ink), 0.3)
65
+ : seriesColor(cell);
66
+ const color = emphasis === 'outlined' ? tone.clone().lerp(page, 0.4) : tone;
67
+ const start = inBox(next.axes.y, cell.from) * ey;
68
+ const top = inBox(next.axes.y, cell.from + cell.value) * ey;
69
+ const tall = Math.max(Math.abs(top - start), 1e-3);
70
+ const x = inBox(next.axes.x, cell.across) * ex;
71
+ const z = inBox(next.axes.z, cell.lane) * ez;
72
+ const box = new BoxGeometry(width, tall, width);
73
+ box.translate(x, Math.min(top, start) + tall / 2, z);
74
+ solids.push(painted(box, color));
75
+ lines.push(painted(new EdgesGeometry(box), emphasis === 'solid' ? edgeOf(color) : tone));
76
+ drawnCells.push(index);
77
+ tops.set(index, new Vector3(x, Math.max(top, start), z));
78
+ });
79
+ lookThrough(barMaterial, (emphasis === 'subtle' ? 0.2 : 1) * through);
80
+ lookThrough(edgeMaterial, through);
81
+ bars.geometry.dispose();
82
+ edges.geometry.dispose();
83
+ bars.geometry = (solids.length > 0 && mergeGeometries(solids)) || new BufferGeometry();
84
+ edges.geometry = (lines.length > 0 && mergeGeometries(lines)) || new BufferGeometry();
85
+ for (const one of [...solids, ...lines]) {
86
+ one.dispose();
87
+ }
88
+ stage.setAxes(next.axes, colors, font);
89
+ if (!framed) {
90
+ return;
91
+ }
92
+ if (colors.look.box || tops.size === 0) {
93
+ stage.frame(new Vector3(-HALF * ex, -HALF * ey, -HALF * ez), new Vector3(HALF * ex, HALF * ey, HALF * ez));
94
+ }
95
+ else {
96
+ const around = new Box3().setFromBufferAttribute(bars.geometry.getAttribute('position'));
97
+ stage.frame(around.min, around.max);
98
+ }
99
+ };
41
100
  return {
42
101
  draw: (next, colors, font) => {
43
- field = next;
44
- const [ex, ey, ez] = next.axes.extent ?? [1, 1, 1];
45
- const spacing = Math.min((2 * HALF * ex) / Math.max(next.categories.length, 1), (2 * HALF * ez) / Math.max(next.lanes, 1));
46
- const width = spacing * FOOTPRINT;
47
- const page = new Color(colors.page);
48
- const { emphasis, muted, through } = colors.look;
49
- const solids = [];
50
- const lines = [];
51
- drawnCells = [];
52
- tops = new Map();
53
- next.cells.forEach((cell, index) => {
54
- if (cell.value === undefined || (next.stacked && cell.value === 0)) {
55
- return;
56
- }
57
- const toned = cell.tone ? colors.extra[`tone-${cell.tone}`] : undefined;
58
- const tone = toned
59
- ? new Color(toned)
60
- : muted
61
- ? new Color(colors.ground).lerp(new Color(colors.ink), 0.3)
62
- : new Color(colors.groups[cell.depth % colors.groups.length] ?? colors.ink);
63
- const color = emphasis === 'outlined' ? tone.clone().lerp(page, 0.4) : tone;
64
- const start = inBox(next.axes.y, cell.from) * ey;
65
- const top = inBox(next.axes.y, cell.from + cell.value) * ey;
66
- const tall = Math.max(Math.abs(top - start), 1e-3);
67
- const x = inBox(next.axes.x, cell.across) * ex;
68
- const z = inBox(next.axes.z, cell.lane) * ez;
69
- const box = new BoxGeometry(width, tall, width);
70
- box.translate(x, Math.min(top, start) + tall / 2, z);
71
- solids.push(painted(box, color));
72
- lines.push(painted(new EdgesGeometry(box), emphasis === 'solid' ? edgeOf(color) : tone));
73
- drawnCells.push(index);
74
- tops.set(index, new Vector3(x, Math.max(top, start), z));
75
- });
76
- lookThrough(barMaterial, (emphasis === 'subtle' ? 0.2 : 1) * through);
77
- lookThrough(edgeMaterial, through);
78
- bars.geometry.dispose();
79
- edges.geometry.dispose();
80
- bars.geometry = (solids.length > 0 && mergeGeometries(solids)) || new BufferGeometry();
81
- edges.geometry = (lines.length > 0 && mergeGeometries(lines)) || new BufferGeometry();
82
- for (const one of [...solids, ...lines]) {
83
- one.dispose();
84
- }
85
- stage.setAxes(next.axes, colors, font);
86
- if (colors.look.box || tops.size === 0) {
87
- stage.frame(new Vector3(-HALF * ex, -HALF * ey, -HALF * ez), new Vector3(HALF * ex, HALF * ey, HALF * ez));
88
- }
89
- else {
90
- const around = new Box3().setFromBufferAttribute(bars.geometry.getAttribute('position'));
91
- stage.frame(around.min, around.max);
92
- }
102
+ build(next, colors, font, true);
93
103
  },
94
104
  focus: (index) => {
95
105
  stage.setMarker(field ? tops.get(index) : undefined);
96
106
  },
107
+ move: (next, colors, font) => {
108
+ build(next, colors, font, false);
109
+ },
97
110
  onHover: (listener) => stage.onHover(listener),
98
111
  onPlace: (listener) => stage.onPlace(listener),
99
112
  onPress: (listener) => stage.onPress(listener),
@@ -24,6 +24,9 @@ export interface ThreeHeatmapDriverOptions {
24
24
  * **Each reading is a prism on a slab**, as tall as the chart's own drawing
25
25
  * stands it and in its tone, lit from above and the upper left, with each
26
26
  * edge set a little apart from its face. A day with nothing in it is a tile.
27
+ * **The prisms grow in and move to new readings as the chart's own drawing
28
+ * does**: the chart works out each frame, and the driver draws it with the
29
+ * view held still.
27
30
  *
28
31
  * **Dragging turns the relief, and the wheel and a pinch bring it nearer.**
29
32
  * Shift with an arrow on the chart turns it a step. It never turns by itself.
@@ -47,72 +47,81 @@ export const threeHeatmapDriver = (container, options = {}) => {
47
47
  geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
48
48
  return geometry;
49
49
  };
50
- return {
51
- draw: (next, colors) => {
52
- field = next;
53
- const unit = SPAN / Math.max(next.columns, next.rows, 1);
54
- const tile = new Color(colors.extra.tile ?? colors.ground);
55
- const page = new Color(colors.page);
56
- const { emphasis, through } = colors.look;
57
- const solids = [];
58
- const lines = [];
59
- tops = next.cells.map((cell) => {
60
- const tone = cell.tone ? new Color(colors.extra[`tone-${cell.tone}`] ?? colors.ink) : tile;
61
- const color = emphasis === 'outlined' ? tone.clone().lerp(page, 0.4) : tone;
62
- const tall = Math.max(cell.height, TILE) * unit;
63
- const x = (cell.column + 0.5 - next.columns / 2) * unit;
64
- const z = (cell.row + 0.5 - next.rows / 2) * unit;
65
- const box = new BoxGeometry(unit * FOOTPRINT, tall, unit * FOOTPRINT);
66
- box.translate(x, FLOOR + tall / 2, z);
67
- solids.push(painted(box, color));
68
- lines.push(painted(new EdgesGeometry(box), emphasis === 'solid' ? edgeOf(color) : tone));
69
- return new Vector3(x, FLOOR + tall, z);
70
- });
71
- const area = emphasis === 'subtle' ? 0.2 : 1;
72
- lookThrough(prismMaterial, area * through);
73
- lookThrough(edgeMaterial, through);
74
- prisms.geometry.dispose();
75
- edges.geometry.dispose();
76
- prisms.geometry = (solids.length > 0 && mergeGeometries(solids)) || new BufferGeometry();
77
- edges.geometry = (lines.length > 0 && mergeGeometries(lines)) || new BufferGeometry();
78
- for (const one of [...solids, ...lines]) {
79
- one.dispose();
50
+ const build = (next, colors, whole) => {
51
+ field = next;
52
+ const unit = SPAN / Math.max(next.columns, next.rows, 1);
53
+ const tile = new Color(colors.extra.tile ?? colors.ground);
54
+ const page = new Color(colors.page);
55
+ const { emphasis, through } = colors.look;
56
+ const solids = [];
57
+ const lines = [];
58
+ tops = next.cells.map((cell) => {
59
+ const tone = cell.tone ? new Color(colors.extra[`tone-${cell.tone}`] ?? colors.ink) : tile;
60
+ const color = emphasis === 'outlined' ? tone.clone().lerp(page, 0.4) : tone;
61
+ const tall = Math.max(cell.height, TILE) * unit;
62
+ const x = (cell.column + 0.5 - next.columns / 2) * unit;
63
+ const z = (cell.row + 0.5 - next.rows / 2) * unit;
64
+ const box = new BoxGeometry(unit * FOOTPRINT, tall, unit * FOOTPRINT);
65
+ box.translate(x, FLOOR + tall / 2, z);
66
+ solids.push(painted(box, color));
67
+ lines.push(painted(new EdgesGeometry(box), emphasis === 'solid' ? edgeOf(color) : tone));
68
+ return new Vector3(x, FLOOR + tall, z);
69
+ });
70
+ const area = emphasis === 'subtle' ? 0.2 : 1;
71
+ lookThrough(prismMaterial, area * through);
72
+ lookThrough(edgeMaterial, through);
73
+ prisms.geometry.dispose();
74
+ edges.geometry.dispose();
75
+ prisms.geometry = (solids.length > 0 && mergeGeometries(solids)) || new BufferGeometry();
76
+ edges.geometry = (lines.length > 0 && mergeGeometries(lines)) || new BufferGeometry();
77
+ for (const one of [...solids, ...lines]) {
78
+ one.dispose();
79
+ }
80
+ base.scale.set((next.columns + 2 * MARGIN) * unit, THICKNESS * unit, (next.rows + 2 * MARGIN) * unit);
81
+ base.position.set(0, FLOOR - (THICKNESS * unit) / 2, 0);
82
+ baseMaterial.color.setStyle(colors.extra.base ?? colors.grid);
83
+ base.visible = next.cells.length > 0;
84
+ if (!whole) {
85
+ return;
86
+ }
87
+ const tallest = Math.max(TILE, ...next.cells.map((cell) => cell.height)) * unit;
88
+ const wide = (next.columns + 2 * MARGIN) * unit;
89
+ const deep = (next.rows + 2 * MARGIN) * unit;
90
+ const high = tallest + THICKNESS * unit;
91
+ stage.frame(new Vector3(-wide / 2, FLOOR - THICKNESS * unit, -deep / 2), new Vector3(wide / 2, FLOOR - THICKNESS * unit + high, deep / 2), framed ? undefined : new Vector3(1, 1, 1));
92
+ framed = true;
93
+ unfollow?.();
94
+ const foot = FLOOR - THICKNESS * unit;
95
+ const corners = [];
96
+ for (const x of [-wide / 2, wide / 2]) {
97
+ for (const z of [deep / 2, -deep / 2]) {
98
+ corners.push(new Vector3(x, foot, z), new Vector3(x, foot + high, z));
80
99
  }
81
- base.scale.set((next.columns + 2 * MARGIN) * unit, THICKNESS * unit, (next.rows + 2 * MARGIN) * unit);
82
- base.position.set(0, FLOOR - (THICKNESS * unit) / 2, 0);
83
- baseMaterial.color.setStyle(colors.extra.base ?? colors.grid);
84
- base.visible = next.cells.length > 0;
85
- const tallest = Math.max(TILE, ...next.cells.map((cell) => cell.height)) * unit;
86
- const wide = (next.columns + 2 * MARGIN) * unit;
87
- const deep = (next.rows + 2 * MARGIN) * unit;
88
- const high = tallest + THICKNESS * unit;
89
- stage.frame(new Vector3(-wide / 2, FLOOR - THICKNESS * unit, -deep / 2), new Vector3(wide / 2, FLOOR - THICKNESS * unit + high, deep / 2), framed ? undefined : new Vector3(1, 1, 1));
90
- framed = true;
91
- unfollow?.();
92
- const foot = FLOOR - THICKNESS * unit;
93
- const corners = [];
94
- for (const x of [-wide / 2, wide / 2]) {
95
- for (const z of [deep / 2, -deep / 2]) {
96
- corners.push(new Vector3(x, foot, z), new Vector3(x, foot + high, z));
97
- }
100
+ }
101
+ unfollow = stage.track(corners, (at) => {
102
+ if (!at) {
103
+ cornered?.(undefined);
104
+ return;
98
105
  }
99
- unfollow = stage.track(corners, (at) => {
100
- if (!at) {
101
- cornered?.(undefined);
102
- return;
103
- }
104
- const [lastStart, firstStart, lastEnd, firstEnd] = [0, 2, 4, 6].map((index) => at[index]);
105
- const last = lastStart.y + lastEnd.y >= firstStart.y + firstEnd.y;
106
- cornered?.({
107
- end: last ? lastEnd : firstEnd,
108
- outline: at,
109
- start: last ? lastStart : firstStart,
110
- });
106
+ const [lastStart, firstStart, lastEnd, firstEnd] = [0, 2, 4, 6].map((index) => at[index]);
107
+ const last = lastStart.y + lastEnd.y >= firstStart.y + firstEnd.y;
108
+ cornered?.({
109
+ end: last ? lastEnd : firstEnd,
110
+ outline: at,
111
+ start: last ? lastStart : firstStart,
111
112
  });
113
+ });
114
+ };
115
+ return {
116
+ draw: (next, colors) => {
117
+ build(next, colors, true);
112
118
  },
113
119
  focus: (index) => {
114
120
  stage.setMarker(tops[index]);
115
121
  },
122
+ move: (next, colors) => {
123
+ build(next, colors, false);
124
+ },
116
125
  onCorners: (listener) => {
117
126
  cornered = listener;
118
127
  return () => {
@@ -24,6 +24,9 @@ export interface ThreeRibbonDriverOptions {
24
24
  * **Each series is a ribbon in its own depth**, its top following the
25
25
  * values and its sides falling to zero, in a box long across and shallow in
26
26
  * depth, lit from above. Each series takes a series color from the theme.
27
+ * **The ribbons grow in and move to new readings as the chart's own drawing
28
+ * does**: the chart works out each frame, and the driver draws it with the
29
+ * view held still.
27
30
  *
28
31
  * **Dragging turns the box, and the wheel and a pinch bring it nearer.**
29
32
  * Shift with an arrow on the chart turns it a step. It never turns by itself.
@@ -38,81 +38,89 @@ export const threeRibbonDriver = (container, options = {}) => {
38
38
  const sun = new DirectionalLight(0xffffff, 1);
39
39
  sun.position.set(-2, 4, 1);
40
40
  stage.scene.add(ribbons, edges, sky, sun);
41
- return {
42
- draw: (next, colors, font) => {
43
- field = next;
44
- const [ex, ey, ez] = next.axes.extent ?? [1, 1, 1];
45
- const count = Math.max(next.series.length, 1);
46
- const half = ((THICKNESS * 2) / count / 2) * HALF * ez;
47
- const zero = inBox(next.axes.y, Math.max(next.axes.y.range[0], 0)) * ey;
48
- const page = new Color(colors.page);
49
- const { emphasis, through } = colors.look;
50
- const positions = [];
51
- const tints = [];
52
- const lines = [];
53
- const lineTints = [];
54
- readings = new Map();
55
- next.series.forEach((_, series) => {
56
- const tone = new Color(colors.groups[series % colors.groups.length] ?? colors.ink);
57
- const color = emphasis === 'outlined' ? tone.clone().lerp(page, 0.4) : tone;
58
- const edge = emphasis === 'solid' ? edgeOf(color) : tone;
59
- const z = inBox(next.axes.z, series) * ez;
60
- const points = [];
61
- next.categories.forEach((__, across) => {
62
- const index = across * next.series.length + series;
63
- const value = next.cells[index]?.value;
64
- if (value !== undefined) {
65
- const at = new Vector3(inBox(next.axes.x, across) * ex, inBox(next.axes.y, value) * ey, z);
66
- points.push(at);
67
- readings.set(index, at.clone().setZ(z + half));
68
- }
69
- });
70
- const quad = (a, b, c, d) => {
71
- for (const one of [a, b, c, a, c, d]) {
72
- positions.push(one.x, one.y, one.z);
73
- tints.push(color.r, color.g, color.b);
74
- }
75
- };
76
- const line = (a, b) => {
77
- lines.push(a.x, a.y, a.z, b.x, b.y, b.z);
78
- lineTints.push(edge.r, edge.g, edge.b, edge.r, edge.g, edge.b);
79
- };
80
- const near = (point, y = point.y) => new Vector3(point.x, y, z + half);
81
- const far = (point, y = point.y) => new Vector3(point.x, y, z - half);
82
- for (let at = 0; at + 1 < points.length; at++) {
83
- const [a, b] = [points[at], points[at + 1]];
84
- quad(near(a), near(b), far(b), far(a));
85
- quad(near(a, zero), near(b, zero), near(b), near(a));
86
- quad(far(a, zero), far(b, zero), far(b), far(a));
87
- line(near(a), near(b));
88
- line(far(a), far(b));
89
- }
90
- const [first, last] = [points[0], points.at(-1)];
91
- for (const end of [first, last]) {
92
- if (end) {
93
- quad(near(end, zero), near(end), far(end), far(end, zero));
94
- }
41
+ const build = (next, colors, font, framed) => {
42
+ field = next;
43
+ const [ex, ey, ez] = next.axes.extent ?? [1, 1, 1];
44
+ const count = Math.max(next.series.length, 1);
45
+ const half = ((THICKNESS * 2) / count / 2) * HALF * ez;
46
+ const zero = inBox(next.axes.y, Math.max(next.axes.y.range[0], 0)) * ey;
47
+ const page = new Color(colors.page);
48
+ const { emphasis, through } = colors.look;
49
+ const positions = [];
50
+ const tints = [];
51
+ const lines = [];
52
+ const lineTints = [];
53
+ readings = new Map();
54
+ next.series.forEach((_, series) => {
55
+ const tone = new Color(colors.groups[series % colors.groups.length] ?? colors.ink);
56
+ const color = emphasis === 'outlined' ? tone.clone().lerp(page, 0.4) : tone;
57
+ const edge = emphasis === 'solid' ? edgeOf(color) : tone;
58
+ const z = inBox(next.axes.z, series) * ez;
59
+ const points = [];
60
+ next.cells.forEach((cell, index) => {
61
+ if (cell.depth === series && cell.value !== undefined) {
62
+ const at = new Vector3(inBox(next.axes.x, cell.across) * ex, inBox(next.axes.y, cell.value) * ey, z);
63
+ points.push(at);
64
+ readings.set(index, at.clone().setZ(z + half));
95
65
  }
96
66
  });
97
- ribbons.geometry.dispose();
98
- const geometry = new BufferGeometry();
99
- geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
100
- geometry.setAttribute('color', new Float32BufferAttribute(tints, 3));
101
- geometry.computeVertexNormals();
102
- ribbons.geometry = geometry;
103
- edges.geometry.dispose();
104
- const lined = new BufferGeometry();
105
- lined.setAttribute('position', new Float32BufferAttribute(lines, 3));
106
- lined.setAttribute('color', new Float32BufferAttribute(lineTints, 3));
107
- edges.geometry = lined;
108
- lookThrough(ribbonMaterial, (emphasis === 'subtle' ? 0.2 : 1) * through);
109
- lookThrough(edgeMaterial, through);
110
- stage.setAxes(next.axes, colors, font);
111
- stage.frame(new Vector3(-HALF * ex - ROOM, -HALF * ey - ROOM, -HALF * ez - ROOM), new Vector3(HALF * ex + ROOM, HALF * ey, HALF * ez + ROOM));
67
+ points.sort((one, other) => one.x - other.x);
68
+ const quad = (a, b, c, d) => {
69
+ for (const one of [a, b, c, a, c, d]) {
70
+ positions.push(one.x, one.y, one.z);
71
+ tints.push(color.r, color.g, color.b);
72
+ }
73
+ };
74
+ const line = (a, b) => {
75
+ lines.push(a.x, a.y, a.z, b.x, b.y, b.z);
76
+ lineTints.push(edge.r, edge.g, edge.b, edge.r, edge.g, edge.b);
77
+ };
78
+ const near = (point, y = point.y) => new Vector3(point.x, y, z + half);
79
+ const far = (point, y = point.y) => new Vector3(point.x, y, z - half);
80
+ for (let at = 0; at + 1 < points.length; at++) {
81
+ const [a, b] = [points[at], points[at + 1]];
82
+ quad(near(a), near(b), far(b), far(a));
83
+ quad(near(a, zero), near(b, zero), near(b), near(a));
84
+ quad(far(a, zero), far(b, zero), far(b), far(a));
85
+ line(near(a), near(b));
86
+ line(far(a), far(b));
87
+ }
88
+ const [first, last] = [points[0], points.at(-1)];
89
+ for (const end of [first, last]) {
90
+ if (end) {
91
+ quad(near(end, zero), near(end), far(end), far(end, zero));
92
+ }
93
+ }
94
+ });
95
+ ribbons.geometry.dispose();
96
+ const geometry = new BufferGeometry();
97
+ geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
98
+ geometry.setAttribute('color', new Float32BufferAttribute(tints, 3));
99
+ geometry.computeVertexNormals();
100
+ ribbons.geometry = geometry;
101
+ edges.geometry.dispose();
102
+ const lined = new BufferGeometry();
103
+ lined.setAttribute('position', new Float32BufferAttribute(lines, 3));
104
+ lined.setAttribute('color', new Float32BufferAttribute(lineTints, 3));
105
+ edges.geometry = lined;
106
+ lookThrough(ribbonMaterial, (emphasis === 'subtle' ? 0.2 : 1) * through);
107
+ lookThrough(edgeMaterial, through);
108
+ stage.setAxes(next.axes, colors, font);
109
+ if (!framed) {
110
+ return;
111
+ }
112
+ stage.frame(new Vector3(-HALF * ex - ROOM, -HALF * ey - ROOM, -HALF * ez - ROOM), new Vector3(HALF * ex + ROOM, HALF * ey, HALF * ez + ROOM));
113
+ };
114
+ return {
115
+ draw: (next, colors, font) => {
116
+ build(next, colors, font, true);
112
117
  },
113
118
  focus: (index) => {
114
119
  stage.setMarker(field ? readings.get(index) : undefined);
115
120
  },
121
+ move: (next, colors, font) => {
122
+ build(next, colors, font, false);
123
+ },
116
124
  onHover: (listener) => stage.onHover(listener),
117
125
  onPlace: (listener) => stage.onPlace(listener),
118
126
  onPress: (listener) => stage.onPress(listener),
@@ -26,6 +26,8 @@ export interface ThreeScatterDriverOptions {
26
26
  * **The points stand in a box**, each axis' range from one side of it to the
27
27
  * other, with a grid on its floor and two of its walls at the ticks, and the
28
28
  * axes named along its edges. Each group is a color of the theme's series.
29
+ * **The points grow in and move to new readings as the chart's own drawing
30
+ * does**: the chart works out each frame, and the driver draws it.
29
31
  *
30
32
  * **Dragging turns the box, and the wheel and a pinch bring it nearer.**
31
33
  * Shift with an arrow on the chart turns it a step. It never turns by itself.
@@ -26,7 +26,8 @@ export interface ThreeSurfaceDriverOptions {
26
26
  * two of its walls. The surface is shaded along the ramp from
27
27
  * `--spatial-surface-chart-low` to `--spatial-surface-chart-high`, lit from above, and ruled along
28
28
  * the grid. A place the table has no reading for leaves a hole rather than a
29
- * pit.
29
+ * pit. **The surface rises in and moves to new readings as the chart's own
30
+ * drawing does**: the chart works out each frame, and the driver draws it.
30
31
  *
31
32
  * **Dragging turns the box, and the wheel and a pinch bring it nearer.**
32
33
  * Shift with an arrow on the chart turns it a step. It never turns by itself.
@@ -24,7 +24,9 @@ export interface ThreeTreemapDriverOptions {
24
24
  * **Each block stands on its part of the floor, from zero to its height**,
25
25
  * or as one slab where the table gives no heights, in a box with the
26
26
  * height's grid on two of its walls, lit from above. Each group takes a
27
- * series color from the theme.
27
+ * series color from the theme. **The blocks grow in and move to new readings
28
+ * as the chart's own drawing does**: the chart works out each frame, and the
29
+ * driver draws it with the view held still.
28
30
  *
29
31
  * **Dragging turns the box, and the wheel and a pinch bring it nearer.**
30
32
  * Shift with an arrow on the chart turns it a step. It never turns by itself.
@@ -37,59 +37,68 @@ export const threeTreemapDriver = (container, options = {}) => {
37
37
  geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
38
38
  return geometry;
39
39
  };
40
+ const build = (next, colors, font, framed) => {
41
+ field = next;
42
+ const [ex, ey, ez] = next.axes.extent ?? [1, 1, 1];
43
+ const zero = inBox(next.axes.y, 0) * ey;
44
+ const page = new Color(colors.page);
45
+ const { emphasis, through } = colors.look;
46
+ const solids = [];
47
+ const lines = [];
48
+ drawnBlocks = [];
49
+ tops = new Map();
50
+ next.blocks.forEach((block, index) => {
51
+ const tone = new Color(colors.groups[block.groupIndex % colors.groups.length] ?? colors.ink);
52
+ const color = emphasis === 'outlined' ? tone.clone().lerp(page, 0.4) : tone;
53
+ const top = inBox(next.axes.y, (next.height === '' ? 1 : (block.height ?? 0)) * (block.grown ?? 1)) * ey;
54
+ const tall = Math.max(Math.abs(top - zero), 1e-3);
55
+ const [x0, x1] = [
56
+ inBox(next.axes.x, block.area.x0) * ex,
57
+ inBox(next.axes.x, block.area.x1) * ex,
58
+ ];
59
+ const [z0, z1] = [
60
+ inBox(next.axes.z, block.area.z0) * ez,
61
+ inBox(next.axes.z, block.area.z1) * ez,
62
+ ];
63
+ const box = new BoxGeometry(Math.abs(x1 - x0), tall, Math.abs(z1 - z0));
64
+ const [x, z] = [(x0 + x1) / 2, (z0 + z1) / 2];
65
+ box.translate(x, Math.min(top, zero) + tall / 2, z);
66
+ solids.push(painted(box, color));
67
+ lines.push(painted(new EdgesGeometry(box), emphasis === 'solid' ? edgeOf(color) : tone));
68
+ drawnBlocks.push(index);
69
+ tops.set(index, new Vector3(x, Math.max(top, zero), z));
70
+ });
71
+ lookThrough(blockMaterial, (emphasis === 'subtle' ? 0.2 : 1) * through);
72
+ lookThrough(edgeMaterial, through);
73
+ blocks.geometry.dispose();
74
+ edges.geometry.dispose();
75
+ blocks.geometry = (solids.length > 0 && mergeGeometries(solids)) || new BufferGeometry();
76
+ edges.geometry = (lines.length > 0 && mergeGeometries(lines)) || new BufferGeometry();
77
+ for (const one of [...solids, ...lines]) {
78
+ one.dispose();
79
+ }
80
+ stage.setAxes(next.axes, colors, font);
81
+ if (!framed) {
82
+ return;
83
+ }
84
+ if (colors.look.box || tops.size === 0) {
85
+ stage.frame(new Vector3(-HALF * ex, -HALF * ey, -HALF * ez), new Vector3(HALF * ex, HALF * ey, HALF * ez));
86
+ }
87
+ else {
88
+ const around = new Box3().setFromBufferAttribute(blocks.geometry.getAttribute('position'));
89
+ stage.frame(around.min, around.max);
90
+ }
91
+ };
40
92
  return {
41
93
  draw: (next, colors, font) => {
42
- field = next;
43
- const [ex, ey, ez] = next.axes.extent ?? [1, 1, 1];
44
- const zero = inBox(next.axes.y, 0) * ey;
45
- const page = new Color(colors.page);
46
- const { emphasis, through } = colors.look;
47
- const solids = [];
48
- const lines = [];
49
- drawnBlocks = [];
50
- tops = new Map();
51
- next.blocks.forEach((block, index) => {
52
- const tone = new Color(colors.groups[block.groupIndex % colors.groups.length] ?? colors.ink);
53
- const color = emphasis === 'outlined' ? tone.clone().lerp(page, 0.4) : tone;
54
- const top = inBox(next.axes.y, next.height === '' ? 1 : (block.height ?? 0)) * ey;
55
- const tall = Math.max(Math.abs(top - zero), 1e-3);
56
- const [x0, x1] = [
57
- inBox(next.axes.x, block.area.x0) * ex,
58
- inBox(next.axes.x, block.area.x1) * ex,
59
- ];
60
- const [z0, z1] = [
61
- inBox(next.axes.z, block.area.z0) * ez,
62
- inBox(next.axes.z, block.area.z1) * ez,
63
- ];
64
- const box = new BoxGeometry(Math.abs(x1 - x0), tall, Math.abs(z1 - z0));
65
- const [x, z] = [(x0 + x1) / 2, (z0 + z1) / 2];
66
- box.translate(x, Math.min(top, zero) + tall / 2, z);
67
- solids.push(painted(box, color));
68
- lines.push(painted(new EdgesGeometry(box), emphasis === 'solid' ? edgeOf(color) : tone));
69
- drawnBlocks.push(index);
70
- tops.set(index, new Vector3(x, Math.max(top, zero), z));
71
- });
72
- lookThrough(blockMaterial, (emphasis === 'subtle' ? 0.2 : 1) * through);
73
- lookThrough(edgeMaterial, through);
74
- blocks.geometry.dispose();
75
- edges.geometry.dispose();
76
- blocks.geometry = (solids.length > 0 && mergeGeometries(solids)) || new BufferGeometry();
77
- edges.geometry = (lines.length > 0 && mergeGeometries(lines)) || new BufferGeometry();
78
- for (const one of [...solids, ...lines]) {
79
- one.dispose();
80
- }
81
- stage.setAxes(next.axes, colors, font);
82
- if (colors.look.box || tops.size === 0) {
83
- stage.frame(new Vector3(-HALF * ex, -HALF * ey, -HALF * ez), new Vector3(HALF * ex, HALF * ey, HALF * ez));
84
- }
85
- else {
86
- const around = new Box3().setFromBufferAttribute(blocks.geometry.getAttribute('position'));
87
- stage.frame(around.min, around.max);
88
- }
94
+ build(next, colors, font, true);
89
95
  },
90
96
  focus: (index) => {
91
97
  stage.setMarker(field ? tops.get(index) : undefined);
92
98
  },
99
+ move: (next, colors, font) => {
100
+ build(next, colors, font, false);
101
+ },
93
102
  onHover: (listener) => stage.onHover(listener),
94
103
  onPlace: (listener) => stage.onPlace(listener),
95
104
  onPress: (listener) => stage.onPress(listener),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fusion.dev/helix-plot",
3
3
  "description": "Connects the Helix spatial charts to three.js, which draws them in three dimensions: Spatial Bar Chart, Spatial Heatmap, Spatial Ribbon Chart, Spatial Scatter Chart, Spatial Surface Chart, and Spatial Treemap.",
4
- "version": "0.245.0",
4
+ "version": "0.246.0",
5
5
  "license": "MIT",
6
6
  "author": "Fusion Development Group",
7
7
  "repository": {
@@ -36,11 +36,11 @@
36
36
  },
37
37
  "bugs": "https://github.com/project-fusion/fusion/issues",
38
38
  "dependencies": {
39
- "@fusion.dev/helix-core": "0.245.0"
39
+ "@fusion.dev/helix-core": "0.246.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@fusion.dev/helix-headless": "0.245.0",
43
- "@fusion.dev/helix-testing": "0.245.0",
42
+ "@fusion.dev/helix-headless": "0.246.0",
43
+ "@fusion.dev/helix-testing": "0.246.0",
44
44
  "@types/bun": "^1.4.4",
45
45
  "@types/three": "^0.186.0",
46
46
  "three": "^0.186.1"