higlass 1.13.2 → 1.13.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.
Files changed (244) hide show
  1. package/README.md +0 -2
  2. package/app/globals.d.ts +4 -4
  3. package/app/missing-types.d.ts +3 -3
  4. package/app/scripts/AddTrackDialog.jsx +1 -0
  5. package/app/scripts/AddTrackPositionMenu.jsx +17 -4
  6. package/app/scripts/Annotations1dTrack.js +1 -0
  7. package/app/scripts/Annotations2dTrack.js +1 -0
  8. package/app/scripts/ArrowheadDomainsTrack.js +1 -0
  9. package/app/scripts/Autocomplete.jsx +1 -0
  10. package/app/scripts/AxisPixi.js +1 -0
  11. package/app/scripts/BarTrack.js +1 -0
  12. package/app/scripts/BedLikeTrack.js +1 -0
  13. package/app/scripts/Button.jsx +1 -0
  14. package/app/scripts/CNVIntervalTrack.js +1 -0
  15. package/app/scripts/CenterTiledPlot.jsx +1 -0
  16. package/app/scripts/CenterTrack.jsx +1 -0
  17. package/app/scripts/Chromosome2DAnnotations.js +1 -0
  18. package/app/scripts/Chromosome2DLabels.js +1 -0
  19. package/app/scripts/ChromosomeGrid.js +1 -0
  20. package/app/scripts/ChromosomeInfo.js +1 -0
  21. package/app/scripts/CloseTrackMenu.jsx +1 -0
  22. package/app/scripts/CombinedTrack.js +1 -0
  23. package/app/scripts/ConfigTrackMenu.jsx +1 -0
  24. package/app/scripts/ConfigViewMenu.jsx +1 -0
  25. package/app/scripts/ConfigureSeriesMenu.jsx +1 -0
  26. package/app/scripts/ContextMenuContainer.jsx +1 -0
  27. package/app/scripts/ContextMenuItem.jsx +1 -0
  28. package/app/scripts/Cross.jsx +1 -0
  29. package/app/scripts/CrossRule.js +1 -0
  30. package/app/scripts/CustomTrackDialog.jsx +1 -0
  31. package/app/scripts/Dialog.jsx +1 -0
  32. package/app/scripts/DivergentBarTrack.js +1 -0
  33. package/app/scripts/DragListeningDiv.jsx +1 -0
  34. package/app/scripts/DraggableDiv.jsx +1 -0
  35. package/app/scripts/ExportLinkDialog.jsx +1 -0
  36. package/app/scripts/FixedTrack.jsx +1 -0
  37. package/app/scripts/GalleryTracks.jsx +1 -0
  38. package/app/scripts/GenomePositionSearchBox.jsx +1 -0
  39. package/app/scripts/HeatmapOptions.jsx +1 -0
  40. package/app/scripts/HeatmapTiledPixiTrack.js +1 -0
  41. package/app/scripts/HiGlassComponent.jsx +1 -0
  42. package/app/scripts/HiGlassTrackComponent.jsx +1 -0
  43. package/app/scripts/Horizontal1dHeatmapTrack.js +1 -0
  44. package/app/scripts/Horizontal2DDomainsTrack.js +1 -0
  45. package/app/scripts/HorizontalChromosomeLabels.js +1 -0
  46. package/app/scripts/HorizontalGeneAnnotationsTrack.js +1 -0
  47. package/app/scripts/HorizontalHeatmapTrack.js +1 -0
  48. package/app/scripts/HorizontalItem.jsx +1 -0
  49. package/app/scripts/HorizontalLine1DPixiTrack.js +1 -0
  50. package/app/scripts/HorizontalMultivecTrack.js +1 -0
  51. package/app/scripts/HorizontalPoint1DPixiTrack.js +1 -0
  52. package/app/scripts/HorizontalRule.js +1 -0
  53. package/app/scripts/HorizontalTiled1DPixiTrack.js +1 -0
  54. package/app/scripts/HorizontalTiledPlot.jsx +1 -0
  55. package/app/scripts/HorizontalTrack.jsx +1 -0
  56. package/app/scripts/Id2DTiledPixiTrack.js +1 -0
  57. package/app/scripts/IdHorizontal1DTiledPixiTrack.js +1 -0
  58. package/app/scripts/IdVertical1DTiledPixiTrack.js +1 -0
  59. package/app/scripts/LeftAxisTrack.js +1 -0
  60. package/app/scripts/LeftTrackModifier.js +1 -0
  61. package/app/scripts/ListWrapper.jsx +1 -0
  62. package/app/scripts/MapboxTilesTrack.js +1 -0
  63. package/app/scripts/Modal.jsx +1 -0
  64. package/app/scripts/MoveableTrack.jsx +1 -0
  65. package/app/scripts/NestedContextMenu.jsx +1 -0
  66. package/app/scripts/OSMTileIdsTrack.js +1 -0
  67. package/app/scripts/OSMTilesTrack.js +1 -0
  68. package/app/scripts/OverlayTrack.js +1 -0
  69. package/app/scripts/PixiTrack.js +0 -1
  70. package/app/scripts/PlotTypeChooser.jsx +1 -0
  71. package/app/scripts/PopupMenu.jsx +1 -0
  72. package/app/scripts/RasterTilesTrack.js +1 -0
  73. package/app/scripts/RuleMixin.js +1 -0
  74. package/app/scripts/SVGTrack.js +1 -0
  75. package/app/scripts/SearchField.js +1 -0
  76. package/app/scripts/SeriesListItems.jsx +1 -0
  77. package/app/scripts/SeriesListMenu.jsx +1 -0
  78. package/app/scripts/SeriesListSubmenuMixin.jsx +1 -0
  79. package/app/scripts/SketchInlinePicker.jsx +1 -0
  80. package/app/scripts/SortableList.jsx +1 -0
  81. package/app/scripts/SquareMarkersTrack.js +1 -0
  82. package/app/scripts/Tiled1DPixiTrack.js +1 -0
  83. package/app/scripts/TiledPixiTrack.js +1 -0
  84. package/app/scripts/TiledPlot.jsx +9 -0
  85. package/app/scripts/TilesetFinder.jsx +1 -0
  86. package/app/scripts/TopAxisTrack.js +1 -0
  87. package/app/scripts/Track.js +0 -1
  88. package/app/scripts/TrackArea.jsx +1 -0
  89. package/app/scripts/TrackControl.jsx +1 -0
  90. package/app/scripts/TrackRenderer.jsx +0 -1
  91. package/app/scripts/UnknownPixiTrack.js +1 -0
  92. package/app/scripts/ValueIntervalTrack.js +1 -0
  93. package/app/scripts/VerticalItem.jsx +1 -0
  94. package/app/scripts/VerticalRule.js +1 -0
  95. package/app/scripts/VerticalTiled1DPixiTrack.js +1 -0
  96. package/app/scripts/VerticalTiledPlot.jsx +1 -0
  97. package/app/scripts/VerticalTrack.jsx +1 -0
  98. package/app/scripts/ViewConfigEditor.jsx +1 -0
  99. package/app/scripts/ViewContextMenu.jsx +1 -0
  100. package/app/scripts/ViewHeader.jsx +1 -0
  101. package/app/scripts/ViewportTracker2D.js +1 -0
  102. package/app/scripts/ViewportTracker2DPixi.js +1 -0
  103. package/app/scripts/ViewportTrackerHorizontal.js +1 -0
  104. package/app/scripts/ViewportTrackerVertical.js +1 -0
  105. package/app/scripts/api.js +1 -0
  106. package/app/scripts/configs/available-track-types.js +1 -0
  107. package/app/scripts/configs/colormaps.js +1 -0
  108. package/app/scripts/configs/datatype-to-track-type.js +1 -0
  109. package/app/scripts/configs/default-tracks-for-datatype.js +0 -1
  110. package/app/scripts/configs/dense-data-extrema-config.js +1 -0
  111. package/app/scripts/configs/globals.js +1 -0
  112. package/app/scripts/configs/index.js +1 -0
  113. package/app/scripts/configs/positions-by-datatype.js +1 -0
  114. package/app/scripts/configs/primitives.js +0 -1
  115. package/app/scripts/configs/themes.js +1 -0
  116. package/app/scripts/configs/tracks-info-by-type.js +0 -1
  117. package/app/scripts/configs/tracks-info.js +0 -1
  118. package/app/scripts/d3-context-menu.js +1 -0
  119. package/app/scripts/data-fetchers/DataFetcher.js +193 -153
  120. package/app/scripts/data-fetchers/genbank-fetcher.js +205 -87
  121. package/app/scripts/data-fetchers/index.js +1 -0
  122. package/app/scripts/data-fetchers/local-tile-fetcher.js +37 -4
  123. package/app/scripts/hglib.jsx +1 -0
  124. package/app/scripts/hocs/with-modal.jsx +1 -0
  125. package/app/scripts/hocs/with-pub-sub.jsx +1 -0
  126. package/app/scripts/hocs/with-theme.jsx +1 -0
  127. package/app/scripts/icons.jsx +1 -0
  128. package/app/scripts/mixwith.js +1 -0
  129. package/app/scripts/options-info.js +1 -0
  130. package/app/scripts/plugins/available-for-plugins.js +1 -0
  131. package/app/scripts/plugins/get-data-fetcher.js +1 -0
  132. package/app/scripts/plugins/index.js +1 -0
  133. package/app/scripts/services/chrom-info.js +1 -0
  134. package/app/scripts/services/dom-event.js +1 -0
  135. package/app/scripts/services/element-resize-listener.js +1 -0
  136. package/app/scripts/services/index.js +1 -0
  137. package/app/scripts/services/tile-proxy.js +14 -10
  138. package/app/scripts/services/worker.js +161 -84
  139. package/app/scripts/symbol.js +1 -0
  140. package/app/scripts/test-helpers/index.js +1 -0
  141. package/app/scripts/test-helpers/test-helpers.jsx +1 -0
  142. package/app/scripts/track-utils.js +1 -0
  143. package/app/scripts/types.ts +59 -22
  144. package/app/scripts/utils/DenseDataExtrema1D.js +32 -19
  145. package/app/scripts/utils/DenseDataExtrema2D.js +51 -31
  146. package/app/scripts/utils/LruCache.js +1 -0
  147. package/app/scripts/utils/abs-to-chr.js +0 -1
  148. package/app/scripts/utils/accessor-transposition.js +0 -2
  149. package/app/scripts/utils/add-arrays.js +0 -2
  150. package/app/scripts/utils/add-class.js +0 -1
  151. package/app/scripts/utils/add-event-listener-once.js +0 -2
  152. package/app/scripts/utils/background-task-scheduler.js +0 -2
  153. package/app/scripts/utils/base64-to-canvas.js +0 -2
  154. package/app/scripts/utils/chr-to-abs.js +0 -2
  155. package/app/scripts/utils/chrom-info-bisector.js +0 -1
  156. package/app/scripts/utils/clone-event.js +0 -2
  157. package/app/scripts/utils/color-domain-to-rgba-array.js +1 -0
  158. package/app/scripts/utils/color-to-hex.js +0 -1
  159. package/app/scripts/utils/color-to-rgba.js +0 -1
  160. package/app/scripts/utils/data-to-genomic-loci.js +0 -1
  161. package/app/scripts/utils/debounce.js +0 -2
  162. package/app/scripts/utils/dec-to-hex-str.js +0 -1
  163. package/app/scripts/utils/dict-from-tuples.js +0 -2
  164. package/app/scripts/utils/dict-items.js +0 -2
  165. package/app/scripts/utils/dict-keys.js +0 -2
  166. package/app/scripts/utils/dict-values.js +0 -2
  167. package/app/scripts/utils/download.js +0 -2
  168. package/app/scripts/utils/expand-combined-tracks.js +1 -0
  169. package/app/scripts/utils/fill-in-min-widths.js +1 -0
  170. package/app/scripts/utils/flatten.js +1 -0
  171. package/app/scripts/utils/for-each.js +0 -1
  172. package/app/scripts/utils/forward-event.js +0 -1
  173. package/app/scripts/utils/genome-loci-to-pixels.js +0 -1
  174. package/app/scripts/utils/genomic-range-to-chromosome-chunks.js +0 -2
  175. package/app/scripts/utils/get-aggregation-function.js +6 -12
  176. package/app/scripts/utils/get-default-track-for-datatype.js +1 -0
  177. package/app/scripts/utils/get-element-dim.js +0 -1
  178. package/app/scripts/utils/get-higlass-components.js +1 -0
  179. package/app/scripts/utils/get-track-by-uid.js +1 -0
  180. package/app/scripts/utils/get-track-conf-from-hgc.js +1 -0
  181. package/app/scripts/utils/get-track-obj-by-id.js +1 -0
  182. package/app/scripts/utils/get-track-position-by-uid.js +1 -0
  183. package/app/scripts/utils/get-xylofon.js +1 -0
  184. package/app/scripts/utils/gradient.js +0 -2
  185. package/app/scripts/utils/has-class.js +0 -2
  186. package/app/scripts/utils/has-parent.js +1 -0
  187. package/app/scripts/utils/hex-string-to-int.js +0 -1
  188. package/app/scripts/utils/index.js +0 -1
  189. package/app/scripts/utils/interval-tree.js +1 -0
  190. package/app/scripts/utils/into-the-void.js +0 -1
  191. package/app/scripts/utils/is-track-or-child-track.js +0 -1
  192. package/app/scripts/utils/is-track-range-selectable.js +0 -1
  193. package/app/scripts/utils/is-within.js +0 -2
  194. package/app/scripts/utils/lat-to-y.js +0 -2
  195. package/app/scripts/utils/lng-to-x.js +0 -1
  196. package/app/scripts/utils/load-chrom-infos.js +1 -0
  197. package/app/scripts/utils/map.js +0 -1
  198. package/app/scripts/utils/max-non-zero.js +0 -1
  199. package/app/scripts/utils/max.js +0 -1
  200. package/app/scripts/utils/min-non-zero.js +0 -1
  201. package/app/scripts/utils/min.js +0 -1
  202. package/app/scripts/utils/mod.js +0 -1
  203. package/app/scripts/utils/ndarray-assign.js +1 -0
  204. package/app/scripts/utils/ndarray-flatten.js +1 -0
  205. package/app/scripts/utils/ndarray-to-list.js +1 -0
  206. package/app/scripts/utils/numericify-version.js +0 -1
  207. package/app/scripts/utils/obj-vals.js +1 -0
  208. package/app/scripts/utils/or.js +0 -1
  209. package/app/scripts/utils/parse-chromsizes-rows.js +0 -2
  210. package/app/scripts/utils/pixi-text-to-svg.js +1 -0
  211. package/app/scripts/utils/q.js +1 -0
  212. package/app/scripts/utils/rad-to-deg.js +0 -1
  213. package/app/scripts/utils/range-query-2d.js +1 -0
  214. package/app/scripts/utils/reduce.js +1 -0
  215. package/app/scripts/utils/rel-to-abs-chrom-pos.js +0 -2
  216. package/app/scripts/utils/remove-class.js +0 -1
  217. package/app/scripts/utils/reset-d3-brush-style.js +0 -2
  218. package/app/scripts/utils/rgb-to-hex.js +0 -2
  219. package/app/scripts/utils/scales-center-and-k.js +0 -2
  220. package/app/scripts/utils/scales-to-genome-loci.js +0 -1
  221. package/app/scripts/utils/segments-to-rows.js +1 -0
  222. package/app/scripts/utils/selected-items-to-cum-weights.js +0 -1
  223. package/app/scripts/utils/selected-items-to-size.js +0 -1
  224. package/app/scripts/utils/show-mouse-position.js +0 -1
  225. package/app/scripts/utils/some.js +0 -1
  226. package/app/scripts/utils/sum.js +0 -1
  227. package/app/scripts/utils/svg-line.js +1 -0
  228. package/app/scripts/utils/throttle-and-debounce.js +0 -1
  229. package/app/scripts/utils/tile-to-canvas.js +0 -1
  230. package/app/scripts/utils/timeout.js +0 -1
  231. package/app/scripts/utils/to-void.js +0 -1
  232. package/app/scripts/utils/total-track-pixel-height.js +0 -1
  233. package/app/scripts/utils/trim-trailing-slash.js +0 -1
  234. package/app/scripts/utils/type-guards.js +0 -2
  235. package/app/scripts/utils/value-to-color.js +0 -1
  236. package/app/scripts/utils/visit-positioned-tracks.js +0 -1
  237. package/app/scripts/utils/visit-tracks.js +0 -1
  238. package/dist/esm.html +13 -14
  239. package/dist/hglib.css +1 -1724
  240. package/dist/hglib.js +122664 -28
  241. package/dist/hglib.min.js +116 -119
  242. package/dist/higlass.mjs +122646 -28
  243. package/dist/index.html +5 -6
  244. package/package.json +23 -16
@@ -6,28 +6,17 @@ import {
6
6
  selectedItemsToSize,
7
7
  } from '../utils';
8
8
 
9
- /*
10
- function countTransform(count) {
11
- return Math.sqrt(Math.sqrt(count + 1));
12
- }
13
-
14
- function countTransform(count) {
15
- return Math.log(count+0.0001);
16
- }
17
- */
18
-
19
9
  /**
20
10
  * This function helps to fill in pixData by calling setPixData()
21
11
  * when selectedRowsOptions have been passed to workerSetPix().
22
- * @param {array} data The tile data array.
23
- * @param {array} shape Array `[numRows, numCols]`, used when iterating over a subset of rows,
24
- * when one needs to know the width of each column.
25
- * @param {function} setPixData The setPixData function created by workerSetPix().
26
- * @param {number[]} selectedRows Array of row indices, for ordering and filtering rows.
27
- * Used by the HorizontalMultivecTrack.
28
- * @param {string} selectedRowsAggregationMode String that specifies the aggregation function to use ("mean", "sum", etc).
29
- * @param {boolean} selectedRowsAggregationWithRelativeHeight Boolean that determines whether the height of row groups should be relative to the size of the group.
30
- * @param {string} selectedRowsAggregationMethod Where will the aggregation be performed? Possible values: "client", "server".
12
+ *
13
+ * @param {ArrayLike<number>} data - The (2D) tile data array.
14
+ * @param {[numRows: number, numCols: number]} shape - Array shape (number of rows and columns).
15
+ * @param {(pixDataIndex: number, dataPoint: number) => void} setPixData - The setPixData function created by workerSetPix().
16
+ * @param {number[] | number[][]} selectedRows - Row indices, for ordering and filtering rows. Used by the HorizontalMultivecTrack.
17
+ * @param {'mean' | 'sum' | 'variance' | 'deviation'} selectedRowsAggregationMode - The aggregation function to use ("mean", "sum", etc).
18
+ * @param {boolean} selectedRowsAggregationWithRelativeHeight - Whether the height of row groups should be relative to the size of the group.
19
+ * @param {'client' | 'server'} selectedRowsAggregationMethod - Where will the aggregation be performed? Possible values: "client", "server".
31
20
  */
32
21
  function setPixDataForSelectedRows(
33
22
  data,
@@ -39,39 +28,54 @@ function setPixDataForSelectedRows(
39
28
  selectedRowsAggregationMethod,
40
29
  ) {
41
30
  // We need to set the pixels in the order specified by the `selectedRows` parameter.
31
+ /** @type {((data: number[]) => number | undefined) | undefined} */
42
32
  let aggFunc;
33
+ /** @type {((columnIndex: number, rowIndices: number[]) => number) | undefined} */
43
34
  let aggFromDataFunc;
44
35
  if (selectedRowsAggregationMode) {
45
- aggFunc = getAggregationFunction(selectedRowsAggregationMode);
36
+ const agg = getAggregationFunction(selectedRowsAggregationMode);
37
+ aggFunc = agg;
46
38
  aggFromDataFunc = (colI, rowIs) =>
47
- aggFunc(rowIs.map((rowI) => data[rowI * shape[1] + colI]));
39
+ agg(rowIs.map((rowI) => data[rowI * shape[1] + colI])) ?? 0;
48
40
  }
41
+ /** @type {number} */
49
42
  let d;
43
+ /** @type {number} */
50
44
  let pixRowI;
45
+ /** @type {number} */
51
46
  let colI;
47
+ /** @type {number} */
52
48
  let selectedRowI;
49
+ /** @type {number} */
53
50
  let selectedRowGroupItemI;
51
+ /** @type {number | number[]} */
52
+ let selectedRow;
53
+
54
54
  for (colI = 0; colI < shape[1]; colI++) {
55
55
  // For this column, aggregate along the row axis.
56
56
  pixRowI = 0;
57
57
  for (selectedRowI = 0; selectedRowI < selectedRows.length; selectedRowI++) {
58
+ selectedRow = selectedRows[selectedRowI];
58
59
  if (aggFunc && selectedRowsAggregationMethod === 'server') {
59
60
  d = data[selectedRowI * shape[1] + colI];
60
- } else if (Array.isArray(selectedRows[selectedRowI]) && aggFunc) {
61
+ } else if (Array.isArray(selectedRow)) {
62
+ if (!aggFromDataFunc) {
63
+ throw new Error("row aggregation requires 'aggFromDataFunc'");
64
+ }
61
65
  // An aggregation step must be performed for this data point.
62
- d = aggFromDataFunc(colI, selectedRows[selectedRowI]);
66
+ d = aggFromDataFunc(colI, selectedRow);
63
67
  } else {
64
- d = data[selectedRows[selectedRowI] * shape[1] + colI];
68
+ d = data[selectedRow * shape[1] + colI];
65
69
  }
66
70
 
67
71
  if (
68
72
  selectedRowsAggregationWithRelativeHeight &&
69
- Array.isArray(selectedRows[selectedRowI])
73
+ Array.isArray(selectedRow)
70
74
  ) {
71
75
  // Set a pixel for multiple rows, proportionate to the size of the row aggregation group.
72
76
  for (
73
77
  selectedRowGroupItemI = 0;
74
- selectedRowGroupItemI < selectedRows[selectedRowI].length;
78
+ selectedRowGroupItemI < selectedRow.length;
75
79
  selectedRowGroupItemI++
76
80
  ) {
77
81
  setPixData(
@@ -92,24 +96,33 @@ function setPixDataForSelectedRows(
92
96
  } // end col for
93
97
  }
94
98
 
99
+ /**
100
+ * @typedef SelectedRowsOptions
101
+ * @property {number[] | number[][]} selectedRows - Row indices, for ordering and filtering rows. Used by the HorizontalMultivecTrack.
102
+ * @property {'mean' | 'sum' | 'variance' | 'deviation'} selectedRowsAggregationMode - The aggregation function to use ("mean", "sum", etc).
103
+ * @property {boolean} selectedRowsAggregationWithRelativeHeight - Whether the height of row groups should be relative to the size of the group.
104
+ * @property {'client' | 'server'} selectedRowsAggregationMethod - Where will the aggregation be performed? Possible values: "client", "server".
105
+ */
106
+
95
107
  /**
96
108
  * This function takes in tile data and other rendering parameters,
97
109
  * and generates an array of pixel data that can be passed to a canvas
98
110
  * (and subsequently passed to a PIXI sprite).
99
- * @param {number} size The length of the `data` parameter. Often set to a tile's
100
- * `tile.tileData.dense.length` value.
101
- * @param {array} data The tile data array.
102
- * @param {string} valueScaleType 'log' or 'linear'.
103
- * @param {array} valueScaleDomain
104
- * @param {number} pseudocount The pseudocount is generally the minimum non-zero value and is
111
+ *
112
+ * @param {number} size - `data` parameter length. Often set to a tile's `tile.tileData.dense.length` value.
113
+ * @param {Array<number>} data - The tile data array.
114
+ * @param {'log' | 'linear'} valueScaleType 'log' or 'linear'.
115
+ * @param {[number, number]} valueScaleDomain
116
+ * @param {number} pseudocount - The pseudocount is generally the minimum non-zero value and is
105
117
  * used so that our log scaling doesn't lead to NaN values.
106
- * @param {array} colorScale
118
+ * @param {Array<[r: number, g: number, b: number, a: number]>} colorScale
107
119
  * @param {boolean} ignoreUpperRight
108
120
  * @param {boolean} ignoreLowerLeft
109
- * @param {array} shape Array `[numRows, numCols]`, used when iterating over a subset of rows,
121
+ * @param {[numRows: number, numCols: number] | null} shape - Array `[numRows, numCols]`, used when iterating over a subset of rows,
110
122
  * when one needs to know the width of each column.
111
- * @param {array} zeroValueColor The color to use for rendering zero data values, [r, g, b, a].
112
- * @param {object} selectedRowsOptions Rendering options when using a `selectRows` track option.
123
+ * @param {[r: number, g: number, b: number, a: number] | null} zeroValueColor - The color to use for rendering zero data values, [r, g, b, a].
124
+ * @param {Partial<SelectedRowsOptions> | null} selectedRowsOptions - Rendering options when using a `selectRows` track option.
125
+ *
113
126
  * @returns {Uint8ClampedArray} A flattened array of pixel values.
114
127
  */
115
128
  export function workerSetPix(
@@ -125,7 +138,8 @@ export function workerSetPix(
125
138
  zeroValueColor = null,
126
139
  selectedRowsOptions = null,
127
140
  ) {
128
- let valueScale = null;
141
+ /** @type {import('../types').Scale} */
142
+ let valueScale;
129
143
 
130
144
  if (valueScaleType === 'log') {
131
145
  valueScale = scaleLog().range([254, 0]).domain(valueScaleDomain);
@@ -140,13 +154,12 @@ export function workerSetPix(
140
154
  valueScale = scaleLinear().range([254, 0]).domain(valueScaleDomain);
141
155
  }
142
156
 
143
- // De-structure the selectedRowsOptions object.
144
157
  const {
145
- selectedRows = null,
146
- selectedRowsAggregationMode = null,
147
- selectedRowsAggregationWithRelativeHeight = null,
148
- selectedRowsAggregationMethod = null,
149
- } = selectedRowsOptions || {};
158
+ selectedRows,
159
+ selectedRowsAggregationMode = 'mean',
160
+ selectedRowsAggregationWithRelativeHeight = false,
161
+ selectedRowsAggregationMethod = 'client',
162
+ } = selectedRowsOptions ?? {};
150
163
 
151
164
  let filteredSize = size;
152
165
  if (shape && selectedRows) {
@@ -165,6 +178,7 @@ export function workerSetPix(
165
178
  const tileWidth = shape ? shape[1] : Math.sqrt(size);
166
179
  const pixData = new Uint8ClampedArray(filteredSize * 4);
167
180
 
181
+ /** @type {(x: number) => number} */
168
182
  const dToRgbIdx = (x) => {
169
183
  const v = valueScale(x);
170
184
  if (Number.isNaN(v)) return 254;
@@ -174,8 +188,9 @@ export function workerSetPix(
174
188
  /**
175
189
  * Set the ith element of the pixData array, using value d.
176
190
  * (well not really, since i is scaled to make space for each rgb value).
177
- * @param i Index of the element.
178
- * @param d The value to be transformed and then inserted.
191
+ *
192
+ * @param {number} i - Index of the element.
193
+ * @param {number} d - The value to be transformed and then inserted.
179
194
  */
180
195
  const setPixData = (i, d) => {
181
196
  // Transparent
@@ -216,7 +231,7 @@ export function workerSetPix(
216
231
 
217
232
  let d;
218
233
  try {
219
- if (selectedRows) {
234
+ if (selectedRows && shape) {
220
235
  // We need to set the pixels in the order specified by the `selectedRows` parameter.
221
236
  // Call the setPixDataForSelectedRows helper function,
222
237
  // which will loop over the data for us and call setPixData().
@@ -239,6 +254,8 @@ export function workerSetPix(
239
254
  }
240
255
  } catch (err) {
241
256
  console.warn('Odd datapoint');
257
+ console.warn('d:', d);
258
+ d = d ?? 0;
242
259
  console.warn('valueScale.domain():', valueScale.domain());
243
260
  console.warn('valueScale.range():', valueScale.range());
244
261
  console.warn('value:', valueScale(d + pseudocount));
@@ -251,14 +268,16 @@ export function workerSetPix(
251
268
  return pixData;
252
269
  }
253
270
 
271
+ /**
272
+ * Yanked from https://github.com/numpy/numpy/blob/master/numpy/core/src/npymath/halffloat.c#L466
273
+ *
274
+ * Does not support infinities or NaN. All requests with such
275
+ * values should be encoded as float32
276
+ *
277
+ * @param {number} h
278
+ * @returns {number}
279
+ */
254
280
  function float32(h) {
255
- /**
256
- * Yanked from https://github.com/numpy/numpy/blob/master/numpy/core/src/npymath/halffloat.c#L466
257
- *
258
- * Does not support infinities or NaN. All requests with such
259
- * values should be encoded as float32
260
- */
261
-
262
281
  let hExp = h & 0x7c00;
263
282
  let hSig;
264
283
  let fExp;
@@ -295,7 +314,12 @@ function float32(h) {
295
314
  }
296
315
  }
297
316
 
298
- function _base64ToArrayBuffer(base64) {
317
+ /**
318
+ * Convert a base64 string to an array buffer
319
+ * @param {string} base64
320
+ * @returns {ArrayBuffer}
321
+ */
322
+ function base64ToArrayBuffer(base64) {
299
323
  const binaryString = atob(base64);
300
324
  const len = binaryString.length;
301
325
 
@@ -308,7 +332,13 @@ function _base64ToArrayBuffer(base64) {
308
332
  return bytes.buffer;
309
333
  }
310
334
 
311
- function _uint16ArrayToFloat32Array(uint16array) {
335
+ /**
336
+ * Convert a uint16 array to a float32 array
337
+ *
338
+ * @param {Uint16Array} uint16array
339
+ * @returns {Float32Array}
340
+ */
341
+ function uint16ArrayToFloat32Array(uint16array) {
312
342
  const bytes = new Uint32Array(uint16array.length);
313
343
 
314
344
  for (let i = 0; i < uint16array.length; i++) {
@@ -321,14 +351,60 @@ function _uint16ArrayToFloat32Array(uint16array) {
321
351
  }
322
352
 
323
353
  /**
324
- * Convert a response from the tile server to
325
- * data that can be used by higlass
354
+ * @typedef TileData<Server>
355
+ * @property {string} server
356
+ * @property {string} tileId
357
+ * @property {number} zoomLevel
358
+ * @property {[number] | [number, number]} tilePos
359
+ * @property {string} tilesetUid
360
+ */
361
+
362
+ /**
363
+ * @typedef DenseTileData
364
+ * @property {string} server
365
+ * @property {string} tileId
366
+ * @property {number} zoomLevel
367
+ * @property {[number] | [number, number]} tilePos
368
+ * @property {string} tilesetUid
369
+ * @property {Float32Array} dense
370
+ * @property {string} dtype
371
+ * @property {DenseDataExtrema1D | DenseDataExtrema2D} denseDataExtrema
372
+ * @property {number} minNonZero
373
+ * @property {number} maxNonZero
374
+ */
375
+
376
+ /**
377
+ * @template T
378
+ * @typedef {Omit<T, keyof DenseTileData> & (TileData | DenseTileData)} CompletedTileData
326
379
  */
327
- export function tileResponseToData(data, server, theseTileIds) {
328
- if (!data) {
329
- // probably an error
330
- data = {};
331
- }
380
+
381
+ /**
382
+ * @typedef TileResponse
383
+ * @property {string=} dense - a base64 encoded string
384
+ */
385
+
386
+ /**
387
+ * Convert a response from the tile server to data that can be used by higlass.
388
+ *
389
+ * WARNING: Mutates the data object.
390
+ *
391
+ * @template {TileResponse} T
392
+ * @param {Record<string, T>} inputData
393
+ * @param {string} server
394
+ * @param {string[]} theseTileIds
395
+ *
396
+ * @returns {Record<string, CompletedTileData<T>>}
397
+ *
398
+ * Trevor: This function is littered with ts-expect-error comments because
399
+ * the type of mutation happening to the input object is very tricky to type.
400
+ * The type signature of the function tries to adequately describe the mutation,
401
+ * to outside users.
402
+ */
403
+ export function tileResponseToData(inputData, server, theseTileIds) {
404
+ /** @type {Record<string, Partial<DenseTileData>>} */
405
+ // @ts-expect-error - This function works by overriing all the properties of inputData
406
+ // It's not great, but I don't want to touch the implementation.
407
+ const data = inputData ?? {};
332
408
 
333
409
  for (const thisId of theseTileIds) {
334
410
  if (!(thisId in data)) {
@@ -345,21 +421,28 @@ export function tileResponseToData(data, server, theseTileIds) {
345
421
 
346
422
  // slice from position 2 to exclude tileId and zoomLevel
347
423
  // filter by NaN to exclude metadata portions of the tile request
348
- data[key].tilePos = keyParts
424
+ /** @type {[number] | [number, number]} */
425
+ // @ts-expect-error - tilePos is [number] or [number, number]
426
+ const tilePos = keyParts
349
427
  .slice(2, keyParts.length)
350
428
  .map((x) => +x)
351
429
  .filter((x) => !Number.isNaN(x));
430
+ data[key].tilePos = tilePos;
352
431
  data[key].tilesetUid = keyParts[0];
353
432
 
354
433
  if ('dense' in data[key]) {
355
- const arrayBuffer = _base64ToArrayBuffer(data[key].dense);
434
+ /** @type {string} */
435
+ // @ts-expect-error - The input of this function requires that dense is a string
436
+ // We are overriding the property on the input object, so TS is upset.
437
+ const base64 = data[key].dense;
438
+ const arrayBuffer = base64ToArrayBuffer(base64);
356
439
  let a;
357
440
 
358
441
  if (data[key].dtype === 'float16') {
359
442
  // data is encoded as float16s
360
443
  /* comment out until next empty line for 32 bit arrays */
361
444
  const uint16Array = new Uint16Array(arrayBuffer);
362
- const newDense = _uint16ArrayToFloat32Array(uint16Array);
445
+ const newDense = uint16ArrayToFloat32Array(uint16Array);
363
446
  a = newDense;
364
447
  } else {
365
448
  // data is encoded as float32s
@@ -367,7 +450,7 @@ export function tileResponseToData(data, server, theseTileIds) {
367
450
  }
368
451
 
369
452
  const dde =
370
- data[key].tilePos.length === 2
453
+ tilePos.length === 2
371
454
  ? new DenseDataExtrema2D(a)
372
455
  : new DenseDataExtrema1D(a);
373
456
 
@@ -375,22 +458,23 @@ export function tileResponseToData(data, server, theseTileIds) {
375
458
  data[key].denseDataExtrema = dde;
376
459
  data[key].minNonZero = dde.minNonZeroInTile;
377
460
  data[key].maxNonZero = dde.maxNonZeroInTile;
378
- /*
379
- if (data[key]['minNonZero'] === Number.MAX_SAFE_INTEGER &&
380
- data[key]['maxNonZero'] === Number.MIN_SAFE_INTEGER) {
381
- // if there's no values except 0,
382
- // then do use it as the min value
383
-
384
- data[key]['minNonZero'] = 0;
385
- data[key]['maxNonZero'] = 1;
386
- }
387
- */
388
461
  }
389
462
  }
390
463
 
464
+ // @ts-expect-error - We have completed the tile data.
391
465
  return data;
392
466
  }
393
467
 
468
+ /**
469
+ * Fetch tiles from the server.
470
+ *
471
+ * @param {string} outUrl
472
+ * @param {string} server
473
+ * @param {string[]} theseTileIds
474
+ * @param {string} authHeader
475
+ * @param {(data: Record<string, CompletedTileData<TileResponse>>) => void} done
476
+ * @param {Record<string, unknown>} requestBody
477
+ */
394
478
  export function workerGetTiles(
395
479
  outUrl,
396
480
  server,
@@ -399,6 +483,7 @@ export function workerGetTiles(
399
483
  done,
400
484
  requestBody,
401
485
  ) {
486
+ /** @type {Record<string, string>} */
402
487
  const headers = {
403
488
  'content-type': 'application/json',
404
489
  };
@@ -418,14 +503,6 @@ export function workerGetTiles(
418
503
  .then((response) => response.json())
419
504
  .then((data) => {
420
505
  done(tileResponseToData(data, server, theseTileIds));
421
- /*
422
- const denses = Object.values(data)
423
- .filter(x => x.dense)
424
- .map(x => x.dense);
425
- */
426
- // .map(x => x.dense.buffer);
427
-
428
- // done.transfer(data, denses);
429
506
  })
430
507
  .catch((err) => console.warn('err:', err));
431
508
  }
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  /**
2
3
  * Create a path-based symbol icon
3
4
  *
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  export {
2
3
  changeOptions,
3
4
  waitForJsonComplete,
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  import React from 'react';
2
3
  import ReactDOM from 'react-dom';
3
4
 
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  import { zoomIdentity } from 'd3-zoom';
2
3
  import AxisPixi from './AxisPixi';
3
4
 
@@ -1,16 +1,17 @@
1
1
  /* eslint-disable */
2
2
 
3
- import type { THEME_DARK, THEME_LIGHT } from "./configs";
3
+ import type { THEME_DARK, THEME_LIGHT } from './configs';
4
4
 
5
- export type Scale = import("d3-scale").ScaleContinuousNumeric<number, number>;
5
+ export type Scale = import('d3-scale').ScaleContinuousNumeric<number, number>;
6
6
 
7
- export type TrackPosition = typeof import('./configs/primitives').TRACK_LOCATIONS[number];
7
+ export type TrackPosition =
8
+ typeof import('./configs/primitives').TRACK_LOCATIONS[number];
8
9
 
9
10
  export type ChromInfo<Name extends string = string> = {
10
- cumPositions: { id?: number; pos: number; chr: Name }[];
11
- chrPositions: Record<Name, { pos: number }>;
12
- chromLengths: Record<Name, number>;
13
- totalLength: number;
11
+ cumPositions: { id?: number; pos: number; chr: Name }[];
12
+ chrPositions: Record<Name, { pos: number }>;
13
+ chromLengths: Record<Name, number>;
14
+ totalLength: number;
14
15
  };
15
16
 
16
17
  export type UnknownTrackConfig = {
@@ -30,7 +31,7 @@ export type UnknownTrackConfig = {
30
31
  registerViewportChanged?: unknown;
31
32
  removeViewportChanged?: unknown;
32
33
  setDomainsCallback?: unknown;
33
- }
34
+ };
34
35
 
35
36
  export type CombinedTrackConfig = {
36
37
  uid: string;
@@ -50,17 +51,25 @@ export type CombinedTrackConfig = {
50
51
  registerViewportChanged?: unknown;
51
52
  removeViewportChanged?: unknown;
52
53
  setDomainsCallback?: unknown;
53
- }
54
+ };
54
55
 
55
56
  export type TrackConfig = UnknownTrackConfig | CombinedTrackConfig;
56
57
 
57
58
  export type TrackVisitor = {
58
59
  (track: TrackConfig, position: null | TrackPosition): void;
59
- }
60
+ };
60
61
 
61
62
  type ZoomedFunction = {
62
- (xScale: Scale, yScale: Scale, k?: number, x?: number, y?: number, xPosition?: number, yPosition?: number): void;
63
- }
63
+ (
64
+ xScale: Scale,
65
+ yScale: Scale,
66
+ k?: number,
67
+ x?: number,
68
+ y?: number,
69
+ xPosition?: number,
70
+ yPosition?: number,
71
+ ): void;
72
+ };
64
73
 
65
74
  export interface TrackObject {
66
75
  draw(): void;
@@ -82,24 +91,52 @@ export interface TrackObject {
82
91
 
83
92
  export type Theme = typeof THEME_DARK | typeof THEME_LIGHT;
84
93
 
85
- type TilesetInfoBase = {
94
+ /** Minimum information describing a tileset. */
95
+ export type TilesetInfoShared = {
86
96
  name: string;
87
- coordSystem: string;
88
- min_pos: number[];
89
- max_pos: number[];
97
+ min_pos: number[]; // should be [number, number] | [number]
98
+ max_pos: number[]; // should be [number, number] | [number]
90
99
  max_zoom: number;
100
+ coordSystem?: string;
91
101
  tile_size?: number;
92
102
  max_tile_width?: number;
93
- transforms?: { name: string, value: string }[];
94
- }
103
+ transforms?: { name: string; value: string }[];
104
+ };
95
105
 
96
- export type LegacyTilesetInfo = TilesetInfoBase & {
106
+ export type LegacyTilesetInfo = TilesetInfoShared & {
97
107
  max_width: number;
98
108
  bins_per_dimension?: number;
99
- }
109
+ };
100
110
 
101
- export type ResolutionsTilesetInfo = TilesetInfoBase & {
111
+ export type ResolutionsTilesetInfo = TilesetInfoShared & {
102
112
  resolutions: number[];
103
- }
113
+ };
104
114
 
105
115
  export type TilesetInfo = LegacyTilesetInfo | ResolutionsTilesetInfo;
116
+
117
+ export type DataConfig = {
118
+ server?: string;
119
+ url?: string;
120
+ filetype?: string;
121
+ coordSystem?: string;
122
+ children?: DataConfig[];
123
+ options?: unknown;
124
+ type?: string;
125
+ slicePos?: number;
126
+ };
127
+
128
+ export type HandleTilesetInfoFinished = {
129
+ (info: null): void;
130
+ (info: TilesetInfo, tilesetUid?: string): void;
131
+ (error: { error: string }): void;
132
+ };
133
+
134
+ export interface AbstractDataFetcher<TileType> {
135
+ tilesetInfo(
136
+ callback?: HandleTilesetInfoFinished,
137
+ ): Promise<TilesetInfo | undefined>;
138
+ fetchTilesDebounced(
139
+ receivedTiles: (tiles: Record<string, TileType>) => void,
140
+ tileIds: string[],
141
+ ): Promise<Record<string, TileType>>;
142
+ }