@unovis/ts 1.4.0-beta.6 → 1.4.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/components/annotations/index.d.ts +4 -2
- package/components/annotations/index.js +30 -37
- package/components/annotations/index.js.map +1 -1
- package/components/annotations/style.d.ts +4 -1
- package/components/annotations/style.js +8 -4
- package/components/annotations/style.js.map +1 -1
- package/components/annotations/types.d.ts +2 -13
- package/components/annotations/types.js +0 -6
- package/components/annotations/types.js.map +1 -1
- package/components/area/index.js +2 -0
- package/components/area/index.js.map +1 -1
- package/components/chord-diagram/modules/label.js +1 -0
- package/components/chord-diagram/modules/label.js.map +1 -1
- package/components/chord-diagram/modules/link.js +1 -1
- package/components/chord-diagram/modules/link.js.map +1 -1
- package/components/crosshair/config.d.ts +4 -0
- package/components/crosshair/config.js +1 -1
- package/components/crosshair/config.js.map +1 -1
- package/components/crosshair/index.js +12 -4
- package/components/crosshair/index.js.map +1 -1
- package/components/crosshair/style.js +4 -2
- package/components/crosshair/style.js.map +1 -1
- package/components/crosshair/types.d.ts +2 -0
- package/components/graph/config.d.ts +22 -15
- package/components/graph/config.js +4 -2
- package/components/graph/config.js.map +1 -1
- package/components/graph/index.d.ts +7 -2
- package/components/graph/index.js +114 -110
- package/components/graph/index.js.map +1 -1
- package/components/graph/modules/layout.js +30 -19
- package/components/graph/modules/layout.js.map +1 -1
- package/components/graph/modules/link/helper.d.ts +4 -6
- package/components/graph/modules/link/helper.js +15 -25
- package/components/graph/modules/link/helper.js.map +1 -1
- package/components/graph/modules/link/index.d.ts +3 -3
- package/components/graph/modules/link/index.js +111 -89
- package/components/graph/modules/link/index.js.map +1 -1
- package/components/graph/modules/link/style.d.ts +5 -5
- package/components/graph/modules/link/style.js +26 -22
- package/components/graph/modules/link/style.js.map +1 -1
- package/components/graph/modules/node/helper.d.ts +1 -0
- package/components/graph/modules/node/helper.js +4 -1
- package/components/graph/modules/node/helper.js.map +1 -1
- package/components/graph/modules/node/index.js +28 -11
- package/components/graph/modules/node/index.js.map +1 -1
- package/components/graph/modules/node/style.d.ts +1 -1
- package/components/graph/modules/node/style.js +13 -6
- package/components/graph/modules/node/style.js.map +1 -1
- package/components/graph/modules/shape.d.ts +0 -2
- package/components/graph/modules/shape.js +7 -9
- package/components/graph/modules/shape.js.map +1 -1
- package/components/graph/types.d.ts +63 -5
- package/components/graph/types.js +1 -0
- package/components/graph/types.js.map +1 -1
- package/components/sankey/modules/node.js +1 -1
- package/components/sankey/modules/node.js.map +1 -1
- package/components/tooltip/config.d.ts +1 -1
- package/components/tooltip/config.js.map +1 -1
- package/components/tooltip/index.js +3 -1
- package/components/tooltip/index.js.map +1 -1
- package/components/xy-labels/index.js +1 -1
- package/components/xy-labels/index.js.map +1 -1
- package/containers/single-container/config.js +1 -1
- package/containers/single-container/config.js.map +1 -1
- package/containers/xy-container/config.js +1 -1
- package/containers/xy-container/config.js.map +1 -1
- package/containers/xy-container/index.js.map +1 -1
- package/core/component/index.d.ts +3 -3
- package/core/component/index.js +1 -1
- package/core/component/index.js.map +1 -1
- package/index.js +0 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/types.js +1 -1
- package/utils/data.js +1 -1
- package/utils/data.js.map +1 -1
- package/utils/svg.d.ts +3 -0
- package/utils/svg.js +61 -0
- package/utils/svg.js.map +1 -0
- package/utils/text.js.map +1 -1
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { Selection } from 'd3-selection';
|
|
2
2
|
import { ComponentCore } from "../../core/component";
|
|
3
|
-
import { Spacing } from "../../types/spacing";
|
|
4
3
|
import { AnnotationsConfigInterface } from './config';
|
|
5
4
|
import * as s from './style';
|
|
6
5
|
export declare class Annotations extends ComponentCore<unknown[], AnnotationsConfigInterface> {
|
|
7
6
|
static selectors: typeof s;
|
|
8
7
|
static cssVariables: {
|
|
8
|
+
annotationsTextColor: "--vis-annotations-text-color";
|
|
9
9
|
annotationsConnectorStrokeColor: "--vis-annotations-connector-stroke-color";
|
|
10
10
|
annotationsConnectorStrokeWidth: "--vis-annotations-connector-stroke-width";
|
|
11
11
|
annotationsConnectorStrokeDasharray: "--vis-annotations-connector-stroke-dasharray";
|
|
12
12
|
annotationsSubjectStrokeColor: "--vis-annotations-subject-stroke-color";
|
|
13
13
|
annotationsSubjectFillColor: "--vis-annotations-subject-fill-color";
|
|
14
14
|
annotationsSubjectStrokeDasharray: "--vis-annotations-subject-stroke-dasharray";
|
|
15
|
+
darkAnnotationsTextColor: "--vis-dark-annotations-text-color";
|
|
16
|
+
darkAnnotationsConnectorStrokeColor: "--vis-dark-annotations-connector-stroke-color";
|
|
17
|
+
darkAnnotationsSubjectStrokeColor: "--vis-dark-annotations-subject-stroke-color";
|
|
15
18
|
};
|
|
16
19
|
protected _defaultConfig: AnnotationsConfigInterface;
|
|
17
20
|
config: AnnotationsConfigInterface;
|
|
18
21
|
g: Selection<SVGGElement, unknown, null, undefined>;
|
|
19
22
|
events: {};
|
|
20
23
|
constructor(config?: AnnotationsConfigInterface);
|
|
21
|
-
get bleed(): Spacing;
|
|
22
24
|
_render(customDuration?: number): void;
|
|
23
25
|
private _renderSubject;
|
|
24
26
|
}
|
|
@@ -4,9 +4,10 @@ import { isNumber } from '../../utils/data.js';
|
|
|
4
4
|
import { smartTransition } from '../../utils/d3.js';
|
|
5
5
|
import { renderTextIntoFrame } from '../../utils/text.js';
|
|
6
6
|
import { parseUnit } from '../../utils/misc.js';
|
|
7
|
+
import { UNOVIS_TEXT_DEFAULT } from '../../styles/index.js';
|
|
7
8
|
import { AnnotationsDefaultConfig } from './config.js';
|
|
8
9
|
import * as style from './style.js';
|
|
9
|
-
import { annotation, annotationContent,
|
|
10
|
+
import { annotation, annotationContent, annotationSubject, variables } from './style.js';
|
|
10
11
|
|
|
11
12
|
class Annotations extends ComponentCore {
|
|
12
13
|
constructor(config) {
|
|
@@ -17,56 +18,49 @@ class Annotations extends ComponentCore {
|
|
|
17
18
|
if (config)
|
|
18
19
|
this.setConfig(config);
|
|
19
20
|
}
|
|
20
|
-
// Todo: implement
|
|
21
|
-
get bleed() {
|
|
22
|
-
return { top: 0, bottom: 0, left: 0, right: 0 };
|
|
23
|
-
}
|
|
24
21
|
_render(customDuration) {
|
|
25
|
-
var _a, _b;
|
|
26
22
|
super._render(customDuration);
|
|
27
23
|
const { config } = this;
|
|
28
24
|
const duration = isNumber(customDuration) ? customDuration : config.duration;
|
|
29
|
-
const annotations = this.g
|
|
30
|
-
.
|
|
31
|
-
.data((_a = config.items) !== null && _a !== void 0 ? _a : []);
|
|
25
|
+
const annotations = this.g.selectAll(`.${annotation}`)
|
|
26
|
+
.data(config.items, d => JSON.stringify(d));
|
|
32
27
|
const annotationsEnter = annotations.enter().append('g')
|
|
33
|
-
.attr('class', annotation)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
.attr('class', annotation)
|
|
29
|
+
.style('opacity', 0);
|
|
30
|
+
// Content
|
|
31
|
+
annotationsEnter.append('g').attr('class', annotationContent);
|
|
32
|
+
// Subject
|
|
33
|
+
const subject = annotationsEnter.append('g')
|
|
38
34
|
.attr('class', annotationSubject);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
subject.append('circle');
|
|
36
|
+
subject.append('line');
|
|
37
|
+
const annotationsMerged = annotationsEnter.merge(annotations)
|
|
38
|
+
.attr('cursor', d => d === null || d === void 0 ? void 0 : d.cursor)
|
|
43
39
|
.each((annotation, i, elements) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const contentGroupElement = select(elements[i])
|
|
47
|
-
.select(`.${annotationContent}`);
|
|
48
|
-
const content = typeof annotation.content === 'string' ? { text: annotation.content, fontSize: 12 } : annotation.content;
|
|
40
|
+
if (annotation.content) {
|
|
41
|
+
const content = typeof annotation.content === 'string' ? Object.assign(Object.assign({}, UNOVIS_TEXT_DEFAULT), { text: annotation.content }) : annotation.content;
|
|
49
42
|
const x = parseUnit(annotation.x, this._width);
|
|
50
43
|
const y = parseUnit(annotation.y, this._height);
|
|
51
44
|
const width = parseUnit(annotation.width, this._width);
|
|
52
45
|
const height = parseUnit(annotation.height, this._height);
|
|
53
46
|
const options = Object.assign(Object.assign({}, annotation), { x, y, width, height });
|
|
47
|
+
const contentGroupElement = select(elements[i]).select(`.${annotationContent}`);
|
|
54
48
|
renderTextIntoFrame(contentGroupElement.node(), content, options);
|
|
55
49
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
requestAnimationFrame(() => this._renderSubject(elements[i], annotation.subject, duration));
|
|
50
|
+
if (annotation.subject) {
|
|
51
|
+
requestAnimationFrame(() => this._renderSubject(elements[i], annotation.subject));
|
|
59
52
|
}
|
|
60
53
|
});
|
|
54
|
+
smartTransition(annotationsMerged, duration)
|
|
55
|
+
.style('opacity', 1);
|
|
61
56
|
smartTransition(annotations.exit(), duration)
|
|
62
57
|
.style('opacity', 0)
|
|
63
58
|
.remove();
|
|
64
59
|
}
|
|
65
|
-
_renderSubject(annotationGroupElement, subject
|
|
60
|
+
_renderSubject(annotationGroupElement, subject) {
|
|
66
61
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const subjectGroup = select(subjectGroupElement);
|
|
62
|
+
const contentGroup = select(annotationGroupElement).select(`.${annotationContent}`);
|
|
63
|
+
const subjectGroup = select(annotationGroupElement).select(`.${annotationSubject}`);
|
|
70
64
|
const subjectX = (_a = parseUnit(typeof (subject === null || subject === void 0 ? void 0 : subject.x) === 'function' ? subject.x() : subject === null || subject === void 0 ? void 0 : subject.x, this._width)) !== null && _a !== void 0 ? _a : null;
|
|
71
65
|
const subjectY = (_b = parseUnit(typeof (subject === null || subject === void 0 ? void 0 : subject.y) === 'function' ? subject.y() : subject === null || subject === void 0 ? void 0 : subject.y, this._height)) !== null && _b !== void 0 ? _b : null;
|
|
72
66
|
const subjectStrokeColor = (_c = subject === null || subject === void 0 ? void 0 : subject.strokeColor) !== null && _c !== void 0 ? _c : null;
|
|
@@ -76,7 +70,7 @@ class Annotations extends ComponentCore {
|
|
|
76
70
|
const connectorLineStrokeDasharray = (_g = subject === null || subject === void 0 ? void 0 : subject.connectorLineStrokeDasharray) !== null && _g !== void 0 ? _g : null;
|
|
77
71
|
const subjectRadius = (_h = subject === null || subject === void 0 ? void 0 : subject.radius) !== null && _h !== void 0 ? _h : 0;
|
|
78
72
|
const padding = (_j = subject === null || subject === void 0 ? void 0 : subject.padding) !== null && _j !== void 0 ? _j : 5;
|
|
79
|
-
const contentBbox =
|
|
73
|
+
const contentBbox = contentGroup.node().getBBox();
|
|
80
74
|
const dy = Math.abs(subjectY - (contentBbox.y + contentBbox.height / 2));
|
|
81
75
|
const dx = Math.abs(subjectX - (contentBbox.x + contentBbox.width / 2));
|
|
82
76
|
const annotationPadding = 5;
|
|
@@ -89,9 +83,7 @@ class Annotations extends ComponentCore {
|
|
|
89
83
|
const angle = Math.atan2(y2 - subjectY, x2 - subjectX) * 180 / Math.PI;
|
|
90
84
|
const x1 = subjectX + Math.cos(angle * Math.PI / 180) * (subjectRadius + padding);
|
|
91
85
|
const y1 = subjectY + Math.sin(angle * Math.PI / 180) * (subjectRadius + padding);
|
|
92
|
-
|
|
93
|
-
const lineSelection = subjectGroup.select('line');
|
|
94
|
-
circleSelection
|
|
86
|
+
subjectGroup.select('circle')
|
|
95
87
|
.attr('visibility', subject ? null : 'hidden')
|
|
96
88
|
.attr('cx', subjectX)
|
|
97
89
|
.attr('cy', subjectY)
|
|
@@ -99,15 +91,16 @@ class Annotations extends ComponentCore {
|
|
|
99
91
|
.style('stroke', subjectStrokeColor)
|
|
100
92
|
.style('fill', subjectFillColor)
|
|
101
93
|
.style('stroke-dasharray', subjectStrokeDasharray);
|
|
102
|
-
|
|
94
|
+
subjectGroup.select('line')
|
|
103
95
|
.attr('visibility', subject ? null : 'hidden')
|
|
104
96
|
.attr('x1', x1)
|
|
105
97
|
.attr('y1', y1)
|
|
98
|
+
.attr('x2', x1)
|
|
99
|
+
.attr('y2', y1)
|
|
106
100
|
.attr('x2', x2)
|
|
107
101
|
.attr('y2', y2)
|
|
108
102
|
.style('stroke', connectorLineColor)
|
|
109
|
-
.style('stroke-dasharray', connectorLineStrokeDasharray)
|
|
110
|
-
.style('fill', 'none');
|
|
103
|
+
.style('stroke-dasharray', connectorLineStrokeDasharray);
|
|
111
104
|
}
|
|
112
105
|
}
|
|
113
106
|
Annotations.selectors = style;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/annotations/index.ts"],"sourcesContent":["import { select, Selection } from 'd3-selection'\n\n// Core\nimport { ComponentCore } from 'core/component'\n\n// Utils\nimport { isNumber } from 'utils/data'\nimport { smartTransition } from 'utils/d3'\nimport { renderTextIntoFrame } from 'utils/text'\nimport { parseUnit } from 'utils/misc'\n\n// Types\nimport { Spacing } from 'types/spacing'\n\n// Local Types\nimport { AnnotationItem, AnnotationSubject } from './types'\n\n// Config\nimport { AnnotationsDefaultConfig, AnnotationsConfigInterface } from './config'\n\n// Styles\nimport * as s from './style'\n\nexport class Annotations extends ComponentCore<unknown[], AnnotationsConfigInterface> {\n static selectors = s\n static cssVariables = s.variables\n protected _defaultConfig = AnnotationsDefaultConfig as AnnotationsConfigInterface\n public config: AnnotationsConfigInterface = this._defaultConfig\n\n g: Selection<SVGGElement, unknown, null, undefined>\n\n events = {}\n\n constructor (config?: AnnotationsConfigInterface) {\n super()\n if (config) this.setConfig(config)\n }\n\n // Todo: implement\n get bleed (): Spacing {\n return { top: 0, bottom: 0, left: 0, right: 0 }\n }\n\n _render (customDuration?: number): void {\n super._render(customDuration)\n const { config } = this\n const duration = isNumber(customDuration) ? customDuration : config.duration\n\n const annotations = this.g\n .selectAll<SVGGElement, AnnotationItem>(`.${s.annotation}`)\n .data(config.items ?? [])\n\n const annotationsEnter = annotations.enter().append('g')\n .attr('class', s.annotation)\n\n annotationsEnter.append('g')\n .attr('class', s.annotationContent)\n .classed(s.clickable, config.events?.[s.annotationContent] !== undefined)\n\n const annotationsSubject = annotationsEnter.append('g')\n .attr('class', s.annotationSubject)\n\n annotationsSubject.append('circle')\n annotationsSubject.append('line')\n\n // Todo: smooth transition\n annotationsEnter.merge(annotations)\n .each((annotation, i, elements) => {\n // Content rendering\n if (annotation?.content) {\n const contentGroupElement = select(elements[i])\n .select<SVGGElement>(`.${s.annotationContent}`)\n const content = typeof annotation.content === 'string' ? { text: annotation.content, fontSize: 12 } : annotation.content\n const x = parseUnit(annotation.x, this._width)\n const y = parseUnit(annotation.y, this._height)\n const width = parseUnit(annotation.width, this._width)\n const height = parseUnit(annotation.height, this._height)\n const options = { ...annotation, x, y, width, height }\n\n\n renderTextIntoFrame(contentGroupElement.node(), content, options)\n }\n // Subject rendering\n if (annotation?.subject) {\n requestAnimationFrame(() => this._renderSubject(elements[i], annotation.subject, duration))\n }\n })\n smartTransition(annotations.exit(), duration)\n .style('opacity', 0)\n .remove()\n }\n\n private _renderSubject (\n annotationGroupElement: SVGGElement,\n subject: AnnotationSubject | undefined,\n duration?: number\n ): void {\n const contentGroupElement = annotationGroupElement.querySelector<SVGGElement>(`.${s.annotationContent}`)\n const subjectGroupElement = annotationGroupElement.querySelector<SVGGElement>(`.${s.annotationSubject}`)\n const subjectGroup = select(subjectGroupElement)\n\n const subjectX: number | null = parseUnit(typeof subject?.x === 'function' ? subject.x() : subject?.x, this._width) ?? null\n const subjectY: number | null = parseUnit(typeof subject?.y === 'function' ? subject.y() : subject?.y, this._height) ?? null\n const subjectStrokeColor: string | null = subject?.strokeColor ?? null\n const subjectFillColor: string | null = subject?.fillColor ?? null\n const subjectStrokeDasharray: string | null = subject?.strokeDasharray ?? null\n const connectorLineColor: string | null = subject?.connectorLineColor ?? null\n const connectorLineStrokeDasharray: string | null = subject?.connectorLineStrokeDasharray ?? null\n const subjectRadius: number | null = subject?.radius ?? 0\n const padding = subject?.padding ?? 5\n\n const contentBbox = contentGroupElement.getBBox()\n const dy = Math.abs(subjectY - (contentBbox.y + contentBbox.height / 2))\n const dx = Math.abs(subjectX - (contentBbox.x + contentBbox.width / 2))\n const annotationPadding = 5\n const x2 = (dx < dy) && ((subjectY < contentBbox.y) || (subjectY > (contentBbox.y + contentBbox.height)))\n ? contentBbox.x + contentBbox.width / 2\n : (subjectX < contentBbox.x) ? contentBbox.x - annotationPadding : contentBbox.x + contentBbox.width + annotationPadding\n\n const y2 = (dx >= dy) || ((subjectY >= contentBbox.y) && (subjectY <= (contentBbox.y + contentBbox.height)))\n ? contentBbox.y + contentBbox.height / 2\n : (subjectY < contentBbox.y) ? contentBbox.y - annotationPadding : contentBbox.y + contentBbox.height + annotationPadding\n\n const angle = Math.atan2(y2 - subjectY, x2 - subjectX) * 180 / Math.PI\n const x1 = subjectX + Math.cos(angle * Math.PI / 180) * (subjectRadius + padding)\n const y1 = subjectY + Math.sin(angle * Math.PI / 180) * (subjectRadius + padding)\n\n const circleSelection = subjectGroup.select('circle')\n const lineSelection = subjectGroup.select('line')\n circleSelection\n .attr('visibility', subject ? null : 'hidden')\n .attr('cx', subjectX)\n .attr('cy', subjectY)\n .attr('r', subjectRadius)\n .style('stroke', subjectStrokeColor)\n .style('fill', subjectFillColor)\n .style('stroke-dasharray', subjectStrokeDasharray)\n\n lineSelection\n .attr('visibility', subject ? null : 'hidden')\n .attr('x1', x1)\n .attr('y1', y1)\n .attr('x2', x2)\n .attr('y2', y2)\n .style('stroke', connectorLineColor)\n .style('stroke-dasharray', connectorLineStrokeDasharray)\n .style('fill', 'none')\n }\n}\n"],"names":["s.annotation","s.annotationContent","s.clickable","s.annotationSubject","s","s.variables"],"mappings":";;;;;;;;;;AAuBM,MAAO,WAAY,SAAQ,aAAoD,CAAA;AAUnF,IAAA,WAAA,CAAa,MAAmC,EAAA;AAC9C,QAAA,KAAK,EAAE,CAAA;QARC,IAAc,CAAA,cAAA,GAAG,wBAAsD,CAAA;AAC1E,QAAA,IAAA,CAAA,MAAM,GAA+B,IAAI,CAAC,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CAAC,CAAA;QACjD,eAAe;AACZ,aAAA,IAAI,CAAC,YAAY,EAAE,OAAO,GAAG,IAAI,GAAG,QAAQ,CAAC;AAC7C,aAAA,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC;AACpB,aAAA,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC;AACpB,aAAA,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC;AACxB,aAAA,KAAK,CAAC,QAAQ,EAAE,kBAAkB,CAAC;AACnC,aAAA,KAAK,CAAC,MAAM,EAAE,gBAAgB,CAAC;AAC/B,aAAA,KAAK,CAAC,kBAAkB,EAAE,sBAAsB,CAAC,CAAA;QAEpD,aAAa;AACV,aAAA,IAAI,CAAC,YAAY,EAAE,OAAO,GAAG,IAAI,GAAG,QAAQ,CAAC;AAC7C,aAAA,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;AACd,aAAA,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;AACd,aAAA,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;AACd,aAAA,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;AACd,aAAA,KAAK,CAAC,QAAQ,EAAE,kBAAkB,CAAC;AACnC,aAAA,KAAK,CAAC,kBAAkB,EAAE,4BAA4B,CAAC;AACvD,aAAA,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KACzB;;AA3HM,WAAS,CAAA,SAAA,GAAGC,KAAC,CAAA;AACb,WAAA,CAAA,YAAY,GAAGC,SAAW;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/annotations/index.ts"],"sourcesContent":["import { select, Selection } from 'd3-selection'\n\n// Core\nimport { ComponentCore } from 'core/component'\n\n// Utils\nimport { isNumber } from 'utils/data'\nimport { smartTransition } from 'utils/d3'\nimport { renderTextIntoFrame } from 'utils/text'\nimport { parseUnit } from 'utils/misc'\nimport { UNOVIS_TEXT_DEFAULT } from 'styles'\n\n// Local Types\nimport { AnnotationItem, AnnotationSubject } from './types'\n\n// Config\nimport { AnnotationsDefaultConfig, AnnotationsConfigInterface } from './config'\n\n// Styles\nimport * as s from './style'\n\nexport class Annotations extends ComponentCore<unknown[], AnnotationsConfigInterface> {\n static selectors = s\n static cssVariables = s.variables\n protected _defaultConfig = AnnotationsDefaultConfig as AnnotationsConfigInterface\n public config: AnnotationsConfigInterface = this._defaultConfig\n\n g: Selection<SVGGElement, unknown, null, undefined>\n\n events = {}\n\n constructor (config?: AnnotationsConfigInterface) {\n super()\n if (config) this.setConfig(config)\n }\n\n _render (customDuration?: number): void {\n super._render(customDuration)\n const { config } = this\n\n const duration = isNumber(customDuration) ? customDuration : config.duration\n\n const annotations = this.g.selectAll<SVGGElement, AnnotationItem[]>(`.${s.annotation}`)\n .data(config.items, d => JSON.stringify(d))\n\n const annotationsEnter = annotations.enter().append('g')\n .attr('class', s.annotation)\n .style('opacity', 0)\n\n // Content\n annotationsEnter.append('g').attr('class', s.annotationContent)\n\n // Subject\n const subject = annotationsEnter.append('g')\n .attr('class', s.annotationSubject)\n\n subject.append('circle')\n subject.append('line')\n\n const annotationsMerged = annotationsEnter.merge(annotations)\n .attr('cursor', d => d?.cursor)\n .each((annotation, i, elements) => {\n if (annotation.content) {\n const content = typeof annotation.content === 'string' ? { ...UNOVIS_TEXT_DEFAULT, text: annotation.content } : annotation.content\n const x = parseUnit(annotation.x, this._width)\n const y = parseUnit(annotation.y, this._height)\n const width = parseUnit(annotation.width, this._width)\n const height = parseUnit(annotation.height, this._height)\n const options = { ...annotation, x, y, width, height }\n\n const contentGroupElement = select(elements[i]).select<SVGGElement>(`.${s.annotationContent}`)\n renderTextIntoFrame(contentGroupElement.node(), content, options)\n }\n\n if (annotation.subject) {\n requestAnimationFrame(() => this._renderSubject(elements[i], annotation.subject))\n }\n })\n\n smartTransition(annotationsMerged, duration)\n .style('opacity', 1)\n\n smartTransition(annotations.exit(), duration)\n .style('opacity', 0)\n .remove()\n }\n\n\n private _renderSubject (\n annotationGroupElement: SVGElement,\n subject: AnnotationSubject | undefined\n ): void {\n const contentGroup = select(annotationGroupElement).select<SVGGElement>(`.${s.annotationContent}`)\n const subjectGroup = select(annotationGroupElement).select<SVGGElement>(`.${s.annotationSubject}`)\n\n const subjectX: number | null = parseUnit(typeof subject?.x === 'function' ? subject.x() : subject?.x, this._width) ?? null\n const subjectY: number | null = parseUnit(typeof subject?.y === 'function' ? subject.y() : subject?.y, this._height) ?? null\n\n const subjectStrokeColor: string | null = subject?.strokeColor ?? null\n const subjectFillColor: string | null = subject?.fillColor ?? null\n const subjectStrokeDasharray: string | null = subject?.strokeDasharray ?? null\n const connectorLineColor: string | null = subject?.connectorLineColor ?? null\n const connectorLineStrokeDasharray: string | null = subject?.connectorLineStrokeDasharray ?? null\n const subjectRadius: number | null = subject?.radius ?? 0\n const padding = subject?.padding ?? 5\n\n const contentBbox = contentGroup.node().getBBox()\n const dy = Math.abs(subjectY - (contentBbox.y + contentBbox.height / 2))\n const dx = Math.abs(subjectX - (contentBbox.x + contentBbox.width / 2))\n const annotationPadding = 5\n const x2 = (dx < dy) && ((subjectY < contentBbox.y) || (subjectY > (contentBbox.y + contentBbox.height)))\n ? contentBbox.x + contentBbox.width / 2\n : (subjectX < contentBbox.x) ? contentBbox.x - annotationPadding : contentBbox.x + contentBbox.width + annotationPadding\n\n const y2 = (dx >= dy) || ((subjectY >= contentBbox.y) && (subjectY <= (contentBbox.y + contentBbox.height)))\n ? contentBbox.y + contentBbox.height / 2\n : (subjectY < contentBbox.y) ? contentBbox.y - annotationPadding : contentBbox.y + contentBbox.height + annotationPadding\n\n const angle = Math.atan2(y2 - subjectY, x2 - subjectX) * 180 / Math.PI\n const x1 = subjectX + Math.cos(angle * Math.PI / 180) * (subjectRadius + padding)\n const y1 = subjectY + Math.sin(angle * Math.PI / 180) * (subjectRadius + padding)\n\n subjectGroup.select('circle')\n .attr('visibility', subject ? null : 'hidden')\n .attr('cx', subjectX)\n .attr('cy', subjectY)\n .attr('r', subjectRadius)\n .style('stroke', subjectStrokeColor)\n .style('fill', subjectFillColor)\n .style('stroke-dasharray', subjectStrokeDasharray)\n\n subjectGroup.select('line')\n .attr('visibility', subject ? null : 'hidden')\n .attr('x1', x1)\n .attr('y1', y1)\n .attr('x2', x1)\n .attr('y2', y1)\n .attr('x2', x2)\n .attr('y2', y2)\n .style('stroke', connectorLineColor)\n .style('stroke-dasharray', connectorLineStrokeDasharray)\n }\n}\n"],"names":["s.annotation","s.annotationContent","s.annotationSubject","s","s.variables"],"mappings":";;;;;;;;;;;AAqBM,MAAO,WAAY,SAAQ,aAAoD,CAAA;AAUnF,IAAA,WAAA,CAAa,MAAmC,EAAA;AAC9C,QAAA,KAAK,EAAE,CAAA;QARC,IAAc,CAAA,cAAA,GAAG,wBAAsD,CAAA;AAC1E,QAAA,IAAA,CAAA,MAAM,GAA+B,IAAI,CAAC,cAAc,CAAA;QAI/D,IAAM,CAAA,MAAA,GAAG,EAAE,CAAA;AAIT,QAAA,IAAI,MAAM;AAAE,YAAA,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;KACnC;AAED,IAAA,OAAO,CAAE,cAAuB,EAAA;AAC9B,QAAA,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;AAC7B,QAAA,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;AAEvB,QAAA,MAAM,QAAQ,GAAG,QAAQ,CAAC,cAAc,CAAC,GAAG,cAAc,GAAG,MAAM,CAAC,QAAQ,CAAA;AAE5E,QAAA,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,SAAS,CAAgC,CAAI,CAAA,EAAAA,UAAY,EAAE,CAAC;AACpF,aAAA,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;QAE7C,MAAM,gBAAgB,GAAG,WAAW,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC;AACrD,aAAA,IAAI,CAAC,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,CAAA;AACb,WAAA,CAAA,YAAY,GAAGC,SAAW;;;;"}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
export declare const root: string;
|
|
2
2
|
export declare const variables: {
|
|
3
|
+
annotationsTextColor: "--vis-annotations-text-color";
|
|
3
4
|
annotationsConnectorStrokeColor: "--vis-annotations-connector-stroke-color";
|
|
4
5
|
annotationsConnectorStrokeWidth: "--vis-annotations-connector-stroke-width";
|
|
5
6
|
annotationsConnectorStrokeDasharray: "--vis-annotations-connector-stroke-dasharray";
|
|
6
7
|
annotationsSubjectStrokeColor: "--vis-annotations-subject-stroke-color";
|
|
7
8
|
annotationsSubjectFillColor: "--vis-annotations-subject-fill-color";
|
|
8
9
|
annotationsSubjectStrokeDasharray: "--vis-annotations-subject-stroke-dasharray";
|
|
10
|
+
darkAnnotationsTextColor: "--vis-dark-annotations-text-color";
|
|
11
|
+
darkAnnotationsConnectorStrokeColor: "--vis-dark-annotations-connector-stroke-color";
|
|
12
|
+
darkAnnotationsSubjectStrokeColor: "--vis-dark-annotations-subject-stroke-color";
|
|
9
13
|
};
|
|
10
14
|
export declare const annotation: string;
|
|
11
15
|
export declare const annotationSubject: string;
|
|
12
16
|
export declare const annotationContent: string;
|
|
13
|
-
export declare const clickable: string;
|
|
@@ -2,12 +2,16 @@ import { css } from '@emotion/css';
|
|
|
2
2
|
import { getCssVarNames, injectGlobalCssVariables } from '../../utils/style.js';
|
|
3
3
|
|
|
4
4
|
const cssVarDefaults = {
|
|
5
|
+
'--vis-annotations-text-color': '#282C34',
|
|
5
6
|
'--vis-annotations-connector-stroke-color': '#444',
|
|
6
7
|
'--vis-annotations-connector-stroke-width': '1px',
|
|
7
8
|
'--vis-annotations-connector-stroke-dasharray': 'none',
|
|
8
9
|
'--vis-annotations-subject-stroke-color': '#444',
|
|
9
10
|
'--vis-annotations-subject-fill-color': 'none',
|
|
10
11
|
'--vis-annotations-subject-stroke-dasharray': 'none',
|
|
12
|
+
'--vis-dark-annotations-text-color': '#e8e9ef',
|
|
13
|
+
'--vis-dark-annotations-connector-stroke-color': '#fff',
|
|
14
|
+
'--vis-dark-annotations-subject-stroke-color': '#fff',
|
|
11
15
|
};
|
|
12
16
|
const root = css `
|
|
13
17
|
label: annotations-component;
|
|
@@ -34,10 +38,10 @@ const annotationSubject = css `
|
|
|
34
38
|
`;
|
|
35
39
|
const annotationContent = css `
|
|
36
40
|
label: annotationContent;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
> text {
|
|
42
|
+
fill: var(--vis-annotations-text-color);
|
|
43
|
+
}
|
|
40
44
|
`;
|
|
41
45
|
|
|
42
|
-
export { annotation, annotationContent, annotationSubject,
|
|
46
|
+
export { annotation, annotationContent, annotationSubject, root, variables };
|
|
43
47
|
//# sourceMappingURL=style.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.js","sources":["../../../src/components/annotations/style.ts"],"sourcesContent":["import { css } from '@emotion/css'\n\n// Utils\nimport { getCssVarNames, injectGlobalCssVariables } from 'utils/style'\n\nconst cssVarDefaults = {\n '--vis-annotations-connector-stroke-color': '#444',\n '--vis-annotations-connector-stroke-width': '1px',\n '--vis-annotations-connector-stroke-dasharray': 'none',\n\n '--vis-annotations-subject-stroke-color': '#444',\n '--vis-annotations-subject-fill-color': 'none',\n '--vis-annotations-subject-stroke-dasharray': 'none',\n}\n\nexport const root = css`\n label: annotations-component;\n`\nexport const variables = getCssVarNames(cssVarDefaults)\ninjectGlobalCssVariables(cssVarDefaults, root)\n\nexport const annotation = css`\n label: annotation;\n`\n\nexport const annotationSubject = css`\n label: annotationSubject;\n\n line {\n stroke: var(${variables.annotationsConnectorStrokeColor});\n stroke-width: var(${variables.annotationsConnectorStrokeWidth});\n stroke-dasharray: var(${variables.annotationsConnectorStrokeDasharray});\n }\n\n circle {\n stroke: var(${variables.annotationsSubjectStrokeColor});\n fill: var(${variables.annotationsSubjectFillColor});\n stroke-dasharray: var(${variables.annotationsSubjectStrokeDasharray});\n }\n`\n\nexport const annotationContent = css`\n label: annotationContent;\n
|
|
1
|
+
{"version":3,"file":"style.js","sources":["../../../src/components/annotations/style.ts"],"sourcesContent":["import { css } from '@emotion/css'\n\n// Utils\nimport { getCssVarNames, injectGlobalCssVariables } from 'utils/style'\n\nconst cssVarDefaults = {\n '--vis-annotations-text-color': '#282C34',\n\n '--vis-annotations-connector-stroke-color': '#444',\n '--vis-annotations-connector-stroke-width': '1px',\n '--vis-annotations-connector-stroke-dasharray': 'none',\n\n '--vis-annotations-subject-stroke-color': '#444',\n '--vis-annotations-subject-fill-color': 'none',\n '--vis-annotations-subject-stroke-dasharray': 'none',\n\n '--vis-dark-annotations-text-color': '#e8e9ef',\n '--vis-dark-annotations-connector-stroke-color': '#fff',\n '--vis-dark-annotations-subject-stroke-color': '#fff',\n}\n\nexport const root = css`\n label: annotations-component;\n`\nexport const variables = getCssVarNames(cssVarDefaults)\ninjectGlobalCssVariables(cssVarDefaults, root)\n\nexport const annotation = css`\n label: annotation;\n`\n\nexport const annotationSubject = css`\n label: annotationSubject;\n\n line {\n stroke: var(${variables.annotationsConnectorStrokeColor});\n stroke-width: var(${variables.annotationsConnectorStrokeWidth});\n stroke-dasharray: var(${variables.annotationsConnectorStrokeDasharray});\n }\n\n circle {\n stroke: var(${variables.annotationsSubjectStrokeColor});\n fill: var(${variables.annotationsSubjectFillColor});\n stroke-dasharray: var(${variables.annotationsSubjectStrokeDasharray});\n }\n`\n\nexport const annotationContent = css`\n label: annotationContent;\n > text {\n fill: var(--vis-annotations-text-color);\n }\n`\n"],"names":[],"mappings":";;;AAKA,MAAM,cAAc,GAAG;AACrB,IAAA,8BAA8B,EAAE,SAAS;AAEzC,IAAA,0CAA0C,EAAE,MAAM;AAClD,IAAA,0CAA0C,EAAE,KAAK;AACjD,IAAA,8CAA8C,EAAE,MAAM;AAEtD,IAAA,wCAAwC,EAAE,MAAM;AAChD,IAAA,sCAAsC,EAAE,MAAM;AAC9C,IAAA,4CAA4C,EAAE,MAAM;AAEpD,IAAA,mCAAmC,EAAE,SAAS;AAC9C,IAAA,+CAA+C,EAAE,MAAM;AACvD,IAAA,6CAA6C,EAAE,MAAM;CACtD,CAAA;AAEM,MAAM,IAAI,GAAG,GAAG,CAAA,CAAA;;EAEtB;MACY,SAAS,GAAG,cAAc,CAAC,cAAc,EAAC;AACvD,wBAAwB,CAAC,cAAc,EAAE,IAAI,CAAC,CAAA;AAEvC,MAAM,UAAU,GAAG,GAAG,CAAA,CAAA;;EAE5B;AAEM,MAAM,iBAAiB,GAAG,GAAG,CAAA,CAAA;;;;AAIlB,gBAAA,EAAA,SAAS,CAAC,+BAA+B,CAAA;AACnC,sBAAA,EAAA,SAAS,CAAC,+BAA+B,CAAA;AACrC,0BAAA,EAAA,SAAS,CAAC,mCAAmC,CAAA;;;;AAIvD,gBAAA,EAAA,SAAS,CAAC,6BAA6B,CAAA;AACzC,cAAA,EAAA,SAAS,CAAC,2BAA2B,CAAA;AACzB,0BAAA,EAAA,SAAS,CAAC,iCAAiC,CAAA;;EAEtE;AAEM,MAAM,iBAAiB,GAAG,GAAG,CAAA,CAAA;;;;;;;;;"}
|
|
@@ -7,25 +7,14 @@ export declare type AnnotationItem = UnovisTextFrameOptions & {
|
|
|
7
7
|
y?: LengthUnit;
|
|
8
8
|
width?: LengthUnit;
|
|
9
9
|
height?: LengthUnit;
|
|
10
|
+
cursor?: string;
|
|
10
11
|
};
|
|
11
12
|
export declare type AnnotationSubjectLocationXY = {
|
|
12
13
|
x: LengthUnit | (() => LengthUnit);
|
|
13
14
|
y: LengthUnit | (() => LengthUnit);
|
|
14
15
|
};
|
|
15
|
-
export declare enum AnnotationSubjectType {
|
|
16
|
-
Circle = "circle",
|
|
17
|
-
Rect = "rect"
|
|
18
|
-
}
|
|
19
16
|
export declare type AnnotationSubjectStyle = {
|
|
20
|
-
/**
|
|
21
|
-
* Default: AnnotationSubjectType.Circle
|
|
22
|
-
*/
|
|
23
|
-
shape?: AnnotationSubjectType | string;
|
|
24
|
-
/** Subject width. Only for `AnnotationSubjectType.Rect` */
|
|
25
|
-
width?: number;
|
|
26
|
-
/** Subject height. Only for `AnnotationSubjectType.Rect` */
|
|
27
|
-
height?: number;
|
|
28
|
-
/** Subject radius. Only for `AnnotationSubjectType.Circle` */
|
|
17
|
+
/** Subject radius */
|
|
29
18
|
radius?: number;
|
|
30
19
|
/** Subject fill color */
|
|
31
20
|
fillColor?: string;
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
var AnnotationSubjectType;
|
|
2
|
-
(function (AnnotationSubjectType) {
|
|
3
|
-
AnnotationSubjectType["Circle"] = "circle";
|
|
4
|
-
AnnotationSubjectType["Rect"] = "rect";
|
|
5
|
-
})(AnnotationSubjectType || (AnnotationSubjectType = {}));
|
|
6
1
|
|
|
7
|
-
export { AnnotationSubjectType };
|
|
8
2
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":[
|
|
1
|
+
{"version":3,"file":"types.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/components/area/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/area/index.ts"],"sourcesContent":["import { select } from 'd3-selection'\nimport { Transition } from 'd3-transition'\nimport { area, Area as AreaInterface } from 'd3-shape'\nimport { interpolatePath } from 'd3-interpolate-path'\n\n// Core\nimport { XYComponentCore } from 'core/xy-component'\n\n// Utils\nimport { getNumber, getString, isArray, isNumber, getStackedExtent, getStackedData, filterDataByRange } from 'utils/data'\nimport { smartTransition } from 'utils/d3'\nimport { getColor } from 'utils/color'\n\n// Types\nimport { Curve, CurveType } from 'types/curve'\nimport { NumericAccessor } from 'types/accessor'\n\n// Local Types\nimport { AreaDatum } from './types'\n\n// Config\nimport { AreaDefaultConfig, AreaConfigInterface } from './config'\n\n// Styles\nimport * as s from './style'\n\nexport class Area<Datum> extends XYComponentCore<Datum, AreaConfigInterface<Datum>> {\n static selectors = s\n protected _defaultConfig = AreaDefaultConfig as AreaConfigInterface<Datum>\n public config: AreaConfigInterface<Datum> = this._defaultConfig\n public stacked = true\n private _areaGen: AreaInterface<AreaDatum>\n private _prevNegative: boolean[] | undefined // To help guessing the stack direction when an accessor was set to null or 0\n\n events = {\n [Area.selectors.area]: {},\n }\n\n constructor (config?: AreaConfigInterface<Datum>) {\n super()\n if (config) this.setConfig(config)\n }\n\n _render (customDuration?: number): void {\n super._render(customDuration)\n const { config, datamodel: { data } } = this\n const duration = isNumber(customDuration) ? customDuration : config.duration\n\n const curveGen = Curve[config.curveType as CurveType]\n this._areaGen = area<AreaDatum>()\n .x(d => d.x)\n .y0(d => d.y0)\n .y1(d => {\n const isSmallerThanPixel = Math.abs(d.y1 - d.y0) < 1\n return d.y1 - ((isSmallerThanPixel && config.minHeight1Px) ? 1 : 0)\n })\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n .curve(curveGen)\n\n const yAccessors = (isArray(config.y) ? config.y : [config.y]) as NumericAccessor<Datum>[]\n const areaDataX = data.map((d, i) => this.xScale(getNumber(d, config.x, i)))\n\n const stacked = getStackedData(data, config.baseline, yAccessors, this._prevNegative)\n this._prevNegative = stacked.map(s => !!s.negative)\n const stackedData: AreaDatum[][] = stacked.map(\n arr => arr.map(\n (d, j) => ({\n y0: this.yScale(d[0]),\n y1: this.yScale(d[1]),\n x: areaDataX[j],\n })\n )\n )\n\n // We reverse the data in order to have the first areas to be displayed on top\n // for better visibility when they're close to zero\n const areaMaxIdx = stackedData.length - 1\n const stackedDataReversed = stackedData.reverse()\n const areas = this.g\n .selectAll<SVGPathElement, AreaDatum>(`.${s.area}`)\n .data(stackedDataReversed)\n\n const areasEnter = areas.enter().append('path')\n .attr('class', s.area)\n .attr('d', d => this._areaGen(d) || this._emptyPath())\n .style('opacity', 0)\n .style('fill', (d, i) => getColor(data, config.color, areaMaxIdx - i))\n\n const areasMerged = smartTransition(areasEnter.merge(areas), duration)\n .style('opacity', (d, i) => {\n const isDefined = d.some(p => (p.y0 - p.y1) !== 0)\n return isDefined ? getNumber(data, config.opacity, areaMaxIdx - i) : 0\n })\n .style('fill', (d, i) => getColor(data, config.color, areaMaxIdx - i))\n .style('cursor', (d, i) => getString(data, config.cursor, areaMaxIdx - i))\n\n if (duration) {\n const transition = areasMerged as Transition<SVGPathElement, AreaDatum[], SVGGElement, AreaDatum[]>\n transition.attrTween('d', (d, i, el) => {\n const previous = select(el[i]).attr('d')\n const next = this._areaGen(d) || this._emptyPath()\n return interpolatePath(previous, next)\n })\n } else {\n areasMerged.attr('d', d => this._areaGen(d) || this._emptyPath())\n }\n\n smartTransition(areas.exit(), duration)\n .style('opacity', 0)\n .remove()\n }\n\n getYDataExtent (scaleByVisibleData: boolean): number[] {\n const { config, datamodel } = this\n const yAccessors = (isArray(config.y) ? config.y : [config.y]) as NumericAccessor<Datum>[]\n\n const data = scaleByVisibleData ? filterDataByRange(datamodel.data, this.xScale.domain() as [number, number], config.x) : datamodel.data\n return getStackedExtent(data, config.baseline, ...yAccessors)\n }\n\n _emptyPath (): string {\n const xRange = this.xScale.range()\n const yDomain = this.yScale.domain() as number[]\n\n const y0 = this.yScale((yDomain[0] + yDomain[1]) / 2)\n const y1 = y0\n\n return this._areaGen([\n { y0, y1, x: xRange[0] },\n { y0, y1, x: xRange[1] },\n ])\n }\n}\n"],"names":["s.area","s"],"mappings":";;;;;;;;;;;;AA0BM,MAAO,IAAY,SAAQ,eAAkD,CAAA;AAYjF,IAAA,WAAA,CAAa,MAAmC,EAAA;AAC9C,QAAA,KAAK,EAAE,CAAA;QAXC,IAAc,CAAA,cAAA,GAAG,iBAA+C,CAAA;AACnE,QAAA,IAAA,CAAA,MAAM,GAA+B,IAAI,CAAC,cAAc,CAAA;QACxD,IAAO,CAAA,OAAA,GAAG,IAAI,CAAA;AAIrB,QAAA,IAAA,CAAA,MAAM,GAAG;AACP,YAAA,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,GAAG,EAAE;SAC1B,CAAA;AAIC,QAAA,IAAI,MAAM;AAAE,YAAA,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/area/index.ts"],"sourcesContent":["import { select } from 'd3-selection'\nimport { Transition } from 'd3-transition'\nimport { area, Area as AreaInterface } from 'd3-shape'\nimport { interpolatePath } from 'd3-interpolate-path'\n\n// Core\nimport { XYComponentCore } from 'core/xy-component'\n\n// Utils\nimport { getNumber, getString, isArray, isNumber, getStackedExtent, getStackedData, filterDataByRange } from 'utils/data'\nimport { smartTransition } from 'utils/d3'\nimport { getColor } from 'utils/color'\n\n// Types\nimport { Curve, CurveType } from 'types/curve'\nimport { NumericAccessor } from 'types/accessor'\n\n// Local Types\nimport { AreaDatum } from './types'\n\n// Config\nimport { AreaDefaultConfig, AreaConfigInterface } from './config'\n\n// Styles\nimport * as s from './style'\n\nexport class Area<Datum> extends XYComponentCore<Datum, AreaConfigInterface<Datum>> {\n static selectors = s\n protected _defaultConfig = AreaDefaultConfig as AreaConfigInterface<Datum>\n public config: AreaConfigInterface<Datum> = this._defaultConfig\n public stacked = true\n private _areaGen: AreaInterface<AreaDatum>\n private _prevNegative: boolean[] | undefined // To help guessing the stack direction when an accessor was set to null or 0\n\n events = {\n [Area.selectors.area]: {},\n }\n\n constructor (config?: AreaConfigInterface<Datum>) {\n super()\n if (config) this.setConfig(config)\n\n // Determine if the provided chart should be stacked\n this.stacked = Array.isArray(this.config.y)\n }\n\n _render (customDuration?: number): void {\n super._render(customDuration)\n const { config, datamodel: { data } } = this\n const duration = isNumber(customDuration) ? customDuration : config.duration\n\n const curveGen = Curve[config.curveType as CurveType]\n this._areaGen = area<AreaDatum>()\n .x(d => d.x)\n .y0(d => d.y0)\n .y1(d => {\n const isSmallerThanPixel = Math.abs(d.y1 - d.y0) < 1\n return d.y1 - ((isSmallerThanPixel && config.minHeight1Px) ? 1 : 0)\n })\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n .curve(curveGen)\n\n const yAccessors = (isArray(config.y) ? config.y : [config.y]) as NumericAccessor<Datum>[]\n const areaDataX = data.map((d, i) => this.xScale(getNumber(d, config.x, i)))\n\n const stacked = getStackedData(data, config.baseline, yAccessors, this._prevNegative)\n this._prevNegative = stacked.map(s => !!s.negative)\n const stackedData: AreaDatum[][] = stacked.map(\n arr => arr.map(\n (d, j) => ({\n y0: this.yScale(d[0]),\n y1: this.yScale(d[1]),\n x: areaDataX[j],\n })\n )\n )\n\n // We reverse the data in order to have the first areas to be displayed on top\n // for better visibility when they're close to zero\n const areaMaxIdx = stackedData.length - 1\n const stackedDataReversed = stackedData.reverse()\n const areas = this.g\n .selectAll<SVGPathElement, AreaDatum>(`.${s.area}`)\n .data(stackedDataReversed)\n\n const areasEnter = areas.enter().append('path')\n .attr('class', s.area)\n .attr('d', d => this._areaGen(d) || this._emptyPath())\n .style('opacity', 0)\n .style('fill', (d, i) => getColor(data, config.color, areaMaxIdx - i))\n\n const areasMerged = smartTransition(areasEnter.merge(areas), duration)\n .style('opacity', (d, i) => {\n const isDefined = d.some(p => (p.y0 - p.y1) !== 0)\n return isDefined ? getNumber(data, config.opacity, areaMaxIdx - i) : 0\n })\n .style('fill', (d, i) => getColor(data, config.color, areaMaxIdx - i))\n .style('cursor', (d, i) => getString(data, config.cursor, areaMaxIdx - i))\n\n if (duration) {\n const transition = areasMerged as Transition<SVGPathElement, AreaDatum[], SVGGElement, AreaDatum[]>\n transition.attrTween('d', (d, i, el) => {\n const previous = select(el[i]).attr('d')\n const next = this._areaGen(d) || this._emptyPath()\n return interpolatePath(previous, next)\n })\n } else {\n areasMerged.attr('d', d => this._areaGen(d) || this._emptyPath())\n }\n\n smartTransition(areas.exit(), duration)\n .style('opacity', 0)\n .remove()\n }\n\n getYDataExtent (scaleByVisibleData: boolean): number[] {\n const { config, datamodel } = this\n const yAccessors = (isArray(config.y) ? config.y : [config.y]) as NumericAccessor<Datum>[]\n\n const data = scaleByVisibleData ? filterDataByRange(datamodel.data, this.xScale.domain() as [number, number], config.x) : datamodel.data\n return getStackedExtent(data, config.baseline, ...yAccessors)\n }\n\n _emptyPath (): string {\n const xRange = this.xScale.range()\n const yDomain = this.yScale.domain() as number[]\n\n const y0 = this.yScale((yDomain[0] + yDomain[1]) / 2)\n const y1 = y0\n\n return this._areaGen([\n { y0, y1, x: xRange[0] },\n { y0, y1, x: xRange[1] },\n ])\n }\n}\n"],"names":["s.area","s"],"mappings":";;;;;;;;;;;;AA0BM,MAAO,IAAY,SAAQ,eAAkD,CAAA;AAYjF,IAAA,WAAA,CAAa,MAAmC,EAAA;AAC9C,QAAA,KAAK,EAAE,CAAA;QAXC,IAAc,CAAA,cAAA,GAAG,iBAA+C,CAAA;AACnE,QAAA,IAAA,CAAA,MAAM,GAA+B,IAAI,CAAC,cAAc,CAAA;QACxD,IAAO,CAAA,OAAA,GAAG,IAAI,CAAA;AAIrB,QAAA,IAAA,CAAA,MAAM,GAAG;AACP,YAAA,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,GAAG,EAAE;SAC1B,CAAA;AAIC,QAAA,IAAI,MAAM;AAAE,YAAA,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;;AAGlC,QAAA,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;KAC5C;AAED,IAAA,OAAO,CAAE,cAAuB,EAAA;AAC9B,QAAA,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;QAC7B,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,IAAI,CAAA;AAC5C,QAAA,MAAM,QAAQ,GAAG,QAAQ,CAAC,cAAc,CAAC,GAAG,cAAc,GAAG,MAAM,CAAC,QAAQ,CAAA;QAE5E,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,SAAsB,CAAC,CAAA;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,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAA6B,CAAA;AAE1F,QAAA,MAAM,IAAI,GAAG,kBAAkB,GAAG,iBAAiB,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,EAAsB,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,IAAI,CAAA;QACxI,OAAO,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,EAAE,GAAG,UAAU,CAAC,CAAA;KAC9D;IAED,UAAU,GAAA;QACR,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;QAClC,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAc,CAAA;QAEhD,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;QACrD,MAAM,EAAE,GAAG,EAAE,CAAA;QAEb,OAAO,IAAI,CAAC,QAAQ,CAAC;YACnB,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE;YACxB,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE;AACzB,SAAA,CAAC,CAAA;KACH;;AA5GM,IAAS,CAAA,SAAA,GAAGC,KAAC;;;;"}
|
|
@@ -68,6 +68,7 @@ function updateLabel(selection, config, width, radiusScale, duration) {
|
|
|
68
68
|
const label = selection.select(`.${labelText}`);
|
|
69
69
|
label.selectAll('textPath').remove();
|
|
70
70
|
label.text(d => getString(d.data, nodeLabel))
|
|
71
|
+
.style('transition', `fill ${duration}ms`)
|
|
71
72
|
.style('fill', d => { var _a; return (_a = getColor(d.data, nodeLabelColor)) !== null && _a !== void 0 ? _a : getLabelFillColor(d, config); })
|
|
72
73
|
.style('text-anchor', d => getLabelTextAnchor(d, config))
|
|
73
74
|
.each((d, i, elements) => {
|
|
@@ -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.labelText)\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.labelText}`)\n label.selectAll('textPath').remove()\n\n label.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 .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 textElement = select(elements[i])\n .call(trimSVGText, maxWidth)\n .attr('dx', nodeLabelAlignment === ChordLabelAlignment.Along ? LABEL_PADDING : null)\n .attr('dy', nodeLabelAlignment === ChordLabelAlignment.Along ? getNumber(d.data, nodeWidth) / 2 : null)\n\n const textWidth = textElement.node().getComputedTextLength()\n const labelText = textElement.text()\n if (nodeLabelAlignment === ChordLabelAlignment.Along) {\n textElement.text('')\n if (textWidth <= maxWidth) {\n textElement.append('textPath')\n .attr('href', `#${d.uid}`)\n .text(labelText)\n }\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.labelText"],"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;A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AAQ,EAAE;AACzB,gBAAA,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC;qBAC3B,IAAI,CAAC,MAAM,EAAE,CAAA,CAAA,EAAI,CAAC,CAAC,GAAG,EAAE,CAAC;qBACzB,IAAI,CAAC,SAAS,CAAC,CAAA;AACnB,aAAA;AACF,SAAA;AACH,KAAC,CAAC,CAAA;AAEJ,IAAA,eAAe,CAAC,KAAK,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 { 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.labelText)\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.labelText}`)\n label.selectAll('textPath').remove()\n\n label.text(d => getString(d.data, nodeLabel))\n .style('transition', `fill ${duration}ms`)\n .style('fill', d => getColor(d.data, nodeLabelColor) ?? getLabelFillColor(d, config))\n .style('text-anchor', d => getLabelTextAnchor(d, config))\n .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 textElement = select(elements[i])\n .call(trimSVGText, maxWidth)\n .attr('dx', nodeLabelAlignment === ChordLabelAlignment.Along ? LABEL_PADDING : null)\n .attr('dy', nodeLabelAlignment === ChordLabelAlignment.Along ? getNumber(d.data, nodeWidth) / 2 : null)\n\n const textWidth = textElement.node().getComputedTextLength()\n const labelText = textElement.text()\n if (nodeLabelAlignment === ChordLabelAlignment.Along) {\n textElement.text('')\n if (textWidth <= maxWidth) {\n textElement.append('textPath')\n .attr('href', `#${d.uid}`)\n .text(labelText)\n }\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.labelText"],"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,SAAA;AACD,QAAA,KAAK,mBAAmB,CAAC,KAAK,EAAE;AAC9B,YAAA,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC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AE,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;;;;"}
|
|
@@ -43,7 +43,7 @@ function createLink(selection, radiusScale) {
|
|
|
43
43
|
}
|
|
44
44
|
function updateLink(selection, config, radiusScale, duration) {
|
|
45
45
|
selection
|
|
46
|
-
.style('transition', `fill
|
|
46
|
+
.style('transition', `fill ${duration}ms`)
|
|
47
47
|
.style('fill', d => getColor(d.data, config.linkColor))
|
|
48
48
|
.style('stroke', d => getColor(d.data, config.linkColor));
|
|
49
49
|
const transition = smartTransition(selection, duration)
|
|
@@ -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 { 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 { ChordDiagramConfigInterface } 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 const linkPath = link(points) as string\n\n if (points.length === 2) return linkPath\n\n // Replace closePath with line to starting point\n const area = linkPath.slice(0, -1)\n const path = area.concat(`L${area.match(/M-?\\d*\\.?\\d*[,\\s*]-?\\d*\\.?\\d*/)?.[0].slice(1)}`)\n\n // Convert line edges to arcs\n const radius = Math.max(radiusScale(points[0].r), 0)\n return convertLineToArc(path, 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, L>, SVGGElement, unknown>,\n config: ChordDiagramConfigInterface<N, L>,\n radiusScale: ScalePower<number, number>,\n duration: number\n): void {\n selection\n .style('transition', `fill
|
|
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 { 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 { ChordDiagramConfigInterface } 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 const linkPath = link(points) as string\n\n if (points.length === 2) return linkPath\n\n // Replace closePath with line to starting point\n const area = linkPath.slice(0, -1)\n const path = area.concat(`L${area.match(/M-?\\d*\\.?\\d*[,\\s*]-?\\d*\\.?\\d*/)?.[0].slice(1)}`)\n\n // Convert line edges to arcs\n const radius = Math.max(radiusScale(points[0].r), 0)\n return convertLineToArc(path, 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, L>, SVGGElement, unknown>,\n config: ChordDiagramConfigInterface<N, L>,\n radiusScale: ScalePower<number, number>,\n duration: number\n): void {\n selection\n .style('transition', `fill ${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, L>, 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":";;;;;;;;;AAmBA;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,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CAAA;AACH,KAAA;AAAM,SAAA;QACL,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA;AACzE,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;;;;"}
|
|
@@ -11,6 +11,10 @@ export interface CrosshairConfigInterface<Datum> extends WithOptional<XYComponen
|
|
|
11
11
|
y?: NumericAccessor<Datum> | NumericAccessor<Datum>[];
|
|
12
12
|
/** Optional color array or color accessor function for crosshair circles. Default: `d => d.color` */
|
|
13
13
|
color?: ColorAccessor<Datum>;
|
|
14
|
+
/** Optional stroke color accessor function for crosshair circles. Default: `undefined` */
|
|
15
|
+
strokeColor?: ColorAccessor<Datum>;
|
|
16
|
+
/** Optional stroke width for crosshair circles. Default: `undefined` */
|
|
17
|
+
strokeWidth?: NumericAccessor<Datum>;
|
|
14
18
|
/** Separate array of accessors for stacked components (eg StackedBar, Area). Default: `undefined` */
|
|
15
19
|
yStacked?: NumericAccessor<Datum>[];
|
|
16
20
|
/** Baseline accessor function for stacked values, useful with stacked areas. Default: `null` */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { XYComponentDefaultConfig } from '../../core/xy-component/config.js';
|
|
2
2
|
|
|
3
|
-
const CrosshairDefaultConfig = Object.assign(Object.assign({}, XYComponentDefaultConfig), { yStacked: undefined, baseline: null, duration: 100, tooltip: undefined, template: (d, x) => '', hideWhenFarFromPointer: true, hideWhenFarFromPointerDistance: 100, snapToData: true, getCircles: undefined, color: undefined });
|
|
3
|
+
const CrosshairDefaultConfig = Object.assign(Object.assign({}, XYComponentDefaultConfig), { yStacked: undefined, baseline: null, duration: 100, tooltip: undefined, template: (d, x) => '', hideWhenFarFromPointer: true, hideWhenFarFromPointerDistance: 100, snapToData: true, getCircles: undefined, color: undefined, strokeColor: undefined, strokeWidth: undefined });
|
|
4
4
|
|
|
5
5
|
export { CrosshairDefaultConfig };
|
|
6
6
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../../src/components/crosshair/config.ts"],"sourcesContent":["import { XYComponentConfigInterface, XYComponentDefaultConfig } 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>;\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 | Date | Date, data: Datum[], yScale: ContinuousScale) => CrosshairCircle[];\n}\n\nexport const CrosshairDefaultConfig: CrosshairConfigInterface<unknown> = {\n ...XYComponentDefaultConfig,\n yStacked: undefined,\n baseline: null,\n duration: 100,\n tooltip: undefined,\n template: <Datum>(d: Datum, x: number | Date): string => '',\n hideWhenFarFromPointer: true,\n hideWhenFarFromPointerDistance: 100,\n snapToData: true,\n getCircles: undefined,\n color: undefined,\n}\n\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../../src/components/crosshair/config.ts"],"sourcesContent":["import { XYComponentConfigInterface, XYComponentDefaultConfig } 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>;\n /** Optional stroke color accessor function for crosshair circles. Default: `undefined` */\n strokeColor?: ColorAccessor<Datum>;\n /** Optional stroke width for crosshair circles. Default: `undefined` */\n strokeWidth?: NumericAccessor<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 | Date | Date, data: Datum[], yScale: ContinuousScale) => CrosshairCircle[];\n}\n\nexport const CrosshairDefaultConfig: CrosshairConfigInterface<unknown> = {\n ...XYComponentDefaultConfig,\n yStacked: undefined,\n baseline: null,\n duration: 100,\n tooltip: undefined,\n template: <Datum>(d: Datum, x: number | Date): string => '',\n hideWhenFarFromPointer: true,\n hideWhenFarFromPointerDistance: 100,\n snapToData: true,\n getCircles: undefined,\n color: undefined,\n strokeColor: undefined,\n strokeWidth: undefined,\n}\n\n"],"names":[],"mappings":";;AAgDO,MAAM,sBAAsB,GAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAC9B,wBAAwB,CAAA,EAAA,EAC3B,QAAQ,EAAE,SAAS,EACnB,QAAQ,EAAE,IAAI,EACd,QAAQ,EAAE,GAAG,EACb,OAAO,EAAE,SAAS,EAClB,QAAQ,EAAE,CAAQ,CAAQ,EAAE,CAAgB,KAAa,EAAE,EAC3D,sBAAsB,EAAE,IAAI,EAC5B,8BAA8B,EAAE,GAAG,EACnC,UAAU,EAAE,IAAI,EAChB,UAAU,EAAE,SAAS,EACrB,KAAK,EAAE,SAAS,EAChB,WAAW,EAAE,SAAS,EACtB,WAAW,EAAE,SAAS;;;;"}
|
|
@@ -71,13 +71,17 @@ class Crosshair extends XYComponentCore {
|
|
|
71
71
|
.attr('r', 0)
|
|
72
72
|
.attr('cx', this.x)
|
|
73
73
|
.attr('cy', d => d.y)
|
|
74
|
-
.style('fill', d => d.color)
|
|
74
|
+
.style('fill', d => d.color)
|
|
75
|
+
.style('stroke', d => d.strokeColor)
|
|
76
|
+
.style('stroke-width', d => d.strokeWidth);
|
|
75
77
|
smartTransition(circlesEnter.merge(circles), duration, easeLinear)
|
|
76
78
|
.attr('cx', this.x)
|
|
77
79
|
.attr('cy', d => d.y)
|
|
78
80
|
.attr('r', 4)
|
|
79
81
|
.style('opacity', d => d.opacity)
|
|
80
|
-
.style('fill', d => d.color)
|
|
82
|
+
.style('fill', d => d.color)
|
|
83
|
+
.style('stroke', d => d.strokeColor)
|
|
84
|
+
.style('stroke-width', d => d.strokeWidth);
|
|
81
85
|
circles.exit().remove();
|
|
82
86
|
}
|
|
83
87
|
hide() {
|
|
@@ -161,16 +165,20 @@ class Crosshair extends XYComponentCore {
|
|
|
161
165
|
const stackedValues = getStackedValues(this.datum, this.datumIndex, ...yStackedAccessors)
|
|
162
166
|
.map((value, index, arr) => ({
|
|
163
167
|
y: this.yScale(value + baselineValue),
|
|
164
|
-
opacity: getNumber(this.datum, yStackedAccessors[index]) ? 1 : 0,
|
|
168
|
+
opacity: isNumber(getNumber(this.datum, yStackedAccessors[index])) ? 1 : 0,
|
|
165
169
|
color: getColor(this.datum, config.color, index),
|
|
170
|
+
strokeColor: config.strokeColor ? getColor(this.datum, config.strokeColor, index) : undefined,
|
|
171
|
+
strokeWidth: config.strokeWidth ? getNumber(this.datum, config.strokeWidth, index) : undefined,
|
|
166
172
|
}));
|
|
167
173
|
const regularValues = yAccessors
|
|
168
174
|
.map((a, index) => {
|
|
169
175
|
const value = getNumber(this.datum, a);
|
|
170
176
|
return {
|
|
171
177
|
y: this.yScale(value),
|
|
172
|
-
opacity: value ? 1 : 0,
|
|
178
|
+
opacity: isNumber(value) ? 1 : 0,
|
|
173
179
|
color: getColor(this.datum, config.color, stackedValues.length + index),
|
|
180
|
+
strokeColor: config.strokeColor ? getColor(this.datum, config.strokeColor, index) : undefined,
|
|
181
|
+
strokeWidth: config.strokeWidth ? getNumber(this.datum, config.strokeWidth, index) : undefined,
|
|
174
182
|
};
|
|
175
183
|
});
|
|
176
184
|
return stackedValues.concat(regularValues);
|