@fjader/svelte 0.2.2 → 0.2.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 (118) hide show
  1. package/dist/components/axes/BandAxisTicks.svelte +63 -24
  2. package/dist/components/axes/BandAxisTicks.svelte.d.ts +5 -5
  3. package/dist/components/charts/ChartContainer.svelte +2 -1
  4. package/dist/components/guides/legend/ContinuousColorLegend.svelte +2 -1
  5. package/dist/components/guides/legend/OrdinalColorLegend.svelte +92 -34
  6. package/dist/components/marks/AreaMarkX.svelte +19 -6
  7. package/dist/components/marks/AreaMarkY.svelte +19 -6
  8. package/dist/components/marks/BarMarkX.svelte +3 -0
  9. package/dist/components/marks/BarMarkY.svelte +3 -0
  10. package/dist/components/marks/DotsMark.svelte +3 -0
  11. package/dist/components/marks/LineMark.svelte +3 -0
  12. package/dist/components/marks/ParallelCoordinatesMark.svelte +6 -0
  13. package/dist/components/marks/ParallelCoordinatesMark.svelte.d.ts +3 -0
  14. package/dist/components/marks/RectMark.svelte +3 -0
  15. package/dist/components/marks/RectXMark.svelte +3 -0
  16. package/dist/components/marks/RectYMark.svelte +3 -0
  17. package/dist/components/marks/RuleMarkX.svelte +10 -2
  18. package/dist/components/marks/RuleMarkY.svelte +10 -2
  19. package/dist/components/marks/TextMark.svelte +68 -4
  20. package/dist/components/marks/lifecycle/MarkLifecycleV2.svelte.d.ts +15 -1
  21. package/dist/components/marks/lifecycle/MarkLifecycleV2.svelte.js +116 -27
  22. package/dist/components/marks/lifecycle/domain-queries.js +13 -11
  23. package/dist/components/marks/lifecycle/transform-scale-key.d.ts +16 -0
  24. package/dist/components/marks/lifecycle/transform-scale-key.js +27 -0
  25. package/dist/components/marks/utils/area-outline.d.ts +24 -0
  26. package/dist/components/marks/utils/area-outline.js +10 -0
  27. package/dist/components/marks/utils/reactive-config.d.ts +1 -1
  28. package/dist/components/marks/utils/reactive-config.js +3 -0
  29. package/dist/components/rendering/Areas.svelte +30 -6
  30. package/dist/components/rendering/Areas.svelte.d.ts +2 -0
  31. package/dist/components/rendering/BaseGPURenderer.svelte.js +4 -1
  32. package/dist/components/rendering/Dots.svelte +24 -3
  33. package/dist/components/rendering/Dots.svelte.d.ts +2 -0
  34. package/dist/components/rendering/GridLine.svelte +2 -1
  35. package/dist/components/rendering/Lines.svelte +49 -7
  36. package/dist/components/rendering/Lines.svelte.d.ts +9 -0
  37. package/dist/components/rendering/ParallelLines.svelte +26 -7
  38. package/dist/components/rendering/ParallelLines.svelte.d.ts +2 -0
  39. package/dist/components/rendering/Rects.svelte +20 -5
  40. package/dist/components/rendering/Rects.svelte.d.ts +2 -0
  41. package/dist/components/rendering/RuleX.svelte +20 -5
  42. package/dist/components/rendering/RuleX.svelte.d.ts +2 -0
  43. package/dist/components/rendering/RuleY.svelte +20 -5
  44. package/dist/components/rendering/RuleY.svelte.d.ts +2 -0
  45. package/dist/components/rendering/activity-reads.d.ts +93 -0
  46. package/dist/components/rendering/activity-reads.js +135 -0
  47. package/dist/components/rendering/uniform-sizes.d.ts +26 -0
  48. package/dist/components/rendering/uniform-sizes.js +28 -0
  49. package/dist/config/ChartConfig.svelte.d.ts +2 -0
  50. package/dist/gpu/ColorScaleShaderLib.d.ts +13 -1
  51. package/dist/gpu/ColorScaleShaderLib.js +56 -5
  52. package/dist/gpu/GPUCoordinator.svelte.d.ts +8 -0
  53. package/dist/gpu/GPUCoordinator.svelte.js +68 -32
  54. package/dist/gpu/ResolveShader.d.ts +2 -2
  55. package/dist/gpu/ResolveShader.js +2 -2
  56. package/dist/gpu/ScaleTemplateSystem.d.ts +19 -0
  57. package/dist/gpu/ScaleTemplateSystem.js +86 -7
  58. package/dist/gpu/SizeScaleShaderLib.d.ts +4 -4
  59. package/dist/gpu/SizeScaleShaderLib.js +4 -4
  60. package/dist/gpu/identity-slot-packing.d.ts +157 -40
  61. package/dist/gpu/identity-slot-packing.js +262 -62
  62. package/dist/gpu/tracked-scales.d.ts +14 -0
  63. package/dist/gpu/tracked-scales.js +18 -0
  64. package/dist/index.js +1 -0
  65. package/dist/interactors/BandLabelToggle.svelte +5 -9
  66. package/dist/interactors/BandLabelToggle.svelte.d.ts +3 -3
  67. package/dist/interactors/DerivedInterval1D.svelte +26 -54
  68. package/dist/interactors/Interval1D.svelte +2 -1
  69. package/dist/interactors/Interval2D.svelte +2 -1
  70. package/dist/interactors/ParallelAxisSource.svelte +4 -4
  71. package/dist/interactors/ParallelAxisSource.svelte.d.ts +2 -1
  72. package/dist/interactors/ParallelBrushes.svelte +8 -9
  73. package/dist/interactors/ParallelBrushes.svelte.d.ts +3 -3
  74. package/dist/interactors/Toggle.svelte +17 -36
  75. package/dist/interactors/Toggle.svelte.d.ts +4 -3
  76. package/dist/interactors/Tooltip.svelte +2 -1
  77. package/dist/interactors/TooltipManager.svelte.js +8 -3
  78. package/dist/interactors/relay-clauses.d.ts +23 -0
  79. package/dist/interactors/relay-clauses.js +60 -0
  80. package/dist/query-engine/CrossfilterSelection.svelte.d.ts +88 -15
  81. package/dist/query-engine/CrossfilterSelection.svelte.js +94 -20
  82. package/dist/query-engine/FieldActivity.svelte.d.ts +79 -0
  83. package/dist/query-engine/FieldActivity.svelte.js +207 -0
  84. package/dist/query-engine/FilterGroup.svelte.d.ts +53 -29
  85. package/dist/query-engine/FilterGroup.svelte.js +181 -122
  86. package/dist/query-engine/FilterGroupRegistry.svelte.d.ts +42 -0
  87. package/dist/query-engine/FilterGroupRegistry.svelte.js +103 -1
  88. package/dist/query-engine/MarkHandle.svelte.d.ts +9 -1
  89. package/dist/query-engine/MarkHandle.svelte.js +12 -2
  90. package/dist/query-engine/QueryEngine.d.ts +52 -16
  91. package/dist/query-engine/QueryEngine.js +90 -28
  92. package/dist/query-engine/categorical-identity.d.ts +99 -27
  93. package/dist/query-engine/categorical-identity.js +210 -51
  94. package/dist/query-engine/index.d.ts +2 -1
  95. package/dist/query-engine/index.js +1 -0
  96. package/dist/query-engine/preagg/Preagg.d.ts +1 -1
  97. package/dist/query-engine/preagg/Preagg.js +11 -9
  98. package/dist/query-engine/preagg/plan.d.ts +9 -5
  99. package/dist/query-engine/preagg/plan.js +13 -11
  100. package/dist/query-engine/toggle-predicate.js +12 -1
  101. package/dist/scales/ActivityTable.d.ts +99 -0
  102. package/dist/scales/ActivityTable.js +211 -0
  103. package/dist/scales/BandScaleState.svelte.d.ts +28 -7
  104. package/dist/scales/BandScaleState.svelte.js +55 -20
  105. package/dist/scales/ChartScales.svelte.d.ts +2 -2
  106. package/dist/scales/ColorScaleState.svelte.d.ts +36 -8
  107. package/dist/scales/ColorScaleState.svelte.js +118 -24
  108. package/dist/scales/DomainResolver.d.ts +2 -0
  109. package/dist/scales/DomainResolver.js +15 -8
  110. package/dist/scales/ScaleRegistry.svelte.d.ts +9 -0
  111. package/dist/scales/ScaleRegistry.svelte.js +22 -1
  112. package/dist/scales/TimeScaleState.svelte.js +7 -1
  113. package/dist/spec/index.js +1 -0
  114. package/dist/spec/types.d.ts +2 -0
  115. package/dist/transforms/index.d.ts +27 -0
  116. package/dist/transforms/index.js +97 -3
  117. package/dist/types.d.ts +30 -0
  118. package/package.json +1 -1
@@ -36,6 +36,18 @@ export const COLOR_CONFIG_BYTES = 48;
36
36
  export const COLOR_CONFIG_SLOT_BASE_OFFSET = 32;
37
37
  /** `slotBase` meaning "this channel already carries a palette index". */
38
38
  export const NO_SLOT_TABLE = 0xffffffff;
39
+ /**
40
+ * The rank of a category an ordinal colour scale draws in the null colour: it
41
+ * takes no palette slot, so it reads as missing data and shifts no category's
42
+ * colour. The NULL category and the Other buckets. -1, by contrast, is a category
43
+ * outside this scale's domain, which draws transparent.
44
+ */
45
+ export const NULL_COLOR_RANK = -2;
46
+ /**
47
+ * How many colour configs the buffer holds. A uniform array has a fixed length
48
+ * in WGSL, so the shader declaration and the buffer size both read this.
49
+ */
50
+ export const MAX_COLOR_SLOTS = 64;
39
51
  export const COLOR_SCALE_STRUCTS = /* wgsl */ `
40
52
  struct ColorConfig {
41
53
  domainMin: f32, // byte 0 — pre-transformed for non-linear types
@@ -70,8 +82,14 @@ const COLOR_TRANSFORM_SYMLOG: u32 = 2u;
70
82
  const COLOR_TRANSFORM_SQRT: u32 = 3u;
71
83
  const COLOR_TRANSFORM_POW: u32 = 4u;
72
84
  `;
85
+ // colorConfigs is a UNIFORM, visible to the vertex stage as well: selection
86
+ // dimming reads a colour scale's slotBase per vertex. As storage it would take
87
+ // the last of the vertex stage's default 8 storage buffers on Rects, which uses
88
+ // 7 (six channels and the identity slot table); as a uniform it leaves that
89
+ // slot free. 64 × 48 bytes is 3 KB, written when a scale changes, which is what
90
+ // uniform buffers are for.
73
91
  export const COLOR_SCALE_BINDINGS = /* wgsl */ `
74
- @group(2) @binding(1) var<storage, read> colorConfigs: array<ColorConfig>;
92
+ @group(2) @binding(1) var<uniform> colorConfigs: array<ColorConfig, ${MAX_COLOR_SLOTS}>;
75
93
  @group(2) @binding(2) var<storage, read> colorRamps: array<vec4<f32>>;
76
94
  @group(2) @binding(3) var<storage, read> ordinalPalettes: array<vec4<f32>>;
77
95
  `;
@@ -120,7 +138,7 @@ fn sampleRamp(config: ColorConfig, t: f32) -> vec4<f32> {
120
138
  return colorRamps[config.rampOffset + idx];
121
139
  }
122
140
 
123
- fn samplePalette(config: ColorConfig, categoryIndex: u32) -> vec4<f32> {
141
+ fn samplePalette(config: ColorConfig, categoryIndex: u32, nullColor: vec4<f32>) -> vec4<f32> {
124
142
  // The channel carries an identity id, which is stable and has nothing to do
125
143
  // with this scale's palette. Resolve it to this scale's own rank first; the
126
144
  // palette is indexed by rank, so the plotted categories take palette colours
@@ -129,7 +147,12 @@ fn samplePalette(config: ColorConfig, categoryIndex: u32) -> vec4<f32> {
129
147
  if (config.slotBase != NO_SLOT_TABLE) {
130
148
  let slot = identitySlot(config.slotBase, categoryIndex);
131
149
  if (slot < 0.0) {
132
- // Not ranked by this scale: a category outside its domain.
150
+ // ${NULL_COLOR_RANK}: a category drawn in the null colour, which takes no
151
+ // palette slot (the NULL category, an Other bucket).
152
+ if (slot < -1.5) {
153
+ return nullColor;
154
+ }
155
+ // -1: not ranked by this scale, a category outside its domain.
133
156
  return vec4<f32>(0.0, 0.0, 0.0, 0.0);
134
157
  }
135
158
  idx = u32(slot);
@@ -146,7 +169,7 @@ fn getColorFromScale(scaleIndex: u32, value: f32, nullColor: vec4<f32>) -> vec4<
146
169
  return nullColor;
147
170
  }
148
171
  let catIdx = u32(value);
149
- return samplePalette(config, catIdx);
172
+ return samplePalette(config, catIdx, nullColor);
150
173
  }
151
174
 
152
175
  if (${isNanExpr('value')}) {
@@ -165,7 +188,7 @@ fn getColorFromScale(scaleIndex: u32, value: f32, nullColor: vec4<f32>) -> vec4<
165
188
  fn getOrdinalColor(scaleIndex: u32, categoryIndex: u32, nullColor: vec4<f32>) -> vec4<f32> {
166
189
  // Note: This function expects u32, so caller must handle -1 check before casting
167
190
  let config = colorConfigs[scaleIndex];
168
- return samplePalette(config, categoryIndex);
191
+ return samplePalette(config, categoryIndex, nullColor);
169
192
  }
170
193
 
171
194
  fn getContinuousColor(scaleIndex: u32, value: f32, nullColor: vec4<f32>) -> vec4<f32> {
@@ -179,4 +202,32 @@ fn getContinuousColor(scaleIndex: u32, value: f32, nullColor: vec4<f32>) -> vec4
179
202
  let t = normalizeValue(config, value);
180
203
  return sampleRamp(config, t);
181
204
  }
205
+
206
+ /**
207
+ * How selected this value's category is on an ordinal colour scale, 0..1.
208
+ *
209
+ * Read per vertex for selection dimming. 1.0 for anything that has no category
210
+ * to select: a continuous scale, an ordinal scale whose channel does not carry
211
+ * identity ids yet (NO_SLOT_TABLE), and a missing category. The -1 and NaN
212
+ * checks come before the cast, because u32() of a negative or NaN float is
213
+ * indeterminate in WGSL and would read an arbitrary activity.
214
+ */
215
+ fn colorActivity(scaleIndex: u32, value: f32, group: u32) -> f32 {
216
+ if (value < 0.0 || ${isNanExpr('value')}) {
217
+ return 1.0;
218
+ }
219
+ let config = colorConfigs[scaleIndex];
220
+ if (config.scaleType != COLOR_SCALE_ORDINAL || config.slotBase == NO_SLOT_TABLE) {
221
+ return 1.0;
222
+ }
223
+ return identityActivity(config.slotBase, group, u32(value));
224
+ }
225
+
226
+ /** A mark's colour activity in its filter group: 1.0 unless it colours through a scale. */
227
+ fn markColorActivity(colorMode: u32, colorScaleIndex: u32, colorValue: f32, group: u32) -> f32 {
228
+ if (colorMode != 1u) {
229
+ return 1.0;
230
+ }
231
+ return colorActivity(colorScaleIndex, colorValue, group);
232
+ }
182
233
  `;
@@ -1,5 +1,6 @@
1
1
  import type { RendererDefinition } from './ScaleTemplateSystem';
2
2
  import type { ScaleRegistry } from '../scales/ScaleRegistry.svelte';
3
+ import type { FilterGroupRegistry } from '../query-engine/FilterGroupRegistry.svelte';
3
4
  /** Number of color stops per ramp slot. Shared with ColorScaleState for bakeGradient(). */
4
5
  export declare const COLOR_RAMP_RESOLUTION = 256;
5
6
  interface LayerConfig {
@@ -182,6 +183,13 @@ export declare class GPUCoordinator {
182
183
  */
183
184
  releaseRenderer(rendererId: string): void;
184
185
  setScaleRegistry(scaleRegistry: ScaleRegistry): void;
186
+ /**
187
+ * The page's filter groups, whose field activity the packer writes into the
188
+ * identity slot table. Their fades run on this loop and redraw the charts
189
+ * drawing any scale on their field. Set before any selection, so no fade is
190
+ * created without the loop.
191
+ */
192
+ setFilterGroups(filterGroups: FilterGroupRegistry): void;
185
193
  registerScale(scaleId: string, scaleType?: string): void;
186
194
  unregisterScale(scaleId: string): void;
187
195
  scheduleTopologyUpdate(): void;
@@ -7,7 +7,8 @@ import { RESOLVE_IMMEDIATE_SIZE, RESOLVE_WORKGROUP, resolvePipelineFor } from '.
7
7
  import { IDENTITY_SLOT_CAPACITY, IDENTITY_SLOT_EMPTY, createIdentitySlotState, packIdentitySlots } from './identity-slot-packing';
8
8
  import { frameUniformIsStale } from './frame-uniform-sync';
9
9
  import { immediatesSupported, IMMEDIATES_MISSING_MESSAGE } from './immediates';
10
- import { COLOR_CONFIG_BYTES, COLOR_CONFIG_SLOT_BASE_OFFSET } from './ColorScaleShaderLib';
10
+ import { COLOR_CONFIG_BYTES, COLOR_CONFIG_SLOT_BASE_OFFSET, MAX_COLOR_SLOTS } from './ColorScaleShaderLib';
11
+ import { trackScalesById } from './tracked-scales';
11
12
  /** Number of color stops per ramp slot. Shared with ColorScaleState for bakeGradient(). */
12
13
  export const COLOR_RAMP_RESOLUTION = 256;
13
14
  /**
@@ -18,6 +19,8 @@ export const COLOR_RAMP_RESOLUTION = 256;
18
19
  function layerCanDraw(layer, chartScalesKnown) {
19
20
  return (!!layer.renderer?.perDataBindGroup && (chartScalesKnown || layer.readsChartScales === false));
20
21
  }
22
+ /** No fields to pack, for a coordinator without filter groups. */
23
+ const NO_FIELDS = [];
21
24
  // =============================================================================
22
25
  // HELPER CLASSES
23
26
  // =============================================================================
@@ -113,6 +116,7 @@ export class GPUCoordinator {
113
116
  #animatedSources = new Set(); // Set for O(1) membership check
114
117
  #animatedSourcesArray = []; // Array for O(1) iteration (no allocation)
115
118
  #scaleRegistry = null;
119
+ #filterGroups = null;
116
120
  // =========================================================================
117
121
  // HOVER STATE (Keep loop warm while any chart is hovered)
118
122
  // =========================================================================
@@ -196,7 +200,7 @@ export class GPUCoordinator {
196
200
  #sizeConfigBuffer = null; // MAX_SIZE_SLOTS × 16 bytes = 1KB
197
201
  #maxSizeSlots = MAX_SIZE_SLOTS;
198
202
  // Constants
199
- #maxColorSlots = 64;
203
+ #maxColorSlots = MAX_COLOR_SLOTS;
200
204
  #rampColorsPerSlot = COLOR_RAMP_RESOLUTION;
201
205
  #paletteColorsPerSlot = 32;
202
206
  // =========================================================================
@@ -363,10 +367,17 @@ export class GPUCoordinator {
363
367
  label: 'scale-resources-layout',
364
368
  entries: [
365
369
  {
366
- // Binding 1: Color scale configs (fragment only)
370
+ // Binding 1: Color scale configs.
371
+ //
372
+ // Uniform, and visible to the VERTEX stage as well: selection
373
+ // dimming reads a colour scale's slotBase per vertex. As storage
374
+ // it would take the last of the vertex stage's default 8 storage
375
+ // buffers on Rects, which uses 7; as a uniform it counts against
376
+ // the separate uniform limit and leaves that slot free. Same move
377
+ // as binding 4.
367
378
  binding: 1,
368
- visibility: GPUShaderStage.FRAGMENT, // ← Changed
369
- buffer: { type: 'read-only-storage' }
379
+ visibility: GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT,
380
+ buffer: { type: 'uniform' }
370
381
  },
371
382
  {
372
383
  // Binding 2: Color ramps (fragment only)
@@ -400,8 +411,9 @@ export class GPUCoordinator {
400
411
  // buffer and do no interpolation.
401
412
  //
402
413
  // Storage, where it used to be two uniforms. It costs the vertex
403
- // stage one binding where the pair cost none — Rects lands at 8 of
404
- // 8, the default maxStorageBuffersPerShaderStage — and in exchange
414
+ // stage one binding where the pair cost none — Rects lands at 7 of
415
+ // the default maxStorageBuffersPerShaderStage of 8, its six channels
416
+ // and this — and in exchange
405
417
  // the vec4 packing, the 64 KB uniform binding cap and the
406
418
  // 16384-float global ceiling all go away with the address space.
407
419
  //
@@ -409,8 +421,9 @@ export class GPUCoordinator {
409
421
  // the compute pipeline, which has its own budget.
410
422
  //
411
423
  // FRAGMENT as well as VERTEX: band axes resolve a slot in the
412
- // vertex stage, ordinal colour carries the same ids and resolves
413
- // in the fragment stage.
424
+ // vertex stage, and ordinal colour resolves its palette rank in
425
+ // the fragment stage. Both read their selection activity, the
426
+ // second half of each block, in the vertex stage.
414
427
  binding: 5,
415
428
  visibility: GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT,
416
429
  buffer: { type: 'read-only-storage' }
@@ -435,11 +448,12 @@ export class GPUCoordinator {
435
448
  }
436
449
  #createColorScaleBuffers() {
437
450
  const device = this.#device;
438
- // ColorConfig buffer: 64 slots × 48 bytes each
451
+ // ColorConfig buffer: 64 slots × 48 bytes each. A uniform, so the vertex
452
+ // stage can read it without a storage binding — see COLOR_SCALE_BINDINGS.
439
453
  this.#colorConfigBuffer = device.createBuffer({
440
- label: 'ColorConfig SSBO',
454
+ label: 'ColorConfig uniform',
441
455
  size: this.#maxColorSlots * COLOR_CONFIG_BYTES,
442
- usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST
456
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
443
457
  });
444
458
  // Color ramp buffer: 64 slots × 256 colors × 4 floats × 4 bytes
445
459
  this.#colorRampBuffer = device.createBuffer({
@@ -578,9 +592,16 @@ export class GPUCoordinator {
578
592
  const slots = scale.slots;
579
593
  if (!slots)
580
594
  continue;
581
- const entry = (pool[scales.length] ??= { id: '', slots });
595
+ const entry = (pool[scales.length] ??= { id: '', slots, field: null });
582
596
  entry.id = scale.id;
583
597
  entry.slots = slots;
598
+ // The field whose activity block this scale's header points at. Every
599
+ // field a scale draws has one, so a selection moves nothing; the
600
+ // registry creates its FieldActivity once (a Map lookup after that).
601
+ const field = scale.identityKey ?? null;
602
+ entry.field = field;
603
+ if (field)
604
+ this.#filterGroups?.field(field);
584
605
  scales.push(entry);
585
606
  // Index-aligned with `scales`, so the base can be handed back after
586
607
  // packing without searching for the instance again.
@@ -588,7 +609,14 @@ export class GPUCoordinator {
588
609
  ? scale
589
610
  : null);
590
611
  }
591
- const { uploadStart, uploadEnd } = packIdentitySlots(scales, state);
612
+ // Every field follows its live identity here, where nothing is reactive:
613
+ // a reload snaps its fades, a grown dim extends them. Two comparisons a
614
+ // field when nothing moved.
615
+ const registry = this.#filterGroups;
616
+ const fields = registry?.fields ?? NO_FIELDS;
617
+ for (let i = 0; i < fields.length; i++)
618
+ fields[i].reconcile();
619
+ const { uploadStart, uploadEnd } = packIdentitySlots(scales, state, fields, registry?.groupCount ?? 0);
592
620
  // Hand back the base to any scale that reads it from its own config rather
593
621
  // than from p4. A band scale's base is refilled into p4 every frame; an
594
622
  // ordinal colour scale's lives in a config uploaded only when the scale
@@ -960,12 +988,13 @@ export class GPUCoordinator {
960
988
  }
961
989
  const passEncoder = commandEncoder.beginRenderPass(this.#createRenderPassDescriptor(view, chartConfig));
962
990
  // The chart's scales, written once for the whole pass and before the
963
- // first draw. Every pipeline declares the same 32 bytes and a draw
964
- // requires every declared byte to have been set, so this is the whole
965
- // range, every pass. Immediate data survives setPipeline between
966
- // layouts of the same size, which is what makes once enough. Pushed even
967
- // when the chart's scales are not both known: a layer that does not
968
- // read them still needs every byte set before it may draw.
991
+ // first draw. Every pipeline declares the same
992
+ // CHART_SCALE_IMMEDIATE_SIZE and a draw requires every declared byte to
993
+ // have been set, so this is the whole range, every pass. Immediate data
994
+ // survives setPipeline between layouts of the same size, which is what
995
+ // makes once enough. Pushed even when the chart's scales are not both
996
+ // known: a layer that does not read them still needs every byte set
997
+ // before it may draw.
969
998
  const scalesKnown = this.#writeChartScales(chartConfig, this.#chartScaleImmediates);
970
999
  passEncoder.setImmediates(0, this.#chartScaleImmediates);
971
1000
  if (chartConfig.perFrameBindGroup) {
@@ -1226,6 +1255,16 @@ export class GPUCoordinator {
1226
1255
  setScaleRegistry(scaleRegistry) {
1227
1256
  this.#scaleRegistry = scaleRegistry;
1228
1257
  }
1258
+ /**
1259
+ * The page's filter groups, whose field activity the packer writes into the
1260
+ * identity slot table. Their fades run on this loop and redraw the charts
1261
+ * drawing any scale on their field. Set before any selection, so no fade is
1262
+ * created without the loop.
1263
+ */
1264
+ setFilterGroups(filterGroups) {
1265
+ this.#filterGroups = filterGroups;
1266
+ filterGroups.setAnimation(this, (key, out) => this.#scaleRegistry ? this.#scaleRegistry.chartsDrawingField(key, out) : out);
1267
+ }
1229
1268
  registerScale(scaleId, scaleType = 'linear') {
1230
1269
  if (!this.#initialized)
1231
1270
  return;
@@ -1249,18 +1288,15 @@ export class GPUCoordinator {
1249
1288
  const usageMap = this.#scaleRegistry.scaleUsage;
1250
1289
  if (!usageMap || typeof usageMap[Symbol.iterator] !== 'function')
1251
1290
  return;
1252
- // Clear and rebuild
1253
- this.#scaleIdToInstance.clear();
1254
- for (const [scaleInstance] of usageMap) {
1255
- // Only positional scales (Linear, Band, Time) carry an id.
1256
- const scale = scaleInstance;
1257
- if (!scale?.id)
1258
- continue;
1259
- // The redraw list is NOT rebuilt here any more. It belongs to the
1260
- // registry, derived from the same usage map this reads, and a scale
1261
- // asks for it. Copying it from a second owner is how it went stale.
1262
- this.#scaleIdToInstance.set(scale.id, scale);
1263
- }
1291
+ // Clear and rebuild: every scale with an id — positional scales, and
1292
+ // ordinal colour, whose slots the packer needs too. The id map is only
1293
+ // looked up with a chart's x and y scale ids, so a colour scale in it is
1294
+ // never mistaken for a positional one.
1295
+ //
1296
+ // The redraw list is NOT rebuilt here any more. It belongs to the
1297
+ // registry, derived from the same usage map this reads, and a scale asks
1298
+ // for it. Copying it from a second owner is how it went stale.
1299
+ trackScalesById(usageMap.keys(), this.#scaleIdToInstance);
1264
1300
  this.#scales = [...this.#scaleIdToInstance.values()];
1265
1301
  }
1266
1302
  // =========================================================================
@@ -6,8 +6,8 @@
6
6
  * are bound to the compute pipeline; the render stages bind `resolved` alone.
7
7
  * So an animated channel REPLACES a vertex binding rather than adding one, and
8
8
  * animating any number of channels leaves that stage's budget where it was —
9
- * which is what makes this affordable on a mark that already sits at the
10
- * default limit of 8.
9
+ * which is what makes this affordable on a mark that already uses 7 of the
10
+ * default 8 storage buffers (Rects).
11
11
  *
12
12
  * ONE KERNEL FOR BOTH, because the two differ only in where a range starts. A
13
13
  * value channel is one mark's rows in buffers of their own, so it starts at 0.
@@ -7,8 +7,8 @@ import { isNanExpr } from './NanShaderLib';
7
7
  * are bound to the compute pipeline; the render stages bind `resolved` alone.
8
8
  * So an animated channel REPLACES a vertex binding rather than adding one, and
9
9
  * animating any number of channels leaves that stage's budget where it was —
10
- * which is what makes this affordable on a mark that already sits at the
11
- * default limit of 8.
10
+ * which is what makes this affordable on a mark that already uses 7 of the
11
+ * default 8 storage buffers (Rects).
12
12
  *
13
13
  * ONE KERNEL FOR BOTH, because the two differ only in where a range starts. A
14
14
  * value channel is one mark's rows in buffers of their own, so it starts at 0.
@@ -36,6 +36,9 @@ interface ShaderResult {
36
36
  * `ScaleParam`, 16 bytes each. Every layout declares the same size because a
37
37
  * draw requires every declared byte to have been set, and the pass sets them
38
38
  * once, before its first draw.
39
+ *
40
+ * Immediates carry state shared across the pass and read by several marks: the
41
+ * chart's scales and settings. 64 bytes are available on M-series Macs.
39
42
  */
40
43
  export declare const CHART_SCALE_IMMEDIATE_SIZE = 32;
41
44
  /**
@@ -66,6 +69,22 @@ export declare class ScaleTemplateSystem {
66
69
  * @private
67
70
  */
68
71
  _buildDeclarations(xFragment: ScaleFragment, yFragment: ScaleFragment): string;
72
+ /**
73
+ * `bandActivityX(value, group)` and `bandActivityY(value, group)`: how
74
+ * selected a band or point axis's category is in the mark's filter group,
75
+ * 0..1, for selection dimming.
76
+ *
77
+ * Emitted for every shader, so a renderer can call both without knowing its
78
+ * scale types: an axis that is not band or point returns 1.0. On a band or
79
+ * point axis the value is an identity id and the chart's scale carries its
80
+ * block base in p4, as for the slot lookup. A missing category (-1) or a NaN
81
+ * is fully active, checked before the cast, since u32() of a negative or NaN
82
+ * float is indeterminate in WGSL.
83
+ */
84
+ _buildBandActivityHelpers(scaleTypes: {
85
+ x: string;
86
+ y: string;
87
+ }): string;
69
88
  /**
70
89
  * The shared slot table, and the lookup into it.
71
90
  *
@@ -1,6 +1,9 @@
1
1
  // src/lib/gpu/ScaleTemplateSystem.ts
2
2
  import { COLOR_SCALE_STRUCTS, COLOR_SCALE_BINDINGS, COLOR_SCALE_FUNCTIONS } from './ColorScaleShaderLib';
3
3
  import { SIZE_SCALE_STRUCTS, SIZE_SCALE_BINDINGS, SIZE_SCALE_FUNCTIONS } from './SizeScaleShaderLib';
4
+ import { NO_GROUP } from './identity-slot-packing';
5
+ import { isNanExpr } from './NanShaderLib';
6
+ import { DEFAULT_INACTIVE_OPACITY } from '../scales/ActivityTable';
4
7
  /**
5
8
  * Scale fragment definitions
6
9
  * Each scale type provides: declaration, function call, and implementation
@@ -280,6 +283,9 @@ function _scaleFunctionName(scaleType, axis) {
280
283
  * `ScaleParam`, 16 bytes each. Every layout declares the same size because a
281
284
  * draw requires every declared byte to have been set, and the pass sets them
282
285
  * once, before its first draw.
286
+ *
287
+ * Immediates carry state shared across the pass and read by several marks: the
288
+ * chart's scales and settings. 64 bytes are available on M-series Macs.
283
289
  */
284
290
  export const CHART_SCALE_IMMEDIATE_SIZE = 32;
285
291
  /**
@@ -370,6 +376,7 @@ export class ScaleTemplateSystem {
370
376
  // ===== 3. HELPER FUNCTIONS =====
371
377
 
372
378
  ${this._buildSlotTableHelpers()}
379
+ ${this._buildBandActivityHelpers(scaleTypes)}
373
380
  ${bandHelpers}
374
381
  ${implementations}
375
382
  ${scaleFunctions}
@@ -409,6 +416,24 @@ export class ScaleTemplateSystem {
409
416
  };
410
417
  var<immediate> chartScales: ChartScales;
411
418
 
419
+ // Selection dimming: a mark's activity mapped to an opacity, with
420
+ // inactive categories at DEFAULT_INACTIVE_OPACITY. selectionOpacity in
421
+ // ActivityTable.ts is its CPU twin, for band labels and legend entries,
422
+ // and both read the same constant so they cannot drift apart.
423
+ const SELECTION_DIM_STRENGTH: f32 = ${(1 - DEFAULT_INACTIVE_OPACITY).toFixed(6)};
424
+ fn selectionDim(activity: f32) -> f32 {
425
+ return 1.0 - SELECTION_DIM_STRENGTH * (1.0 - activity);
426
+ }
427
+
428
+ // A mark's activities combined: colour, and band for marks on band axes.
429
+ // The least active wins rather than the product, so a bar whose colour
430
+ // and band are the same field fades on the same curve as its label
431
+ // instead of twice as fast. At rest every activity is 0 or 1, where the
432
+ // two agree.
433
+ fn markActivity(color: f32, bandX: f32, bandY: f32) -> f32 {
434
+ return min(color, min(bandX, bandY));
435
+ }
436
+
412
437
  // The ONE place that says where a chart's scales come from. Every
413
438
  // consumer reads through these — scaleX/scaleY, the bandwidth helpers,
414
439
  // and mark code that needs the raw params. A mark with scales of its own
@@ -423,6 +448,39 @@ export class ScaleTemplateSystem {
423
448
  `;
424
449
  return `${structDef}\n${chartScaleDeclaration}`;
425
450
  }
451
+ /**
452
+ * `bandActivityX(value, group)` and `bandActivityY(value, group)`: how
453
+ * selected a band or point axis's category is in the mark's filter group,
454
+ * 0..1, for selection dimming.
455
+ *
456
+ * Emitted for every shader, so a renderer can call both without knowing its
457
+ * scale types: an axis that is not band or point returns 1.0. On a band or
458
+ * point axis the value is an identity id and the chart's scale carries its
459
+ * block base in p4, as for the slot lookup. A missing category (-1) or a NaN
460
+ * is fully active, checked before the cast, since u32() of a negative or NaN
461
+ * float is indeterminate in WGSL.
462
+ */
463
+ _buildBandActivityHelpers(scaleTypes) {
464
+ const helper = (axis, type) => {
465
+ if (type !== 'band' && type !== 'point') {
466
+ return `fn bandActivity${axis}(value: f32, group: u32) -> f32 {
467
+ return 1.0;
468
+ }`;
469
+ }
470
+ return `fn bandActivity${axis}(value: f32, group: u32) -> f32 {
471
+ if (value < 0.0 || ${isNanExpr('value')}) {
472
+ return 1.0;
473
+ }
474
+ return identityActivity(u32(chartScale${axis}().p4), group, u32(value));
475
+ }`;
476
+ };
477
+ return `
478
+ // ===== BAND SELECTION ACTIVITY =====
479
+ ${helper('X', scaleTypes.x)}
480
+
481
+ ${helper('Y', scaleTypes.y)}
482
+ `;
483
+ }
426
484
  /**
427
485
  * The shared slot table, and the lookup into it.
428
486
  *
@@ -459,12 +517,12 @@ export class ScaleTemplateSystem {
459
517
  }
460
518
 
461
519
  fn identitySlot(base: u32, id: u32) -> f32 {
462
- // Block layout: [count, slot0, slot1, ...]. The count is what makes a
463
- // block self-describing, so an id past this scale's end is discarded
464
- // instead of reading into the next scale's slots. It survives the resolve
465
- // exactly because it holds the same value in both halves, and the kernel
466
- // returns equal ends as they are — u32() truncates, so an inexact mix
467
- // would drop the last id.
520
+ // Block layout: [count, actRef, n, slot0, slot1, ...]. The count is what
521
+ // makes a block self-describing, so an id past this scale's end is
522
+ // discarded instead of reading into the next scale's slots. It survives
523
+ // the resolve exactly because it holds the same value in both halves, and
524
+ // the kernel returns equal ends as they are — u32() truncates, so an
525
+ // inexact mix would drop the last id.
468
526
  let count = u32(identitySlots[base]);
469
527
  if (id >= count) {
470
528
  return -1.0;
@@ -473,7 +531,28 @@ export class ScaleTemplateSystem {
473
531
  // both halves, so the resolve wrote -1 without a branch; one that is
474
532
  // leaving holds a real slot in both, which is what lets it travel. The
475
533
  // scale normalises that before packing, so nothing here re-derives it.
476
- return identitySlots[base + 1u + id];
534
+ return identitySlots[base + 3u + id];
535
+ }
536
+
537
+ fn identityActivity(base: u32, group: u32, id: u32) -> f32 {
538
+ // How selected this id is in the mark's filter group, 1 active and 0
539
+ // inactive, already resolved at that group's selection clock. The scale
540
+ // block's header points at its field's activity block (actRef) and says
541
+ // how many ids it covers (n); the block holds one run of n per group.
542
+ // Header first, so this is two dependent reads. Past n, or in the empty
543
+ // block where n is 0, an id is fully active.
544
+ //
545
+ // NO_GROUP (a mark whose selectionResponse is 'filter') is fully active,
546
+ // checked before anything is read, so it never becomes an offset.
547
+ if (group == ${NO_GROUP}u) {
548
+ return 1.0;
549
+ }
550
+ let actRef = u32(identitySlots[base + 1u]);
551
+ let n = u32(identitySlots[base + 2u]);
552
+ if (id >= n) {
553
+ return 1.0;
554
+ }
555
+ return identitySlots[actRef + n * group + id];
477
556
  }
478
557
  `;
479
558
  }
@@ -19,10 +19,10 @@ export declare const MAX_SIZE_SLOTS = 64;
19
19
  * changes rather than per frame. Every property that makes a uniform buffer the
20
20
  * right container was already true of it.
21
21
  *
22
- * What it buys: the vertex stage sits at the default
23
- * maxStorageBuffersPerShaderStage of 8 (six mark channels, scale params, and
24
- * this), and animating a value channel needs a `from` and a `to` where there is
25
- * now one buffer. Uniform buffers are nowhere near their own default of 12.
22
+ * What it buys: a slot in the vertex stage's storage budget, the default
23
+ * maxStorageBuffersPerShaderStage of 8, of which Rects uses 7 (six mark
24
+ * channels and the identity slot table). Uniform buffers are nowhere near
25
+ * their own default of 12.
26
26
  *
27
27
  * Dynamic indexing — `sizeConfigs[scaleIndex]` — is permitted on uniform arrays
28
28
  * in WGSL, and the shared slot table already relies on the same thing.
@@ -28,10 +28,10 @@ export const MAX_SIZE_SLOTS = 64;
28
28
  * changes rather than per frame. Every property that makes a uniform buffer the
29
29
  * right container was already true of it.
30
30
  *
31
- * What it buys: the vertex stage sits at the default
32
- * maxStorageBuffersPerShaderStage of 8 (six mark channels, scale params, and
33
- * this), and animating a value channel needs a `from` and a `to` where there is
34
- * now one buffer. Uniform buffers are nowhere near their own default of 12.
31
+ * What it buys: a slot in the vertex stage's storage budget, the default
32
+ * maxStorageBuffersPerShaderStage of 8, of which Rects uses 7 (six mark
33
+ * channels and the identity slot table). Uniform buffers are nowhere near
34
+ * their own default of 12.
35
35
  *
36
36
  * Dynamic indexing — `sizeConfigs[scaleIndex]` — is permitted on uniform arrays
37
37
  * in WGSL, and the shared slot table already relies on the same thing.