gosling.js 2.0.0-alpha.2 → 2.0.0-alpha.4

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/dist/gosling.js CHANGED
@@ -35,7 +35,7 @@ import { scaleLinear, scaleLog, scaleQuantile, scaleSequential, scaleOrdinal, sc
35
35
  import { drag } from "d3-drag";
36
36
  import { sampleSize, isEqual, uniqBy } from "lodash-es";
37
37
  import { interpolateViridis } from "d3-scale-chromatic";
38
- import { A as Ajv, r as resolveSuperposedTracks, I as IsChannelDeep, t as traverseTracks, a as IsTemplateTrack, D as DEWFAULT_TITLE_PADDING_ON_TOP_AND_BOTTOM, b as traverseTracksAndViews, c as traverseViewArrangements, d as DEFAULT_AXIS_SIZE, e as Is2DTrack, f as DEFAULT_VIEW_SPACING, g as DEFAULT_INNER_RADIUS_PROP, h as IsDummyTrack, i as IsOverlaidTrack, j as IsXAxis, k as IsYAxis, l as DEFAULT_CIRCULAR_VIEW_PADDING, u as uuid, m as traverseToFixSpecDownstream, n as absToChr, o as colorToHex, p as getTextStyle, q as computeChromSizes, s as cartesianToPolar, v as getHiGlassColorRange, R as RADIAN_GAP, w as valueToRadian, x as pointsToDegree, y as commonjsGlobal, z as RemoteFile, B as chrToAbs, C as IsOneOfFilter, E as IsRangeFilter, F as IsIncludeFilter, G as getChannelKeysByAggregateFnc, H as getChannelKeysByType, J as sanitizeChrName, K as filterUsingGenoPos, L as IsDataDeepTileset, M as IsDomainChr, N as IsDomainInterval, O as IsDomainChrInterval, S as SUPPORTED_CHANNELS, P as IsChannelValue, Q as getValueUsingChannel, T as rectProperty, U as pointProperty, V as barProperty, W as IsStackedChannel, X as IsDomainArray, Y as PREDEFINED_COLOR_STR_MAP, Z as IsRangeArray, _ as isTabularDataFetcher, $ as drawPreEmbellishment, a0 as drawMark, a1 as drawPostEmbellishment, a2 as getRelativeGenomicPosition, a3 as hasDataTransform, a4 as IsMouseEventsDeep, a5 as flatArrayToPairArray, a6 as IsSingleView, a7 as IsMultipleViews, a8 as GenomicPositionHelper } from "./exported-utils-b3ea2b1e.js";
38
+ import { A as Ajv, r as resolveSuperposedTracks, I as IsChannelDeep, t as traverseTracks, a as IsTemplateTrack, D as DEWFAULT_TITLE_PADDING_ON_TOP_AND_BOTTOM, b as traverseTracksAndViews, c as traverseViewArrangements, d as DEFAULT_AXIS_SIZE, e as Is2DTrack, f as DEFAULT_VIEW_SPACING, g as DEFAULT_INNER_RADIUS_PROP, h as IsOverlaidTrack, i as IsXAxis, j as IsYAxis, k as DEFAULT_CIRCULAR_VIEW_PADDING, u as uuid, l as traverseToFixSpecDownstream, m as absToChr, n as colorToHex, o as getTextStyle, p as computeChromSizes, q as cartesianToPolar, s as IsDummyTrack, v as getHiGlassColorRange, R as RADIAN_GAP, w as valueToRadian, x as pointsToDegree, y as commonjsGlobal, z as RemoteFile, B as chrToAbs, C as IsOneOfFilter, E as IsRangeFilter, F as IsIncludeFilter, G as getChannelKeysByAggregateFnc, H as getChannelKeysByType, J as sanitizeChrName, K as filterUsingGenoPos, L as IsDataDeepTileset, M as IsDomainChr, N as IsDomainInterval, O as IsDomainChrInterval, S as SUPPORTED_CHANNELS, P as IsChannelValue, Q as getValueUsingChannel, T as rectProperty, U as pointProperty, V as barProperty, W as IsStackedChannel, X as IsDomainArray, Y as PREDEFINED_COLOR_STR_MAP, Z as IsRangeArray, _ as isTabularDataFetcher, $ as drawPreEmbellishment, a0 as drawMark, a1 as drawPostEmbellishment, a2 as getRelativeGenomicPosition, a3 as hasDataTransform, a4 as IsMouseEventsDeep, a5 as flatArrayToPairArray, a6 as IsSingleView, a7 as IsMultipleViews, a8 as GenomicPositionHelper } from "./exported-utils-b3cf08ff.js";
39
39
  import React, { useState, useImperativeHandle, useEffect } from "react";
40
40
  import { format, precisionPrefix, formatPrefix } from "d3-format";
41
41
  import slugid from "slugid";
@@ -55,7 +55,7 @@ import { createNanoEvents } from "nanoevents";
55
55
  import PubSub$1 from "pubsub-js";
56
56
  import { zoom, ZoomTransform } from "d3-zoom";
57
57
  const name = "gosling.js";
58
- const version = "2.0.0-alpha.2";
58
+ const version = "2.0.0-alpha.4";
59
59
  const $ref$1 = "#/definitions/GoslingSpec";
60
60
  const $schema$1 = "http://json-schema.org/draft-07/schema#";
61
61
  const definitions$1 = {
@@ -846,6 +846,10 @@ const definitions$1 = {
846
846
  description: "Specify the track width in pixels.",
847
847
  type: "number"
848
848
  },
849
+ x: {
850
+ $ref: "#/definitions/X",
851
+ description: "For showing axis"
852
+ },
849
853
  zoomLimits: {
850
854
  description: "Unused property for DummyTrack",
851
855
  items: {
@@ -5604,6 +5608,10 @@ const definitions$1 = {
5604
5608
  },
5605
5609
  {
5606
5610
  $ref: "#/definitions/ChannelValue"
5611
+ },
5612
+ {
5613
+ $ref: "#/definitions/X",
5614
+ description: "For showing axis"
5607
5615
  }
5608
5616
  ]
5609
5617
  },
@@ -11483,9 +11491,6 @@ function traverseAndCollectTrackInfo(spec, output, dx = 0, dy = 0, circularRootN
11483
11491
  const TOTAL_RING_SIZE = TOTAL_RADIUS * (1 - INNER_RADIUS);
11484
11492
  cTracks.forEach((t, i) => {
11485
11493
  var _a, _b;
11486
- if (IsDummyTrack(t.track)) {
11487
- return;
11488
- }
11489
11494
  const circularTrack = t.track;
11490
11495
  circularTrack.layout = "circular";
11491
11496
  circularTrack.outerRadius = TOTAL_RADIUS - PADDING - (t.boundingBox.y - dy) / cumHeight * TOTAL_RING_SIZE;
@@ -11611,8 +11616,6 @@ function collectViewsAndTracks(spec, trackInfos, theme) {
11611
11616
  let isLinear = false;
11612
11617
  if ("layout" in d.track && d.track.layout === "linear") {
11613
11618
  isLinear = true;
11614
- } else if (IsDummyTrack(d.track)) {
11615
- isLinear = true;
11616
11619
  }
11617
11620
  return {
11618
11621
  id: d.track.id,
@@ -11763,6 +11766,7 @@ function compile(spec, templates, theme, containerStatus) {
11763
11766
  trackInfos = getRelativeTrackInfo(specCopy, theme).trackInfos;
11764
11767
  }
11765
11768
  const compileResult = collectViewsAndTracks(specCopy, trackInfos, theme);
11769
+ console.warn(compileResult);
11766
11770
  return compileResult;
11767
11771
  }
11768
11772
  class PixiManager {
@@ -16660,8 +16664,35 @@ const defaultOptions$2 = {
16660
16664
  textFontWeight: "normal",
16661
16665
  textStroke: "#000",
16662
16666
  textStrokeWidth: 0.1,
16663
- outline: "#fff"
16667
+ outline: "#fff",
16668
+ layout: "linear",
16669
+ outerRadius: 0,
16670
+ innerRadius: 0
16664
16671
  };
16672
+ function makeArc(width, height, innerRadius, outerRadius) {
16673
+ const startAngle = -Math.PI / 2;
16674
+ const endAngle = -Math.PI / 2 + 2 * Math.PI - 1e-6;
16675
+ const startX = width / 2 + outerRadius * Math.cos(startAngle);
16676
+ const startY = height / 2 + outerRadius * Math.sin(startAngle);
16677
+ const endX = width / 2 + outerRadius * Math.cos(endAngle);
16678
+ const endY = height / 2 + outerRadius * Math.sin(endAngle);
16679
+ const innerStartX = width / 2 + innerRadius * Math.cos(startAngle);
16680
+ const innerStartY = height / 2 + innerRadius * Math.sin(startAngle);
16681
+ const innerEndX = width / 2 + innerRadius * Math.cos(endAngle);
16682
+ const innerEndY = height / 2 + innerRadius * Math.sin(endAngle);
16683
+ const pathData = [
16684
+ `M ${startX} ${startY}`,
16685
+ `A ${outerRadius} ${outerRadius} 0 1 1 ${endX} ${endY}`,
16686
+ // Draw outer arc
16687
+ `L ${innerEndX} ${innerEndY}`,
16688
+ // Draw a line to the ending point of the inner arc
16689
+ `A ${innerRadius} ${innerRadius} 0 1 0 ${innerStartX} ${innerStartY}`,
16690
+ // Draw inner arc
16691
+ "Z"
16692
+ // Close the path
16693
+ ].join(" ");
16694
+ return pathData;
16695
+ }
16665
16696
  class DummyTrackClass extends SVGTrack {
16666
16697
  constructor(context, options) {
16667
16698
  super(context, options);
@@ -16671,6 +16702,7 @@ class DummyTrackClass extends SVGTrack {
16671
16702
  */
16672
16703
  __privateAdd(this, _drawText);
16673
16704
  this.options = { ...defaultOptions$2, ...options };
16705
+ console.warn(this.options);
16674
16706
  this.clipRect.attr("width", this.options.width).attr("height", this.options.height);
16675
16707
  __privateMethod(this, _drawBackground, drawBackground_fn).call(this);
16676
16708
  __privateMethod(this, _drawText, drawText_fn).call(this);
@@ -16678,11 +16710,24 @@ class DummyTrackClass extends SVGTrack {
16678
16710
  }
16679
16711
  _drawBackground = new WeakSet();
16680
16712
  drawBackground_fn = function() {
16681
- this.gMain.append("rect").attr("fill", this.options.background).attr("x", 0).attr("y", 0).attr("width", this.options.width).attr("height", this.options.height).style("stroke", this.options.outline);
16713
+ if (this.options.layout === "linear") {
16714
+ this.gMain.append("rect").attr("fill", this.options.background).attr("x", 0).attr("y", 0).attr("width", this.options.width).attr("height", this.options.height).style("stroke", this.options.outline);
16715
+ } else {
16716
+ this.gMain.append("path").attr(
16717
+ "d",
16718
+ makeArc(
16719
+ this.options.width,
16720
+ this.options.height,
16721
+ this.options.innerRadius,
16722
+ this.options.outerRadius
16723
+ )
16724
+ ).attr("fill", this.options.background).attr("stroke", this.options.outline).attr("x", 0).attr("y", 0);
16725
+ }
16682
16726
  };
16683
16727
  _drawText = new WeakSet();
16684
16728
  drawText_fn = function() {
16685
- this.gMain.append("text").attr("x", this.options.width / 2).attr("y", (this.options.height + this.options.textFontSize) / 2).style("text-anchor", "middle").style("font-size", `${this.options.textFontSize}px`).style("font-weight", this.options.textFontWeight).style("stroke", this.options.textStroke).style("stroke-width", this.options.textStrokeWidth).text(this.options.title);
16729
+ const height = this.options.layout === "linear" ? (this.options.height + this.options.textFontSize) / 2 : this.options.height / 2 - this.options.innerRadius - this.options.textFontSize;
16730
+ this.gMain.append("text").attr("x", this.options.width / 2).attr("y", height).style("text-anchor", "middle").style("font-size", `${this.options.textFontSize}px`).style("font-weight", this.options.textFontWeight).style("stroke", this.options.textStroke).style("stroke-width", this.options.textStrokeWidth).text(this.options.title);
16686
16731
  };
16687
16732
  class DummyTrack extends DummyTrackClass {
16688
16733
  constructor(options, overlayDiv) {
@@ -17711,16 +17756,23 @@ function getAxisTrackCircularOptions(track, boundingBox, position, theme) {
17711
17756
  return options;
17712
17757
  }
17713
17758
  function getAxisPositions(track) {
17714
- var _a, _b;
17715
- if (IsTemplateTrack(track) || IsDummyTrack(track)) {
17759
+ var _a, _b, _c;
17760
+ if (IsTemplateTrack(track)) {
17716
17761
  return { xAxisPosition: void 0, yAxisPosition: void 0 };
17717
17762
  }
17763
+ if (IsDummyTrack(track)) {
17764
+ if ((_a = track.x) == null ? void 0 : _a.axis) {
17765
+ return { xAxisPosition: track.x.axis, yAxisPosition: void 0 };
17766
+ } else {
17767
+ return { xAxisPosition: void 0, yAxisPosition: void 0 };
17768
+ }
17769
+ }
17718
17770
  const resolvedSpecs = resolveSuperposedTracks(track);
17719
17771
  const firstResolvedSpec = resolvedSpecs[0];
17720
17772
  const hasXAxis = "x" in firstResolvedSpec && firstResolvedSpec.x && "axis" in firstResolvedSpec.x && firstResolvedSpec.x.axis !== "none" && firstResolvedSpec.x.type === "genomic" || false;
17721
17773
  const hasYAxis = "y" in firstResolvedSpec && firstResolvedSpec.y && "axis" in firstResolvedSpec.y && firstResolvedSpec.y.axis !== "none" && firstResolvedSpec.y.type === "genomic" || false;
17722
- const xAxisPosition = hasXAxis && IsChannelDeep(firstResolvedSpec.x) ? (_a = firstResolvedSpec.x) == null ? void 0 : _a.axis : void 0;
17723
- const yAxisPosition = hasYAxis && IsChannelDeep(firstResolvedSpec.y) ? (_b = firstResolvedSpec.y) == null ? void 0 : _b.axis : void 0;
17774
+ const xAxisPosition = hasXAxis && IsChannelDeep(firstResolvedSpec.x) ? (_b = firstResolvedSpec.x) == null ? void 0 : _b.axis : void 0;
17775
+ const yAxisPosition = hasYAxis && IsChannelDeep(firstResolvedSpec.y) ? (_c = firstResolvedSpec.y) == null ? void 0 : _c.axis : void 0;
17724
17776
  return {
17725
17777
  xAxisPosition,
17726
17778
  yAxisPosition
@@ -18186,8 +18238,15 @@ class BrushCircularTrack extends CircularBrushTrackClass {
18186
18238
  return this;
18187
18239
  }
18188
18240
  }
18189
- function processDummyTrack(track, boundingBox) {
18241
+ function processDummyTrack(track, boundingBox, theme) {
18190
18242
  var _a;
18243
+ const trackDefs = [];
18244
+ const [newTrackBbox, axisTrackDefs] = getAxisTrackDef(track, boundingBox, theme);
18245
+ if (axisTrackDefs) {
18246
+ if (!track.overlayOnPreviousTrack)
18247
+ trackDefs.push(...axisTrackDefs);
18248
+ boundingBox = newTrackBbox;
18249
+ }
18191
18250
  const trackDef = {
18192
18251
  type: TrackType.Dummy,
18193
18252
  trackId: track.id,
@@ -18195,11 +18254,15 @@ function processDummyTrack(track, boundingBox) {
18195
18254
  options: {
18196
18255
  width: boundingBox.width,
18197
18256
  height: boundingBox.height,
18257
+ layout: track.layout,
18258
+ outerRadius: "outerRadius" in track ? track.outerRadius : void 0,
18259
+ innerRadius: "innerRadius" in track ? track.innerRadius : void 0,
18198
18260
  ...track.style,
18199
18261
  title: (_a = track.title) != null ? _a : ""
18200
18262
  }
18201
18263
  };
18202
- return [trackDef];
18264
+ trackDefs.push(trackDef);
18265
+ return trackDefs;
18203
18266
  }
18204
18267
  var TrackType = /* @__PURE__ */ ((TrackType2) => {
18205
18268
  TrackType2[TrackType2["Text"] = 0] = "Text";
@@ -18213,7 +18276,6 @@ var TrackType = /* @__PURE__ */ ((TrackType2) => {
18213
18276
  })(TrackType || {});
18214
18277
  function createTrackDefs(trackInfos, theme) {
18215
18278
  const trackDefs = [];
18216
- console.warn("trackinfos", trackInfos);
18217
18279
  trackInfos.forEach((trackInfo2) => {
18218
18280
  const { track, boundingBox } = trackInfo2;
18219
18281
  if (track.mark === "_header") {
@@ -18223,7 +18285,7 @@ function createTrackDefs(trackInfos, theme) {
18223
18285
  const heatmapTrackDefs = processHeatmapTrack(track, boundingBox, theme);
18224
18286
  trackDefs.push(...heatmapTrackDefs);
18225
18287
  } else if (IsDummyTrack(track)) {
18226
- const dummyTrackDefs = processDummyTrack(track, boundingBox);
18288
+ const dummyTrackDefs = processDummyTrack(track, boundingBox, theme);
18227
18289
  trackDefs.push(...dummyTrackDefs);
18228
18290
  } else {
18229
18291
  const goslingAxisDefs = processGoslingTrack(track, boundingBox, theme);
@@ -30104,7 +30166,7 @@ function getSingleViewLinks(gs) {
30104
30166
  };
30105
30167
  tracks2.forEach((track) => {
30106
30168
  var _a;
30107
- if (hasDiffXDomainThanView(gs, track, assembly2, viewXDomain2) || IsDummyTrack(track))
30169
+ if (hasDiffXDomainThanView(gs, track, assembly2, viewXDomain2))
30108
30170
  return;
30109
30171
  const hasOverlaidTracks = "_overlay" in track;
30110
30172
  if (hasOverlaidTracks) {
@@ -30225,9 +30287,9 @@ function createApiV2(compileResult) {
30225
30287
  if (!compileResult) {
30226
30288
  return createEmptyApi();
30227
30289
  }
30228
- const { tracksAndViews, theme, pixiManager, plots } = compileResult;
30290
+ const { theme, pixiManager, plots } = compileResult;
30229
30291
  const getTracksAndViews = () => {
30230
- return [...tracksAndViews];
30292
+ return [...compileResult.tracksAndViews];
30231
30293
  };
30232
30294
  const getTracks = () => {
30233
30295
  return [...getTracksAndViews().filter((d) => d.type === "track")];
@@ -30362,6 +30424,8 @@ function GoslingComponent(props) {
30362
30424
  theme = "light",
30363
30425
  ref,
30364
30426
  visualized = () => {
30427
+ },
30428
+ resized = () => {
30365
30429
  }
30366
30430
  } = props;
30367
30431
  const [compiledResults, setCompiledResults] = useState();
@@ -30385,12 +30449,12 @@ function GoslingComponent(props) {
30385
30449
  padding,
30386
30450
  background: getTheme(theme).root.background
30387
30451
  });
30388
- const compileResult = renderGosling(spec, plotElement, pixiManager2, theme, urlToFetchOptions);
30452
+ const compileResult = renderGosling(spec, plotElement, pixiManager2, theme, urlToFetchOptions, resized);
30389
30453
  setCompiledResults(compileResult);
30390
30454
  setPixiManager(pixiManager2);
30391
30455
  } else {
30392
30456
  pixiManager.clearAll();
30393
- const compileResult = renderGosling(spec, plotElement, pixiManager, theme, urlToFetchOptions);
30457
+ const compileResult = renderGosling(spec, plotElement, pixiManager, theme, urlToFetchOptions, resized);
30394
30458
  setCompiledResults(compileResult);
30395
30459
  }
30396
30460
  }, [spec]);
@@ -30403,18 +30467,18 @@ function GoslingComponent(props) {
30403
30467
  }
30404
30468
  );
30405
30469
  }
30406
- function renderGosling(gs, container, pixiManager, theme, urlToFetchOptions) {
30470
+ function renderGosling(gs, container, pixiManager, theme, urlToFetchOptions, resized) {
30407
30471
  const themeDeep = getTheme(theme);
30408
30472
  let plots = {};
30409
30473
  const compileResult = compile(gs, [], themeDeep, {});
30410
- const { trackInfos, gs: processedSpec } = compileResult;
30474
+ const { trackInfos, gs: processedSpec, theme: themeComplete } = compileResult;
30411
30475
  const linkedEncodings = getLinkedEncodings(processedSpec);
30476
+ const result = { ...compileResult, plots, pixiManager };
30412
30477
  const { isResponsiveWidth, isResponsiveHeight } = checkResponsiveSpec(processedSpec);
30413
30478
  if (isResponsiveWidth || isResponsiveHeight) {
30414
30479
  const resizeObserver = new ResizeObserver(
30415
30480
  debounce((entries) => {
30416
30481
  const { width: containerWidth, height: containerHeight } = entries[0].contentRect;
30417
- console.warn("Resizing to", containerWidth, containerHeight);
30418
30482
  pixiManager.clearAll();
30419
30483
  const rescaledTracks = rescaleTrackInfos(
30420
30484
  trackInfos,
@@ -30425,10 +30489,14 @@ function renderGosling(gs, container, pixiManager, theme, urlToFetchOptions) {
30425
30489
  isResponsiveWidth,
30426
30490
  isResponsiveHeight
30427
30491
  );
30492
+ const updatedResult = collectViewsAndTracks(processedSpec, rescaledTracks, themeComplete);
30493
+ result.tracksAndViews = updatedResult.tracksAndViews;
30494
+ result.size = updatedResult.size;
30428
30495
  const trackDefs = createTrackDefs(rescaledTracks, themeDeep);
30429
30496
  plots = renderTrackDefs(trackDefs, linkedEncodings, pixiManager, urlToFetchOptions);
30430
30497
  const { width, height } = calculateWidthHeight(rescaledTracks);
30431
30498
  pixiManager.resize(width, height);
30499
+ resized == null ? void 0 : resized();
30432
30500
  }, 300)
30433
30501
  );
30434
30502
  resizeObserver.observe(container);
@@ -30438,7 +30506,7 @@ function renderGosling(gs, container, pixiManager, theme, urlToFetchOptions) {
30438
30506
  const { width, height } = calculateWidthHeight(trackInfos);
30439
30507
  pixiManager.resize(width, height);
30440
30508
  }
30441
- return { ...compileResult, plots, pixiManager };
30509
+ return result;
30442
30510
  }
30443
30511
  function debounce(f, delay) {
30444
30512
  let timer = 0;