gladly-plot 0.0.6 → 0.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gladly-plot",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "GPU-powered multi-axis plotting library with regl + d3",
5
5
  "type": "module",
6
6
  "exports": {
@@ -242,15 +242,17 @@ export class LayerType {
242
242
  }
243
243
 
244
244
  for (const [suffix, qk] of Object.entries(layer.colorAxes)) {
245
- uniforms[`colorscale${suffix}`] = regl.prop(`colorscale_${qk}`)
246
- uniforms[`color_range${suffix}`] = regl.prop(`color_range_${qk}`)
247
- uniforms[`color_scale_type${suffix}`] = regl.prop(`color_scale_type_${qk}`)
248
- uniforms[`alpha_blend${suffix}`] = regl.prop(`alpha_blend_${qk}`)
245
+ const pk = qk.replace(/\./g, '_')
246
+ uniforms[`colorscale${suffix}`] = regl.prop(`colorscale_${pk}`)
247
+ uniforms[`color_range${suffix}`] = regl.prop(`color_range_${pk}`)
248
+ uniforms[`color_scale_type${suffix}`] = regl.prop(`color_scale_type_${pk}`)
249
+ uniforms[`alpha_blend${suffix}`] = regl.prop(`alpha_blend_${pk}`)
249
250
  }
250
251
 
251
252
  for (const [suffix, qk] of Object.entries(layer.filterAxes)) {
252
- uniforms[`filter_range${suffix}`] = regl.prop(`filter_range_${qk}`)
253
- uniforms[`filter_scale_type${suffix}`] = regl.prop(`filter_scale_type_${qk}`)
253
+ const pk = qk.replace(/\./g, '_')
254
+ uniforms[`filter_range${suffix}`] = regl.prop(`filter_range_${pk}`)
255
+ uniforms[`filter_scale_type${suffix}`] = regl.prop(`filter_scale_type_${pk}`)
254
256
  }
255
257
 
256
258
  // Strip spatial uniforms from vert (re-declared in buildSpatialGlsl)
package/src/core/Plot.js CHANGED
@@ -98,46 +98,20 @@ function buildPlotSchema(data, config) {
98
98
  },
99
99
  axes: {
100
100
  type: "object",
101
- properties: {
102
- xaxis_bottom: {
101
+ properties: Object.fromEntries(AXES.map(axisId => {
102
+ const isXAxis = axisId.startsWith('x')
103
+ return [axisId, {
103
104
  type: "object",
104
105
  properties: {
106
+ quantity_kind: { type: "string" },
105
107
  min: { type: "number" },
106
108
  max: { type: "number" },
107
109
  label: { type: "string" },
108
110
  scale: { type: "string", enum: ["linear", "log"] },
109
- rotate: { type: "boolean" }
111
+ ...(isXAxis ? { rotate: { type: "boolean" } } : {})
110
112
  }
111
- },
112
- xaxis_top: {
113
- type: "object",
114
- properties: {
115
- min: { type: "number" },
116
- max: { type: "number" },
117
- label: { type: "string" },
118
- scale: { type: "string", enum: ["linear", "log"] },
119
- rotate: { type: "boolean" }
120
- }
121
- },
122
- yaxis_left: {
123
- type: "object",
124
- properties: {
125
- min: { type: "number" },
126
- max: { type: "number" },
127
- label: { type: "string" },
128
- scale: { type: "string", enum: ["linear", "log"] }
129
- }
130
- },
131
- yaxis_right: {
132
- type: "object",
133
- properties: {
134
- min: { type: "number" },
135
- max: { type: "number" },
136
- label: { type: "string" },
137
- scale: { type: "string", enum: ["linear", "log"] }
138
- }
139
- }
140
- },
113
+ }]
114
+ })),
141
115
  additionalProperties: {
142
116
  // Color/filter/quantity-kind axes.
143
117
  // All fields from the quantity kind registration are valid here and override the registration.
@@ -335,7 +309,7 @@ export class Plot extends GlBase {
335
309
  const [min, max] = scale.domain()
336
310
  const qk = this.axisRegistry.axisQuantityKinds[axisId]
337
311
  const qkDef = qk ? getAxisQuantityKind(qk) : {}
338
- axes[axisId] = { ...qkDef, ...(axes[axisId] ?? {}), min, max }
312
+ axes[axisId] = { ...qkDef, ...(axes[axisId] ?? {}), min, max, ...(qk ? { quantity_kind: qk } : {}) }
339
313
  }
340
314
  }
341
315
  }
@@ -411,7 +385,21 @@ export class Plot extends GlBase {
411
385
  if (this._initEpoch !== epoch) return
412
386
  await this._processLayers(layers, this.currentData, epoch)
413
387
  if (this._initEpoch !== epoch) return
414
- this._setDomains(axes)
388
+
389
+ // Discard any spatial axis config whose stored quantity_kind doesn't match
390
+ // Discard any spatial axis config whose stored quantity_kind doesn't match
391
+ // what the layers assigned — stale settings from a previous axis type.
392
+ const cleanAxes = { ...axes }
393
+ for (const axisId of AXES) {
394
+ const cfg = cleanAxes[axisId]
395
+ if (cfg?.quantity_kind != null &&
396
+ cfg.quantity_kind !== this.axisRegistry.axisQuantityKinds[axisId]) {
397
+ delete cleanAxes[axisId]
398
+ }
399
+ }
400
+ this.currentConfig = { ...this.currentConfig, axes: cleanAxes }
401
+
402
+ this._setDomains(cleanAxes)
415
403
 
416
404
  // Detect 3D mode: any axis outside the 4 standard 2D positions has a scale.
417
405
  this._is3D = AXES.some(a => !AXES_2D.includes(a) && this.axisRegistry.getScale(a) !== null)
@@ -1052,16 +1040,18 @@ void main() {
1052
1040
  }
1053
1041
 
1054
1042
  for (const qk of Object.values(layer.colorAxes)) {
1055
- props[`colorscale_${qk}`] = this.colorAxisRegistry.getColorscaleIndex(qk)
1043
+ const pk = qk.replace(/\./g, '_')
1044
+ props[`colorscale_${pk}`] = this.colorAxisRegistry.getColorscaleIndex(qk)
1056
1045
  const range = this.colorAxisRegistry.getRange(qk)
1057
- props[`color_range_${qk}`] = range ?? [0, 1]
1058
- props[`color_scale_type_${qk}`] = this._getScaleTypeFloat(qk)
1059
- props[`alpha_blend_${qk}`] = this.colorAxisRegistry.getAlphaBlend(qk)
1046
+ props[`color_range_${pk}`] = range ?? [0, 1]
1047
+ props[`color_scale_type_${pk}`] = this._getScaleTypeFloat(qk)
1048
+ props[`alpha_blend_${pk}`] = this.colorAxisRegistry.getAlphaBlend(qk)
1060
1049
  }
1061
1050
 
1062
1051
  for (const qk of Object.values(layer.filterAxes)) {
1063
- props[`filter_range_${qk}`] = this.filterAxisRegistry.getRangeUniform(qk)
1064
- props[`filter_scale_type_${qk}`] = this._getScaleTypeFloat(qk)
1052
+ const pk = qk.replace(/\./g, '_')
1053
+ props[`filter_range_${pk}`] = this.filterAxisRegistry.getRangeUniform(qk)
1054
+ props[`filter_scale_type_${pk}`] = this._getScaleTypeFloat(qk)
1065
1055
  }
1066
1056
 
1067
1057
  layer.draw(props)
@@ -1178,15 +1168,17 @@ void main() {
1178
1168
  }
1179
1169
  if (layer.instanceCount !== null) props.instances = layer.instanceCount
1180
1170
  for (const qk of Object.values(layer.colorAxes)) {
1181
- props[`colorscale_${qk}`] = this.colorAxisRegistry.getColorscaleIndex(qk)
1171
+ const pk = qk.replace(/\./g, '_')
1172
+ props[`colorscale_${pk}`] = this.colorAxisRegistry.getColorscaleIndex(qk)
1182
1173
  const range = this.colorAxisRegistry.getRange(qk)
1183
- props[`color_range_${qk}`] = range ?? [0, 1]
1184
- props[`color_scale_type_${qk}`] = this._getScaleTypeFloat(qk)
1185
- props[`alpha_blend_${qk}`] = this.colorAxisRegistry.getAlphaBlend(qk)
1174
+ props[`color_range_${pk}`] = range ?? [0, 1]
1175
+ props[`color_scale_type_${pk}`] = this._getScaleTypeFloat(qk)
1176
+ props[`alpha_blend_${pk}`] = this.colorAxisRegistry.getAlphaBlend(qk)
1186
1177
  }
1187
1178
  for (const qk of Object.values(layer.filterAxes)) {
1188
- props[`filter_range_${qk}`] = this.filterAxisRegistry.getRangeUniform(qk)
1189
- props[`filter_scale_type_${qk}`] = this._getScaleTypeFloat(qk)
1179
+ const pk = qk.replace(/\./g, '_')
1180
+ props[`filter_range_${pk}`] = this.filterAxisRegistry.getRangeUniform(qk)
1181
+ props[`filter_scale_type_${pk}`] = this._getScaleTypeFloat(qk)
1190
1182
  }
1191
1183
  layer.draw(props)
1192
1184
  }
package/src/data/Data.js CHANGED
@@ -265,6 +265,18 @@ export class Data {
265
265
  }
266
266
 
267
267
  getDomain(col) {
268
- return this._entry(col).domain
268
+ const entry = this._entry(col)
269
+ if (entry.domain) return entry.domain
270
+ const arr = entry.data
271
+ if (!arr || arr.length === 0) return null
272
+ let min = Infinity, max = -Infinity
273
+ for (let i = 0; i < arr.length; i++) {
274
+ const v = arr[i]
275
+ if (isFinite(v)) {
276
+ if (v < min) min = v
277
+ if (v > max) max = v
278
+ }
279
+ }
280
+ return min === Infinity ? null : [min, max]
269
281
  }
270
282
  }