@tetrascience-npm/ts-lib-viz 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +2171 -2
- package/dist/src/builder/PlotPanel.d.ts +42 -0
- package/dist/src/builder/PlotPanel.js +433 -0
- package/dist/src/builder/Popover.d.ts +37 -0
- package/dist/src/builder/Popover.js +32 -0
- package/dist/src/builder/Stepper.d.ts +21 -0
- package/dist/src/builder/Stepper.js +41 -0
- package/dist/src/builder/index.d.ts +10 -0
- package/dist/src/builder/index.js +10 -0
- package/dist/src/core/adapters.d.ts +86 -0
- package/dist/src/core/adapters.js +219 -0
- package/dist/src/core/aggregate.d.ts +74 -0
- package/dist/src/core/aggregate.js +102 -0
- package/dist/src/core/annotations.d.ts +34 -0
- package/dist/src/core/annotations.js +71 -0
- package/dist/src/core/band-order.d.ts +86 -0
- package/dist/src/core/band-order.js +132 -0
- package/dist/src/core/binning.d.ts +123 -0
- package/dist/src/core/binning.js +193 -0
- package/dist/src/core/bounds.d.ts +40 -0
- package/dist/src/core/bounds.js +107 -0
- package/dist/src/core/brush.d.ts +73 -0
- package/dist/src/core/brush.js +102 -0
- package/dist/src/core/build.d.ts +322 -0
- package/dist/src/core/build.js +496 -0
- package/dist/src/core/camera.d.ts +152 -0
- package/dist/src/core/camera.js +303 -0
- package/dist/src/core/capabilities.d.ts +24 -0
- package/dist/src/core/capabilities.js +307 -0
- package/dist/src/core/chord.d.ts +49 -0
- package/dist/src/core/chord.js +57 -0
- package/dist/src/core/circular.d.ts +83 -0
- package/dist/src/core/circular.js +63 -0
- package/dist/src/core/cluster.d.ts +136 -0
- package/dist/src/core/cluster.js +607 -0
- package/dist/src/core/critique.d.ts +92 -0
- package/dist/src/core/critique.js +905 -0
- package/dist/src/core/density.d.ts +38 -0
- package/dist/src/core/density.js +82 -0
- package/dist/src/core/figure-set.d.ts +34 -0
- package/dist/src/core/figure-set.js +55 -0
- package/dist/src/core/finding-codes.d.ts +10 -0
- package/dist/src/core/finding-codes.js +1 -0
- package/dist/src/core/fit-types.d.ts +46 -0
- package/dist/src/core/fit-types.js +7 -0
- package/dist/src/core/fitter.d.ts +62 -0
- package/dist/src/core/fitter.js +102 -0
- package/dist/src/core/frame-geometry.d.ts +407 -0
- package/dist/src/core/frame-geometry.js +612 -0
- package/dist/src/core/frame.d.ts +329 -0
- package/dist/src/core/frame.js +1432 -0
- package/dist/src/core/geom-table.d.ts +503 -0
- package/dist/src/core/geom-table.js +484 -0
- package/dist/src/core/geom-types.d.ts +182 -0
- package/dist/src/core/geom-types.js +17 -0
- package/dist/src/core/grammar.d.ts +359 -0
- package/dist/src/core/grammar.js +397 -0
- package/dist/src/core/heat-reductions.d.ts +36 -0
- package/dist/src/core/heat-reductions.js +133 -0
- package/dist/src/core/hexbin.d.ts +84 -0
- package/dist/src/core/hexbin.js +168 -0
- package/dist/src/core/hierarchy.d.ts +59 -0
- package/dist/src/core/hierarchy.js +248 -0
- package/dist/src/core/hit.d.ts +75 -0
- package/dist/src/core/hit.js +37 -0
- package/dist/src/core/index.d.ts +33 -0
- package/dist/src/core/index.js +18 -0
- package/dist/src/core/internal.d.ts +58 -0
- package/dist/src/core/internal.js +58 -0
- package/dist/src/core/labels.d.ts +37 -0
- package/dist/src/core/labels.js +54 -0
- package/dist/src/core/layers.d.ts +594 -0
- package/dist/src/core/layers.js +2892 -0
- package/dist/src/core/load.d.ts +17 -0
- package/dist/src/core/load.js +356 -0
- package/dist/src/core/marginal.d.ts +65 -0
- package/dist/src/core/marginal.js +116 -0
- package/dist/src/core/mesh.d.ts +69 -0
- package/dist/src/core/mesh.js +237 -0
- package/dist/src/core/omission.d.ts +41 -0
- package/dist/src/core/omission.js +62 -0
- package/dist/src/core/palette-sets.d.ts +623 -0
- package/dist/src/core/palette-sets.js +1058 -0
- package/dist/src/core/palette.d.ts +871 -0
- package/dist/src/core/palette.js +511 -0
- package/dist/src/core/plot-data.d.ts +71 -0
- package/dist/src/core/plot-data.js +82 -0
- package/dist/src/core/predicate.d.ts +50 -0
- package/dist/src/core/predicate.js +20 -0
- package/dist/src/core/profile.d.ts +111 -0
- package/dist/src/core/profile.js +221 -0
- package/dist/src/core/readout.d.ts +108 -0
- package/dist/src/core/readout.js +215 -0
- package/dist/src/core/region.d.ts +56 -0
- package/dist/src/core/region.js +101 -0
- package/dist/src/core/rings.d.ts +96 -0
- package/dist/src/core/rings.js +171 -0
- package/dist/src/core/rules.d.ts +45 -0
- package/dist/src/core/rules.js +69 -0
- package/dist/src/core/sankey.d.ts +49 -0
- package/dist/src/core/sankey.js +96 -0
- package/dist/src/core/select.d.ts +52 -0
- package/dist/src/core/select.js +216 -0
- package/dist/src/core/side-track.d.ts +98 -0
- package/dist/src/core/side-track.js +197 -0
- package/dist/src/core/sizing.d.ts +54 -0
- package/dist/src/core/sizing.js +37 -0
- package/dist/src/core/spec-edit.d.ts +68 -0
- package/dist/src/core/spec-edit.js +105 -0
- package/dist/src/core/spec.d.ts +1111 -0
- package/dist/src/core/spec.js +39 -0
- package/dist/src/core/stats.d.ts +161 -0
- package/dist/src/core/stats.js +318 -0
- package/dist/src/core/tick-format.d.ts +21 -0
- package/dist/src/core/tick-format.js +87 -0
- package/dist/src/core/tokens.d.ts +47 -0
- package/dist/src/core/tokens.js +138 -0
- package/dist/src/core/transform.d.ts +21 -0
- package/dist/src/core/transform.js +19 -0
- package/dist/src/core/voxels.d.ts +53 -0
- package/dist/src/core/voxels.js +129 -0
- package/dist/src/core/zoom.d.ts +76 -0
- package/dist/src/core/zoom.js +103 -0
- package/dist/src/graph/GraphSurface.d.ts +127 -0
- package/dist/src/graph/GraphSurface.js +423 -0
- package/dist/src/graph/data.d.ts +103 -0
- package/dist/src/graph/data.js +140 -0
- package/dist/src/graph/index.d.ts +7 -0
- package/dist/src/graph/index.js +7 -0
- package/dist/src/mcp/data.d.ts +28 -0
- package/dist/src/mcp/data.js +131 -0
- package/dist/src/mcp/index.d.ts +7 -0
- package/dist/src/mcp/index.js +7 -0
- package/dist/src/mcp/paths.d.ts +12 -0
- package/dist/src/mcp/paths.js +30 -0
- package/dist/src/mcp/render.d.ts +67 -0
- package/dist/src/mcp/render.js +189 -0
- package/dist/src/mcp/server.d.ts +7 -0
- package/dist/src/mcp/server.js +25 -0
- package/dist/src/mcp/tools.d.ts +82 -0
- package/dist/src/mcp/tools.js +412 -0
- package/dist/src/react/BrushLayer.d.ts +20 -0
- package/dist/src/react/BrushLayer.js +98 -0
- package/dist/src/react/ColorLegend.d.ts +45 -0
- package/dist/src/react/ColorLegend.js +64 -0
- package/dist/src/react/Figure.d.ts +19 -0
- package/dist/src/react/Figure.js +6 -0
- package/dist/src/react/Frame.d.ts +87 -0
- package/dist/src/react/Frame.js +192 -0
- package/dist/src/react/MarkLegend.d.ts +32 -0
- package/dist/src/react/MarkLegend.js +24 -0
- package/dist/src/react/SeriesLegend.d.ts +38 -0
- package/dist/src/react/SeriesLegend.js +27 -0
- package/dist/src/react/SizeLegend.d.ts +24 -0
- package/dist/src/react/SizeLegend.js +25 -0
- package/dist/src/react/Toolbar.d.ts +109 -0
- package/dist/src/react/Toolbar.js +483 -0
- package/dist/src/react/Tooltip.d.ts +37 -0
- package/dist/src/react/Tooltip.js +59 -0
- package/dist/src/react/Viz.d.ts +112 -0
- package/dist/src/react/Viz.js +1311 -0
- package/dist/src/react/export.d.ts +32 -0
- package/dist/src/react/export.js +181 -0
- package/dist/src/react/geoms/Area.d.ts +38 -0
- package/dist/src/react/geoms/Area.js +48 -0
- package/dist/src/react/geoms/Bars.d.ts +130 -0
- package/dist/src/react/geoms/Bars.js +164 -0
- package/dist/src/react/geoms/Box.d.ts +50 -0
- package/dist/src/react/geoms/Box.js +32 -0
- package/dist/src/react/geoms/Chord.d.ts +60 -0
- package/dist/src/react/geoms/Chord.js +78 -0
- package/dist/src/react/geoms/Contour.d.ts +44 -0
- package/dist/src/react/geoms/Contour.js +78 -0
- package/dist/src/react/geoms/DensityCurve.d.ts +30 -0
- package/dist/src/react/geoms/DensityCurve.js +38 -0
- package/dist/src/react/geoms/FitCurve.d.ts +26 -0
- package/dist/src/react/geoms/FitCurve.js +52 -0
- package/dist/src/react/geoms/Freqpoly.d.ts +30 -0
- package/dist/src/react/geoms/Freqpoly.js +45 -0
- package/dist/src/react/geoms/Gauge.d.ts +42 -0
- package/dist/src/react/geoms/Gauge.js +90 -0
- package/dist/src/react/geoms/Heatmap.d.ts +79 -0
- package/dist/src/react/geoms/Heatmap.js +51 -0
- package/dist/src/react/geoms/Hexbin.d.ts +74 -0
- package/dist/src/react/geoms/Hexbin.js +89 -0
- package/dist/src/react/geoms/Icicle.d.ts +38 -0
- package/dist/src/react/geoms/Icicle.js +9 -0
- package/dist/src/react/geoms/Ideogram.d.ts +58 -0
- package/dist/src/react/geoms/Ideogram.js +77 -0
- package/dist/src/react/geoms/Interval.d.ts +28 -0
- package/dist/src/react/geoms/Interval.js +39 -0
- package/dist/src/react/geoms/Line.d.ts +39 -0
- package/dist/src/react/geoms/Line.js +52 -0
- package/dist/src/react/geoms/Parallel.d.ts +38 -0
- package/dist/src/react/geoms/Parallel.js +131 -0
- package/dist/src/react/geoms/Pie.d.ts +62 -0
- package/dist/src/react/geoms/Pie.js +59 -0
- package/dist/src/react/geoms/Points.d.ts +84 -0
- package/dist/src/react/geoms/Points.js +207 -0
- package/dist/src/react/geoms/Points3d.d.ts +49 -0
- package/dist/src/react/geoms/Points3d.js +58 -0
- package/dist/src/react/geoms/Radar.d.ts +39 -0
- package/dist/src/react/geoms/Radar.js +59 -0
- package/dist/src/react/geoms/Range.d.ts +31 -0
- package/dist/src/react/geoms/Range.js +20 -0
- package/dist/src/react/geoms/RingStack.d.ts +39 -0
- package/dist/src/react/geoms/RingStack.js +65 -0
- package/dist/src/react/geoms/Rule.d.ts +29 -0
- package/dist/src/react/geoms/Rule.js +51 -0
- package/dist/src/react/geoms/Sankey.d.ts +24 -0
- package/dist/src/react/geoms/Sankey.js +51 -0
- package/dist/src/react/geoms/Segment.d.ts +36 -0
- package/dist/src/react/geoms/Segment.js +39 -0
- package/dist/src/react/geoms/Sunburst.d.ts +46 -0
- package/dist/src/react/geoms/Sunburst.js +64 -0
- package/dist/src/react/geoms/Surface.d.ts +32 -0
- package/dist/src/react/geoms/Surface.js +49 -0
- package/dist/src/react/geoms/Text.d.ts +35 -0
- package/dist/src/react/geoms/Text.js +40 -0
- package/dist/src/react/geoms/Treemap.d.ts +39 -0
- package/dist/src/react/geoms/Treemap.js +16 -0
- package/dist/src/react/geoms/Violin.d.ts +56 -0
- package/dist/src/react/geoms/Violin.js +60 -0
- package/dist/src/react/geoms/Volume.d.ts +37 -0
- package/dist/src/react/geoms/Volume.js +40 -0
- package/dist/src/react/geoms/Waterfall.d.ts +43 -0
- package/dist/src/react/geoms/Waterfall.js +18 -0
- package/dist/src/react/geoms/cube-stage.d.ts +39 -0
- package/dist/src/react/geoms/cube-stage.js +85 -0
- package/dist/src/react/geoms/hierarchy-cells.d.ts +42 -0
- package/dist/src/react/geoms/hierarchy-cells.js +59 -0
- package/dist/src/react/geoms/sector-axis.d.ts +66 -0
- package/dist/src/react/geoms/sector-axis.js +99 -0
- package/dist/src/react/gl/GlMesh.d.ts +22 -0
- package/dist/src/react/gl/GlMesh.js +78 -0
- package/dist/src/react/gl/GlPoints.d.ts +45 -0
- package/dist/src/react/gl/GlPoints.js +117 -0
- package/dist/src/react/gl/GlVolume.d.ts +28 -0
- package/dist/src/react/gl/GlVolume.js +112 -0
- package/dist/src/react/gl/GlWalls.d.ts +24 -0
- package/dist/src/react/gl/GlWalls.js +55 -0
- package/dist/src/react/gl/context.d.ts +71 -0
- package/dist/src/react/gl/context.js +98 -0
- package/dist/src/react/gl/encode.d.ts +120 -0
- package/dist/src/react/gl/encode.js +215 -0
- package/dist/src/react/gl/index.d.ts +10 -0
- package/dist/src/react/gl/index.js +8 -0
- package/dist/src/react/gl/refresh.d.ts +7 -0
- package/dist/src/react/gl/refresh.js +19 -0
- package/dist/src/react/gl/renderer.d.ts +377 -0
- package/dist/src/react/gl/renderer.js +1081 -0
- package/dist/src/react/gl/shaders.d.ts +92 -0
- package/dist/src/react/gl/shaders.js +405 -0
- package/dist/src/react/gl/surface.d.ts +31 -0
- package/dist/src/react/gl/surface.js +73 -0
- package/dist/src/react/index.d.ts +12 -0
- package/dist/src/react/index.js +11 -0
- package/dist/src/react/orbit.d.ts +38 -0
- package/dist/src/react/orbit.js +81 -0
- package/dist/src/react/sides/DendrogramPanel.d.ts +32 -0
- package/dist/src/react/sides/DendrogramPanel.js +39 -0
- package/dist/src/react/sides/DensityPanel.d.ts +31 -0
- package/dist/src/react/sides/DensityPanel.js +37 -0
- package/dist/src/react/sides/HistogramPanel.d.ts +30 -0
- package/dist/src/react/sides/HistogramPanel.js +18 -0
- package/dist/src/react/sides/RugPanel.d.ts +28 -0
- package/dist/src/react/sides/RugPanel.js +21 -0
- package/dist/src/react/sides/TrackPanel.d.ts +37 -0
- package/dist/src/react/sides/TrackPanel.js +27 -0
- package/dist/src/react/theme.d.ts +48 -0
- package/dist/src/react/theme.js +148 -0
- package/dist/src/react/useFits.d.ts +26 -0
- package/dist/src/react/useFits.js +62 -0
- package/dist/src/react/useZoom.d.ts +50 -0
- package/dist/src/react/useZoom.js +141 -0
- package/package.json +164 -5
- package/theme/default.css +62 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every core module, for the package's own entry points and tests.
|
|
3
|
+
*
|
|
4
|
+
* No DOM and no React. The exports map publishes `index.ts` and leaves this file out, so a name
|
|
5
|
+
* here is semver surface only where `index.ts` also lists it.
|
|
6
|
+
*/
|
|
7
|
+
export * from "./spec.js";
|
|
8
|
+
export * from "./load.js";
|
|
9
|
+
export * from "./grammar.js";
|
|
10
|
+
export * from "./tokens.js";
|
|
11
|
+
export * from "./camera.js";
|
|
12
|
+
export * from "./mesh.js";
|
|
13
|
+
export * from "./voxels.js";
|
|
14
|
+
export * from "./sizing.js";
|
|
15
|
+
export * from "./spec-edit.js";
|
|
16
|
+
export * from "./build.js";
|
|
17
|
+
export * from "./annotations.js";
|
|
18
|
+
export * from "./predicate.js";
|
|
19
|
+
export * from "./plot-data.js";
|
|
20
|
+
export * from "./aggregate.js";
|
|
21
|
+
export * from "./stats.js";
|
|
22
|
+
export * from "./density.js";
|
|
23
|
+
export * from "./geom-types.js";
|
|
24
|
+
export * from "./geom-table.js";
|
|
25
|
+
export * from "./hierarchy.js";
|
|
26
|
+
export * from "./sankey.js";
|
|
27
|
+
export * from "./circular.js";
|
|
28
|
+
export * from "./chord.js";
|
|
29
|
+
export * from "./rings.js";
|
|
30
|
+
export * from "./fit-types.js";
|
|
31
|
+
export * from "./transform.js";
|
|
32
|
+
export * from "./frame-geometry.js";
|
|
33
|
+
export * from "./labels.js";
|
|
34
|
+
export * from "./tick-format.js";
|
|
35
|
+
export * from "./hit.js";
|
|
36
|
+
export * from "./brush.js";
|
|
37
|
+
export * from "./binning.js";
|
|
38
|
+
export * from "./hexbin.js";
|
|
39
|
+
export * from "./heat-reductions.js";
|
|
40
|
+
export * from "./cluster.js";
|
|
41
|
+
export * from "./band-order.js";
|
|
42
|
+
export * from "./side-track.js";
|
|
43
|
+
export * from "./marginal.js";
|
|
44
|
+
export * from "./figure-set.js";
|
|
45
|
+
export * from "./palette.js";
|
|
46
|
+
export * from "./layers.js";
|
|
47
|
+
export * from "./omission.js";
|
|
48
|
+
export * from "./frame.js";
|
|
49
|
+
export * from "./rules.js";
|
|
50
|
+
export * from "./fitter.js";
|
|
51
|
+
export * from "./zoom.js";
|
|
52
|
+
export * from "./readout.js";
|
|
53
|
+
export * from "./select.js";
|
|
54
|
+
export * from "./region.js";
|
|
55
|
+
export * from "./capabilities.js";
|
|
56
|
+
export * from "./adapters.js";
|
|
57
|
+
export * from "./profile.js";
|
|
58
|
+
export * from "./critique.js";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every core module, for the package's own entry points and tests.
|
|
3
|
+
*
|
|
4
|
+
* No DOM and no React. The exports map publishes `index.ts` and leaves this file out, so a name
|
|
5
|
+
* here is semver surface only where `index.ts` also lists it.
|
|
6
|
+
*/
|
|
7
|
+
export * from "./spec.js";
|
|
8
|
+
export * from "./load.js";
|
|
9
|
+
export * from "./grammar.js";
|
|
10
|
+
export * from "./tokens.js";
|
|
11
|
+
export * from "./camera.js";
|
|
12
|
+
export * from "./mesh.js";
|
|
13
|
+
export * from "./voxels.js";
|
|
14
|
+
export * from "./sizing.js";
|
|
15
|
+
export * from "./spec-edit.js";
|
|
16
|
+
export * from "./build.js";
|
|
17
|
+
export * from "./annotations.js";
|
|
18
|
+
export * from "./predicate.js";
|
|
19
|
+
export * from "./plot-data.js";
|
|
20
|
+
export * from "./aggregate.js";
|
|
21
|
+
export * from "./stats.js";
|
|
22
|
+
export * from "./density.js";
|
|
23
|
+
export * from "./geom-types.js";
|
|
24
|
+
export * from "./geom-table.js";
|
|
25
|
+
export * from "./hierarchy.js";
|
|
26
|
+
export * from "./sankey.js";
|
|
27
|
+
export * from "./circular.js";
|
|
28
|
+
export * from "./chord.js";
|
|
29
|
+
export * from "./rings.js";
|
|
30
|
+
export * from "./fit-types.js";
|
|
31
|
+
export * from "./transform.js";
|
|
32
|
+
export * from "./frame-geometry.js";
|
|
33
|
+
export * from "./labels.js";
|
|
34
|
+
export * from "./tick-format.js";
|
|
35
|
+
export * from "./hit.js";
|
|
36
|
+
export * from "./brush.js";
|
|
37
|
+
export * from "./binning.js";
|
|
38
|
+
export * from "./hexbin.js";
|
|
39
|
+
export * from "./heat-reductions.js";
|
|
40
|
+
export * from "./cluster.js";
|
|
41
|
+
export * from "./band-order.js";
|
|
42
|
+
export * from "./side-track.js";
|
|
43
|
+
export * from "./marginal.js";
|
|
44
|
+
export * from "./figure-set.js";
|
|
45
|
+
export * from "./palette.js";
|
|
46
|
+
export * from "./layers.js";
|
|
47
|
+
export * from "./omission.js";
|
|
48
|
+
export * from "./frame.js";
|
|
49
|
+
export * from "./rules.js";
|
|
50
|
+
export * from "./fitter.js";
|
|
51
|
+
export * from "./zoom.js";
|
|
52
|
+
export * from "./readout.js";
|
|
53
|
+
export * from "./select.js";
|
|
54
|
+
export * from "./region.js";
|
|
55
|
+
export * from "./capabilities.js";
|
|
56
|
+
export * from "./adapters.js";
|
|
57
|
+
export * from "./profile.js";
|
|
58
|
+
export * from "./critique.js";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which geoms get a direct label.
|
|
3
|
+
*
|
|
4
|
+
* Chart-design rule 2 is selective and most geoms stay bare. The cap applies to all rules and
|
|
5
|
+
* the footer reports it.
|
|
6
|
+
*/
|
|
7
|
+
import type { LabelWhen } from "./spec.js";
|
|
8
|
+
/** Positions are all a rule reads. A geom's other fields belong to the caller. */
|
|
9
|
+
export interface Labeled {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
}
|
|
13
|
+
/** Maximum labels per frame. */
|
|
14
|
+
export declare const LABEL_CAP = 40;
|
|
15
|
+
export interface Chosen {
|
|
16
|
+
/** Positions in the input, in the order the rule ranked them. */
|
|
17
|
+
indices: number[];
|
|
18
|
+
/** Geoms the rule matched beyond the cap. The footer reports this count. */
|
|
19
|
+
dropped: number;
|
|
20
|
+
}
|
|
21
|
+
/** A placed label's footprint in pixels. */
|
|
22
|
+
export interface LabelBox {
|
|
23
|
+
/** Horizontal center, matching the anchor a `Labeled` geom carries. */
|
|
24
|
+
x: number;
|
|
25
|
+
/** Vertical center, on the same convention. */
|
|
26
|
+
y: number;
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Drops labels that would land on one already placed.
|
|
32
|
+
*
|
|
33
|
+
* Greedy in input order. The first geom keeps its label and a later overlap yields. Callers
|
|
34
|
+
* should pass the rule's ranking.
|
|
35
|
+
*/
|
|
36
|
+
export declare function withoutCollisions(boxes: LabelBox[]): number[];
|
|
37
|
+
export declare function chooseLabels(points: Labeled[], when: LabelWhen, cap?: number): Chosen;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which geoms get a direct label.
|
|
3
|
+
*
|
|
4
|
+
* Chart-design rule 2 is selective and most geoms stay bare. The cap applies to all rules and
|
|
5
|
+
* the footer reports it.
|
|
6
|
+
*/
|
|
7
|
+
/** Maximum labels per frame. */
|
|
8
|
+
export const LABEL_CAP = 40;
|
|
9
|
+
const overlaps = (a, b) => Math.abs(a.x - b.x) * 2 < a.width + b.width && Math.abs(a.y - b.y) * 2 < a.height + b.height;
|
|
10
|
+
/**
|
|
11
|
+
* Drops labels that would land on one already placed.
|
|
12
|
+
*
|
|
13
|
+
* Greedy in input order. The first geom keeps its label and a later overlap yields. Callers
|
|
14
|
+
* should pass the rule's ranking.
|
|
15
|
+
*/
|
|
16
|
+
export function withoutCollisions(boxes) {
|
|
17
|
+
const kept = [];
|
|
18
|
+
const indices = [];
|
|
19
|
+
for (let index = 0; index < boxes.length; index += 1) {
|
|
20
|
+
const box = boxes[index];
|
|
21
|
+
if (kept.some((placed) => overlaps(placed, box)))
|
|
22
|
+
continue;
|
|
23
|
+
kept.push(box);
|
|
24
|
+
indices.push(index);
|
|
25
|
+
}
|
|
26
|
+
return indices;
|
|
27
|
+
}
|
|
28
|
+
export function chooseLabels(points, when, cap = LABEL_CAP) {
|
|
29
|
+
if (when.kind === "top") {
|
|
30
|
+
const wanted = Math.max(0, Math.min(when.count, cap));
|
|
31
|
+
const ranked = points
|
|
32
|
+
.map((point, index) => ({ index, value: when.on === "x" ? point.x : point.y }))
|
|
33
|
+
.sort((a, b) => (when.end === "high" ? b.value - a.value : a.value - b.value));
|
|
34
|
+
const taken = ranked.slice(0, wanted);
|
|
35
|
+
return {
|
|
36
|
+
indices: taken.map((entry) => entry.index),
|
|
37
|
+
dropped: Math.max(0, Math.min(when.count, points.length) - taken.length),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const matched = [];
|
|
41
|
+
for (let index = 0; index < points.length; index += 1) {
|
|
42
|
+
if (when.kind === "all") {
|
|
43
|
+
matched.push(index);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const value = when.on === "x" ? points[index].x : points[index].y;
|
|
47
|
+
if (when.op === "above" ? value > when.value : value < when.value)
|
|
48
|
+
matched.push(index);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
indices: matched.slice(0, cap),
|
|
52
|
+
dropped: Math.max(0, matched.length - cap),
|
|
53
|
+
};
|
|
54
|
+
}
|