@d3plus/core 4.11.0 → 4.12.0
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/es/internal.js +15 -5
- package/es/src/charts/Alluvial/emit.js +2 -2
- package/es/src/charts/Alluvial/index.js +7 -1
- package/es/src/charts/Alluvial/titles.js +24 -4
- package/es/src/charts/ArcDiagram/emit.js +27 -13
- package/es/src/charts/ArcDiagram/events.js +6 -2
- package/es/src/charts/ArcDiagram/index.js +2 -0
- package/es/src/charts/BarChart/index.js +3 -10
- package/es/src/charts/Calendar/index.js +2 -0
- package/es/src/charts/Candlestick/index.js +4 -10
- package/es/src/charts/Gantt/applyLayout.js +2 -4
- package/es/src/charts/Geomap/flowEmit.js +11 -6
- package/es/src/charts/Hexbin/index.js +2 -0
- package/es/src/charts/Icicle/index.js +3 -1
- package/es/src/charts/Matrix/applyLayout.js +20 -9
- package/es/src/charts/Matrix/index.js +19 -1
- package/es/src/charts/Network/applyLayout.js +36 -5
- package/es/src/charts/Network/bundle.js +5 -4
- package/es/src/charts/Network/emit.js +39 -40
- package/es/src/charts/Network/graph.js +34 -5
- package/es/src/charts/Network/graphFluent.js +5 -3
- package/es/src/charts/Network/index.js +6 -1
- package/es/src/charts/Pack/applyLayout.js +16 -5
- package/es/src/charts/Pack/emit.js +15 -8
- package/es/src/charts/Pack/groupRows.js +61 -0
- package/es/src/charts/Pack/index.js +3 -0
- package/es/src/charts/Pack/neutralPaint.js +20 -0
- package/es/src/charts/Pack/nodeNames.js +35 -0
- package/es/src/charts/ParallelCoordinates/axes.js +22 -22
- package/es/src/charts/ParallelCoordinates/chrome.js +18 -0
- package/es/src/charts/ParallelCoordinates/index.js +3 -1
- package/es/src/charts/ParallelCoordinates/titles.js +17 -9
- package/es/src/charts/Pie/emit.js +9 -1
- package/es/src/charts/Pie/index.js +10 -0
- package/es/src/charts/Plot/areaEnter.js +68 -0
- package/es/src/charts/Plot/draw.js +26 -12
- package/es/src/charts/Plot/index.js +4 -10
- package/es/src/charts/Plot/lineMarkerKeys.js +19 -0
- package/es/src/charts/Plot/plotInit.js +6 -0
- package/es/src/charts/Plot/shapeLabelLegend.js +67 -0
- package/es/src/charts/Plot/sharedHover.js +2 -1
- package/es/src/charts/Plot/sharedTooltip.js +13 -3
- package/es/src/charts/PolarArea/index.js +2 -1
- package/es/src/charts/Priestley/applyLayout.js +11 -7
- package/es/src/charts/Priestley/index.js +0 -2
- package/es/src/charts/Priestley/timeAxis.js +11 -8
- package/es/src/charts/Pyramid/gutter.js +52 -16
- package/es/src/charts/Pyramid/index.js +55 -7
- package/es/src/charts/Pyramid/scene.js +4 -4
- package/es/src/charts/Radar/applyLayout.js +31 -33
- package/es/src/charts/Radar/axisDecorations.js +29 -17
- package/es/src/charts/Radar/curvedLabels.js +43 -2
- package/es/src/charts/Radar/emit.js +30 -15
- package/es/src/charts/Radar/index.js +41 -2
- package/es/src/charts/Radar/points.js +85 -0
- package/es/src/charts/RadialBar/emit.js +6 -1
- package/es/src/charts/RadialBar/index.js +10 -0
- package/es/src/charts/RadialMatrix/applyLayout.js +115 -31
- package/es/src/charts/RadialMatrix/index.js +15 -2
- package/es/src/charts/Rings/applyLayout.js +11 -150
- package/es/src/charts/Rings/emit.js +80 -40
- package/es/src/charts/Rings/index.js +27 -4
- package/es/src/charts/Rings/ringsCurves.js +156 -0
- package/es/src/charts/Rings/ringsParallel.js +20 -3
- package/es/src/charts/Rings/ringsPlacement.js +152 -0
- package/es/src/charts/Rings/ringsSizing.js +61 -38
- package/es/src/charts/Sankey/applyLayout.js +18 -4
- package/es/src/charts/Sankey/index.js +7 -1
- package/es/src/charts/Sunburst/emit.js +9 -1
- package/es/src/charts/Sunburst/index.js +13 -1
- package/es/src/charts/Tree/applyLayout.js +44 -14
- package/es/src/charts/Tree/emit.js +5 -5
- package/es/src/charts/Tree/index.js +10 -12
- package/es/src/charts/Tree/keys.js +33 -0
- package/es/src/charts/Tree/nodeLabel.js +15 -0
- package/es/src/charts/Treemap/emitGroupHeaders.js +3 -5
- package/es/src/charts/definition/makeChart.js +6 -2
- package/es/src/charts/drawSteps/minimap.js +4 -20
- package/es/src/charts/drawSteps/zoomActions.js +36 -0
- package/es/src/charts/drawSteps/zoomControls.js +31 -18
- package/es/src/charts/drawSteps/zoomControlsMarkup.js +23 -4
- package/es/src/charts/drawSteps/zoomDrag.js +188 -0
- package/es/src/charts/drawSteps/zoomFit.js +69 -0
- package/es/src/charts/events/click.legend.js +4 -2
- package/es/src/charts/events/click.shape.js +5 -3
- package/es/src/charts/events/mouseenter.js +6 -16
- package/es/src/charts/events/mouseleave.js +9 -2
- package/es/src/charts/events/mousemove.legend.js +28 -32
- package/es/src/charts/events/mousemove.shape.js +44 -44
- package/es/src/charts/features/axes.js +15 -4
- package/es/src/charts/features/axesFinal.js +7 -2
- package/es/src/charts/features/axesMeasure.js +26 -8
- package/es/src/charts/features/axisTooltip.js +138 -0
- package/es/src/charts/features/centerLabel.js +177 -0
- package/es/src/charts/features/colorScaleBivariate.js +83 -0
- package/es/src/charts/features/colorScaleBucket.js +18 -0
- package/es/src/charts/features/colorScaleHover.js +30 -5
- package/es/src/charts/features/colorScaleLimit.js +73 -0
- package/es/src/charts/features/colorScaleTooltip.js +77 -0
- package/es/src/charts/features/colorScaleTop.js +61 -0
- package/es/src/charts/features/curvedArrows.js +33 -0
- package/es/src/charts/features/depthKey.js +26 -0
- package/es/src/charts/features/edgeArrows.js +61 -2
- package/es/src/charts/features/featuresColorScale.js +57 -16
- package/es/src/charts/features/hoverTicks.js +41 -0
- package/es/src/charts/features/idleQueue.js +72 -0
- package/es/src/charts/features/linkInteraction.js +59 -7
- package/es/src/charts/features/networkMeasures.js +241 -0
- package/es/src/charts/features/nodeStats.js +309 -0
- package/es/src/charts/features/plotEndLabels.js +28 -7
- package/es/src/charts/features/plotPaint.js +9 -2
- package/es/src/charts/features/shapeEmit.js +7 -1
- package/es/src/charts/features/textHalo.js +3 -2
- package/es/src/charts/partition/chartFields.js +12 -3
- package/es/src/charts/partition/interaction.js +10 -5
- package/es/src/charts/pipeline/insetPlacement.js +8 -3
- package/es/src/charts/polar/chrome.js +81 -9
- package/es/src/charts/polar/config.js +4 -0
- package/es/src/charts/polar/wedgeLayout.js +2 -1
- package/es/src/charts/viz/Viz.js +24 -15
- package/es/src/charts/viz/VizBase.js +39 -4
- package/es/src/charts/viz/backgroundInk.js +10 -0
- package/es/src/charts/viz/emphasis.js +14 -0
- package/es/src/charts/viz/fillStroke.js +10 -0
- package/es/src/charts/viz/interactionOpacity.js +115 -32
- package/es/src/charts/viz/reportDrawError.js +15 -0
- package/es/src/charts/viz/setCursor.js +29 -0
- package/es/src/charts/viz/tooltipEnabled.js +38 -0
- package/es/src/charts/viz/userClick.js +34 -0
- package/es/src/charts/viz/vizDataPolling.js +0 -1
- package/es/src/charts/viz/vizDefaults.js +13 -34
- package/es/src/charts/viz/vizFields.js +6 -1
- package/es/src/charts/viz/vizRender.js +35 -5
- package/es/src/charts/viz/vizVisibility.js +12 -2
- package/es/src/components/Axis/Axis.js +29 -2
- package/es/src/components/Axis/axisBreak.js +29 -7
- package/es/src/components/Axis/axisDefaults.js +11 -0
- package/es/src/components/Axis/axisLabelKinds.js +36 -0
- package/es/src/components/Axis/axisLabelLineHeight.js +19 -0
- package/es/src/components/Axis/axisLabelRoom.js +37 -0
- package/es/src/components/Axis/axisLabelSize.js +171 -0
- package/es/src/components/Axis/axisLabelThinning.js +98 -4
- package/es/src/components/Axis/axisLayout.js +71 -46
- package/es/src/components/Axis/axisLayoutLabels.js +82 -140
- package/es/src/components/Axis/axisLayoutScale.js +9 -10
- package/es/src/components/Axis/axisLimit.js +27 -0
- package/es/src/components/Axis/axisMaxSize.js +39 -0
- package/es/src/components/Axis/axisRender.js +20 -8
- package/es/src/components/Axis/axisRounding.js +16 -1
- package/es/src/components/Axis/axisScene.js +11 -2
- package/es/src/components/Axis/axisTitle.js +53 -0
- package/es/src/components/Axis/axisTooltipTargets.js +128 -0
- package/es/src/components/ColorScale/ColorScale.js +62 -18
- package/es/src/components/ColorScale/bivariateRender.js +353 -0
- package/es/src/components/ColorScale/bivariateScale.js +150 -0
- package/es/src/components/ColorScale/colorScaleRender.js +32 -2
- package/es/src/components/ColorScale/colorScaleSwatchTooltips.js +77 -0
- package/es/src/components/Legend/Legend.js +10 -2
- package/es/src/components/Legend/legendCut.js +108 -0
- package/es/src/components/Legend/legendRender.js +38 -13
- package/es/src/components/TextBox.js +5 -2
- package/es/src/components/Timeline/timelineRender.js +2 -1
- package/es/src/components/textBoxScene.js +3 -0
- package/es/src/components/textEllipsis.js +7 -0
- package/es/src/components/tooltipDom.js +8 -5
- package/es/src/fluent.js +48 -0
- package/es/src/utils/BaseClass.js +7 -2
- package/es/src/utils/configValue.js +9 -0
- package/package.json +10 -10
- package/types/index.d.ts +1 -1
- package/types/internal.d.ts +22 -5
- package/types/src/charts/Alluvial/titles.d.ts +16 -3
- package/types/src/charts/ArcDiagram/emit.d.ts +3 -2
- package/types/src/charts/ArcDiagram/events.d.ts +2 -1
- package/types/src/charts/Geomap/flowEmit.d.ts +3 -2
- package/types/src/charts/Matrix/applyLayout.d.ts +4 -2
- package/types/src/charts/Network/applyLayout.d.ts +11 -0
- package/types/src/charts/Network/bundle.d.ts +3 -1
- package/types/src/charts/Network/graph.d.ts +12 -4
- package/types/src/charts/Pack/applyLayout.d.ts +2 -0
- package/types/src/charts/Pack/groupRows.d.ts +46 -0
- package/types/src/charts/Pack/index.d.ts +3 -0
- package/types/src/charts/Pack/neutralPaint.d.ts +14 -0
- package/types/src/charts/Pack/nodeNames.d.ts +23 -0
- package/types/src/charts/ParallelCoordinates/chrome.d.ts +12 -0
- package/types/src/charts/ParallelCoordinates/index.d.ts +1 -0
- package/types/src/charts/ParallelCoordinates/titles.d.ts +7 -2
- package/types/src/charts/Plot/areaEnter.d.ts +34 -0
- package/types/src/charts/Plot/index.d.ts +4 -10
- package/types/src/charts/Plot/lineMarkerKeys.d.ts +11 -0
- package/types/src/charts/Plot/shapeLabelLegend.d.ts +19 -0
- package/types/src/charts/Plot/sharedTooltip.d.ts +7 -1
- package/types/src/charts/Priestley/timeAxis.d.ts +7 -4
- package/types/src/charts/Pyramid/gutter.d.ts +28 -6
- package/types/src/charts/Pyramid/scene.d.ts +1 -1
- package/types/src/charts/Radar/applyLayout.d.ts +2 -3
- package/types/src/charts/Radar/axisDecorations.d.ts +5 -2
- package/types/src/charts/Radar/curvedLabels.d.ts +35 -0
- package/types/src/charts/Radar/emit.d.ts +5 -2
- package/types/src/charts/Radar/index.d.ts +7 -2
- package/types/src/charts/Radar/points.d.ts +50 -0
- package/types/src/charts/RadialMatrix/applyLayout.d.ts +6 -4
- package/types/src/charts/Rings/emit.d.ts +24 -2
- package/types/src/charts/Rings/index.d.ts +4 -2
- package/types/src/charts/Rings/ringsCurves.d.ts +50 -0
- package/types/src/charts/Rings/ringsGraph.d.ts +29 -5
- package/types/src/charts/Rings/ringsParallel.d.ts +4 -2
- package/types/src/charts/Rings/ringsPlacement.d.ts +47 -0
- package/types/src/charts/Rings/ringsSizing.d.ts +36 -9
- package/types/src/charts/Tree/applyLayout.d.ts +20 -0
- package/types/src/charts/Tree/keys.d.ts +25 -0
- package/types/src/charts/Tree/nodeLabel.d.ts +11 -0
- package/types/src/charts/definition/ChartDefinition.d.ts +13 -0
- package/types/src/charts/definition/makeChart.d.ts +2 -2
- package/types/src/charts/drawSteps/zoomActions.d.ts +30 -0
- package/types/src/charts/drawSteps/zoomControls.d.ts +15 -0
- package/types/src/charts/drawSteps/zoomControlsMarkup.d.ts +16 -1
- package/types/src/charts/drawSteps/zoomDrag.d.ts +71 -0
- package/types/src/charts/drawSteps/zoomFit.d.ts +30 -0
- package/types/src/charts/features/axisTooltip.d.ts +49 -0
- package/types/src/charts/features/centerLabel.d.ts +75 -0
- package/types/src/charts/features/colorScaleBivariate.d.ts +50 -0
- package/types/src/charts/features/colorScaleBucket.d.ts +10 -0
- package/types/src/charts/features/colorScaleHover.d.ts +13 -3
- package/types/src/charts/features/colorScaleLimit.d.ts +60 -0
- package/types/src/charts/features/colorScaleTooltip.d.ts +43 -0
- package/types/src/charts/features/colorScaleTop.d.ts +30 -0
- package/types/src/charts/features/curvedArrows.d.ts +14 -0
- package/types/src/charts/features/depthKey.d.ts +19 -0
- package/types/src/charts/features/edgeArrows.d.ts +29 -2
- package/types/src/charts/features/hoverTicks.d.ts +30 -0
- package/types/src/charts/features/idleQueue.d.ts +46 -0
- package/types/src/charts/features/linkInteraction.d.ts +13 -4
- package/types/src/charts/features/networkMeasures.d.ts +53 -0
- package/types/src/charts/features/nodeStats.d.ts +93 -0
- package/types/src/charts/features/plotEndLabels.d.ts +14 -1
- package/types/src/charts/features/textHalo.d.ts +4 -3
- package/types/src/charts/partition/chartFields.d.ts +6 -1
- package/types/src/charts/pipeline/insetPlacement.d.ts +6 -0
- package/types/src/charts/polar/chrome.d.ts +19 -6
- package/types/src/charts/viz/Viz.d.ts +10 -3
- package/types/src/charts/viz/VizBase.d.ts +31 -2
- package/types/src/charts/viz/backgroundInk.d.ts +8 -0
- package/types/src/charts/viz/emphasis.d.ts +17 -0
- package/types/src/charts/viz/fillStroke.d.ts +7 -0
- package/types/src/charts/viz/reportDrawError.d.ts +12 -0
- package/types/src/charts/viz/setCursor.d.ts +26 -0
- package/types/src/charts/viz/tooltipEnabled.d.ts +31 -0
- package/types/src/charts/viz/userClick.d.ts +35 -0
- package/types/src/charts/viz/vizFields.d.ts +5 -0
- package/types/src/charts/viz/vizTypes.d.ts +16 -0
- package/types/src/charts/viz/vizVisibility.d.ts +7 -0
- package/types/src/components/Axis/Axis.d.ts +33 -3
- package/types/src/components/Axis/axisBreak.d.ts +19 -3
- package/types/src/components/Axis/axisDefaults.d.ts +12 -0
- package/types/src/components/Axis/axisLabelKinds.d.ts +22 -0
- package/types/src/components/Axis/axisLabelLineHeight.d.ts +27 -0
- package/types/src/components/Axis/axisLabelRoom.d.ts +17 -0
- package/types/src/components/Axis/axisLabelSize.d.ts +82 -0
- package/types/src/components/Axis/axisLabelThinning.d.ts +38 -2
- package/types/src/components/Axis/axisLayout.d.ts +9 -2
- package/types/src/components/Axis/axisLayoutLabels.d.ts +28 -33
- package/types/src/components/Axis/axisLayoutScale.d.ts +3 -1
- package/types/src/components/Axis/axisLimit.d.ts +18 -0
- package/types/src/components/Axis/axisMaxSize.d.ts +48 -0
- package/types/src/components/Axis/axisRounding.d.ts +8 -0
- package/types/src/components/Axis/axisTitle.d.ts +30 -0
- package/types/src/components/Axis/axisTooltipTargets.d.ts +82 -0
- package/types/src/components/ColorScale/ColorScale.d.ts +21 -11
- package/types/src/components/ColorScale/bivariateRender.d.ts +53 -0
- package/types/src/components/ColorScale/bivariateScale.d.ts +92 -0
- package/types/src/components/ColorScale/colorScaleSwatchTooltips.d.ts +48 -0
- package/types/src/components/Legend/Legend.d.ts +5 -0
- package/types/src/components/Legend/legendCut.d.ts +31 -0
- package/types/src/components/Legend/legendRender.d.ts +6 -1
- package/types/src/components/TextBox.d.ts +4 -0
- package/types/src/components/textEllipsis.d.ts +6 -0
- package/types/src/fluent.d.ts +18 -0
- package/types/src/shapes/emitLabels.d.ts +1 -1
- package/types/src/utils/D3plusConfig.d.ts +485 -609
- package/types/src/utils/configValue.d.ts +8 -0
- package/types/src/utils/index.d.ts +1 -1
- package/types/umd-entry.d.ts +4 -0
- package/umd/d3plus-core.full.js +22930 -17936
- package/umd/d3plus-core.full.min.js +2 -2
- package/umd/d3plus-core.js +21240 -16404
- package/umd/d3plus-core.min.js +2 -2
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
`ringsCtx` stashed on `viz.ctx`. Emits flat SceneNodes directly
|
|
4
4
|
(no transient Shape compute pass).
|
|
5
5
|
*/ import { emitLabels } from "../../shapes/emitLabels.js";
|
|
6
|
-
import {
|
|
6
|
+
import { edgeArrowTrims, emphasizedArrowEdge, scaledArrowSize, scaledStrokeWidth, straightEdgeArrows, straightEdgeD } from "../features/edgeArrows.js";
|
|
7
7
|
import { drawNodeLabel, paintFromShapeConfig, resolveAccessor, shapeConfigFor, userLabelConfig } from "../features/emitHelpers.js";
|
|
8
8
|
import { backgroundImageNode } from "../features/backgroundImageEmit.js";
|
|
9
9
|
import { linkAriaLabel, linkHitPath, linkMeta } from "../features/linkInteraction.js";
|
|
@@ -12,19 +12,25 @@ import { cubicMidpoint, segmentMidpoint } from "../features/linkLabelGeometry.js
|
|
|
12
12
|
import { emitLinkLabels, textLineBoxes } from "../features/linkLabels.js";
|
|
13
13
|
import { curvePoints } from "../features/linkLabelPath.js";
|
|
14
14
|
import { selfLoopArrows, selfLoopD } from "../features/selfLoops.js";
|
|
15
|
-
import {
|
|
15
|
+
import { textHalo } from "../features/textHalo.js";
|
|
16
|
+
import { chordArrowNodes, cubicPolyline, cubicsArrowEdge, cubicsPathD } from "../features/curvedArrows.js";
|
|
17
|
+
import { polylineMidpoint } from "../features/polyline.js";
|
|
16
18
|
import { uniqueLinkKeys } from "../features/linkKeys.js";
|
|
19
|
+
import { chartBackground } from "../viz/backgroundInk.js";
|
|
17
20
|
/**
|
|
18
21
|
Arrowheads for one Rings edge. Spline edges already terminate at the node
|
|
19
22
|
boundary, so the tangent comes from the bezier's end control point; straight
|
|
20
|
-
center-links run center-to-center and inset by the node radius.
|
|
21
|
-
|
|
23
|
+
center-links run center-to-center and inset by the node radius. `scale`
|
|
24
|
+
widens the stroke they're sized for (see `emphasizedArrowEdge`).
|
|
25
|
+
*/ function ringsEdgeArrows(viz, edge, datum, stroke, width, i, scale = 1) {
|
|
22
26
|
const arrows = viz.schema.arrows;
|
|
27
|
+
const arrowSize = scaledArrowSize(viz.schema.arrowSize, scale);
|
|
28
|
+
const strokeWidth = scaledStrokeWidth(width, scale);
|
|
23
29
|
const baseKey = `${edge.source.id}-${edge.target.id}-${i}`;
|
|
24
30
|
const fill = typeof stroke === "string" ? stroke : undefined;
|
|
25
31
|
if (edge.loop) return selfLoopArrows({
|
|
26
32
|
arrows,
|
|
27
|
-
arrowSize
|
|
33
|
+
arrowSize,
|
|
28
34
|
strokeWidth,
|
|
29
35
|
datum,
|
|
30
36
|
i,
|
|
@@ -35,7 +41,7 @@ import { uniqueLinkKeys } from "../features/linkKeys.js";
|
|
|
35
41
|
if (!edge.spline) {
|
|
36
42
|
return straightEdgeArrows({
|
|
37
43
|
arrows,
|
|
38
|
-
arrowSize
|
|
44
|
+
arrowSize,
|
|
39
45
|
strokeWidth,
|
|
40
46
|
datum,
|
|
41
47
|
i,
|
|
@@ -45,12 +51,12 @@ import { uniqueLinkKeys } from "../features/linkKeys.js";
|
|
|
45
51
|
target: edge.target
|
|
46
52
|
});
|
|
47
53
|
}
|
|
48
|
-
const
|
|
49
|
-
if (!
|
|
50
|
-
const trims = ringsTrims(viz, edge, i,
|
|
54
|
+
const curves = ringsCurves(edge);
|
|
55
|
+
if (!curves) return [];
|
|
56
|
+
const trims = ringsTrims(viz, edge, i, width, scale);
|
|
51
57
|
if (!trims.ends.source && !trims.ends.target) return [];
|
|
52
58
|
return chordArrowNodes({
|
|
53
|
-
ends:
|
|
59
|
+
ends: cubicsArrowEdge(curves, trims),
|
|
54
60
|
size: trims.size,
|
|
55
61
|
datum,
|
|
56
62
|
keyPrefix: "rings-arrow",
|
|
@@ -61,45 +67,57 @@ import { uniqueLinkKeys } from "../features/linkKeys.js";
|
|
|
61
67
|
fill
|
|
62
68
|
});
|
|
63
69
|
}
|
|
64
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
A spline edge's curves, from its source end to its target end: one
|
|
72
|
+
cubic, or a link along a ring's several. Null for a straight edge.
|
|
73
|
+
*/ function ringsCurves(edge) {
|
|
74
|
+
if (edge.segments?.length) return edge.segments;
|
|
65
75
|
if (!edge.spline || edge.sourceX == null || edge.targetX == null) return null;
|
|
66
76
|
return [
|
|
67
77
|
[
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
[
|
|
79
|
+
edge.sourceX,
|
|
80
|
+
edge.sourceY
|
|
81
|
+
],
|
|
82
|
+
[
|
|
83
|
+
edge.sourceBisectX,
|
|
84
|
+
edge.sourceBisectY
|
|
85
|
+
],
|
|
86
|
+
[
|
|
87
|
+
edge.targetBisectX,
|
|
88
|
+
edge.targetBisectY
|
|
89
|
+
],
|
|
90
|
+
[
|
|
91
|
+
edge.targetX,
|
|
92
|
+
edge.targetY
|
|
93
|
+
]
|
|
82
94
|
]
|
|
83
95
|
];
|
|
84
96
|
}
|
|
85
|
-
/**
|
|
97
|
+
/** A curved edge's points along its curves, or null for a straight edge. */ function ringsCurvePoints(edge) {
|
|
98
|
+
const curves = ringsCurves(edge);
|
|
99
|
+
if (!curves) return null;
|
|
100
|
+
return curves.flatMap((curve, k)=>cubicPolyline(curve).slice(k ? 1 : 0));
|
|
101
|
+
}
|
|
102
|
+
/** An edge's arrow ends, size, and stroke trims, `scale` times as wide. */ const ringsTrims = (viz, edge, i, strokeWidth, scale = 1)=>edgeArrowTrims({
|
|
86
103
|
arrows: viz.schema.arrows,
|
|
87
|
-
arrowSize: viz.schema.arrowSize,
|
|
88
|
-
strokeWidth: typeof strokeWidth === "number" ? strokeWidth : undefined,
|
|
104
|
+
arrowSize: scaledArrowSize(viz.schema.arrowSize, scale),
|
|
105
|
+
strokeWidth: scaledStrokeWidth(typeof strokeWidth === "number" ? strokeWidth : undefined, scale),
|
|
89
106
|
datum: edge.datum,
|
|
90
107
|
i
|
|
91
108
|
});
|
|
92
109
|
/**
|
|
93
110
|
An edge's visible stroke: `d`, cut short inside its arrowheads (see
|
|
94
111
|
`edgeArrowTrims`). A spline edge or a loop follows its curve up to each
|
|
95
|
-
head's base, then runs along the head's axis (see `
|
|
112
|
+
head's base, then runs along the head's axis (see `cubicsArrowEdge`); a
|
|
96
113
|
spline's arrow tips sit on the node's edge, where the curve ends.
|
|
97
|
-
|
|
98
|
-
|
|
114
|
+
`scale` widens the stroke (see `emphasizedArrowEdge`).
|
|
115
|
+
*/ export function ringsVisibleD(viz, edge, i, strokeWidth, d, scale = 1) {
|
|
116
|
+
const trims = ringsTrims(viz, edge, i, strokeWidth, scale);
|
|
99
117
|
if (!trims.source && !trims.target) return d;
|
|
100
118
|
if (edge.loop) return selfLoopD(edge.loop, trims);
|
|
101
|
-
const
|
|
102
|
-
if (
|
|
119
|
+
const curves = ringsCurves(edge);
|
|
120
|
+
if (curves) return cubicsArrowEdge(curves, trims).d;
|
|
103
121
|
return straightEdgeD(edge.source, edge.target, trims);
|
|
104
122
|
}
|
|
105
123
|
/** An edge's base scene key (a loop's names its index, as a node can have several). */ const ringsLinkKey = (edge)=>`rings-link-${edge.source.id}-${edge.target.id}${edge.loop ? `-${linkMeta(edge.datum)?.index ?? 0}` : ""}`;
|
|
@@ -109,6 +127,7 @@ import { uniqueLinkKeys } from "../features/linkKeys.js";
|
|
|
109
127
|
a straight edge's run between its nodes, or at a loop's far point.
|
|
110
128
|
*/ export function ringsEdgeAnchor(edge) {
|
|
111
129
|
if (edge.loop) return edge.loop.apex;
|
|
130
|
+
if (edge.segments?.length) return polylineMidpoint(ringsCurvePoints(edge));
|
|
112
131
|
if (edge.spline && edge.sourceX != null && edge.targetX != null) return cubicMidpoint([
|
|
113
132
|
edge.sourceX,
|
|
114
133
|
edge.sourceY
|
|
@@ -136,15 +155,20 @@ import { uniqueLinkKeys } from "../features/linkKeys.js";
|
|
|
136
155
|
null for a straight edge.
|
|
137
156
|
*/ export function ringsEdgePath(edge) {
|
|
138
157
|
if (edge.loop) return curvePoints(edge.loop.d);
|
|
139
|
-
const
|
|
140
|
-
return
|
|
158
|
+
const curves = ringsCurves(edge);
|
|
159
|
+
return curves ? curvePoints(cubicsPathD(curves)) : null;
|
|
141
160
|
}
|
|
142
|
-
/**
|
|
161
|
+
/**
|
|
162
|
+
One node group's labels, each rotated out from the center along its
|
|
163
|
+
ring. Every label outside its node draws over a halo in the chart's
|
|
164
|
+
background (see `textHalo`) that keeps it readable where links pass
|
|
165
|
+
behind it; the center's label, inside its circle, draws without one.
|
|
166
|
+
*/ function ringsNodeLabels(viz, c, shapeKind, values) {
|
|
143
167
|
const nodeCfg = c.nodeShapeConfig;
|
|
144
168
|
if (!values.length || !nodeCfg.label || !nodeCfg.labelBounds) return [];
|
|
145
169
|
const labelFn = nodeCfg.label;
|
|
146
170
|
const boundsFn = nodeCfg.labelBounds;
|
|
147
|
-
|
|
171
|
+
const labels = emitLabels({
|
|
148
172
|
data: values,
|
|
149
173
|
label: (d, i)=>labelFn(d, i),
|
|
150
174
|
x: (d)=>d.x,
|
|
@@ -160,6 +184,14 @@ import { uniqueLinkKeys } from "../features/linkKeys.js";
|
|
|
160
184
|
...nodeCfg.labelConfig
|
|
161
185
|
}
|
|
162
186
|
});
|
|
187
|
+
const center = values.find((d)=>d.id === viz.schema.center && d.labelInside !== false);
|
|
188
|
+
const insideKey = center ? `rings-label-${center.id}_` : undefined;
|
|
189
|
+
const inside = (node)=>insideKey !== undefined && String(node.key).startsWith(insideKey) && /^\d+$/.test(String(node.key).slice(insideKey.length));
|
|
190
|
+
const haloed = textHalo(labels.filter((node)=>!inside(node)), chartBackground(viz), (text)=>Math.max(2, Math.round((text.font.size ?? 10) / 4)));
|
|
191
|
+
return [
|
|
192
|
+
...haloed,
|
|
193
|
+
...labels.filter(inside)
|
|
194
|
+
];
|
|
163
195
|
}
|
|
164
196
|
/** The edge labels, clear of every node and node label. */ function ringsLinkLabels(viz, c, nodeLabels, keys) {
|
|
165
197
|
return emitLinkLabels(viz, c.edges.map((edge, i)=>({
|
|
@@ -224,10 +256,19 @@ export const ringsEmit = ({ viz })=>{
|
|
|
224
256
|
if (stroke) paint.stroke = stroke;
|
|
225
257
|
const key = keys[j];
|
|
226
258
|
const d = c.linkD(edge);
|
|
259
|
+
const width = typeof paint.strokeWidth === "number" ? paint.strokeWidth : undefined;
|
|
260
|
+
// Optional directional arrowheads.
|
|
261
|
+
const drawn = emphasizedArrowEdge((scale)=>({
|
|
262
|
+
d: ringsVisibleD(viz, edge, i, width, d, scale),
|
|
263
|
+
arrows: ringsEdgeArrows(viz, edge, datum, paint.stroke, width, i, scale)
|
|
264
|
+
}));
|
|
227
265
|
out.push({
|
|
228
266
|
type: "path",
|
|
229
267
|
key,
|
|
230
|
-
d:
|
|
268
|
+
d: drawn.d,
|
|
269
|
+
...drawn.emphasis ? {
|
|
270
|
+
emphasis: drawn.emphasis
|
|
271
|
+
} : {},
|
|
231
272
|
datum,
|
|
232
273
|
index: i,
|
|
233
274
|
paint,
|
|
@@ -236,8 +277,7 @@ export const ringsEmit = ({ viz })=>{
|
|
|
236
277
|
}
|
|
237
278
|
});
|
|
238
279
|
out.push(linkHitPath(key, d, datum, paint.strokeWidth));
|
|
239
|
-
|
|
240
|
-
out.push(...ringsEdgeArrows(viz, edge, datum, paint.stroke, paint.strokeWidth, i));
|
|
280
|
+
out.push(...drawn.arrows);
|
|
241
281
|
}
|
|
242
282
|
out.push(...ringsLinkLabels(viz, c, [
|
|
243
283
|
...nodeLabels.values()
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
Rings — node-link diagram laid out around a central focal node in
|
|
3
|
-
|
|
3
|
+
concentric rings (`hops` of them).
|
|
4
4
|
|
|
5
5
|
Implementation files in this folder:
|
|
6
|
-
- `applyLayout.ts` —
|
|
6
|
+
- `applyLayout.ts` — the layout stage: labels, link strokes, ctx.
|
|
7
7
|
- `emit.ts` — link Paths + per-shape-type node groups.
|
|
8
8
|
- `ringsGraph.ts` — node set + link resolution.
|
|
9
|
+
- `ringsPlacement.ts` — ring claiming, node angles, drawn links.
|
|
10
|
+
- `ringsCurves.ts` — the curves of links between ring nodes.
|
|
9
11
|
- `ringsSizing.ts` — ring geometry + node sizing.
|
|
10
12
|
*/ import { fieldAccessor } from "../../utils/fieldAccessor.js";
|
|
11
13
|
import constant from "../../utils/constant.js";
|
|
@@ -21,6 +23,7 @@ import { effectiveDuration } from "../viz/reducedMotion.js";
|
|
|
21
23
|
import { themed } from "../../utils/theme.js";
|
|
22
24
|
import { clearLinkFocus, focusLink, installFocusBackgroundClick } from "../features/linkFocus.js";
|
|
23
25
|
import { isLinkDatum, linkHighlight, linkMeta, linkTooltipConfig } from "../features/linkInteraction.js";
|
|
26
|
+
import { nodeStatsFields } from "../features/nodeStats.js";
|
|
24
27
|
import { linkSizeMaxField, linkStyleFields } from "../features/linkFields.js";
|
|
25
28
|
/** Installs Rings' nodes/links/size/hover fluent accessors onto the instance. */ function installRingsAccessors(viz) {
|
|
26
29
|
const v = viz;
|
|
@@ -216,12 +219,22 @@ export const ringsDef = {
|
|
|
216
219
|
},
|
|
217
220
|
/**
|
|
218
221
|
The `id` of the node drawn at the center, with the nodes linked to it
|
|
219
|
-
on the inner ring and their other links on the
|
|
220
|
-
node re-centers the chart on it.
|
|
222
|
+
on the inner ring and their other links on the rings outside it (see
|
|
223
|
+
`hops`). Clicking a node re-centers the chart on it.
|
|
221
224
|
@type {string | number}
|
|
222
225
|
*/ {
|
|
223
226
|
key: "center"
|
|
224
227
|
},
|
|
228
|
+
/**
|
|
229
|
+
How many rings of connections to draw around the `center`: `1` shows
|
|
230
|
+
only the nodes linked to the center, `2` adds their connections, and
|
|
231
|
+
each step adds the next ring out. A node reached several ways sits on
|
|
232
|
+
the innermost ring it can. Defaults to 2.
|
|
233
|
+
@type {number}
|
|
234
|
+
*/ {
|
|
235
|
+
key: "hops",
|
|
236
|
+
default: 2
|
|
237
|
+
},
|
|
225
238
|
{
|
|
226
239
|
key: "tooltipConfig",
|
|
227
240
|
merge: true,
|
|
@@ -256,6 +269,15 @@ export const ringsDef = {
|
|
|
256
269
|
key: "noDataMessage",
|
|
257
270
|
default: false
|
|
258
271
|
},
|
|
272
|
+
/**
|
|
273
|
+
Draws the links between two nodes on the outermost ring, which are
|
|
274
|
+
otherwise left out. Each runs out a little past the ring, around it
|
|
275
|
+
the shorter way, and back in to its target.
|
|
276
|
+
@type {boolean}
|
|
277
|
+
*/ {
|
|
278
|
+
key: "ringLinks",
|
|
279
|
+
default: false
|
|
280
|
+
},
|
|
259
281
|
{
|
|
260
282
|
key: "nodes",
|
|
261
283
|
default: []
|
|
@@ -268,6 +290,7 @@ export const ringsDef = {
|
|
|
268
290
|
*/ {
|
|
269
291
|
key: "nodeTooltipLinks"
|
|
270
292
|
},
|
|
293
|
+
...nodeStatsFields(),
|
|
271
294
|
/**
|
|
272
295
|
The maximum pixel radius of a node. Defaults to the largest radius
|
|
273
296
|
that keeps neighboring nodes from overlapping.
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Rings' curved links between ring nodes: a link across rings bends
|
|
3
|
+
through the gap between them, and a link along one ring runs a little
|
|
4
|
+
over a quarter of the way into the gap outside it, around that circle,
|
|
5
|
+
and back in.
|
|
6
|
+
|
|
7
|
+
@module
|
|
8
|
+
*/ /** How far a quarter circle's control points sit along its tangents, per unit of radius. */ const KAPPA = 4 / 3 * Math.tan(Math.PI / 8);
|
|
9
|
+
/** The radius of ring `k` (1 innermost) in `geom`, also past the last ring. */ export const ringRadius = (geom, k)=>geom.primaryRing + geom.ringWidth * (k - 1);
|
|
10
|
+
/** The radius halfway between ring `k` and the ring (or spacing) outside it. */ export const gapMiddle = (geom, k)=>ringRadius(geom, k) + (ringRadius(geom, k + 1) - ringRadius(geom, k)) * 0.5;
|
|
11
|
+
/**
|
|
12
|
+
How far into the gap outside a ring a link along it runs: a little over
|
|
13
|
+
a quarter, close enough to the ring that it usually turns inside the
|
|
14
|
+
links leaving its nodes outward instead of crossing them.
|
|
15
|
+
*/ const RING_ARC_SHARE = 0.28;
|
|
16
|
+
/**
|
|
17
|
+
The circle a link along ring `k` runs around: `RING_ARC_SHARE` of the
|
|
18
|
+
way into the gap outside the ring, and clear of both nodes.
|
|
19
|
+
*/ export const ringArcRadius = (geom, k, nodes)=>Math.max(ringRadius(geom, k) + (ringRadius(geom, k + 1) - ringRadius(geom, k)) * RING_ARC_SHARE, ringRadius(geom, k) + Math.max(...nodes.map((n)=>n.r ?? 0)) + 2);
|
|
20
|
+
const unit = (a)=>[
|
|
21
|
+
Math.cos(a),
|
|
22
|
+
Math.sin(a)
|
|
23
|
+
];
|
|
24
|
+
const along = (p, u, d)=>[
|
|
25
|
+
p[0] + u[0] * d,
|
|
26
|
+
p[1] + u[1] * d
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
The cubics of a circular arc around `c` of `radius`, from angle `from`
|
|
30
|
+
turning `sweep` radians (negative turns the other way), a quarter turn
|
|
31
|
+
or less each.
|
|
32
|
+
*/ export function arcCubics(c, radius, from, sweep) {
|
|
33
|
+
const n = Math.max(1, Math.ceil(Math.abs(sweep) / (Math.PI / 2) - 1e-9));
|
|
34
|
+
const step = sweep / n;
|
|
35
|
+
const k = 4 / 3 * Math.tan(step / 4) * radius;
|
|
36
|
+
return Array.from({
|
|
37
|
+
length: n
|
|
38
|
+
}, (_, i)=>{
|
|
39
|
+
const a0 = from + step * i;
|
|
40
|
+
const a1 = a0 + step;
|
|
41
|
+
const p0 = along(c, unit(a0), radius);
|
|
42
|
+
const p3 = along(c, unit(a1), radius);
|
|
43
|
+
return [
|
|
44
|
+
p0,
|
|
45
|
+
along(p0, unit(a0 + Math.PI / 2), k),
|
|
46
|
+
along(p3, unit(a1 + Math.PI / 2), -k),
|
|
47
|
+
p3
|
|
48
|
+
];
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
The curves of a link between two nodes on one ring, around the circle
|
|
53
|
+
of `radius` about `c`: out from the source's outer side, turning onto
|
|
54
|
+
the circle, along it the shorter way around, and back in to the
|
|
55
|
+
target's outer side. Each turn takes as much of the circle as it rises
|
|
56
|
+
to it (less when the nodes sit closer than that, where the two turns
|
|
57
|
+
meet at the circle in a single arch).
|
|
58
|
+
*/ export function ringArcCubics(source, target, c, radius) {
|
|
59
|
+
const a = source.radians;
|
|
60
|
+
const b = target.radians;
|
|
61
|
+
const turn = Math.atan2(Math.sin(b - a), Math.cos(b - a));
|
|
62
|
+
const s = turn < 0 ? -1 : 1;
|
|
63
|
+
const leg = (n, angle)=>{
|
|
64
|
+
const start = along([
|
|
65
|
+
n.x,
|
|
66
|
+
n.y
|
|
67
|
+
], unit(angle), n.r ?? 0);
|
|
68
|
+
const rise = Math.max(1, radius - Math.hypot(start[0] - c[0], start[1] - c[1]));
|
|
69
|
+
const delta = Math.min(rise / radius, Math.abs(turn) / 2);
|
|
70
|
+
return {
|
|
71
|
+
start,
|
|
72
|
+
rise,
|
|
73
|
+
delta,
|
|
74
|
+
side: radius * delta
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
const out = leg(source, a);
|
|
78
|
+
const back = leg(target, b);
|
|
79
|
+
const qa = a + s * out.delta;
|
|
80
|
+
const q0 = along(c, unit(qa), radius);
|
|
81
|
+
const qb = b - s * back.delta;
|
|
82
|
+
const curves = [
|
|
83
|
+
[
|
|
84
|
+
out.start,
|
|
85
|
+
along(out.start, unit(a), KAPPA * out.rise),
|
|
86
|
+
along(q0, unit(qa + Math.PI / 2), -s * KAPPA * out.side),
|
|
87
|
+
q0
|
|
88
|
+
]
|
|
89
|
+
];
|
|
90
|
+
const rest = turn - s * (out.delta + back.delta);
|
|
91
|
+
if (Math.abs(rest) > 1e-6) curves.push(...arcCubics(c, radius, qa, rest));
|
|
92
|
+
// The turn back in starts exactly where the path so far ends.
|
|
93
|
+
const q1 = curves[curves.length - 1][3];
|
|
94
|
+
curves.push([
|
|
95
|
+
q1,
|
|
96
|
+
along(q1, unit(qb + Math.PI / 2), s * KAPPA * back.side),
|
|
97
|
+
along(back.start, unit(b), KAPPA * back.rise),
|
|
98
|
+
back.start
|
|
99
|
+
]);
|
|
100
|
+
return curves;
|
|
101
|
+
}
|
|
102
|
+
/** Joined cubics as one path's `d`, unrounded like the other Rings links'. */ export const ringsSegmentsD = (curves)=>curves.map(([p0, c1, c2, p3], k)=>`${k ? "" : `M${p0[0]},${p0[1]}`}C${c1[0]},${c1[1]} ${c2[0]},${c2[1]} ${p3[0]},${p3[1]}`).join("");
|
|
103
|
+
/** Lays out a link along one ring around its `arc`: its `segments`, ends, and bisect points. */ export function applyRingArc(edge) {
|
|
104
|
+
const { cx, cy, radius } = edge.arc;
|
|
105
|
+
const curves = ringArcCubics(edge.source, edge.target, [
|
|
106
|
+
cx,
|
|
107
|
+
cy
|
|
108
|
+
], radius);
|
|
109
|
+
const first = curves[0];
|
|
110
|
+
const last = curves[curves.length - 1];
|
|
111
|
+
edge.segments = curves;
|
|
112
|
+
edge.spline = true;
|
|
113
|
+
[edge.sourceX, edge.sourceY] = first[0];
|
|
114
|
+
[edge.sourceBisectX, edge.sourceBisectY] = first[1];
|
|
115
|
+
[edge.targetBisectX, edge.targetBisectY] = last[2];
|
|
116
|
+
[edge.targetX, edge.targetY] = last[3];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
Sets a link's curve between two ring nodes. Across rings, it leaves each
|
|
120
|
+
node on the side facing the other's ring and bends through the middle of
|
|
121
|
+
the gap between them. Along one ring, it runs a little over a quarter
|
|
122
|
+
of the way into the gap outside that ring (or past the last ring),
|
|
123
|
+
around it, and back in (see `ringArcCubics`).
|
|
124
|
+
*/ export function curveRingsEdge(edge, geom) {
|
|
125
|
+
const { width, height } = geom;
|
|
126
|
+
const inner = Math.min(edge.source.ring, edge.target.ring);
|
|
127
|
+
if (edge.source.ring === edge.target.ring) {
|
|
128
|
+
const radius = ringArcRadius(geom, inner, [
|
|
129
|
+
edge.source,
|
|
130
|
+
edge.target
|
|
131
|
+
]);
|
|
132
|
+
edge.arc = {
|
|
133
|
+
cx: width / 2,
|
|
134
|
+
cy: height / 2,
|
|
135
|
+
radius
|
|
136
|
+
};
|
|
137
|
+
applyRingArc(edge);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const middleRing = gapMiddle(geom, inner);
|
|
141
|
+
edge.spline = true;
|
|
142
|
+
const ends = [
|
|
143
|
+
"source",
|
|
144
|
+
"target"
|
|
145
|
+
];
|
|
146
|
+
ends.forEach((endKey)=>{
|
|
147
|
+
const endNode = edge[endKey];
|
|
148
|
+
const endRadians = endNode.radians;
|
|
149
|
+
const rotated = endNode.ring > inner ? endRadians + Math.PI : endRadians;
|
|
150
|
+
const r = endNode.r;
|
|
151
|
+
edge[`${endKey}X`] = endNode.x + Math.cos(rotated) * r;
|
|
152
|
+
edge[`${endKey}Y`] = endNode.y + Math.sin(rotated) * r;
|
|
153
|
+
edge[`${endKey}BisectX`] = width / 2 + middleRing * Math.cos(endRadians);
|
|
154
|
+
edge[`${endKey}BisectY`] = height / 2 + middleRing * Math.sin(endRadians);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Rings' parallel links: several links between the same two nodes, in
|
|
3
3
|
either direction. Each node takes one place on its ring however many
|
|
4
4
|
links reach it, and the links fan out as curves bowed either side of
|
|
5
|
-
the line between their nodes,
|
|
5
|
+
the line between their nodes (or, along one ring, circle around at
|
|
6
|
+
different distances), so each stays its own mark.
|
|
6
7
|
*/ import { LINK_HIT_WIDTH } from "../features/linkInteraction.js";
|
|
8
|
+
import { applyRingArc } from "./ringsCurves.js";
|
|
7
9
|
/** The node at the other end of `edge` from the node `id`. */ const otherEnd = (edge, id)=>edge.source.id === id ? edge.target : edge.source;
|
|
8
10
|
/** `edges` from the node `id`, keeping only the first to each other node. */ export function firstPerNeighbor(edges, id) {
|
|
9
11
|
const seen = new Set();
|
|
@@ -115,13 +117,27 @@
|
|
|
115
117
|
edge.targetBisectX += normal[0] * h;
|
|
116
118
|
edge.targetBisectY += normal[1] * h;
|
|
117
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
Moves a link along one ring `offset` pixels out from the circle it runs
|
|
122
|
+
around (in, for a negative offset), keeping it clear of its nodes.
|
|
123
|
+
*/ function shiftRingArc(edge, offset) {
|
|
124
|
+
const arc = edge.arc;
|
|
125
|
+
const reach = (n)=>Math.hypot((n.x ?? 0) - arc.cx, (n.y ?? 0) - arc.cy) + (n.r ?? 0);
|
|
126
|
+
const floor = Math.max(reach(edge.source), reach(edge.target)) + 2;
|
|
127
|
+
edge.arc = {
|
|
128
|
+
...arc,
|
|
129
|
+
radius: Math.max(floor, arc.radius + offset)
|
|
130
|
+
};
|
|
131
|
+
applyRingArc(edge);
|
|
132
|
+
}
|
|
118
133
|
const isPlaced = (n)=>typeof n.x === "number" && typeof n.y === "number";
|
|
119
134
|
/**
|
|
120
135
|
Fans out each group of parallel links among `edges` (mutated in place),
|
|
121
136
|
leaving a link with no parallel alone. Their middles sit a hit path's
|
|
122
137
|
width (and a gap) apart, so each can be pointed at. A straight link
|
|
123
138
|
becomes a bowed curve (see `bowedEdge`); a curved one moves to the side
|
|
124
|
-
(see `shiftSpline`)
|
|
139
|
+
(see `shiftSpline`); one along a ring circles nearer or farther out (see
|
|
140
|
+
`shiftRingArc`). The side follows the two nodes, not the link's
|
|
125
141
|
direction, so links both ways between them fan apart too.
|
|
126
142
|
*/ export function fanParallelEdges(edges) {
|
|
127
143
|
const groups = new Map();
|
|
@@ -156,7 +172,8 @@ const isPlaced = (n)=>typeof n.x === "number" && typeof n.y === "number";
|
|
|
156
172
|
const step = Math.max(LINK_HIT_WIDTH, widest + 4) + 4;
|
|
157
173
|
parallelOffsets(group.length, step).forEach((offset, k)=>{
|
|
158
174
|
const edge = group[k];
|
|
159
|
-
if (edge.
|
|
175
|
+
if (edge.arc) shiftRingArc(edge, offset);
|
|
176
|
+
else if (edge.spline && edge.sourceX != null && edge.targetX != null) shiftSpline(edge, normal, offset);
|
|
160
177
|
else {
|
|
161
178
|
Object.assign(edge, bowedEdge(edge.source, edge.target, normal, offset));
|
|
162
179
|
edge.spline = true;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Rings' node placement: which ring each node sits on, its angle and
|
|
3
|
+
position, and the curves of the links between the rings.
|
|
4
|
+
|
|
5
|
+
@module
|
|
6
|
+
*/ import { max, min } from "d3-array";
|
|
7
|
+
import { edgesBetween, firstPerNeighbor } from "./ringsParallel.js";
|
|
8
|
+
import { curveRingsEdge } from "./ringsCurves.js";
|
|
9
|
+
import { sizeRingsNodes } from "./ringsSizing.js";
|
|
10
|
+
/** The node at the other end of `edge` from the node `id`. */ const otherEnd = (edge, id)=>edge.source.id === id ? edge.target : edge.source;
|
|
11
|
+
/**
|
|
12
|
+
Claims the nodes on each of `hops` rings around `center`, breadth-first,
|
|
13
|
+
so a node reachable by several paths sits once, on its shallowest ring.
|
|
14
|
+
The first ring is the center's neighbors, fewest links first; each later
|
|
15
|
+
ring is, in order, the unclaimed neighbors of each node on the ring
|
|
16
|
+
inside it, which become that node's children.
|
|
17
|
+
*/ export function claimRings(linkMap, center, hops) {
|
|
18
|
+
const claimed = new Set([
|
|
19
|
+
center
|
|
20
|
+
]);
|
|
21
|
+
const children = new Map();
|
|
22
|
+
const first = [];
|
|
23
|
+
(linkMap[center.id] || []).forEach((edge)=>{
|
|
24
|
+
const node = otherEnd(edge, center.id);
|
|
25
|
+
// A node takes one place however many center links reach it.
|
|
26
|
+
if (claimed.has(node)) return;
|
|
27
|
+
claimed.add(node);
|
|
28
|
+
first.push(node);
|
|
29
|
+
});
|
|
30
|
+
first.sort((a, b)=>(linkMap[a.id] || []).length - (linkMap[b.id] || []).length);
|
|
31
|
+
const rings = [
|
|
32
|
+
first
|
|
33
|
+
];
|
|
34
|
+
while(rings.length < hops){
|
|
35
|
+
const inner = rings[rings.length - 1];
|
|
36
|
+
const ring = [];
|
|
37
|
+
inner.forEach((p)=>{
|
|
38
|
+
const kids = firstPerNeighbor((linkMap[p.id] || []).filter((edge)=>!claimed.has(otherEnd(edge, p.id))), p.id).map((edge)=>otherEnd(edge, p.id));
|
|
39
|
+
kids.forEach((k)=>claimed.add(k));
|
|
40
|
+
children.set(p, kids);
|
|
41
|
+
ring.push(...kids);
|
|
42
|
+
});
|
|
43
|
+
rings.push(ring);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
rings,
|
|
47
|
+
children
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
How many outer-ring slots each node spans: one on the outermost ring (or
|
|
52
|
+
with no children), else the sum of its children's.
|
|
53
|
+
*/ export function ringWeights(tree) {
|
|
54
|
+
const weights = new Map();
|
|
55
|
+
for(let k = tree.rings.length - 1; k >= 0; k--){
|
|
56
|
+
tree.rings[k].forEach((n)=>{
|
|
57
|
+
const kids = tree.children.get(n) ?? [];
|
|
58
|
+
const sum = kids.reduce((total, c)=>total + weights.get(c), 0);
|
|
59
|
+
weights.set(n, sum || 1);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return weights;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
Sets each ring node's angle (`radians`) and position on its ring. The
|
|
66
|
+
circle splits into one slot per outer-ring position (`ringWeights`): the
|
|
67
|
+
first ring's nodes take arcs as wide as their slots, the first centered
|
|
68
|
+
at the top, and each node's children split its arc the same way. Returns
|
|
69
|
+
the number of slots.
|
|
70
|
+
*/ export function placeRings(tree, geom) {
|
|
71
|
+
const { width, height, rings: radii } = geom;
|
|
72
|
+
const weights = ringWeights(tree);
|
|
73
|
+
const total = tree.rings[0].reduce((sum, n)=>sum + weights.get(n), 0);
|
|
74
|
+
const tau = Math.PI * 2;
|
|
75
|
+
const s = tau / total;
|
|
76
|
+
const place = (node, angle, ring)=>{
|
|
77
|
+
node.radians = angle;
|
|
78
|
+
node.x = width / 2 + radii[ring] * Math.cos(angle);
|
|
79
|
+
node.y = height / 2 + radii[ring] * Math.sin(angle);
|
|
80
|
+
const kids = tree.children.get(node) ?? [];
|
|
81
|
+
const span = weights.get(node);
|
|
82
|
+
let before = 0;
|
|
83
|
+
kids.forEach((kid)=>{
|
|
84
|
+
const w = weights.get(kid);
|
|
85
|
+
place(kid, angle - s * span / 2 + s * w / 2 + s * before, ring + 1);
|
|
86
|
+
before += w;
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
let offset = 0;
|
|
90
|
+
tree.rings[0].forEach((p, i)=>{
|
|
91
|
+
const space = tau / total * weights.get(p);
|
|
92
|
+
if (i === 0) offset -= space / 2;
|
|
93
|
+
place(p, offset + space / 2 - tau / 4, 0);
|
|
94
|
+
offset += space;
|
|
95
|
+
});
|
|
96
|
+
return total;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
Places the center node and `geom.rings.length` rings around it, and sizes
|
|
100
|
+
every node. Returns the placed `nodes` (center first, then ring by ring),
|
|
101
|
+
the `rings`, and the size scale (null when unsized).
|
|
102
|
+
*/ export function placeRingsNodes(v, linkMap, center, geom) {
|
|
103
|
+
const { width, height, baseRing } = geom;
|
|
104
|
+
center.x = width / 2;
|
|
105
|
+
center.y = height / 2;
|
|
106
|
+
center.r = v.schema.sizeMin ? max([
|
|
107
|
+
v.schema.sizeMin,
|
|
108
|
+
baseRing * 0.65
|
|
109
|
+
]) : v.schema.sizeMax ? min([
|
|
110
|
+
v.schema.sizeMax,
|
|
111
|
+
baseRing * 0.65
|
|
112
|
+
]) : baseRing * 0.65;
|
|
113
|
+
const tree = claimRings(linkMap, center, geom.rings.length);
|
|
114
|
+
const slots = placeRings(tree, geom);
|
|
115
|
+
const radius = sizeRingsNodes(v, center, geom, slots, tree.rings);
|
|
116
|
+
const nodes = [
|
|
117
|
+
center,
|
|
118
|
+
...tree.rings.flat()
|
|
119
|
+
];
|
|
120
|
+
return {
|
|
121
|
+
nodes,
|
|
122
|
+
rings: tree.rings,
|
|
123
|
+
radius
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
The links drawn between placed nodes, each once: every link from the
|
|
128
|
+
center to the first ring, and every link from a node on a ring inside the
|
|
129
|
+
outermost to another ring node (curved, see `curveRingsEdge`). With
|
|
130
|
+
`ringLinks`, links between two nodes on the outermost ring draw too.
|
|
131
|
+
*/ export function buildRingsEdges(rings, linkMap, center, geom, ringLinks = false) {
|
|
132
|
+
const edges = [];
|
|
133
|
+
const placed = new Set(rings.flat().map((n)=>n.id));
|
|
134
|
+
rings.forEach((ring, k)=>{
|
|
135
|
+
ring.forEach((p)=>{
|
|
136
|
+
if (k === 0) edgesBetween(linkMap[p.id], p.id, center.id).forEach((edge)=>{
|
|
137
|
+
if (!edges.includes(edge)) edges.push(edge);
|
|
138
|
+
});
|
|
139
|
+
const outermost = k === rings.length - 1;
|
|
140
|
+
if (outermost && !ringLinks) return;
|
|
141
|
+
linkMap[p.id].forEach((edge)=>{
|
|
142
|
+
const other = otherEnd(edge, p.id);
|
|
143
|
+
if (other.id === center.id || !placed.has(other.id)) return;
|
|
144
|
+
// From the outermost ring, only its own links are left to draw.
|
|
145
|
+
if (outermost && other.ring !== p.ring) return;
|
|
146
|
+
curveRingsEdge(edge, geom);
|
|
147
|
+
if (!edges.includes(edge)) edges.push(edge);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
return edges;
|
|
152
|
+
}
|