@unovis/ts 1.3.0-beta.2 → 1.3.0-beta.3
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/components/area/config.d.ts +10 -6
- package/components/area/config.js +12 -3
- package/components/area/config.js.map +1 -1
- package/components/area/index.d.ts +6 -5
- package/components/area/index.js +9 -10
- package/components/area/index.js.map +1 -1
- package/components/axis/config.d.ts +27 -3
- package/components/axis/config.js +30 -3
- package/components/axis/config.js.map +1 -1
- package/components/axis/index.d.ts +3 -4
- package/components/axis/index.js +4 -7
- package/components/axis/index.js.map +1 -1
- package/components/brush/config.d.ts +12 -2
- package/components/brush/config.js +20 -11
- package/components/brush/config.js.map +1 -1
- package/components/brush/index.d.ts +3 -4
- package/components/brush/index.js +3 -4
- package/components/brush/index.js.map +1 -1
- package/components/bullet-legend/config.d.ts +10 -1
- package/components/bullet-legend/config.js +14 -11
- package/components/bullet-legend/config.js.map +1 -1
- package/components/bullet-legend/index.d.ts +3 -4
- package/components/bullet-legend/index.js +2 -5
- package/components/bullet-legend/index.js.map +1 -1
- package/components/chord-diagram/config.d.ts +23 -7
- package/components/chord-diagram/config.js +22 -3
- package/components/chord-diagram/config.js.map +1 -1
- package/components/chord-diagram/index.d.ts +3 -4
- package/components/chord-diagram/index.js +6 -7
- package/components/chord-diagram/index.js.map +1 -1
- package/components/chord-diagram/modules/label.d.ts +3 -3
- package/components/chord-diagram/modules/label.js +1 -1
- package/components/chord-diagram/modules/label.js.map +1 -1
- package/components/chord-diagram/modules/link.d.ts +2 -2
- package/components/chord-diagram/modules/link.js.map +1 -1
- package/components/chord-diagram/modules/node.d.ts +2 -2
- package/components/chord-diagram/modules/node.js.map +1 -1
- package/components/chord-diagram/types.d.ts +2 -3
- package/components/chord-diagram/types.js.map +1 -1
- package/components/crosshair/config.d.ts +14 -4
- package/components/crosshair/config.js +16 -3
- package/components/crosshair/config.js.map +1 -1
- package/components/crosshair/index.d.ts +3 -4
- package/components/crosshair/index.js +3 -4
- package/components/crosshair/index.js.map +1 -1
- package/components/donut/config.d.ts +19 -2
- package/components/donut/config.js +24 -5
- package/components/donut/config.js.map +1 -1
- package/components/donut/index.d.ts +3 -4
- package/components/donut/index.js +4 -5
- package/components/donut/index.js.map +1 -1
- package/components/donut/modules/arc.d.ts +3 -3
- package/components/donut/modules/arc.js.map +1 -1
- package/components/flow-legend/config.d.ts +11 -1
- package/components/flow-legend/config.js +16 -11
- package/components/flow-legend/config.js.map +1 -1
- package/components/flow-legend/index.d.ts +3 -4
- package/components/flow-legend/index.js +2 -5
- package/components/flow-legend/index.js.map +1 -1
- package/components/free-brush/config.d.ts +12 -2
- package/components/free-brush/config.js +20 -11
- package/components/free-brush/config.js.map +1 -1
- package/components/free-brush/index.d.ts +3 -4
- package/components/free-brush/index.js +5 -6
- package/components/free-brush/index.js.map +1 -1
- package/components/graph/config.d.ts +75 -3
- package/components/graph/config.js +78 -12
- package/components/graph/config.js.map +1 -1
- package/components/graph/index.d.ts +7 -8
- package/components/graph/index.js +3 -4
- package/components/graph/index.js.map +1 -1
- package/components/graph/modules/layout.d.ts +7 -7
- package/components/graph/modules/layout.js.map +1 -1
- package/components/graph/modules/link/helper.d.ts +5 -5
- package/components/graph/modules/link/helper.js.map +1 -1
- package/components/graph/modules/link/index.d.ts +6 -6
- package/components/graph/modules/link/index.js.map +1 -1
- package/components/graph/modules/node/index.d.ts +6 -6
- package/components/graph/modules/node/index.js +2 -2
- package/components/graph/modules/node/index.js.map +1 -1
- package/components/graph/modules/panel/helper.d.ts +4 -4
- package/components/graph/modules/panel/helper.js.map +1 -1
- package/components/graph/modules/panel/index.d.ts +3 -3
- package/components/graph/modules/panel/index.js.map +1 -1
- package/components/grouped-bar/config.d.ts +13 -5
- package/components/grouped-bar/config.js +16 -5
- package/components/grouped-bar/config.js.map +1 -1
- package/components/grouped-bar/index.d.ts +3 -4
- package/components/grouped-bar/index.js +3 -4
- package/components/grouped-bar/index.js.map +1 -1
- package/components/leaflet-flow-map/config.d.ts +16 -2
- package/components/leaflet-flow-map/config.js +21 -3
- package/components/leaflet-flow-map/config.js.map +1 -1
- package/components/leaflet-flow-map/index.d.ts +3 -4
- package/components/leaflet-flow-map/index.js +2 -3
- package/components/leaflet-flow-map/index.js.map +1 -1
- package/components/leaflet-map/config.d.ts +59 -4
- package/components/leaflet-map/config.js +67 -23
- package/components/leaflet-map/config.js.map +1 -1
- package/components/leaflet-map/index.d.ts +3 -4
- package/components/leaflet-map/index.js +3 -4
- package/components/leaflet-map/index.js.map +1 -1
- package/components/leaflet-map/modules/map.d.ts +3 -3
- package/components/leaflet-map/modules/map.js.map +1 -1
- package/components/leaflet-map/modules/utils.d.ts +4 -4
- package/components/leaflet-map/modules/utils.js +2 -6
- package/components/leaflet-map/modules/utils.js.map +1 -1
- package/components/leaflet-map/renderer/mapboxgl-layer.d.ts +2 -2
- package/components/leaflet-map/renderer/mapboxgl-layer.js.map +1 -1
- package/components/line/config.d.ts +11 -6
- package/components/line/config.js +13 -3
- package/components/line/config.js.map +1 -1
- package/components/line/index.d.ts +3 -4
- package/components/line/index.js +4 -5
- package/components/line/index.js.map +1 -1
- package/components/nested-donut/config.d.ts +21 -2
- package/components/nested-donut/config.js +24 -3
- package/components/nested-donut/config.js.map +1 -1
- package/components/nested-donut/index.d.ts +3 -4
- package/components/nested-donut/index.js +3 -4
- package/components/nested-donut/index.js.map +1 -1
- package/components/nested-donut/modules/arc.d.ts +3 -3
- package/components/nested-donut/modules/arc.js.map +1 -1
- package/components/nested-donut/modules/label.d.ts +2 -2
- package/components/nested-donut/modules/label.js.map +1 -1
- package/components/sankey/config.d.ts +47 -2
- package/components/sankey/config.js +57 -10
- package/components/sankey/config.js.map +1 -1
- package/components/sankey/index.d.ts +3 -4
- package/components/sankey/index.js +2 -3
- package/components/sankey/index.js.map +1 -1
- package/components/sankey/modules/label.d.ts +7 -7
- package/components/sankey/modules/label.js.map +1 -1
- package/components/sankey/modules/link.d.ts +2 -2
- package/components/sankey/modules/link.js.map +1 -1
- package/components/sankey/modules/node.d.ts +7 -7
- package/components/sankey/modules/node.js +1 -1
- package/components/sankey/modules/node.js.map +1 -1
- package/components/scatter/config.d.ts +16 -4
- package/components/scatter/config.js +19 -5
- package/components/scatter/config.js.map +1 -1
- package/components/scatter/index.d.ts +3 -4
- package/components/scatter/index.js +5 -5
- package/components/scatter/index.js.map +1 -1
- package/components/scatter/modules/point.d.ts +2 -2
- package/components/scatter/modules/point.js.map +1 -1
- package/components/scatter/modules/utils.d.ts +2 -2
- package/components/scatter/modules/utils.js.map +1 -1
- package/components/stacked-bar/config.d.ts +13 -5
- package/components/stacked-bar/config.js +16 -5
- package/components/stacked-bar/config.js.map +1 -1
- package/components/stacked-bar/index.d.ts +3 -4
- package/components/stacked-bar/index.js +3 -4
- package/components/stacked-bar/index.js.map +1 -1
- package/components/timeline/config.d.ts +16 -5
- package/components/timeline/config.js +21 -9
- package/components/timeline/config.js.map +1 -1
- package/components/timeline/index.d.ts +3 -4
- package/components/timeline/index.js +3 -4
- package/components/timeline/index.js.map +1 -1
- package/components/tooltip/config.d.ts +15 -1
- package/components/tooltip/config.js +16 -12
- package/components/tooltip/config.js.map +1 -1
- package/components/tooltip/index.d.ts +3 -4
- package/components/tooltip/index.js +3 -5
- package/components/tooltip/index.js.map +1 -1
- package/components/topojson-map/config.d.ts +36 -4
- package/components/topojson-map/config.js +38 -3
- package/components/topojson-map/config.js.map +1 -1
- package/components/topojson-map/index.d.ts +3 -4
- package/components/topojson-map/index.js +4 -4
- package/components/topojson-map/index.js.map +1 -1
- package/components/vis-controls/config.d.ts +5 -1
- package/components/vis-controls/config.js +9 -6
- package/components/vis-controls/config.js.map +1 -1
- package/components/vis-controls/index.d.ts +2 -3
- package/components/vis-controls/index.js +2 -5
- package/components/vis-controls/index.js.map +1 -1
- package/components/xy-labels/config.d.ts +16 -4
- package/components/xy-labels/config.js +20 -5
- package/components/xy-labels/config.js.map +1 -1
- package/components/xy-labels/index.d.ts +3 -4
- package/components/xy-labels/index.js +2 -3
- package/components/xy-labels/index.js.map +1 -1
- package/components/xy-labels/modules/label.d.ts +3 -3
- package/components/xy-labels/modules/label.js +1 -1
- package/components/xy-labels/modules/label.js.map +1 -1
- package/containers/single-container/config.d.ts +4 -2
- package/containers/single-container/config.js +8 -3
- package/containers/single-container/config.js.map +1 -1
- package/containers/single-container/index.d.ts +3 -4
- package/containers/single-container/index.js +2 -2
- package/containers/single-container/index.js.map +1 -1
- package/containers/xy-container/config.d.ts +22 -2
- package/containers/xy-container/config.js +26 -3
- package/containers/xy-container/config.js.map +1 -1
- package/containers/xy-container/index.d.ts +2 -5
- package/containers/xy-container/index.js +2 -2
- package/containers/xy-container/index.js.map +1 -1
- package/core/component/config.d.ts +6 -1
- package/core/component/config.js +12 -6
- package/core/component/config.js.map +1 -1
- package/core/component/index.d.ts +5 -7
- package/core/component/index.js +7 -8
- package/core/component/index.js.map +1 -1
- package/core/config/index.d.ts +3 -0
- package/core/config/index.js +16 -0
- package/core/config/index.js.map +1 -0
- package/core/container/config.d.ts +21 -1
- package/core/container/config.js +25 -21
- package/core/container/config.js.map +1 -1
- package/core/container/index.d.ts +4 -5
- package/core/container/index.js +3 -4
- package/core/container/index.js.map +1 -1
- package/core/xy-component/config.d.ts +10 -2
- package/core/xy-component/config.js +16 -7
- package/core/xy-component/config.js.map +1 -1
- package/core/xy-component/index.d.ts +4 -5
- package/core/xy-component/index.js +0 -2
- package/core/xy-component/index.js.map +1 -1
- package/data-models/map-graph.d.ts +1 -1
- package/data-models/map-graph.js +1 -1
- package/data-models/map-graph.js.map +1 -1
- package/package.json +1 -1
- package/types/accessor.d.ts +1 -1
- package/utils/data.d.ts +1 -1
- package/utils/data.js.map +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Selection } from 'd3-selection';
|
|
2
2
|
import { ScaleContinuousNumeric } from 'd3-scale';
|
|
3
|
-
import {
|
|
3
|
+
import { ChordDiagramConfig } from '../config';
|
|
4
4
|
import { ChordInputLink, ChordInputNode, ChordNode } from '../types';
|
|
5
5
|
export declare const LABEL_PADDING = 3;
|
|
6
|
-
export declare function createLabel<N extends ChordInputNode, L extends ChordInputLink>(selection: Selection<SVGGElement, ChordNode<N>, SVGGElement, unknown>, config:
|
|
7
|
-
export declare function updateLabel<N extends ChordInputNode, L extends ChordInputLink>(selection: Selection<SVGGElement, ChordNode<N>, SVGGElement, unknown>, config:
|
|
6
|
+
export declare function createLabel<N extends ChordInputNode, L extends ChordInputLink>(selection: Selection<SVGGElement, ChordNode<N>, SVGGElement, unknown>, config: ChordDiagramConfig<N, L>, radiusScale: ScaleContinuousNumeric<number, number>): void;
|
|
7
|
+
export declare function updateLabel<N extends ChordInputNode, L extends ChordInputLink>(selection: Selection<SVGGElement, ChordNode<N>, SVGGElement, unknown>, config: ChordDiagramConfig<N, L>, width: number, radiusScale: ScaleContinuousNumeric<number, number>, duration: number): void;
|
|
8
8
|
export declare function removeLabel(selection: Selection<SVGGElement, unknown, SVGGElement, unknown>, duration: number): void;
|
|
@@ -74,7 +74,7 @@ function updateLabel(selection, config, width, radiusScale, duration) {
|
|
|
74
74
|
label$1.each((d, i, elements) => {
|
|
75
75
|
var _a;
|
|
76
76
|
const nodeLabelAlignment = (_a = getValue(d.data, config.nodeLabelAlignment)) !== null && _a !== void 0 ? _a : ChordLabelAlignment.Along;
|
|
77
|
-
const radianArcLength = d.x1 - d.x0 - getNumber(d
|
|
77
|
+
const radianArcLength = d.x1 - d.x0 - getNumber(d, config.padAngle) * 2;
|
|
78
78
|
const radius = radiusScale(d.y1) - getNumber(d, config.nodeWidth) / 2;
|
|
79
79
|
const arcLength = radius * radianArcLength;
|
|
80
80
|
const maxWidth = (nodeLabelAlignment === ChordLabelAlignment.Along ? arcLength : width) - LABEL_PADDING * 2;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"label.js","sources":["../../../../src/components/chord-diagram/modules/label.ts"],"sourcesContent":["import { select, Selection } from 'd3-selection'\nimport { ScaleContinuousNumeric } from 'd3-scale'\nimport { color } from 'd3-color'\n\n// Utils\nimport { trimSVGText } from 'utils/text'\nimport { smartTransition } from 'utils/d3'\nimport { getNumber, getString, getValue } from 'utils/data'\nimport { getColor, hexToBrightness } from 'utils/color'\n\n// Config\nimport { ChordDiagramConfigInterface } from '../config'\n\n// Local Types\nimport { ChordInputLink, ChordInputNode, ChordLabelAlignment, ChordNode } from '../types'\n\n// Styles\nimport * as s from '../style'\n\nexport const LABEL_PADDING = 3\n\nfunction getLabelFillColor<N extends ChordInputNode, L extends ChordInputLink> (\n d: ChordNode<N>,\n config: ChordDiagramConfigInterface<N, L>\n): string {\n const nodeLabelAlignment = getValue(d.data, config.nodeLabelAlignment) ?? ChordLabelAlignment.Along\n switch (nodeLabelAlignment) {\n case ChordLabelAlignment.Perpendicular: {\n return getColor(d.data, config.nodeColor, d.height)\n }\n case ChordLabelAlignment.Along: {\n const c = getColor(d.data, config.nodeColor, d.height)\n const colorParsed = color(c)\n const brightness = colorParsed ? hexToBrightness(colorParsed.hex()) : 0\n return brightness > 0.65 ? 'var(--vis-chord-diagram-label-text-fill-color-dark)' : 'var(--vis-chord-diagram-label-text-fill-color-bright)'\n }\n }\n}\n\nfunction getLabelTextAnchor<N extends ChordInputNode, L extends ChordInputLink> (\n d: ChordNode<N>,\n config: ChordDiagramConfigInterface<N, L>\n): string | null {\n const nodeLabelAlignment = getValue(d.data, config.nodeLabelAlignment) ?? ChordLabelAlignment.Along\n switch (nodeLabelAlignment) {\n case ChordLabelAlignment.Perpendicular: {\n const angleCenter = (d.x0 + d.x1) / 2\n const angleDegree = angleCenter * 180 / Math.PI\n return angleDegree < 180 ? 'start' : 'end'\n }\n case ChordLabelAlignment.Along: {\n return null\n }\n }\n}\n\nfunction getLabelTransform<N extends ChordInputNode, L extends ChordInputLink> (\n d: ChordNode<N>,\n config: ChordDiagramConfigInterface<N, L>,\n radiusScale: ScaleContinuousNumeric<number, number>\n): string | null {\n const nodeLabelAlignment = getValue(d.data, config.nodeLabelAlignment) ?? ChordLabelAlignment.Along\n switch (nodeLabelAlignment) {\n case ChordLabelAlignment.Perpendicular: {\n const r = radiusScale(d.y1) + LABEL_PADDING\n const angleCenter = (d.x0 + d.x1) / 2\n const angle = angleCenter - Math.PI / 2\n const x = r * Math.cos(angle)\n const y = r * Math.sin(angle)\n return `translate(${x}, ${y})`\n }\n case ChordLabelAlignment.Along:\n return null\n }\n}\n\nexport function createLabel<N extends ChordInputNode, L extends ChordInputLink> (\n selection: Selection<SVGGElement, ChordNode<N>, SVGGElement, unknown>,\n config: ChordDiagramConfigInterface<N, L>,\n radiusScale: ScaleContinuousNumeric<number, number>\n): void {\n selection.style('opacity', 0)\n .attr('transform', d => getLabelTransform(d, config, radiusScale))\n\n selection.append('text')\n .attr('class', s.label)\n .style('fill', d => getColor(d.data, config.nodeColor, d.height))\n}\n\nexport function updateLabel<N extends ChordInputNode, L extends ChordInputLink> (\n selection: Selection<SVGGElement, ChordNode<N>, SVGGElement, unknown>,\n config: ChordDiagramConfigInterface<N, L>,\n width: number,\n radiusScale: ScaleContinuousNumeric<number, number>,\n duration: number\n): void {\n const { nodeLabel, nodeLabelColor, nodeWidth } = config\n\n smartTransition(selection, duration)\n .attr('transform', d => getLabelTransform(d, config, radiusScale))\n .style('opacity', 1)\n\n const label: Selection<SVGTextElement, ChordNode<N>, SVGElement, unknown> = selection.select(`.${s.label}`)\n label.select('textPath').remove()\n label\n .text(d => getString(d.data, nodeLabel))\n .style('fill', d => getColor(d.data, nodeLabelColor) ?? getLabelFillColor(d, config))\n .style('text-anchor', d => getLabelTextAnchor(d, config))\n\n label.each((d: ChordNode<N>, i: number, elements) => {\n const nodeLabelAlignment = getValue(d.data, config.nodeLabelAlignment) ?? ChordLabelAlignment.Along\n const radianArcLength = d.x1 - d.x0 - getNumber(d.data, config.padAngle) * 2\n const radius = radiusScale(d.y1) - getNumber(d, config.nodeWidth) / 2\n const arcLength = radius * radianArcLength\n const maxWidth = (nodeLabelAlignment === ChordLabelAlignment.Along ? arcLength : width) - LABEL_PADDING * 2\n\n const textElementSelection = select(elements[i])\n trimSVGText(textElementSelection, maxWidth)\n textElementSelection\n .attr('dx', nodeLabelAlignment === ChordLabelAlignment.Along ? LABEL_PADDING : null)\n .attr('dy', nodeLabelAlignment === ChordLabelAlignment.Along ? getNumber(d.data, nodeWidth) / 2 : null)\n\n if (nodeLabelAlignment === ChordLabelAlignment.Along) {\n const textElement = select(elements[i])\n const textWidth = textElement.node().getBoundingClientRect().width\n const labelText = textElement.text()\n\n select(elements[i])\n .text('')\n .style('display', textWidth > maxWidth && 'none')\n\n select(elements[i]).append('textPath')\n .attr('href', `#${d.uid}`)\n .text(labelText)\n }\n })\n\n smartTransition(label, duration)\n .attr('transform', d => {\n const nodeLabelAlignment = getValue(d.data, config.nodeLabelAlignment)\n if (nodeLabelAlignment !== ChordLabelAlignment.Perpendicular) return null\n const angleCenter = (d.x0 + d.x1) / 2\n const angleDegree = angleCenter * 180 / Math.PI\n return `rotate(${angleDegree < 180 ? angleDegree - 90 : angleDegree + 90})`\n })\n}\n\nexport function removeLabel (\n selection: Selection<SVGGElement, unknown, SVGGElement, unknown>,\n duration: number\n): void {\n smartTransition(selection, duration)\n .style('opacity', 0)\n .remove()\n}\n"],"names":["s.label","label"],"mappings":";;;;;;;;;AAmBO,MAAM,aAAa,GAAG,EAAC;AAE9B,SAAS,iBAAiB,CACxB,CAAe,EACf,MAAyC,EAAA;;AAEzC,IAAA,MAAM,kBAAkB,GAAG,CAAA,EAAA,GAAA,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,kBAAkB,CAAC,mCAAI,mBAAmB,CAAC,KAAK,CAAA;AACnG,IAAA,QAAQ,kBAAkB;AACxB,QAAA,KAAK,mBAAmB,CAAC,aAAa,EAAE;AACtC,YAAA,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;AACpD,S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Q,IAAI,MAAM,CAAC,CAAA;YAEnD,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC;iBACnC,IAAI,CAAC,MAAM,EAAE,CAAA,CAAA,EAAI,CAAC,CAAC,GAAG,EAAE,CAAC;iBACzB,IAAI,CAAC,SAAS,CAAC,CAAA;AACnB,SAAA;AACH,KAAC,CAAC,CAAA;AAEF,IAAA,eAAe,CAACA,OAAK,EAAE,QAAQ,CAAC;AAC7B,SAAA,IAAI,CAAC,WAAW,EAAE,CAAC,IAAG;AACrB,QAAA,MAAM,kBAAkB,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAA;AACtE,QAAA,IAAI,kBAAkB,KAAK,mBAAmB,CAAC,aAAa;AAAE,YAAA,OAAO,IAAI,CAAA;AACzE,QAAA,MAAM,WAAW,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;QACrC,MAAM,WAAW,GAAG,WAAW,GAAG,GAAG,GAAG,IAAI,CAAC,EAAE,CAAA;AAC/C,QAAA,OAAO,UAAU,WAAW,GAAG,GAAG,GAAG,WAAW,GAAG,EAAE,GAAG,WAAW,GAAG,EAAE,GAAG,CAAA;AAC7E,KAAC,CAAC,CAAA;AACN,CAAC;AAEe,SAAA,WAAW,CACzB,SAAgE,EAChE,QAAgB,EAAA;AAEhB,IAAA,eAAe,CAAC,SAAS,EAAE,QAAQ,CAAC;AACjC,SAAA,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;AACnB,SAAA,MAAM,EAAE,CAAA;AACb;;;;"}
|
|
1
|
+
{"version":3,"file":"label.js","sources":["../../../../src/components/chord-diagram/modules/label.ts"],"sourcesContent":["import { select, Selection } from 'd3-selection'\nimport { ScaleContinuousNumeric } from 'd3-scale'\nimport { color } from 'd3-color'\n\n// Utils\nimport { trimSVGText } from 'utils/text'\nimport { smartTransition } from 'utils/d3'\nimport { getNumber, getString, getValue } from 'utils/data'\nimport { getColor, hexToBrightness } from 'utils/color'\n\n// Config\nimport { ChordDiagramConfig } from '../config'\n\n// Local Types\nimport { ChordInputLink, ChordInputNode, ChordLabelAlignment, ChordNode } from '../types'\n\n// Styles\nimport * as s from '../style'\n\nexport const LABEL_PADDING = 3\n\nfunction getLabelFillColor<N extends ChordInputNode, L extends ChordInputLink> (\n d: ChordNode<N>,\n config: ChordDiagramConfig<N, L>\n): string {\n const nodeLabelAlignment = getValue(d.data, config.nodeLabelAlignment) ?? ChordLabelAlignment.Along\n switch (nodeLabelAlignment) {\n case ChordLabelAlignment.Perpendicular: {\n return getColor(d.data, config.nodeColor, d.height)\n }\n case ChordLabelAlignment.Along: {\n const c = getColor(d.data, config.nodeColor, d.height)\n const colorParsed = color(c)\n const brightness = colorParsed ? hexToBrightness(colorParsed.hex()) : 0\n return brightness > 0.65 ? 'var(--vis-chord-diagram-label-text-fill-color-dark)' : 'var(--vis-chord-diagram-label-text-fill-color-bright)'\n }\n }\n}\n\nfunction getLabelTextAnchor<N extends ChordInputNode, L extends ChordInputLink> (\n d: ChordNode<N>,\n config: ChordDiagramConfig<N, L>\n): string | null {\n const nodeLabelAlignment = getValue(d.data, config.nodeLabelAlignment) ?? ChordLabelAlignment.Along\n switch (nodeLabelAlignment) {\n case ChordLabelAlignment.Perpendicular: {\n const angleCenter = (d.x0 + d.x1) / 2\n const angleDegree = angleCenter * 180 / Math.PI\n return angleDegree < 180 ? 'start' : 'end'\n }\n case ChordLabelAlignment.Along: {\n return null\n }\n }\n}\n\nfunction getLabelTransform<N extends ChordInputNode, L extends ChordInputLink> (\n d: ChordNode<N>,\n config: ChordDiagramConfig<N, L>,\n radiusScale: ScaleContinuousNumeric<number, number>\n): string | null {\n const nodeLabelAlignment = getValue(d.data, config.nodeLabelAlignment) ?? ChordLabelAlignment.Along\n switch (nodeLabelAlignment) {\n case ChordLabelAlignment.Perpendicular: {\n const r = radiusScale(d.y1) + LABEL_PADDING\n const angleCenter = (d.x0 + d.x1) / 2\n const angle = angleCenter - Math.PI / 2\n const x = r * Math.cos(angle)\n const y = r * Math.sin(angle)\n return `translate(${x}, ${y})`\n }\n case ChordLabelAlignment.Along:\n return null\n }\n}\n\nexport function createLabel<N extends ChordInputNode, L extends ChordInputLink> (\n selection: Selection<SVGGElement, ChordNode<N>, SVGGElement, unknown>,\n config: ChordDiagramConfig<N, L>,\n radiusScale: ScaleContinuousNumeric<number, number>\n): void {\n selection.style('opacity', 0)\n .attr('transform', d => getLabelTransform(d, config, radiusScale))\n\n selection.append('text')\n .attr('class', s.label)\n .style('fill', d => getColor(d.data, config.nodeColor, d.height))\n}\n\nexport function updateLabel<N extends ChordInputNode, L extends ChordInputLink> (\n selection: Selection<SVGGElement, ChordNode<N>, SVGGElement, unknown>,\n config: ChordDiagramConfig<N, L>,\n width: number,\n radiusScale: ScaleContinuousNumeric<number, number>,\n duration: number\n): void {\n const { nodeLabel, nodeLabelColor, nodeWidth } = config\n\n smartTransition(selection, duration)\n .attr('transform', d => getLabelTransform(d, config, radiusScale))\n .style('opacity', 1)\n\n const label: Selection<SVGTextElement, ChordNode<N>, SVGElement, unknown> = selection.select(`.${s.label}`)\n label.select('textPath').remove()\n label\n .text(d => getString(d.data, nodeLabel))\n .style('fill', d => getColor(d.data, nodeLabelColor) ?? getLabelFillColor(d, config))\n .style('text-anchor', d => getLabelTextAnchor(d, config))\n\n label.each((d: ChordNode<N>, i: number, elements) => {\n const nodeLabelAlignment = getValue(d.data, config.nodeLabelAlignment) ?? ChordLabelAlignment.Along\n const radianArcLength = d.x1 - d.x0 - getNumber(d, config.padAngle) * 2\n const radius = radiusScale(d.y1) - getNumber(d, config.nodeWidth) / 2\n const arcLength = radius * radianArcLength\n const maxWidth = (nodeLabelAlignment === ChordLabelAlignment.Along ? arcLength : width) - LABEL_PADDING * 2\n\n const textElementSelection = select(elements[i])\n trimSVGText(textElementSelection, maxWidth)\n textElementSelection\n .attr('dx', nodeLabelAlignment === ChordLabelAlignment.Along ? LABEL_PADDING : null)\n .attr('dy', nodeLabelAlignment === ChordLabelAlignment.Along ? getNumber(d.data, nodeWidth) / 2 : null)\n\n if (nodeLabelAlignment === ChordLabelAlignment.Along) {\n const textElement = select(elements[i])\n const textWidth = textElement.node().getBoundingClientRect().width\n const labelText = textElement.text()\n\n select(elements[i])\n .text('')\n .style('display', textWidth > maxWidth && 'none')\n\n select(elements[i]).append('textPath')\n .attr('href', `#${d.uid}`)\n .text(labelText)\n }\n })\n\n smartTransition(label, duration)\n .attr('transform', d => {\n const nodeLabelAlignment = getValue(d.data, config.nodeLabelAlignment)\n if (nodeLabelAlignment !== ChordLabelAlignment.Perpendicular) return null\n const angleCenter = (d.x0 + d.x1) / 2\n const angleDegree = angleCenter * 180 / Math.PI\n return `rotate(${angleDegree < 180 ? angleDegree - 90 : angleDegree + 90})`\n })\n}\n\nexport function removeLabel (\n selection: Selection<SVGGElement, unknown, SVGGElement, unknown>,\n duration: number\n): void {\n smartTransition(selection, duration)\n .style('opacity', 0)\n .remove()\n}\n"],"names":["s.label","label"],"mappings":";;;;;;;;;AAmBO,MAAM,aAAa,GAAG,EAAC;AAE9B,SAAS,iBAAiB,CACxB,CAAe,EACf,MAAgC,EAAA;;AAEhC,IAAA,MAAM,kBAAkB,GAAG,CAAA,EAAA,GAAA,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,kBAAkB,CAAC,mCAAI,mBAAmB,CAAC,KAAK,CAAA;AACnG,IAAA,QAAQ,kBAAkB;AACxB,QAAA,KAAK,mBAAmB,CAAC,aAAa,EAAE;AACtC,YAAA,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;AACpD,SAAA;AACD,QAAA,KAAK,mBAAmB,CAAC,KAAK,EAAE;AAC9B,YAAA,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,IAA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CAAC,MAAM,EAAE,CAAA,CAAA,EAAI,CAAC,CAAC,GAAG,EAAE,CAAC;iBACzB,IAAI,CAAC,SAAS,CAAC,CAAA;AACnB,SAAA;AACH,KAAC,CAAC,CAAA;AAEF,IAAA,eAAe,CAACA,OAAK,EAAE,QAAQ,CAAC;AAC7B,SAAA,IAAI,CAAC,WAAW,EAAE,CAAC,IAAG;AACrB,QAAA,MAAM,kBAAkB,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAA;AACtE,QAAA,IAAI,kBAAkB,KAAK,mBAAmB,CAAC,aAAa;AAAE,YAAA,OAAO,IAAI,CAAA;AACzE,QAAA,MAAM,WAAW,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;QACrC,MAAM,WAAW,GAAG,WAAW,GAAG,GAAG,GAAG,IAAI,CAAC,EAAE,CAAA;AAC/C,QAAA,OAAO,UAAU,WAAW,GAAG,GAAG,GAAG,WAAW,GAAG,EAAE,GAAG,WAAW,GAAG,EAAE,GAAG,CAAA;AAC7E,KAAC,CAAC,CAAA;AACN,CAAC;AAEe,SAAA,WAAW,CACzB,SAAgE,EAChE,QAAgB,EAAA;AAEhB,IAAA,eAAe,CAAC,SAAS,EAAE,QAAQ,CAAC;AACjC,SAAA,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;AACnB,SAAA,MAAM,EAAE,CAAA;AACb;;;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Selection } from 'd3-selection';
|
|
2
2
|
import { ScalePower } from 'd3-scale';
|
|
3
3
|
import { ChordInputLink, ChordInputNode, ChordRibbon } from '../types';
|
|
4
|
-
import {
|
|
4
|
+
import { ChordDiagramConfig } from '../config';
|
|
5
5
|
export declare function emptyPath(): string;
|
|
6
6
|
export declare function createLink<N extends ChordInputNode>(selection: Selection<SVGPathElement, ChordRibbon<N>, SVGGElement, unknown>, radiusScale: ScalePower<number, number>): void;
|
|
7
|
-
export declare function updateLink<N extends ChordInputNode, L extends ChordInputLink>(selection: Selection<SVGPathElement, ChordRibbon<N
|
|
7
|
+
export declare function updateLink<N extends ChordInputNode, L extends ChordInputLink>(selection: Selection<SVGPathElement, ChordRibbon<N>, SVGGElement, unknown>, config: ChordDiagramConfig<N, L>, radiusScale: ScalePower<number, number>, duration: number): void;
|
|
8
8
|
export declare function removeLink(selection: Selection<SVGPathElement, unknown, SVGGElement, unknown>, duration: number): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.js","sources":["../../../../src/components/chord-diagram/modules/link.ts"],"sourcesContent":["import { Selection, select } from 'd3-selection'\nimport { ribbon } from 'd3-chord'\nimport { path } from 'd3-path'\nimport { ScalePower } from 'd3-scale'\nimport { areaRadial } from 'd3-shape'\nimport { Transition } from 'd3-transition'\nimport { interpolatePath } from 'd3-interpolate-path'\n\n// Types\nimport { Curve } from 'types/curve'\n\n// Utils\nimport { getColor } from 'utils/color'\nimport { smartTransition } from 'utils/d3'\nimport { convertLineToArc } from 'utils/path'\n\n// Local Types\nimport { ChordInputLink, ChordInputNode, ChordRibbon, ChordRibbonPoint } from '../types'\nimport {
|
|
1
|
+
{"version":3,"file":"link.js","sources":["../../../../src/components/chord-diagram/modules/link.ts"],"sourcesContent":["import { Selection, select } from 'd3-selection'\nimport { ribbon } from 'd3-chord'\nimport { path } from 'd3-path'\nimport { ScalePower } from 'd3-scale'\nimport { areaRadial } from 'd3-shape'\nimport { Transition } from 'd3-transition'\nimport { interpolatePath } from 'd3-interpolate-path'\n\n// Types\nimport { Curve } from 'types/curve'\n\n// Utils\nimport { getColor } from 'utils/color'\nimport { smartTransition } from 'utils/d3'\nimport { convertLineToArc } from 'utils/path'\n\n// Local Types\nimport { ChordInputLink, ChordInputNode, ChordRibbon, ChordRibbonPoint } from '../types'\nimport { ChordDiagramConfig } from '../config'\n\n// Generators\nexport function emptyPath (): string {\n return 'M0,0 L0,0'\n}\n\n// Generators\nconst ribbonGen = ribbon<ChordRibbonPoint[], ChordRibbonPoint>()\n .source(d => d[0])\n .target(d => d[d.length - 1])\n .startAngle(d => d.a0)\n .endAngle(d => d.a1)\n\nconst areaGen = areaRadial<ChordRibbonPoint>()\n .curve(Curve.catmullRom.alpha(0.5))\n .startAngle((d, i, points) => i < points.length / 2 ? d.a1 : d.a0)\n .endAngle((d, i, points) => i < points.length / 2 ? d.a0 : d.a1)\n\n\n// Creates a path from set of points\nfunction linkGen (points: ChordRibbonPoint[], radiusScale: ScalePower<number, number>): string {\n const link = (points.length === 2 ? ribbonGen : areaGen)\n link.radius(d => radiusScale(d.r))\n\n if (points.length === 2) {\n return link(points) as string\n }\n const p = path()\n const src = points[0]\n const radius = Math.max(radiusScale(src.r), 0)\n\n link.context(p as CanvasRenderingContext2D)\n link(points)\n p.arc(0, 0, radius, src.a0 - Math.PI / 2, src.a1 - Math.PI / 2, src.a1 - src.a0 <= Number.EPSILON)\n\n return convertLineToArc(p, radius)\n}\n\nexport function createLink<N extends ChordInputNode> (\n selection: Selection<SVGPathElement, ChordRibbon<N>, SVGGElement, unknown>,\n radiusScale: ScalePower<number, number>\n): void {\n selection\n .attr('d', d => linkGen(d.points, radiusScale) || emptyPath())\n .style('opacity', 0)\n}\n\nexport function updateLink<N extends ChordInputNode, L extends ChordInputLink> (\n selection: Selection<SVGPathElement, ChordRibbon<N>, SVGGElement, unknown>,\n config: ChordDiagramConfig<N, L>,\n radiusScale: ScalePower<number, number>,\n duration: number\n): void {\n selection\n .style('transition', `fill-opacity: ${duration}ms`)\n .style('fill', d => getColor(d.data, config.linkColor))\n .style('stroke', d => getColor(d.data, config.linkColor))\n\n const transition = smartTransition(selection, duration)\n .style('opacity', 1) as Transition<SVGPathElement, ChordRibbon<N>, SVGGElement, unknown>\n\n if (duration) {\n transition.attrTween('d', (d, i, el) => {\n const previous = select(el[i]).attr('d')\n const next = linkGen(d.points, radiusScale) || emptyPath()\n return interpolatePath(previous, next)\n })\n } else {\n transition.attr('d', d => linkGen(d.points, radiusScale) || emptyPath())\n }\n}\n\nexport function removeLink (\n selection: Selection<SVGPathElement, unknown, SVGGElement, unknown>,\n duration: number\n): void {\n smartTransition(selection, duration)\n .style('opacity', 0)\n .remove()\n}\n"],"names":[],"mappings":";;;;;;;;;;AAoBA;SACgB,SAAS,GAAA;AACvB,IAAA,OAAO,WAAW,CAAA;AACpB,CAAC;AAED;AACA,MAAM,SAAS,GAAG,MAAM,EAAwC;KAC7D,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACjB,KAAA,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;KAC5B,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;KACrB,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAA;AAEtB,MAAM,OAAO,GAAG,UAAU,EAAoB;KAC3C,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAClC,KAAA,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;AACjE,KAAA,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAA;AAGlE;AACA,SAAS,OAAO,CAAE,MAA0B,EAAE,WAAuC,EAAA;AACnF,IAAA,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,CAAA;AACxD,IAAA,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,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
|
3
3
|
import { ChordInputNode, ChordInputLink, ChordNode } from '../types';
|
|
4
|
-
import {
|
|
4
|
+
import { ChordDiagramConfig } from '../config';
|
|
5
5
|
declare type AnimState = {
|
|
6
6
|
x0: number;
|
|
7
7
|
x1: number;
|
|
@@ -12,6 +12,6 @@ export interface ArcNode extends SVGElement {
|
|
|
12
12
|
_animState?: AnimState;
|
|
13
13
|
}
|
|
14
14
|
export declare function createNode<N extends ChordInputNode, L extends ChordInputLink>(selection: Selection<SVGPathElement, ChordNode<N>, SVGGElement, unknown>): void;
|
|
15
|
-
export declare function updateNode<N extends ChordInputNode, L extends ChordInputLink>(selection: Selection<SVGPathElement, ChordNode<N>, SVGGElement, unknown>, config:
|
|
15
|
+
export declare function updateNode<N extends ChordInputNode, L extends ChordInputLink>(selection: Selection<SVGPathElement, ChordNode<N>, SVGGElement, unknown>, config: ChordDiagramConfig<N, L>, arcGen: Arc<unknown, AnimState>, duration: number): void;
|
|
16
16
|
export declare function removeNode<N extends ChordInputNode>(selection: Selection<SVGPathElement, unknown, SVGGElement, unknown>, duration: number): void;
|
|
17
17
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","sources":["../../../../src/components/chord-diagram/modules/node.ts"],"sourcesContent":["import { Selection } from 'd3-selection'\nimport { Transition } from 'd3-transition'\nimport { interpolate } from 'd3-interpolate'\nimport { Arc } from 'd3-shape'\n\n// Utils\nimport { getColor } from 'utils/color'\nimport { smartTransition } from 'utils/d3'\n\n// Local Types\nimport { ChordInputNode, ChordInputLink, ChordNode } from '../types'\n\n// Config\nimport {
|
|
1
|
+
{"version":3,"file":"node.js","sources":["../../../../src/components/chord-diagram/modules/node.ts"],"sourcesContent":["import { Selection } from 'd3-selection'\nimport { Transition } from 'd3-transition'\nimport { interpolate } from 'd3-interpolate'\nimport { Arc } from 'd3-shape'\n\n// Utils\nimport { getColor } from 'utils/color'\nimport { smartTransition } from 'utils/d3'\n\n// Local Types\nimport { ChordInputNode, ChordInputLink, ChordNode } from '../types'\n\n// Config\nimport { ChordDiagramConfig } from '../config'\n\ntype AnimState = { x0: number; x1: number; y0: number; y1: number }\nexport interface ArcNode extends SVGElement {\n _animState?: AnimState;\n}\n\nexport function createNode<N extends ChordInputNode, L extends ChordInputLink> (\n selection: Selection<SVGPathElement, ChordNode<N>, SVGGElement, unknown>\n): void {\n selection\n .style('opacity', 0)\n .each((d, i, els) => {\n const arcNode: ArcNode = els[i]\n const angleCenter = (d.x0 + d.x1) / 2\n const angleHalfWidth = (d.x1 - d.x0) / 2\n arcNode._animState = {\n x0: angleCenter - angleHalfWidth * 0.8,\n x1: angleCenter + angleHalfWidth * 0.8,\n y0: d.y0,\n y1: d.y1,\n }\n })\n}\n\nexport function updateNode<N extends ChordInputNode, L extends ChordInputLink> (\n selection: Selection<SVGPathElement, ChordNode<N>, SVGGElement, unknown>,\n config: ChordDiagramConfig<N, L>,\n arcGen: Arc<unknown, AnimState>,\n duration: number\n): void {\n const nodeColor = (d: ChordNode<N>): string => getColor(d.data, config.nodeColor, d.height)\n\n selection\n .attr('id', d => d.uid)\n .style('transition', `fill ${duration}ms`) // Animate color with CSS because we're using CSS-variables\n .style('fill', nodeColor)\n .style('stroke', nodeColor)\n\n if (duration) {\n const transition = smartTransition(selection, duration)\n .style('opacity', 1) as Transition<SVGPathElement, ChordNode<N>, SVGGElement, ChordNode<N>>\n\n transition.attrTween('d', (d, i, els) => {\n const arcNode: ArcNode = els[i]\n const nextAnimState = { x0: d.x0, x1: d.x1, y0: d.y0, y1: d.y1 }\n const datum = interpolate(arcNode._animState, nextAnimState)\n\n return (t: number): string => {\n arcNode._animState = datum(t)\n return arcGen(arcNode._animState)\n }\n })\n } else {\n selection.attr('d', d => arcGen(d))\n .style('opacity', 1)\n }\n}\n\nexport function removeNode<N extends ChordInputNode> (\n selection: Selection<SVGPathElement, unknown, SVGGElement, unknown>,\n duration: number\n): void {\n smartTransition(selection, duration)\n .style('opacity', 0)\n .remove()\n}\n"],"names":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S,EAAE,QAAQ,CAAC;AACpD,aAAA,KAAK,CAAC,SAAS,EAAE,CAAC,CAAwE,CAAA;AAE7F,QAAA,UAAU,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,KAAI;AACtC,YAAA,MAAM,OAAO,GAAY,GAAG,CAAC,CAAC,CAAC,CAAA;YAC/B,MAAM,aAAa,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAA;YAChE,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,UAAU,EAAE,aAAa,CAAC,CAAA;YAE5D,OAAO,CAAC,CAAS,KAAY;AAC3B,gBAAA,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;AAC7B,gBAAA,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;AACnC,aAAC,CAAA;AACH,SAAC,CAAC,CAAA;AACH,KAAA;AAAM,SAAA;AACL,QAAA,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC;AAChC,aAAA,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;AACvB,KAAA;AACH,CAAC;AAEe,SAAA,UAAU,CACxB,SAAmE,EACnE,QAAgB,EAAA;AAEhB,IAAA,eAAe,CAAC,SAAS,EAAE,QAAQ,CAAC;AACjC,SAAA,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;AACnB,SAAA,MAAM,EAAE,CAAA;AACb;;;;"}
|
|
@@ -32,7 +32,6 @@ export declare type ChordNodeCore<N> = HierarchyRectangularNode<N> & ChordNodeSt
|
|
|
32
32
|
uid: string;
|
|
33
33
|
};
|
|
34
34
|
export declare type ChordNodeDatum<N> = ChordHierarchyNode<N> | N;
|
|
35
|
-
export declare type ChordLinkDatum<N extends ChordInputNode, L extends ChordInputLink = ChordInputLink> = GraphLinkCore<N, L>;
|
|
36
35
|
export declare type ChordNode<N extends ChordInputNode> = ChordNodeCore<ChordNodeDatum<N>>;
|
|
37
36
|
export declare type ChordLeafNode<N extends ChordInputNode> = ChordNodeCore<N>;
|
|
38
37
|
export declare type ChordRibbonPoint = {
|
|
@@ -40,11 +39,11 @@ export declare type ChordRibbonPoint = {
|
|
|
40
39
|
a1: number;
|
|
41
40
|
r: number;
|
|
42
41
|
};
|
|
43
|
-
export interface ChordRibbon<N extends ChordInputNode
|
|
42
|
+
export interface ChordRibbon<N extends ChordInputNode> {
|
|
44
43
|
source: ChordLeafNode<N>;
|
|
45
44
|
target: ChordLeafNode<N>;
|
|
46
45
|
points: ChordRibbonPoint[];
|
|
47
|
-
data:
|
|
46
|
+
data: GraphLinkCore<N, ChordInputLink>;
|
|
48
47
|
_state: {
|
|
49
48
|
hovered?: boolean;
|
|
50
49
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../../src/components/chord-diagram/types.ts"],"sourcesContent":["import { HierarchyRectangularNode } from 'd3-hierarchy'\nimport { GraphLinkCore, GraphNodeCore } from 'types'\n\n// Node data flow in the component:\n// Input data (N extends ChordInputNode, L extends ChordInputLink)\n// => GraphNodeCore<N>[] (we reference it only in a few places when it's needed, to make the code easier to read)\n// => ChordHierarchyNode (nested object representing node hierarchy)\n// => ChordNode[] and ChordLeafNode[] (HierarchyRectangularNode[] from D3 partition)\n\nexport interface ChordInputNode {\n id?: string;\n}\n\nexport interface ChordInputLink {\n id?: string;\n source: number | string | ChordInputNode;\n target: number | string | ChordInputNode;\n}\n\nexport type ChordDiagramData<\n N extends ChordInputNode,\n L extends ChordInputLink,\n> = {\n nodes: N[];\n links?: L[];\n}\n\nexport interface ChordHierarchyNode<N> {\n key: string;\n values: (ChordHierarchyNode<N> | N)[];\n depth?: number;\n height?: number;\n value?: number;\n ancestors?: string[];\n}\n\nexport type ChordNodeState = {\n _state: {\n hovered?: boolean;\n value?: number;\n };\n _prevX1?: number;\n}\n\nexport type ChordNodeCore<N> = HierarchyRectangularNode<N> & ChordNodeState & {\n data: GraphNodeCore<N, ChordInputLink>;\n uid: string; // Unique id for textPath href\n}\n\nexport type ChordNodeDatum<N> = ChordHierarchyNode<N> | N\
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../src/components/chord-diagram/types.ts"],"sourcesContent":["import { HierarchyRectangularNode } from 'd3-hierarchy'\nimport { GraphLinkCore, GraphNodeCore } from 'types'\n\n// Node data flow in the component:\n// Input data (N extends ChordInputNode, L extends ChordInputLink)\n// => GraphNodeCore<N>[] (we reference it only in a few places when it's needed, to make the code easier to read)\n// => ChordHierarchyNode (nested object representing node hierarchy)\n// => ChordNode[] and ChordLeafNode[] (HierarchyRectangularNode[] from D3 partition)\n\nexport interface ChordInputNode {\n id?: string;\n}\n\nexport interface ChordInputLink {\n id?: string;\n source: number | string | ChordInputNode;\n target: number | string | ChordInputNode;\n}\n\nexport type ChordDiagramData<\n N extends ChordInputNode,\n L extends ChordInputLink,\n> = {\n nodes: N[];\n links?: L[];\n}\n\nexport interface ChordHierarchyNode<N> {\n key: string;\n values: (ChordHierarchyNode<N> | N)[];\n depth?: number;\n height?: number;\n value?: number;\n ancestors?: string[];\n}\n\nexport type ChordNodeState = {\n _state: {\n hovered?: boolean;\n value?: number;\n };\n _prevX1?: number;\n}\n\nexport type ChordNodeCore<N> = HierarchyRectangularNode<N> & ChordNodeState & {\n data: GraphNodeCore<N, ChordInputLink>;\n uid: string; // Unique id for textPath href\n}\n\nexport type ChordNodeDatum<N> = ChordHierarchyNode<N> | N\n\nexport type ChordNode<N extends ChordInputNode> = ChordNodeCore<ChordNodeDatum<N>>\nexport type ChordLeafNode<N extends ChordInputNode> = ChordNodeCore<N>\n\nexport type ChordRibbonPoint = { a0: number; a1: number; r: number }\nexport interface ChordRibbon<N extends ChordInputNode> {\n source: ChordLeafNode<N>;\n target: ChordLeafNode<N>;\n points: ChordRibbonPoint[];\n data: GraphLinkCore<N, ChordInputLink>;\n _state: {\n hovered?: boolean;\n };\n}\n\nexport enum ChordLabelAlignment {\n Along = 'along',\n Perpendicular = 'perpendicular',\n}\n"],"names":[],"mappings":"IAiEY,oBAGX;AAHD,CAAA,UAAY,mBAAmB,EAAA;AAC7B,IAAA,mBAAA,CAAA,OAAA,CAAA,GAAA,OAAe,CAAA;AACf,IAAA,mBAAA,CAAA,eAAA,CAAA,GAAA,eAA+B,CAAA;AACjC,CAAC,EAHW,mBAAmB,KAAnB,mBAAmB,GAG9B,EAAA,CAAA,CAAA;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { XYComponentConfigInterface } from "../../core/xy-component/config";
|
|
1
|
+
import { XYComponentConfigInterface, XYComponentConfig } from "../../core/xy-component/config";
|
|
2
2
|
import { Tooltip } from "../tooltip";
|
|
3
3
|
import { NumericAccessor, ColorAccessor } from "../../types/accessor";
|
|
4
4
|
import { ContinuousScale } from "../../types/scale";
|
|
@@ -10,7 +10,7 @@ export interface CrosshairConfigInterface<Datum> extends WithOptional<XYComponen
|
|
|
10
10
|
/** Optional single of multiple accessor functions for getting the values along the Y axis. Default: `undefined` */
|
|
11
11
|
y?: NumericAccessor<Datum> | NumericAccessor<Datum>[];
|
|
12
12
|
/** Optional color array or color accessor function for crosshair circles. Default: `d => d.color` */
|
|
13
|
-
color?: ColorAccessor<Datum>;
|
|
13
|
+
color?: ColorAccessor<Datum> | ColorAccessor<Datum[]>;
|
|
14
14
|
/** Separate array of accessors for stacked components (eg StackedBar, Area). Default: `undefined` */
|
|
15
15
|
yStacked?: NumericAccessor<Datum>[];
|
|
16
16
|
/** Baseline accessor function for stacked values, useful with stacked areas. Default: `null` */
|
|
@@ -35,6 +35,16 @@ export interface CrosshairConfigInterface<Datum> extends WithOptional<XYComponen
|
|
|
35
35
|
* It has to return an array of the CrosshairCircle objects: `{ y: number; color: string; opacity?: number }[]`.
|
|
36
36
|
* Default: `undefined`
|
|
37
37
|
*/
|
|
38
|
-
getCircles?: (x: number
|
|
38
|
+
getCircles?: (x: number, data: Datum[], yScale: ContinuousScale) => CrosshairCircle[];
|
|
39
|
+
}
|
|
40
|
+
export declare class CrosshairConfig<Datum> extends XYComponentConfig<Datum> implements CrosshairConfigInterface<Datum> {
|
|
41
|
+
yStacked: any;
|
|
42
|
+
baseline: any;
|
|
43
|
+
duration: number;
|
|
44
|
+
tooltip: Tooltip;
|
|
45
|
+
template: ((data: Datum, x: number | Date) => string | HTMLElement);
|
|
46
|
+
hideWhenFarFromPointer: boolean;
|
|
47
|
+
hideWhenFarFromPointerDistance: number;
|
|
48
|
+
snapToData: boolean;
|
|
49
|
+
getCircles: any;
|
|
39
50
|
}
|
|
40
|
-
export declare const CrosshairDefaultConfig: CrosshairConfigInterface<unknown>;
|
|
@@ -1,6 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { XYComponentConfig } from '../../core/xy-component/config.js';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
class CrosshairConfig extends XYComponentConfig {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.yStacked = undefined;
|
|
7
|
+
this.baseline = null;
|
|
8
|
+
this.duration = 100;
|
|
9
|
+
this.tooltip = undefined;
|
|
10
|
+
this.template = (d) => '';
|
|
11
|
+
this.hideWhenFarFromPointer = true;
|
|
12
|
+
this.hideWhenFarFromPointerDistance = 100;
|
|
13
|
+
this.snapToData = true;
|
|
14
|
+
this.getCircles = undefined;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
4
17
|
|
|
5
|
-
export {
|
|
18
|
+
export { CrosshairConfig };
|
|
6
19
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../../src/components/crosshair/config.ts"],"sourcesContent":["import { XYComponentConfigInterface,
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../../src/components/crosshair/config.ts"],"sourcesContent":["import { XYComponentConfigInterface, XYComponentConfig } from 'core/xy-component/config'\nimport { Tooltip } from 'components/tooltip'\n\n// Types\nimport { NumericAccessor, ColorAccessor } from 'types/accessor'\nimport { ContinuousScale } from 'types/scale'\nimport { WithOptional } from 'types/misc'\nimport { CrosshairCircle } from './types'\n\n// We extend partial XY config interface because x and y properties are optional for Crosshair\nexport interface CrosshairConfigInterface<Datum> extends WithOptional<XYComponentConfigInterface<Datum>, 'x' | 'y'> {\n /** Optional accessor function for getting the values along the X axis. Default: `undefined` */\n x?: NumericAccessor<Datum>;\n /** Optional single of multiple accessor functions for getting the values along the Y axis. Default: `undefined` */\n y?: NumericAccessor<Datum> | NumericAccessor<Datum>[];\n /** Optional color array or color accessor function for crosshair circles. Default: `d => d.color` */\n color?: ColorAccessor<Datum> | ColorAccessor<Datum[]>;\n /** Separate array of accessors for stacked components (eg StackedBar, Area). Default: `undefined` */\n yStacked?: NumericAccessor<Datum>[];\n /** Baseline accessor function for stacked values, useful with stacked areas. Default: `null` */\n baseline?: NumericAccessor<Datum>;\n /** An instance of the Tooltip component to be used with Crosshair. Default: `undefined` */\n tooltip?: Tooltip | undefined;\n /** Tooltip template accessor. The function is supposed to return either a valid HTML string or an HTMLElement. Default: `d => ''` */\n template?: (data: Datum, x: number | Date) => string | HTMLElement;\n /** Hide Crosshair when the corresponding element is far from mouse pointer. Default: `true` */\n hideWhenFarFromPointer?: boolean;\n /** Distance in pixels to check in the hideWhenFarFromPointer condition. Default: `100` */\n hideWhenFarFromPointerDistance?: number;\n /** Snap to the nearest data point.\n * If disabled, the tooltip template will receive only the horizontal position of the crosshair and you'll be responsible\n * for getting the underlying data records and crosshair circles (see the `getCircles` configuration option).\n * Default: `true`\n */\n snapToData?: boolean;\n /** Custom function for setting up the crosshair circles, usually needed when `snapToData` is set to `false`.\n * The function receives the horizontal position of the crosshair (in the data space, not in pixels), the data array\n * and the `yScale` instance to help you calculate the correct vertical position of the circles.\n * It has to return an array of the CrosshairCircle objects: `{ y: number; color: string; opacity?: number }[]`.\n * Default: `undefined`\n */\n getCircles?: (x: number, data: Datum[], yScale: ContinuousScale) => CrosshairCircle[];\n}\n\nexport class CrosshairConfig<Datum> extends XYComponentConfig<Datum> implements CrosshairConfigInterface<Datum> {\n yStacked = undefined\n baseline = null\n duration = 100\n tooltip: Tooltip = undefined\n template: ((data: Datum, x: number | Date) => string | HTMLElement) = (d: Datum): string => ''\n hideWhenFarFromPointer = true\n hideWhenFarFromPointerDistance = 100\n snapToData = true\n getCircles = undefined\n}\n"],"names":[],"mappings":";;AA4CM,MAAO,eAAuB,SAAQ,iBAAwB,CAAA;AAApE,IAAA,WAAA,GAAA;;QACE,IAAQ,CAAA,QAAA,GAAG,SAAS,CAAA;QACpB,IAAQ,CAAA,QAAA,GAAG,IAAI,CAAA;QACf,IAAQ,CAAA,QAAA,GAAG,GAAG,CAAA;QACd,IAAO,CAAA,OAAA,GAAY,SAAS,CAAA;AAC5B,QAAA,IAAA,CAAA,QAAQ,GAA8D,CAAC,CAAQ,KAAa,EAAE,CAAA;QAC9F,IAAsB,CAAA,sBAAA,GAAG,IAAI,CAAA;QAC7B,IAA8B,CAAA,8BAAA,GAAG,GAAG,CAAA;QACpC,IAAU,CAAA,UAAA,GAAG,IAAI,CAAA;QACjB,IAAU,CAAA,UAAA,GAAG,SAAS,CAAA;KACvB;AAAA;;;;"}
|
|
@@ -2,13 +2,12 @@ import { Selection } from 'd3-selection';
|
|
|
2
2
|
import { XYComponentCore } from "../../core/xy-component";
|
|
3
3
|
import { Tooltip } from "../tooltip";
|
|
4
4
|
import { CrosshairAccessors } from './types';
|
|
5
|
-
import { CrosshairConfigInterface } from './config';
|
|
5
|
+
import { CrosshairConfig, CrosshairConfigInterface } from './config';
|
|
6
6
|
import * as s from './style';
|
|
7
|
-
export declare class Crosshair<Datum> extends XYComponentCore<Datum, CrosshairConfigInterface<Datum>> {
|
|
7
|
+
export declare class Crosshair<Datum> extends XYComponentCore<Datum, CrosshairConfig<Datum>, CrosshairConfigInterface<Datum>> {
|
|
8
8
|
static selectors: typeof s;
|
|
9
9
|
clippable: boolean;
|
|
10
|
-
|
|
11
|
-
config: CrosshairConfigInterface<Datum>;
|
|
10
|
+
config: CrosshairConfig<Datum>;
|
|
12
11
|
container: Selection<SVGSVGElement, any, SVGSVGElement, any>;
|
|
13
12
|
line: Selection<SVGLineElement, any, SVGElement, any>;
|
|
14
13
|
x: number;
|
|
@@ -4,7 +4,7 @@ import { XYComponentCore } from '../../core/xy-component/index.js';
|
|
|
4
4
|
import { isArray, isNumber, getNearest, clamp, getNumber, isFunction, getStackedValues } from '../../utils/data.js';
|
|
5
5
|
import { smartTransition } from '../../utils/d3.js';
|
|
6
6
|
import { getColor } from '../../utils/color.js';
|
|
7
|
-
import {
|
|
7
|
+
import { CrosshairConfig } from './config.js';
|
|
8
8
|
import * as style from './style.js';
|
|
9
9
|
import { line, circle } from './style.js';
|
|
10
10
|
|
|
@@ -12,8 +12,7 @@ class Crosshair extends XYComponentCore {
|
|
|
12
12
|
constructor(config) {
|
|
13
13
|
super();
|
|
14
14
|
this.clippable = true; // Don't apply clipping path to this component. See XYContainer
|
|
15
|
-
this.
|
|
16
|
-
this.config = this._defaultConfig;
|
|
15
|
+
this.config = new CrosshairConfig();
|
|
17
16
|
this.x = 0;
|
|
18
17
|
this.show = false;
|
|
19
18
|
this._animFrameId = null;
|
|
@@ -25,7 +24,7 @@ class Crosshair extends XYComponentCore {
|
|
|
25
24
|
baseline: undefined,
|
|
26
25
|
};
|
|
27
26
|
if (config)
|
|
28
|
-
this.
|
|
27
|
+
this.config.init(config);
|
|
29
28
|
this.g.style('opacity', this.show ? 1 : 0);
|
|
30
29
|
this.line = this.g.append('line')
|
|
31
30
|
.attr('class', line);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/crosshair/index.ts"],"sourcesContent":["import { Selection, pointer } from 'd3-selection'\nimport { easeLinear } from 'd3-ease'\n\n// Core\nimport { XYComponentCore } from 'core/xy-component'\nimport { Tooltip } from 'components/tooltip'\n\n// Utils\nimport { isNumber, isArray, getNumber, clamp, getStackedValues, getNearest, isFunction } from 'utils/data'\nimport { smartTransition } from 'utils/d3'\nimport { getColor } from 'utils/color'\n\n// Local Types\nimport { CrosshairAccessors, CrosshairCircle } from './types'\n\n// Config\nimport { CrosshairDefaultConfig, CrosshairConfigInterface } from './config'\n\n// Styles\nimport * as s from './style'\n\nexport class Crosshair<Datum> extends XYComponentCore<Datum, CrosshairConfigInterface<Datum>> {\n static selectors = s\n clippable = true // Don't apply clipping path to this component. See XYContainer\n protected _defaultConfig = CrosshairDefaultConfig as CrosshairConfigInterface<Datum>\n public config: CrosshairConfigInterface<Datum> = this._defaultConfig\n container: Selection<SVGSVGElement, any, SVGSVGElement, any>\n line: Selection<SVGLineElement, any, SVGElement, any>\n x = 0\n datum: Datum\n datumIndex: number\n show = false\n private _animFrameId: number = null\n\n /** Tooltip component to be used by Crosshair if not provided by the config.\n * This property is supposed to be set externally by a container component like XYContainer. */\n public tooltip: Tooltip\n\n /** Accessors passed externally (e.g. from XYContainer) */\n private _accessors: CrosshairAccessors<Datum> = {\n x: undefined,\n y: undefined,\n yStacked: undefined,\n baseline: undefined,\n }\n\n public set accessors (accessors: CrosshairAccessors<Datum>) { this._accessors = accessors }\n public get accessors (): CrosshairAccessors<Datum> {\n const { config } = this\n\n const hasConfig = !!(config.x || config.y || config.yStacked)\n const x = hasConfig ? config.x : this._accessors.x\n const yAcc = hasConfig ? config.y : this._accessors.y\n const y = yAcc ? (isArray(yAcc) ? yAcc : [yAcc]) : undefined\n const yStacked = hasConfig ? config.yStacked : this._accessors.yStacked\n const baseline = config.baseline ?? this._accessors.baseline\n\n return { x, y, yStacked, baseline }\n }\n\n constructor (config?: CrosshairConfigInterface<Datum>) {\n super()\n if (config) this.setConfig(config)\n\n this.g.style('opacity', this.show ? 1 : 0)\n this.line = this.g.append('line')\n .attr('class', s.line)\n }\n\n setContainer (containerSvg: Selection<SVGSVGElement, unknown, SVGSVGElement, unknown>): void {\n // Set up mousemove event for Crosshair\n this.container = containerSvg\n this.container.on('mousemove.crosshair', this._onMouseMove.bind(this))\n this.container.on('mouseout.crosshair', this._onMouseOut.bind(this))\n }\n\n _render (customDuration?: number): void {\n const { config } = this\n if (config.snapToData && !this.datum) return\n const duration = isNumber(customDuration) ? customDuration : config.duration\n\n smartTransition(this.g, duration)\n .style('opacity', this.show ? 1 : 0)\n\n this.line\n .attr('y1', 0)\n .attr('y1', this._height)\n\n smartTransition(this.line, duration, easeLinear)\n .attr('x1', this.x)\n .attr('x2', this.x)\n\n const circleData = this.getCircleData()\n const circles = this.g\n .selectAll<SVGCircleElement, CrosshairCircle>('circle')\n .data(circleData, (d, i) => d.id ?? i)\n\n const circlesEnter = circles.enter()\n .append('circle')\n .attr('class', s.circle)\n .attr('r', 0)\n .attr('cx', this.x)\n .attr('cy', d => d.y)\n .style('fill', d => d.color)\n\n smartTransition(circlesEnter.merge(circles), duration, easeLinear)\n .attr('cx', this.x)\n .attr('cy', d => d.y)\n .attr('r', 4)\n .style('opacity', d => d.opacity)\n .style('fill', d => d.color)\n\n circles.exit().remove()\n }\n\n hide (): void {\n this._onMouseOut()\n }\n\n _onMouseMove (event: MouseEvent): void {\n const { config, datamodel, element } = this\n if (!this.accessors.x && datamodel.data?.length) {\n console.warn('Unovis | Crosshair: X accessor function has not been configured. Please check if it\\'s present in the configuration object')\n }\n const [x] = pointer(event, element)\n const xRange = this.xScale.range()\n\n if (config.snapToData) {\n if (!this.accessors.y && !this.accessors.yStacked && datamodel.data?.length) {\n console.warn('Unovis | Crosshair: Y accessors have not been configured. Please check if they\\'re present in the configuration object')\n }\n const scaleX = this.xScale\n const valueX = scaleX.invert(x) as number\n\n this.datum = getNearest(datamodel.data, valueX, this.accessors.x)\n this.datumIndex = datamodel.data.indexOf(this.datum)\n if (!this.datum) return\n\n this.x = clamp(Math.round(scaleX(getNumber(this.datum, this.accessors.x, this.datumIndex))), 0, this._width)\n\n // Show the crosshair only if it's in the chart range and not far from mouse pointer (if configured)\n this.show = (this.x >= 0) && (this.x <= this._width) && (!config.hideWhenFarFromPointer || (Math.abs(this.x - x) < config.hideWhenFarFromPointerDistance))\n } else {\n const tolerance = 2 // Show the crosshair when it is at least 2 pixels close to the chart area\n this.x = clamp(x, xRange[0], xRange[1])\n this.show = (x >= (xRange[0] - tolerance)) && (x <= (xRange[1] + tolerance))\n }\n\n window.cancelAnimationFrame(this._animFrameId)\n this._animFrameId = window.requestAnimationFrame(() => {\n this._render()\n })\n\n if (this.show) this._showTooltip(event)\n else this._hideTooltip()\n }\n\n _onMouseOut (): void {\n this.show = false\n\n window.cancelAnimationFrame(this._animFrameId)\n this._animFrameId = window.requestAnimationFrame(() => {\n this._render()\n })\n this._hideTooltip()\n }\n\n _showTooltip (event: MouseEvent): void {\n const { config } = this\n const tooltip = config.tooltip ?? this.tooltip\n if (!tooltip) return\n\n const container = tooltip.getContainer() || this.container.node()\n const [x, y] = tooltip.isContainerBody() ? [event.clientX, event.clientY] : pointer(event, container)\n const content = config.template(this.datum, this.xScale.invert(this.x))\n if (content) tooltip.show(content, { x, y })\n }\n\n _hideTooltip (): void {\n const { config } = this\n const tooltip = config.tooltip ?? this.tooltip\n tooltip?.hide()\n }\n\n // We don't want Crosshair to be be taken in to account in domain calculations\n getYDataExtent (): number[] {\n return [undefined, undefined]\n }\n\n private getCircleData (): CrosshairCircle[] {\n const { config, datamodel: { data } } = this\n\n if (isFunction(config.getCircles)) return config.getCircles(this.xScale.invert(this.x), data, this.yScale)\n\n if (config.snapToData && this.datum) {\n const yAccessors = this.accessors.y ?? []\n const yStackedAccessors = this.accessors.yStacked ?? []\n const baselineValue = getNumber(this.datum, this.accessors.baseline, this.datumIndex) || 0\n const stackedValues: CrosshairCircle[] = getStackedValues(this.datum, this.datumIndex, ...yStackedAccessors)\n .map((value, index, arr) => ({\n y: this.yScale(value + baselineValue),\n opacity: getNumber(this.datum, yStackedAccessors[index]) ? 1 : 0,\n color: getColor(this.datum, config.color, index),\n }))\n\n const regularValues: CrosshairCircle[] = yAccessors\n .map((a, index) => {\n const value = getNumber(this.datum, a)\n return {\n y: this.yScale(value),\n opacity: value ? 1 : 0,\n color: getColor(this.datum, config.color, stackedValues.length + index),\n }\n })\n\n return stackedValues.concat(regularValues)\n }\n\n return []\n }\n}\n"],"names":["s.line","s.circle","s"],"mappings":";;;;;;;;;;AAqBM,MAAO,SAAiB,SAAQ,eAAuD,CAAA;AAuC3F,IAAA,WAAA,CAAa,MAAwC,EAAA;AACnD,QAAA,KAAK,EAAE,CAAA;AAtCT,QAAA,IAAA,CAAA,SAAS,GAAG,IAAI,CAAA;QACN,IAAc,CAAA,cAAA,GAAG,sBAAyD,CAAA;AAC7E,QAAA,IAAA,CAAA,MAAM,GAAoC,IAAI,CAAC,cAAc,CAAA;QAGpE,IAAC,CAAA,CAAA,GAAG,CAAC,CAAA;QAGL,IAAI,CAAA,IAAA,GAAG,KAAK,CAAA;QACJ,IAAY,CAAA,YAAA,GAAW,IAAI,CAAA;;AAO3B,QAAA,IAAA,CAAA,UAAU,GAA8B;AAC9C,YAAA,CAAC,EAAE,SAAS;AACZ,YAAA,CAAC,EAAE,SAAS;AACZ,YAAA,QAAQ,EAAE,SAAS;AACnB,YAAA,QAAQ,EAAE,SAAS;SACpB,CAAA;AAkBC,QAAA,IAAI,MAAM;AAAE,YAAA,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;AAElC,QAAA,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;QAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;AAC9B,aAAA,IAAI,CAAC,OAAO,EAAEA,IAAM,CAAC,CAAA;KACzB;IArBD,IAAW,SAAS,CAAE,SAAoC,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,UAAU;AAChD,iBAAA,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,KAAI;gBAChB,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;gBACtC,OAAO;AACL,oBAAA,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;oBACrB,OAAO,EAAE,KAAK,GAAG,CAAC,GAAG,CAAC;AACtB,oBAAA,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,GAAG,KAAK,CAAC;iBACxE,CAAA;AACH,aAAC,CAAC,CAAA;AAEJ,YAAA,OAAO,aAAa,CAAC,MAAM,CAAC,aAAa,CAAC,CAAA;AAC3C,SAAA;AAED,QAAA,OAAO,EAAE,CAAA;KACV;;AArMM,SAAS,CAAA,SAAA,GAAGC,KAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/crosshair/index.ts"],"sourcesContent":["import { Selection, pointer } from 'd3-selection'\nimport { easeLinear } from 'd3-ease'\n\n// Core\nimport { XYComponentCore } from 'core/xy-component'\nimport { Tooltip } from 'components/tooltip'\n\n// Utils\nimport { isNumber, isArray, getNumber, clamp, getStackedValues, getNearest, isFunction } from 'utils/data'\nimport { smartTransition } from 'utils/d3'\nimport { getColor } from 'utils/color'\n\n// Local Types\nimport { CrosshairAccessors, CrosshairCircle } from './types'\n\n// Config\nimport { CrosshairConfig, CrosshairConfigInterface } from './config'\n\n// Styles\nimport * as s from './style'\n\nexport class Crosshair<Datum> extends XYComponentCore<Datum, CrosshairConfig<Datum>, CrosshairConfigInterface<Datum>> {\n static selectors = s\n clippable = true // Don't apply clipping path to this component. See XYContainer\n config: CrosshairConfig<Datum> = new CrosshairConfig()\n container: Selection<SVGSVGElement, any, SVGSVGElement, any>\n line: Selection<SVGLineElement, any, SVGElement, any>\n x = 0\n datum: Datum\n datumIndex: number\n show = false\n private _animFrameId: number = null\n\n /** Tooltip component to be used by Crosshair if not provided by the config.\n * This property is supposed to be set externally by a container component like XYContainer. */\n public tooltip: Tooltip\n\n /** Accessors passed externally (e.g. from XYContainer) */\n private _accessors: CrosshairAccessors<Datum> = {\n x: undefined,\n y: undefined,\n yStacked: undefined,\n baseline: undefined,\n }\n\n public set accessors (accessors: CrosshairAccessors<Datum>) { this._accessors = accessors }\n public get accessors (): CrosshairAccessors<Datum> {\n const { config } = this\n\n const hasConfig = !!(config.x || config.y || config.yStacked)\n const x = hasConfig ? config.x : this._accessors.x\n const yAcc = hasConfig ? config.y : this._accessors.y\n const y = yAcc ? (isArray(yAcc) ? yAcc : [yAcc]) : undefined\n const yStacked = hasConfig ? config.yStacked : this._accessors.yStacked\n const baseline = config.baseline ?? this._accessors.baseline\n\n return { x, y, yStacked, baseline }\n }\n\n constructor (config?: CrosshairConfigInterface<Datum>) {\n super()\n if (config) this.config.init(config)\n\n this.g.style('opacity', this.show ? 1 : 0)\n this.line = this.g.append('line')\n .attr('class', s.line)\n }\n\n setContainer (containerSvg: Selection<SVGSVGElement, unknown, SVGSVGElement, unknown>): void {\n // Set up mousemove event for Crosshair\n this.container = containerSvg\n this.container.on('mousemove.crosshair', this._onMouseMove.bind(this))\n this.container.on('mouseout.crosshair', this._onMouseOut.bind(this))\n }\n\n _render (customDuration?: number): void {\n const { config } = this\n if (config.snapToData && !this.datum) return\n const duration = isNumber(customDuration) ? customDuration : config.duration\n\n smartTransition(this.g, duration)\n .style('opacity', this.show ? 1 : 0)\n\n this.line\n .attr('y1', 0)\n .attr('y1', this._height)\n\n smartTransition(this.line, duration, easeLinear)\n .attr('x1', this.x)\n .attr('x2', this.x)\n\n const circleData = this.getCircleData()\n const circles = this.g\n .selectAll<SVGCircleElement, CrosshairCircle>('circle')\n .data(circleData, (d, i) => d.id ?? i)\n\n const circlesEnter = circles.enter()\n .append('circle')\n .attr('class', s.circle)\n .attr('r', 0)\n .attr('cx', this.x)\n .attr('cy', d => d.y)\n .style('fill', d => d.color)\n\n smartTransition(circlesEnter.merge(circles), duration, easeLinear)\n .attr('cx', this.x)\n .attr('cy', d => d.y)\n .attr('r', 4)\n .style('opacity', d => d.opacity)\n .style('fill', d => d.color)\n\n circles.exit().remove()\n }\n\n hide (): void {\n this._onMouseOut()\n }\n\n _onMouseMove (event: MouseEvent): void {\n const { config, datamodel, element } = this\n if (!this.accessors.x && datamodel.data?.length) {\n console.warn('Unovis | Crosshair: X accessor function has not been configured. Please check if it\\'s present in the configuration object')\n }\n const [x] = pointer(event, element)\n const xRange = this.xScale.range()\n\n if (config.snapToData) {\n if (!this.accessors.y && !this.accessors.yStacked && datamodel.data?.length) {\n console.warn('Unovis | Crosshair: Y accessors have not been configured. Please check if they\\'re present in the configuration object')\n }\n const scaleX = this.xScale\n const valueX = scaleX.invert(x) as number\n\n this.datum = getNearest(datamodel.data, valueX, this.accessors.x)\n this.datumIndex = datamodel.data.indexOf(this.datum)\n if (!this.datum) return\n\n this.x = clamp(Math.round(scaleX(getNumber(this.datum, this.accessors.x, this.datumIndex))), 0, this._width)\n\n // Show the crosshair only if it's in the chart range and not far from mouse pointer (if configured)\n this.show = (this.x >= 0) && (this.x <= this._width) && (!config.hideWhenFarFromPointer || (Math.abs(this.x - x) < config.hideWhenFarFromPointerDistance))\n } else {\n const tolerance = 2 // Show the crosshair when it is at least 2 pixels close to the chart area\n this.x = clamp(x, xRange[0], xRange[1])\n this.show = (x >= (xRange[0] - tolerance)) && (x <= (xRange[1] + tolerance))\n }\n\n window.cancelAnimationFrame(this._animFrameId)\n this._animFrameId = window.requestAnimationFrame(() => {\n this._render()\n })\n\n if (this.show) this._showTooltip(event)\n else this._hideTooltip()\n }\n\n _onMouseOut (): void {\n this.show = false\n\n window.cancelAnimationFrame(this._animFrameId)\n this._animFrameId = window.requestAnimationFrame(() => {\n this._render()\n })\n this._hideTooltip()\n }\n\n _showTooltip (event: MouseEvent): void {\n const { config } = this\n const tooltip = config.tooltip ?? this.tooltip\n if (!tooltip) return\n\n const container = tooltip.getContainer() || this.container.node()\n const [x, y] = tooltip.isContainerBody() ? [event.clientX, event.clientY] : pointer(event, container)\n const content = config.template(this.datum, this.xScale.invert(this.x))\n if (content) tooltip.show(content, { x, y })\n }\n\n _hideTooltip (): void {\n const { config } = this\n const tooltip = config.tooltip ?? this.tooltip\n tooltip?.hide()\n }\n\n // We don't want Crosshair to be be taken in to account in domain calculations\n getYDataExtent (): number[] {\n return [undefined, undefined]\n }\n\n private getCircleData (): CrosshairCircle[] {\n const { config, datamodel: { data } } = this\n\n if (isFunction(config.getCircles)) return config.getCircles(this.xScale.invert(this.x), data, this.yScale)\n\n if (config.snapToData && this.datum) {\n const yAccessors = this.accessors.y ?? []\n const yStackedAccessors = this.accessors.yStacked ?? []\n const baselineValue = getNumber(this.datum, this.accessors.baseline, this.datumIndex) || 0\n const stackedValues: CrosshairCircle[] = getStackedValues(this.datum, this.datumIndex, ...yStackedAccessors)\n .map((value, index, arr) => ({\n y: this.yScale(value + baselineValue),\n opacity: getNumber(this.datum, yStackedAccessors[index]) ? 1 : 0,\n color: getColor(this.datum, config.color, index),\n }))\n\n const regularValues: CrosshairCircle[] = yAccessors\n .map((a, index) => {\n const value = getNumber(this.datum, a)\n return {\n y: this.yScale(value),\n opacity: value ? 1 : 0,\n color: getColor(this.datum, config.color, stackedValues.length + index),\n }\n })\n\n return stackedValues.concat(regularValues)\n }\n\n return []\n }\n}\n"],"names":["s.line","s.circle","s"],"mappings":";;;;;;;;;;AAqBM,MAAO,SAAiB,SAAQ,eAA+E,CAAA;AAsCnH,IAAA,WAAA,CAAa,MAAwC,EAAA;AACnD,QAAA,KAAK,EAAE,CAAA;AArCT,QAAA,IAAA,CAAA,SAAS,GAAG,IAAI,CAAA;AAChB,QAAA,IAAA,CAAA,MAAM,GAA2B,IAAI,eAAe,EAAE,CAAA;QAGtD,IAAC,CAAA,CAAA,GAAG,CAAC,CAAA;QAGL,IAAI,CAAA,IAAA,GAAG,KAAK,CAAA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"../../core/component/config";
|
|
1
|
+
import { ComponentConfigInterface, ComponentConfig } from "../../core/component/config";
|
|
2
2
|
import { ColorAccessor, NumericAccessor } from "../../types/accessor";
|
|
3
3
|
export interface DonutConfigInterface<Datum> extends ComponentConfigInterface {
|
|
4
4
|
/** Accessor function for getting the unique data record id. Used for more persistent data updates. Default: `(d, i) => d.id ?? i` */
|
|
@@ -39,4 +39,21 @@ export interface DonutConfigInterface<Datum> extends ComponentConfigInterface {
|
|
|
39
39
|
/** Background angle range. When undefined, the value will be taken from `angleRange`. Default: `undefined` */
|
|
40
40
|
backgroundAngleRange?: [number, number];
|
|
41
41
|
}
|
|
42
|
-
export declare
|
|
42
|
+
export declare class DonutConfig<Datum> extends ComponentConfig implements DonutConfigInterface<Datum> {
|
|
43
|
+
id: (d: Datum, i: number) => string | number;
|
|
44
|
+
value: any;
|
|
45
|
+
angleRange: [number, number];
|
|
46
|
+
padAngle: number;
|
|
47
|
+
sortFunction: any;
|
|
48
|
+
cornerRadius: number;
|
|
49
|
+
color: any;
|
|
50
|
+
radius: any;
|
|
51
|
+
arcWidth: number;
|
|
52
|
+
centralLabel: any;
|
|
53
|
+
centralSubLabel: any;
|
|
54
|
+
centralSubLabelWrap: boolean;
|
|
55
|
+
showEmptySegments: boolean;
|
|
56
|
+
emptySegmentAngle: number;
|
|
57
|
+
showBackground: boolean;
|
|
58
|
+
backgroundAngleRange: any;
|
|
59
|
+
}
|
|
@@ -1,9 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComponentConfig } from '../../core/component/config.js';
|
|
2
2
|
|
|
3
3
|
// Core
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
class DonutConfig extends ComponentConfig {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
// eslint-disable-next-line dot-notation
|
|
8
|
+
this.id = (d, i) => { var _a; return (_a = d['id']) !== null && _a !== void 0 ? _a : i; };
|
|
9
|
+
this.value = undefined;
|
|
10
|
+
this.angleRange = [0, 2 * Math.PI];
|
|
11
|
+
this.padAngle = 0;
|
|
12
|
+
this.sortFunction = undefined;
|
|
13
|
+
this.cornerRadius = 0;
|
|
14
|
+
this.color = undefined;
|
|
15
|
+
this.radius = undefined;
|
|
16
|
+
this.arcWidth = 20;
|
|
17
|
+
this.centralLabel = undefined;
|
|
18
|
+
this.centralSubLabel = undefined;
|
|
19
|
+
this.centralSubLabelWrap = true;
|
|
20
|
+
this.showEmptySegments = false;
|
|
21
|
+
this.emptySegmentAngle = 0.5 * Math.PI / 180;
|
|
22
|
+
this.showBackground = true;
|
|
23
|
+
this.backgroundAngleRange = undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
7
26
|
|
|
8
|
-
export {
|
|
27
|
+
export { DonutConfig };
|
|
9
28
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../../src/components/donut/config.ts"],"sourcesContent":["// Core\nimport { ComponentConfigInterface,
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../../src/components/donut/config.ts"],"sourcesContent":["// Core\nimport { ComponentConfigInterface, ComponentConfig } from 'core/component/config'\n\n// Types\nimport { ColorAccessor, NumericAccessor } from 'types/accessor'\n\nexport interface DonutConfigInterface<Datum> extends ComponentConfigInterface {\n /** Accessor function for getting the unique data record id. Used for more persistent data updates. Default: `(d, i) => d.id ?? i` */\n id?: ((d: Datum, i: number, ...any) => string | number);\n /** Value accessor function. Default: `undefined` */\n value: NumericAccessor<Datum>;\n /** Diagram angle range. Default: `[0, 2 * Math.PI]` */\n angleRange?: [number, number];\n /** Pad angle. Default: `0` */\n padAngle?: number;\n /** Custom sort function. Default: `undefined` */\n sortFunction?: (a: Datum, b: Datum) => number;\n /** Corner Radius. Default: `0` */\n cornerRadius?: number;\n /** Color accessor function. Default: `undefined` */\n color?: ColorAccessor<Datum>;\n /** Explicitly set the donut outer radius. Default: `undefined` */\n radius?: number;\n /** Arc width in pixels. Set to `0` if you want to have a pie chart. Default: `20` */\n arcWidth?: number;\n /** Central label accessor function or text. Default: `undefined` */\n centralLabel?: string;\n /** Central sub-label accessor function or text. Default: `undefined` */\n centralSubLabel?: string;\n /** Enables wrapping for the sub-label. Default: `true` */\n centralSubLabelWrap?: boolean;\n /** When true, the component will display empty segments (the ones that have `0` values) as tiny slices.\n * Default: `false`\n */\n showEmptySegments?: boolean;\n /** Angular size for empty segments in radians. Default: `0.5 * Math.PI / 180` */\n emptySegmentAngle?: number;\n /** Show donut background. The color is configurable via\n * the `--vis-donut-background-color` and `--vis-dark-donut-background-color` CSS variables.\n * Default: `true`\n */\n showBackground?: boolean;\n /** Background angle range. When undefined, the value will be taken from `angleRange`. Default: `undefined` */\n backgroundAngleRange?: [number, number];\n}\n\nexport class DonutConfig<Datum> extends ComponentConfig implements DonutConfigInterface<Datum> {\n // eslint-disable-next-line dot-notation\n id = (d: Datum, i: number): string | number => d['id'] ?? i\n value = undefined\n angleRange: [number, number] = [0, 2 * Math.PI]\n padAngle = 0\n sortFunction = undefined\n cornerRadius = 0\n color = undefined\n radius = undefined\n arcWidth = 20\n centralLabel = undefined\n centralSubLabel = undefined\n centralSubLabelWrap = true\n showEmptySegments = false\n emptySegmentAngle = 0.5 * Math.PI / 180\n showBackground = true\n backgroundAngleRange = undefined\n}\n"],"names":[],"mappings":";;AAAA;AA8CM,MAAO,WAAmB,SAAQ,eAAe,CAAA;AAAvD,IAAA,WAAA,GAAA;;;AAEE,QAAA,IAAA,CAAA,EAAE,GAAG,CAAC,CAAQ,EAAE,CAAS,KAAsB,EAAA,IAAA,EAAA,CAAA,CAAA,OAAA,CAAA,EAAA,GAAA,CAAC,CAAC,IAAI,CAAC,mCAAI,CAAC,CAAA,EAAA,CAAA;QAC3D,IAAK,CAAA,KAAA,GAAG,SAAS,CAAA;QACjB,IAAU,CAAA,UAAA,GAAqB,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAA;QAC/C,IAAQ,CAAA,QAAA,GAAG,CAAC,CAAA;QACZ,IAAY,CAAA,YAAA,GAAG,SAAS,CAAA;QACxB,IAAY,CAAA,YAAA,GAAG,CAAC,CAAA;QAChB,IAAK,CAAA,KAAA,GAAG,SAAS,CAAA;QACjB,IAAM,CAAA,MAAA,GAAG,SAAS,CAAA;QAClB,IAAQ,CAAA,QAAA,GAAG,EAAE,CAAA;QACb,IAAY,CAAA,YAAA,GAAG,SAAS,CAAA;QACxB,IAAe,CAAA,eAAA,GAAG,SAAS,CAAA;QAC3B,IAAmB,CAAA,mBAAA,GAAG,IAAI,CAAA;QAC1B,IAAiB,CAAA,iBAAA,GAAG,KAAK,CAAA;QACzB,IAAiB,CAAA,iBAAA,GAAG,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAA;QACvC,IAAc,CAAA,cAAA,GAAG,IAAI,CAAA;QACrB,IAAoB,CAAA,oBAAA,GAAG,SAAS,CAAA;KACjC;AAAA;;;;"}
|
|
@@ -3,12 +3,11 @@ import { ComponentCore } from "../../core/component";
|
|
|
3
3
|
import { SeriesDataModel } from "../../data-models/series";
|
|
4
4
|
import { Spacing } from "../../types/spacing";
|
|
5
5
|
import { DonutArcAnimState } from './types';
|
|
6
|
-
import { DonutConfigInterface } from './config';
|
|
6
|
+
import { DonutConfig, DonutConfigInterface } from './config';
|
|
7
7
|
import * as s from './style';
|
|
8
|
-
export declare class Donut<Datum> extends ComponentCore<Datum[], DonutConfigInterface<Datum>> {
|
|
8
|
+
export declare class Donut<Datum> extends ComponentCore<Datum[], DonutConfig<Datum>, DonutConfigInterface<Datum>> {
|
|
9
9
|
static selectors: typeof s;
|
|
10
|
-
|
|
11
|
-
config: DonutConfigInterface<Datum>;
|
|
10
|
+
config: DonutConfig<Datum>;
|
|
12
11
|
datamodel: SeriesDataModel<Datum>;
|
|
13
12
|
arcBackground: Selection<SVGPathElement, unknown, SVGGElement, unknown>;
|
|
14
13
|
arcGroup: Selection<SVGGElement, unknown, SVGGElement, unknown>;
|
|
@@ -4,7 +4,7 @@ import { SeriesDataModel } from '../../data-models/series.js';
|
|
|
4
4
|
import { smartTransition } from '../../utils/d3.js';
|
|
5
5
|
import { getNumber, isNumber, clamp } from '../../utils/data.js';
|
|
6
6
|
import { wrapSVGText } from '../../utils/text.js';
|
|
7
|
-
import {
|
|
7
|
+
import { DonutConfig } from './config.js';
|
|
8
8
|
import { createArc, updateArc, removeArc } from './modules/arc.js';
|
|
9
9
|
import * as style from './style.js';
|
|
10
10
|
import { centralLabel, centralSubLabel, segment, segmentExit, background } from './style.js';
|
|
@@ -12,13 +12,12 @@ import { centralLabel, centralSubLabel, segment, segmentExit, background } from
|
|
|
12
12
|
class Donut extends ComponentCore {
|
|
13
13
|
constructor(config) {
|
|
14
14
|
super();
|
|
15
|
-
this.
|
|
16
|
-
this.config = this._defaultConfig;
|
|
15
|
+
this.config = new DonutConfig();
|
|
17
16
|
this.datamodel = new SeriesDataModel();
|
|
18
17
|
this.arcGen = arc();
|
|
19
18
|
this.events = {};
|
|
20
19
|
if (config)
|
|
21
|
-
this.
|
|
20
|
+
this.config.init(config);
|
|
22
21
|
this.arcBackground = this.g.append('path');
|
|
23
22
|
this.arcGroup = this.g.append('g');
|
|
24
23
|
this.centralLabel = this.g.append('text')
|
|
@@ -54,7 +53,7 @@ class Donut extends ComponentCore {
|
|
|
54
53
|
.endAngle((_d = (_c = config.angleRange) === null || _c === void 0 ? void 0 : _c[1]) !== null && _d !== void 0 ? _d : 2 * Math.PI)
|
|
55
54
|
.padAngle(config.padAngle)
|
|
56
55
|
.value(d => getNumber(d.datum, config.value, d.index) || 0)
|
|
57
|
-
.sort(
|
|
56
|
+
.sort(config.sortFunction);
|
|
58
57
|
this.arcGroup.attr('transform', `translate(${this._width / 2},${this._height / 2})`);
|
|
59
58
|
const arcData = pieGen(data).map(d => {
|
|
60
59
|
const arc = Object.assign(Object.assign({}, d), { data: d.data.datum, index: d.data.index, innerRadius,
|