@genome-spy/core 0.32.0 → 0.32.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018-2023 Kari Lavikka
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.es.js CHANGED
@@ -7585,9 +7585,7 @@ class tu {
7585
7585
  // e.g., view background or an x axis.
7586
7586
  // This could also be more generic and work with other faceting views
7587
7587
  // that will be available in the future.
7588
- [...this.unitView.getAncestors()].find(
7589
- (t) => "samples" in t.spec
7590
- )
7588
+ this.unitView.getAncestors().find((t) => "samples" in t.spec)
7591
7589
  )
7592
7590
  return ZM;
7593
7591
  }
@@ -7855,7 +7853,7 @@ class tu {
7855
7853
  }
7856
7854
  /**
7857
7855
  * @param {DrawFunction} draw A function that draws a range of vertices
7858
- * @param {import("./Mark").MarkRenderingOptions} options
7856
+ * @param {import("./mark").MarkRenderingOptions} options
7859
7857
  */
7860
7858
  createRenderCallback(t, n) {
7861
7859
  var l;
@@ -8089,12 +8087,8 @@ class qM extends tu {
8089
8087
  onAfterSampleAnimation() {
8090
8088
  }
8091
8089
  _isRoundedCorners() {
8092
- return ["", "TopLeft", "TopRight", "BottomLeft", "BottomRight"].map(
8093
- (t) => (
8094
- /** @type {keyof import("../spec/mark").MarkConfig} */
8095
- "cornerRadius" + t
8096
- )
8097
- ).some((t) => this.properties[t] > 0);
8090
+ const t = this.properties;
8091
+ return t.cornerRadius || t.cornerRadiusBottomLeft || t.cornerRadiusBottomRight || t.cornerRadiusTopLeft || t.cornerRadiusTopRight;
8098
8092
  }
8099
8093
  _isStroked() {
8100
8094
  const t = this.encoding.strokeWidth;
@@ -8148,7 +8142,7 @@ class qM extends tu {
8148
8142
  ), n;
8149
8143
  }
8150
8144
  /**
8151
- * @param {import("./Mark").MarkRenderingOptions} options
8145
+ * @param {import("./mark").MarkRenderingOptions} options
8152
8146
  */
8153
8147
  render(t) {
8154
8148
  const n = this.gl;
@@ -8581,7 +8575,7 @@ class t6 extends tu {
8581
8575
  ), n;
8582
8576
  }
8583
8577
  /**
8584
- * @param {import("./Mark").MarkRenderingOptions} options
8578
+ * @param {import("./mark").MarkRenderingOptions} options
8585
8579
  */
8586
8580
  render(t) {
8587
8581
  const n = this.gl;
@@ -8723,7 +8717,7 @@ class i6 extends tu {
8723
8717
  ), n;
8724
8718
  }
8725
8719
  /**
8726
- * @param {import("./Mark").MarkRenderingOptions} options
8720
+ * @param {import("./mark").MarkRenderingOptions} options
8727
8721
  */
8728
8722
  render(t) {
8729
8723
  const n = this.gl;
@@ -9021,7 +9015,7 @@ class g6 extends tu {
9021
9015
  updateGraphicsData() {
9022
9016
  const t = this.unitView.getCollector(), n = t.getData(), r = this.encoding, i = this.encoders.text.accessor || this.encoders.text;
9023
9017
  let a = 0;
9024
- const o = r.text.format ? it(r.text.format) : (u) => u;
9018
+ const o = "format" in r.text ? it(r.text.format) : (u) => u;
9025
9019
  for (const u of n) {
9026
9020
  const f = o(i(u)), l = ze(f) ? f : f === null ? "" : "" + f;
9027
9021
  a += l && l.length || 0;
@@ -9060,7 +9054,7 @@ class g6 extends tu {
9060
9054
  ), n;
9061
9055
  }
9062
9056
  /**
9063
- * @param {import("./Mark").MarkRenderingOptions} options
9057
+ * @param {import("./mark").MarkRenderingOptions} options
9064
9058
  */
9065
9059
  render(t) {
9066
9060
  const n = this.gl;
@@ -9334,7 +9328,7 @@ class Sx {
9334
9328
  getSize() {
9335
9329
  return this._cache(
9336
9330
  "size/size",
9337
- () => this.isVisible() ? this.getSizeFromSpec().addPadding(this.getPadding()) : m6
9331
+ () => this.isConfiguredVisible() ? this.getSizeFromSpec().addPadding(this.getPadding()) : m6
9338
9332
  );
9339
9333
  }
9340
9334
  /**
@@ -9380,12 +9374,24 @@ class Sx {
9380
9374
  () => new _i(t("width"), t("height"))
9381
9375
  );
9382
9376
  }
9383
- isVisible() {
9384
- return this.context.isViewVisible(this);
9377
+ isConfiguredVisible() {
9378
+ return this.context.isViewConfiguredVisible(this);
9385
9379
  }
9386
9380
  isVisibleInSpec() {
9387
9381
  return this.spec.visible ?? !0;
9388
9382
  }
9383
+ /**
9384
+ * Returns the effective visibility of this view, e.g., whether this view
9385
+ * and all its ancestors are visible.
9386
+ *
9387
+ * When doing a depth-first traversal on the view hierarchy, it's best to
9388
+ * use `isConfiguredVisible()` instead of this method.
9389
+ *
9390
+ * @returns {boolean}
9391
+ */
9392
+ isVisible() {
9393
+ return this.getAncestors().every((t) => t.isConfiguredVisible());
9394
+ }
9389
9395
  /**
9390
9396
  * Returns the effective opacity of this view, e.g., view's opacity multiplied
9391
9397
  * by opacities of its ancestors.
@@ -9399,16 +9405,23 @@ class Sx {
9399
9405
  return this.opacityFunction(((t = this.parent) == null ? void 0 : t.getEffectiveOpacity()) ?? 1);
9400
9406
  }
9401
9407
  getPathString() {
9402
- return [...this.getAncestors()].map((t) => t.name).reverse().join("/");
9408
+ return this.getAncestors().map((t) => t.name).reverse().join("/");
9403
9409
  }
9404
- *getAncestors() {
9405
- let t = (
9410
+ /**
9411
+ * Returns the ancestor views, starting with this view.
9412
+ *
9413
+ * @returns {View[]}
9414
+ */
9415
+ getAncestors() {
9416
+ const t = [];
9417
+ let n = (
9406
9418
  /** @type {View} */
9407
9419
  this
9408
9420
  );
9409
9421
  do
9410
- yield t, t = t.parent;
9411
- while (t);
9422
+ t.push(n), n = n.parent;
9423
+ while (n);
9424
+ return t;
9412
9425
  }
9413
9426
  /**
9414
9427
  * Handles a broadcast message that is intended for the whole view hierarchy.
@@ -10957,7 +10970,7 @@ class Cr extends Oa {
10957
10970
  * @param {import("./view").RenderingOptions} [options]
10958
10971
  */
10959
10972
  render(t, n, r = {}) {
10960
- if (this.isVisible()) {
10973
+ if (this.isConfiguredVisible()) {
10961
10974
  t.pushView(this, n);
10962
10975
  for (const i of this.children)
10963
10976
  i.render(t, n, r);
@@ -12075,7 +12088,7 @@ class Qx extends Oa {
12075
12088
  * @param {import("./view").RenderingOptions} [options]
12076
12089
  */
12077
12090
  render(n, r, i = {}) {
12078
- if (!this.isVisible())
12091
+ if (!this.isConfiguredVisible())
12079
12092
  return;
12080
12093
  this.parent || (r = r.shrink(this.getPadding())), n.pushView(this, r);
12081
12094
  const a = {
@@ -12176,7 +12189,9 @@ Ca = new WeakMap(), Sa = new WeakMap(), Ut = new WeakMap(), Da = new WeakMap(),
12176
12189
  }
12177
12190
  return r;
12178
12191
  }, In = new WeakSet(), gr = function() {
12179
- return Ce(this, Ut).filter((n) => n.view.isVisible());
12192
+ return Ce(this, Ut).filter(
12193
+ (n) => n.view.isConfiguredVisible()
12194
+ );
12180
12195
  }, Pc = new WeakSet(), Vx = function() {
12181
12196
  return new s1(
12182
12197
  Ce(this, In, gr).length,
@@ -12509,7 +12524,7 @@ class st extends Oa {
12509
12524
  * @param {import("./view").RenderingOptions} [options]
12510
12525
  */
12511
12526
  render(t, n, r = {}) {
12512
- this.isVisible() && (this.coords = n, t.pushView(this, n), t.renderMark(this.mark, r), t.popView(this));
12527
+ this.isConfiguredVisible() && (this.coords = n, t.pushView(this, n), t.renderMark(this.mark, r), t.popView(this));
12513
12528
  }
12514
12529
  getMarkType() {
12515
12530
  return typeof this.spec.mark == "object" ? this.spec.mark.type : this.spec.mark;
@@ -15041,20 +15056,24 @@ class eo extends ru {
15041
15056
  'No channel has been specified for the dynamic data source. Must be either "x" or "y".'
15042
15057
  );
15043
15058
  if (this.channel = n, this.scaleResolution = this.view.getScaleResolution(n), !this.scaleResolution) {
15044
- const r = [
15059
+ const i = [
15045
15060
  `The dynamic data source cannot find a resolved scale for channel "${n}".`
15046
15061
  ];
15047
- throw this.view instanceof st || r.push(
15062
+ throw this.view instanceof st || i.push(
15048
15063
  'Make sure the view has a "shared" scale resolution as it is not a unit view.'
15049
- ), new Error(r.join(" "));
15064
+ ), new Error(i.join(" "));
15050
15065
  }
15051
- this.scaleResolution.addEventListener("domain", (r) => {
15052
- this.onDomainChanged(
15053
- r.scaleResolution.getDomain(),
15066
+ const r = () => {
15067
+ this.view.isVisible() && this.onDomainChanged(
15068
+ this.scaleResolution.getDomain(),
15054
15069
  /** @type {import("../../../spec/genome").ChromosomalLocus[]} */
15055
- r.scaleResolution.getComplexDomain()
15070
+ this.scaleResolution.getComplexDomain()
15056
15071
  );
15057
- });
15072
+ };
15073
+ this.scaleResolution.addEventListener("domain", r), this.view.context.addBroadcastListener(
15074
+ "layoutComputed",
15075
+ r
15076
+ );
15058
15077
  }
15059
15078
  /**
15060
15079
  * Returns the length of the axis in pixels. Chooses the smallest of the views.
@@ -15088,14 +15107,10 @@ class eo extends ru {
15088
15107
  * Rendering should be requested by the collector.
15089
15108
  */
15090
15109
  requestRender() {
15091
- this.scaleResolution.members[0].view.context.animator.requestRender();
15110
+ this.view.context.animator.requestRender();
15092
15111
  }
15093
15112
  async load() {
15094
- this.reset(), this.complete(), await this.onDomainChanged(
15095
- this.scaleResolution.getDomain(),
15096
- /** @type {import("../../../spec/genome").ChromosomalLocus[]}*/
15097
- this.scaleResolution.getComplexDomain()
15098
- );
15113
+ this.reset(), this.complete();
15099
15114
  }
15100
15115
  /**
15101
15116
  *
@@ -15114,7 +15129,6 @@ class gN extends eo {
15114
15129
  * @param {import("../../../view/view").default} view
15115
15130
  */
15116
15131
  constructor(n, r) {
15117
- var a;
15118
15132
  const i = {
15119
15133
  axis: {},
15120
15134
  ...n
@@ -15124,10 +15138,7 @@ class gN extends eo {
15124
15138
  * @type {import("../../../spec/channel").Scalar[]}
15125
15139
  */
15126
15140
  En(this, "ticks", []);
15127
- this.params = n, (a = this.scaleResolution.members[0]) == null || a.view._addBroadcastHandler(
15128
- "layoutComputed",
15129
- () => this.onDomainChanged()
15130
- );
15141
+ this.params = n;
15131
15142
  }
15132
15143
  async onDomainChanged() {
15133
15144
  const n = this.scaleResolution.getScale(), r = this.params.axis, i = this.getAxisLength(), a = (u) => 25 + 60 * dN(100, 700, u), o = _t(r.tickCount) ? r.tickCount : Math.round(i / a(i)), s = _x(n, o, r.tickMinStep), c = r.values ? Ix(n, r.values, s) : v6(n, s);
@@ -27579,7 +27590,7 @@ class X9 {
27579
27590
  * @param {import("./embedApi").EmbedOptions} [options]
27580
27591
  */
27581
27592
  constructor(t, n, r = {}) {
27582
- this.container = t, this.spec = n, this.accessorFactory = new CD(), this.viewFactory = new ST(), this.namedDataProviders = [], this.animator = new N9(() => this.renderAll()), this.genomeStore = void 0, this.viewVisibilityPredicate = (i) => i.isVisibleInSpec(), this._renderingContext = void 0, this._pickingContext = void 0, this._dirtyPickingBuffer = !1, this._currentHover = void 0, this._wheelInertia = new P9(this.animator), this._keyboardListeners = /* @__PURE__ */ new Map(), this._eventListeners = /* @__PURE__ */ new Map(), this.tooltipHandlers = {
27593
+ this.container = t, this.spec = n, this.accessorFactory = new CD(), this.viewFactory = new ST(), this.namedDataProviders = [], this.animator = new N9(() => this.renderAll()), this.genomeStore = void 0, this.viewVisibilityPredicate = (i) => i.isVisibleInSpec(), this._renderingContext = void 0, this._pickingContext = void 0, this._dirtyPickingBuffer = !1, this._currentHover = void 0, this._wheelInertia = new P9(this.animator), this._keyboardListeners = /* @__PURE__ */ new Map(), this._eventListeners = /* @__PURE__ */ new Map(), this._extraBroadcastListeners = /* @__PURE__ */ new Map(), this.tooltipHandlers = {
27583
27594
  default: q9,
27584
27595
  refseqgene: j9,
27585
27596
  ...r.tooltipHandlers ?? {}
@@ -27623,13 +27634,14 @@ class X9 {
27623
27634
  }
27624
27635
  /**
27625
27636
  * Broadcast a message to all views
27626
- *
27627
- * @param {string} type
27637
+
27638
+ * @param {BroadcastEventType} type
27628
27639
  * @param {any} [payload]
27629
27640
  */
27630
27641
  broadcast(t, n) {
27642
+ var i;
27631
27643
  const r = { type: t, payload: n };
27632
- this.viewRoot.visit((i) => i.handleBroadcast(r));
27644
+ this.viewRoot.visit((a) => a.handleBroadcast(r)), (i = this._extraBroadcastListeners.get(t)) == null || i.forEach((a) => a(r));
27633
27645
  }
27634
27646
  _prepareContainer() {
27635
27647
  this.container.classList.add("genome-spy"), this.container.classList.add("loading"), this._glHelper = new jM(this.container, () => {
@@ -27674,7 +27686,16 @@ class X9 {
27674
27686
  let u = this._keyboardListeners.get(s);
27675
27687
  u || (u = [], this._keyboardListeners.set(s, u)), u.push(c);
27676
27688
  },
27677
- isViewVisible: t.viewVisibilityPredicate,
27689
+ addBroadcastListener(s, c) {
27690
+ const u = t._extraBroadcastListeners;
27691
+ let f = u.get(s);
27692
+ f || (f = /* @__PURE__ */ new Set(), u.set(s, f)), f.add(c);
27693
+ },
27694
+ removeBroadcastListener(s, c) {
27695
+ var f;
27696
+ (f = t._extraBroadcastListeners.get(s)) == null || f.delete(c);
27697
+ },
27698
+ isViewConfiguredVisible: t.viewVisibilityPredicate,
27678
27699
  isViewSpec: (s) => t.viewFactory.isViewSpec(s),
27679
27700
  createView: function(s, c, u) {
27680
27701
  return t.viewFactory.createView(
@@ -27775,9 +27796,7 @@ class X9 {
27775
27796
  if (r.type == "click") {
27776
27797
  const c = this._currentHover ? {
27777
27798
  type: r.type,
27778
- viewPath: [
27779
- ...this._currentHover.mark.unitView.getAncestors()
27780
- ].map((u) => u.name).reverse(),
27799
+ viewPath: this._currentHover.mark.unitView.getAncestors().map((u) => u.name).reverse(),
27781
27800
  datum: this._currentHover.datum
27782
27801
  } : {
27783
27802
  type: r.type,