@ixfx/components 0.4.2 → 0.4.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.
package/bundle/index.js CHANGED
@@ -30795,6 +30795,8 @@ function applyAgeModification(base, ageFraction, ageStyle) {
30795
30795
  */
30796
30796
  var PlotDataSeries = class {
30797
30797
  #rangeStream;
30798
+ #rangeAuto;
30799
+ #rangeManual;
30798
30800
  #options;
30799
30801
  /**
30800
30802
  * Constructor.
@@ -30802,20 +30804,46 @@ var PlotDataSeries = class {
30802
30804
  * Default options:
30803
30805
  * - `capacityLimit`: 100
30804
30806
  * - `persistentScaling`: true
30807
+ * - `fixedRange`: null
30805
30808
  * @param options
30806
30809
  */
30807
30810
  constructor(options = {}) {
30808
30811
  this.values = [];
30809
30812
  this.#rangeStream = rangeStream();
30810
- this.range = {
30813
+ this.#rangeAuto = {
30811
30814
  min: 0,
30812
30815
  max: 0
30813
30816
  };
30817
+ this.#rangeManual = null;
30814
30818
  this.#options = {
30815
30819
  capacityLimit: 100,
30816
30820
  persistentScaling: true,
30821
+ fixedRange: null,
30817
30822
  ...options
30818
30823
  };
30824
+ if (this.#options.fixedRange !== null) this.#rangeManual = this.#options.fixedRange;
30825
+ }
30826
+ /**
30827
+ * Sets a manual range, this disabled auto-scaling.
30828
+ * Use {@link unsetRange} to re-enable auto-scaling.
30829
+ * @param min
30830
+ * @param max
30831
+ */
30832
+ setRange(min, max) {
30833
+ this.#rangeManual = {
30834
+ min,
30835
+ max
30836
+ };
30837
+ }
30838
+ /**
30839
+ * Disable the manual range
30840
+ */
30841
+ unsetRange() {
30842
+ this.#rangeManual = null;
30843
+ this.#recompute();
30844
+ }
30845
+ get isAutoRange() {
30846
+ return this.#rangeManual === null;
30819
30847
  }
30820
30848
  /**
30821
30849
  * Adds a single value
@@ -30824,19 +30852,19 @@ var PlotDataSeries = class {
30824
30852
  add(valueOrValues) {
30825
30853
  if (typeof valueOrValues === `number`) {
30826
30854
  this.values.push(valueOrValues);
30827
- this.range = this.#rangeStream.seen(valueOrValues);
30855
+ if (this.isAutoRange) this.#rangeAuto = this.#rangeStream.seen(valueOrValues);
30828
30856
  } else {
30829
30857
  this.values.push(...valueOrValues);
30830
- for (const v of valueOrValues) this.range = this.#rangeStream.seen(v);
30858
+ if (this.isAutoRange) for (const v of valueOrValues) this.#rangeAuto = this.#rangeStream.seen(v);
30831
30859
  }
30832
30860
  if (this.values.length > this.#options.capacityLimit) {
30833
30861
  this.values = this.values.slice(this.values.length - this.#options.capacityLimit);
30834
- if (!this.#options.persistentScaling) this.#recompute();
30862
+ if (!this.#options.persistentScaling && this.isAutoRange) this.#recompute();
30835
30863
  }
30836
30864
  }
30837
30865
  #recompute() {
30838
30866
  if (!this.#options.persistentScaling) this.#rangeStream = rangeStream();
30839
- for (let i = 0; i < this.values.length; i++) this.range = this.#rangeStream.seen(this.values[i]);
30867
+ for (let i = 0; i < this.values.length; i++) this.#rangeAuto = this.#rangeStream.seen(this.values[i]);
30840
30868
  }
30841
30869
  /**
30842
30870
  * Sets the entire data series at once, replacing any existing data. If the number of values exceeds the `capacityLimit`, only the most recent values up to the limit are kept.
@@ -30848,6 +30876,13 @@ var PlotDataSeries = class {
30848
30876
  this.#recompute();
30849
30877
  }
30850
30878
  /**
30879
+ * Returns the manual range if this is in effect, or the automatic
30880
+ */
30881
+ get range() {
30882
+ if (this.#rangeManual) return this.#rangeManual;
30883
+ return this.#rangeAuto;
30884
+ }
30885
+ /**
30851
30886
  * Clear all data and reset range. If `persistentScaling` is _false_, also resets scaling to initial state.
30852
30887
  * @returns _true_ if there was data to clear
30853
30888
  */
@@ -31465,6 +31500,8 @@ let PlotSingleAxis = class PlotSingleAxis extends i$4 {
31465
31500
  this.precise = false;
31466
31501
  this.tooltips = true;
31467
31502
  this.capacity = 100;
31503
+ this.rangeMin = NaN;
31504
+ this.rangeMax = NaN;
31468
31505
  this.persistentScale = true;
31469
31506
  this.paused = false;
31470
31507
  this.clickPauses = false;
@@ -31476,10 +31513,7 @@ let PlotSingleAxis = class PlotSingleAxis extends i$4 {
31476
31513
  this.colorValueMap = null;
31477
31514
  this._width = 100;
31478
31515
  this._height = 40;
31479
- this.#series = new PlotDataSeries({
31480
- capacityLimit: 100,
31481
- persistentScaling: true
31482
- });
31516
+ this.#series = new PlotDataSeries();
31483
31517
  this.#hasProgrammaticData = false;
31484
31518
  this.#lastClientX = null;
31485
31519
  this.#lastClientY = null;
@@ -31531,32 +31565,6 @@ let PlotSingleAxis = class PlotSingleAxis extends i$4 {
31531
31565
  return text.trim().split(/[,\s;]+/).map((t) => Number.parseFloat(t)).filter((n) => !Number.isNaN(n));
31532
31566
  }
31533
31567
  /**
31534
- * Get all values in the data series as a readonly array.
31535
- */
31536
- get values() {
31537
- return this.#series.values;
31538
- }
31539
- /**
31540
- * Get length of data series
31541
- */
31542
- get dataCount() {
31543
- return this.#series.values.length;
31544
- }
31545
- /**
31546
- * Get value at specific index of data series
31547
- * @param index
31548
- */
31549
- getValueAt(index) {
31550
- return this.#series.values[index];
31551
- }
31552
- /**
31553
- * Get value index based on client X position
31554
- * @param clientX
31555
- */
31556
- getIndexFromClientX(clientX) {
31557
- return this.#getIndexFromX(clientX, this.getBoundingClientRect());
31558
- }
31559
- /**
31560
31568
  * Adds a value to the data series.
31561
31569
  *
31562
31570
  * Pass `withholdRedraw = true` to prevent automatic redraw after adding the value. In this case, call `redraw()` manually after adding all values to update the plot.
@@ -31618,11 +31626,16 @@ let PlotSingleAxis = class PlotSingleAxis extends i$4 {
31618
31626
  }
31619
31627
  }
31620
31628
  updated(changed) {
31621
- if (changed.has(`capacity`) || changed.has(`persistentScale`)) {
31629
+ if (changed.has(`capacity`) || changed.has(`persistentScale`) || changed.has(`rangeMin`) || changed.has(`rangeMax`)) {
31622
31630
  const old = [...this.#series.values];
31631
+ const fixedRange = !Number.isNaN(this.rangeMin) && !Number.isNaN(this.rangeMax) ? {
31632
+ min: this.rangeMin,
31633
+ max: this.rangeMax
31634
+ } : null;
31623
31635
  this.#series = new PlotDataSeries({
31624
31636
  capacityLimit: this.capacity,
31625
- persistentScaling: this.persistentScale
31637
+ persistentScaling: this.persistentScale,
31638
+ fixedRange
31626
31639
  });
31627
31640
  if (old.length > 0) this.#series.set(old);
31628
31641
  }
@@ -31659,7 +31672,7 @@ let PlotSingleAxis = class PlotSingleAxis extends i$4 {
31659
31672
  const widthPerPoint = n > 0 ? plotW / n : plotW;
31660
31673
  const scaleX = (i) => padding + (i + .5) * widthPerPoint;
31661
31674
  return values.map((value, index) => {
31662
- const sv = scaleValue(value, min, max);
31675
+ const sv = clamp$3(scaleValue(value, min, max));
31663
31676
  const ageFraction = n > 1 ? index / (n - 1) : 1;
31664
31677
  return {
31665
31678
  x: scaleX(index),
@@ -31671,6 +31684,35 @@ let PlotSingleAxis = class PlotSingleAxis extends i$4 {
31671
31684
  };
31672
31685
  });
31673
31686
  }
31687
+ get series() {
31688
+ return this.#series;
31689
+ }
31690
+ /**
31691
+ * Get all values in the data series as a readonly array.
31692
+ */
31693
+ get values() {
31694
+ return this.#series.values;
31695
+ }
31696
+ /**
31697
+ * Get length of data series
31698
+ */
31699
+ get dataLength() {
31700
+ return this.#series.values.length;
31701
+ }
31702
+ /**
31703
+ * Get value at specific index of data series
31704
+ * @param index
31705
+ */
31706
+ getValueAt(index) {
31707
+ return this.#series.values[index];
31708
+ }
31709
+ /**
31710
+ * Get value index based on client X position
31711
+ * @param clientX
31712
+ */
31713
+ getIndexFromClientX(clientX) {
31714
+ return this.#getIndexFromX(clientX, this.getBoundingClientRect());
31715
+ }
31674
31716
  #renderByStyle(points, crs, strokeW, radius, barW, bottom, top, mid) {
31675
31717
  const lineCr = crs.at(-1) ?? {
31676
31718
  fill: `currentColor`,
@@ -31781,6 +31823,8 @@ __decorate$1([n$2()], PlotSingleAxis.prototype, "title", void 0);
31781
31823
  __decorate$1([n$2({ type: Boolean })], PlotSingleAxis.prototype, "precise", void 0);
31782
31824
  __decorate$1([n$2({ type: Boolean })], PlotSingleAxis.prototype, "tooltips", void 0);
31783
31825
  __decorate$1([n$2({ type: Number })], PlotSingleAxis.prototype, "capacity", void 0);
31826
+ __decorate$1([n$2({ type: Number })], PlotSingleAxis.prototype, "rangeMin", void 0);
31827
+ __decorate$1([n$2({ type: Number })], PlotSingleAxis.prototype, "rangeMax", void 0);
31784
31828
  __decorate$1([n$2({
31785
31829
  type: Boolean,
31786
31830
  attribute: `persistent-scale`