gladly-plot 0.0.7 → 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.7",
3
+ "version": "0.0.8",
4
4
  "description": "GPU-powered multi-axis plotting library with regl + d3",
5
5
  "type": "module",
6
6
  "exports": {
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)
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
  }