@unovis/ts 1.4.0-version.12 → 1.4.1-alpha.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.
Files changed (93) hide show
  1. package/components/annotations/config.d.ts +19 -0
  2. package/components/annotations/config.js +6 -0
  3. package/components/annotations/config.js.map +1 -0
  4. package/components/annotations/index.d.ts +26 -0
  5. package/components/annotations/index.js +110 -0
  6. package/components/annotations/index.js.map +1 -0
  7. package/components/annotations/style.d.ts +16 -0
  8. package/components/annotations/style.js +47 -0
  9. package/components/annotations/style.js.map +1 -0
  10. package/components/annotations/types.d.ts +32 -0
  11. package/components/annotations/types.js +2 -0
  12. package/components/annotations/types.js.map +1 -0
  13. package/components/area/config.d.ts +1 -1
  14. package/components/area/config.js.map +1 -1
  15. package/components/area/index.js +2 -0
  16. package/components/area/index.js.map +1 -1
  17. package/components/bullet-legend/config.d.ts +11 -3
  18. package/components/bullet-legend/config.js +4 -3
  19. package/components/bullet-legend/config.js.map +1 -1
  20. package/components/bullet-legend/index.d.ts +1 -1
  21. package/components/bullet-legend/index.js +22 -20
  22. package/components/bullet-legend/index.js.map +1 -1
  23. package/components/bullet-legend/modules/shape.d.ts +2 -2
  24. package/components/bullet-legend/modules/shape.js +67 -46
  25. package/components/bullet-legend/modules/shape.js.map +1 -1
  26. package/components/bullet-legend/style.d.ts +1 -0
  27. package/components/bullet-legend/style.js +9 -3
  28. package/components/bullet-legend/style.js.map +1 -1
  29. package/components/bullet-legend/types.d.ts +17 -4
  30. package/components/bullet-legend/types.js +10 -7
  31. package/components/bullet-legend/types.js.map +1 -1
  32. package/components/chord-diagram/index.d.ts +3 -3
  33. package/components/chord-diagram/index.js +24 -15
  34. package/components/chord-diagram/index.js.map +1 -1
  35. package/components/chord-diagram/modules/label.js +16 -18
  36. package/components/chord-diagram/modules/label.js.map +1 -1
  37. package/components/chord-diagram/modules/layout.js +9 -5
  38. package/components/chord-diagram/modules/layout.js.map +1 -1
  39. package/components/chord-diagram/modules/link.js +1 -1
  40. package/components/chord-diagram/modules/link.js.map +1 -1
  41. package/components/chord-diagram/style.js +1 -1
  42. package/components/chord-diagram/style.js.map +1 -1
  43. package/components/crosshair/config.d.ts +4 -0
  44. package/components/crosshair/config.js +1 -1
  45. package/components/crosshair/config.js.map +1 -1
  46. package/components/crosshair/index.js +12 -4
  47. package/components/crosshair/index.js.map +1 -1
  48. package/components/crosshair/style.js +4 -2
  49. package/components/crosshair/style.js.map +1 -1
  50. package/components/crosshair/types.d.ts +2 -0
  51. package/components/nested-donut/config.d.ts +14 -2
  52. package/components/nested-donut/config.js +1 -1
  53. package/components/nested-donut/config.js.map +1 -1
  54. package/components/nested-donut/index.js +16 -10
  55. package/components/nested-donut/index.js.map +1 -1
  56. package/components/sankey/modules/node.js +1 -1
  57. package/components/sankey/modules/node.js.map +1 -1
  58. package/components/stacked-bar/index.js.map +1 -1
  59. package/components/vis-controls/index.d.ts +0 -3
  60. package/components/vis-controls/index.js +1 -6
  61. package/components/vis-controls/index.js.map +1 -1
  62. package/components/xy-labels/index.js +1 -1
  63. package/components/xy-labels/index.js.map +1 -1
  64. package/components.d.ts +2 -0
  65. package/components.js +1 -0
  66. package/components.js.map +1 -1
  67. package/containers/single-container/config.d.ts +3 -0
  68. package/containers/single-container/config.js +1 -1
  69. package/containers/single-container/config.js.map +1 -1
  70. package/containers/single-container/index.d.ts +1 -1
  71. package/containers/single-container/index.js +11 -1
  72. package/containers/single-container/index.js.map +1 -1
  73. package/containers/xy-container/config.d.ts +3 -0
  74. package/containers/xy-container/config.js +1 -1
  75. package/containers/xy-container/config.js.map +1 -1
  76. package/containers/xy-container/index.d.ts +2 -2
  77. package/containers/xy-container/index.js +19 -6
  78. package/containers/xy-container/index.js.map +1 -1
  79. package/index.js +2 -1
  80. package/index.js.map +1 -1
  81. package/package.json +1 -1
  82. package/types/misc.d.ts +1 -0
  83. package/types/scale.d.ts +3 -2
  84. package/types/scale.js +2 -1
  85. package/types/scale.js.map +1 -1
  86. package/types.d.ts +1 -0
  87. package/types.js +2 -1
  88. package/types.js.map +1 -1
  89. package/utils/data.js +1 -1
  90. package/utils/data.js.map +1 -1
  91. package/utils/misc.d.ts +2 -1
  92. package/utils/misc.js +13 -1
  93. package/utils/misc.js.map +1 -1
@@ -0,0 +1,19 @@
1
+ import { ComponentConfigInterface } from "../../core/component/config";
2
+ import { AnnotationItem } from './types';
3
+ export interface AnnotationsConfigInterface extends ComponentConfigInterface {
4
+ /** Legend items. Array of `AnnotationItem`:
5
+ * ```
6
+ * {
7
+ * content: string | UnovisText | UnovisText[];
8
+ * subject?: AnnotationSubject;
9
+ * x?: LengthUnit;
10
+ * y?: LengthUnit;
11
+ * width?: LengthUnit;
12
+ * height?: LengthUnit;
13
+ * }
14
+ * ```
15
+ * To learn more, see our docs https://unovis.dev/docs/auxiliary/Annotations/
16
+ * Default: `[]` */
17
+ items: AnnotationItem[] | undefined;
18
+ }
19
+ export declare const AnnotationsDefaultConfig: AnnotationsConfigInterface;
@@ -0,0 +1,6 @@
1
+ import { ComponentDefaultConfig } from '../../core/component/config.js';
2
+
3
+ const AnnotationsDefaultConfig = Object.assign(Object.assign({}, ComponentDefaultConfig), { items: [] });
4
+
5
+ export { AnnotationsDefaultConfig };
6
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sources":["../../../src/components/annotations/config.ts"],"sourcesContent":["import { ComponentConfigInterface, ComponentDefaultConfig } from 'core/component/config'\n\n// Types\nimport { AnnotationItem } from './types'\n\nexport interface AnnotationsConfigInterface extends ComponentConfigInterface {\n /** Legend items. Array of `AnnotationItem`:\n * ```\n * {\n * content: string | UnovisText | UnovisText[];\n * subject?: AnnotationSubject;\n * x?: LengthUnit;\n * y?: LengthUnit;\n * width?: LengthUnit;\n * height?: LengthUnit;\n * }\n * ```\n * To learn more, see our docs https://unovis.dev/docs/auxiliary/Annotations/\n * Default: `[]` */\n items: AnnotationItem[] | undefined;\n}\n\nexport const AnnotationsDefaultConfig: AnnotationsConfigInterface = {\n ...ComponentDefaultConfig,\n items: [],\n}\n"],"names":[],"mappings":";;AAsBa,MAAA,wBAAwB,GAChC,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAA,sBAAsB,KACzB,KAAK,EAAE,EAAE,EAAA;;;;"}
@@ -0,0 +1,26 @@
1
+ import { Selection } from 'd3-selection';
2
+ import { ComponentCore } from "../../core/component";
3
+ import { AnnotationsConfigInterface } from './config';
4
+ import * as s from './style';
5
+ export declare class Annotations extends ComponentCore<unknown[], AnnotationsConfigInterface> {
6
+ static selectors: typeof s;
7
+ static cssVariables: {
8
+ annotationsTextColor: "--vis-annotations-text-color";
9
+ annotationsConnectorStrokeColor: "--vis-annotations-connector-stroke-color";
10
+ annotationsConnectorStrokeWidth: "--vis-annotations-connector-stroke-width";
11
+ annotationsConnectorStrokeDasharray: "--vis-annotations-connector-stroke-dasharray";
12
+ annotationsSubjectStrokeColor: "--vis-annotations-subject-stroke-color";
13
+ annotationsSubjectFillColor: "--vis-annotations-subject-fill-color";
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";
18
+ };
19
+ protected _defaultConfig: AnnotationsConfigInterface;
20
+ config: AnnotationsConfigInterface;
21
+ g: Selection<SVGGElement, unknown, null, undefined>;
22
+ events: {};
23
+ constructor(config?: AnnotationsConfigInterface);
24
+ _render(customDuration?: number): void;
25
+ private _renderSubject;
26
+ }
@@ -0,0 +1,110 @@
1
+ import { select } from 'd3-selection';
2
+ import { ComponentCore } from '../../core/component/index.js';
3
+ import { isNumber } from '../../utils/data.js';
4
+ import { smartTransition } from '../../utils/d3.js';
5
+ import { renderTextIntoFrame } from '../../utils/text.js';
6
+ import { parseUnit } from '../../utils/misc.js';
7
+ import { UNOVIS_TEXT_DEFAULT } from '../../styles/index.js';
8
+ import { AnnotationsDefaultConfig } from './config.js';
9
+ import * as style from './style.js';
10
+ import { annotation, annotationContent, annotationSubject, variables } from './style.js';
11
+
12
+ class Annotations extends ComponentCore {
13
+ constructor(config) {
14
+ super();
15
+ this._defaultConfig = AnnotationsDefaultConfig;
16
+ this.config = this._defaultConfig;
17
+ this.events = {};
18
+ if (config)
19
+ this.setConfig(config);
20
+ }
21
+ _render(customDuration) {
22
+ super._render(customDuration);
23
+ const { config } = this;
24
+ const duration = isNumber(customDuration) ? customDuration : config.duration;
25
+ const annotations = this.g.selectAll(`.${annotation}`)
26
+ .data(config.items, d => JSON.stringify(d));
27
+ const annotationsEnter = annotations.enter().append('g')
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')
34
+ .attr('class', annotationSubject);
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)
39
+ .each((annotation, i, elements) => {
40
+ if (annotation.content) {
41
+ const content = typeof annotation.content === 'string' ? Object.assign(Object.assign({}, UNOVIS_TEXT_DEFAULT), { text: annotation.content }) : annotation.content;
42
+ const x = parseUnit(annotation.x, this._width);
43
+ const y = parseUnit(annotation.y, this._height);
44
+ const width = parseUnit(annotation.width, this._width);
45
+ const height = parseUnit(annotation.height, this._height);
46
+ const options = Object.assign(Object.assign({}, annotation), { x, y, width, height });
47
+ const contentGroupElement = select(elements[i]).select(`.${annotationContent}`);
48
+ renderTextIntoFrame(contentGroupElement.node(), content, options);
49
+ }
50
+ if (annotation.subject) {
51
+ requestAnimationFrame(() => this._renderSubject(elements[i], annotation.subject));
52
+ }
53
+ });
54
+ smartTransition(annotationsMerged, duration)
55
+ .style('opacity', 1);
56
+ smartTransition(annotations.exit(), duration)
57
+ .style('opacity', 0)
58
+ .remove();
59
+ }
60
+ _renderSubject(annotationGroupElement, subject) {
61
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
62
+ const contentGroup = select(annotationGroupElement).select(`.${annotationContent}`);
63
+ const subjectGroup = select(annotationGroupElement).select(`.${annotationSubject}`);
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;
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;
66
+ const subjectStrokeColor = (_c = subject === null || subject === void 0 ? void 0 : subject.strokeColor) !== null && _c !== void 0 ? _c : null;
67
+ const subjectFillColor = (_d = subject === null || subject === void 0 ? void 0 : subject.fillColor) !== null && _d !== void 0 ? _d : null;
68
+ const subjectStrokeDasharray = (_e = subject === null || subject === void 0 ? void 0 : subject.strokeDasharray) !== null && _e !== void 0 ? _e : null;
69
+ const connectorLineColor = (_f = subject === null || subject === void 0 ? void 0 : subject.connectorLineColor) !== null && _f !== void 0 ? _f : null;
70
+ const connectorLineStrokeDasharray = (_g = subject === null || subject === void 0 ? void 0 : subject.connectorLineStrokeDasharray) !== null && _g !== void 0 ? _g : null;
71
+ const subjectRadius = (_h = subject === null || subject === void 0 ? void 0 : subject.radius) !== null && _h !== void 0 ? _h : 0;
72
+ const padding = (_j = subject === null || subject === void 0 ? void 0 : subject.padding) !== null && _j !== void 0 ? _j : 5;
73
+ const contentBbox = contentGroup.node().getBBox();
74
+ const dy = Math.abs(subjectY - (contentBbox.y + contentBbox.height / 2));
75
+ const dx = Math.abs(subjectX - (contentBbox.x + contentBbox.width / 2));
76
+ const annotationPadding = 5;
77
+ const x2 = (dx < dy) && ((subjectY < contentBbox.y) || (subjectY > (contentBbox.y + contentBbox.height)))
78
+ ? contentBbox.x + contentBbox.width / 2
79
+ : (subjectX < contentBbox.x) ? contentBbox.x - annotationPadding : contentBbox.x + contentBbox.width + annotationPadding;
80
+ const y2 = (dx >= dy) || ((subjectY >= contentBbox.y) && (subjectY <= (contentBbox.y + contentBbox.height)))
81
+ ? contentBbox.y + contentBbox.height / 2
82
+ : (subjectY < contentBbox.y) ? contentBbox.y - annotationPadding : contentBbox.y + contentBbox.height + annotationPadding;
83
+ const angle = Math.atan2(y2 - subjectY, x2 - subjectX) * 180 / Math.PI;
84
+ const x1 = subjectX + Math.cos(angle * Math.PI / 180) * (subjectRadius + padding);
85
+ const y1 = subjectY + Math.sin(angle * Math.PI / 180) * (subjectRadius + padding);
86
+ subjectGroup.select('circle')
87
+ .attr('visibility', subject ? null : 'hidden')
88
+ .attr('cx', subjectX)
89
+ .attr('cy', subjectY)
90
+ .attr('r', subjectRadius)
91
+ .style('stroke', subjectStrokeColor)
92
+ .style('fill', subjectFillColor)
93
+ .style('stroke-dasharray', subjectStrokeDasharray);
94
+ subjectGroup.select('line')
95
+ .attr('visibility', subject ? null : 'hidden')
96
+ .attr('x1', x1)
97
+ .attr('y1', y1)
98
+ .attr('x2', x1)
99
+ .attr('y2', y1)
100
+ .attr('x2', x2)
101
+ .attr('y2', y2)
102
+ .style('stroke', connectorLineColor)
103
+ .style('stroke-dasharray', connectorLineStrokeDasharray);
104
+ }
105
+ }
106
+ Annotations.selectors = style;
107
+ Annotations.cssVariables = variables;
108
+
109
+ export { Annotations };
110
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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'\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,KA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AA4B,CAAC,CAAA;KAC3D;;AAvHM,WAAS,CAAA,SAAA,GAAGC,KAAC,CAAA;AACb,WAAA,CAAA,YAAY,GAAGC,SAAW;;;;"}
@@ -0,0 +1,16 @@
1
+ export declare const root: string;
2
+ export declare const variables: {
3
+ annotationsTextColor: "--vis-annotations-text-color";
4
+ annotationsConnectorStrokeColor: "--vis-annotations-connector-stroke-color";
5
+ annotationsConnectorStrokeWidth: "--vis-annotations-connector-stroke-width";
6
+ annotationsConnectorStrokeDasharray: "--vis-annotations-connector-stroke-dasharray";
7
+ annotationsSubjectStrokeColor: "--vis-annotations-subject-stroke-color";
8
+ annotationsSubjectFillColor: "--vis-annotations-subject-fill-color";
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";
13
+ };
14
+ export declare const annotation: string;
15
+ export declare const annotationSubject: string;
16
+ export declare const annotationContent: string;
@@ -0,0 +1,47 @@
1
+ import { css } from '@emotion/css';
2
+ import { getCssVarNames, injectGlobalCssVariables } from '../../utils/style.js';
3
+
4
+ const cssVarDefaults = {
5
+ '--vis-annotations-text-color': '#282C34',
6
+ '--vis-annotations-connector-stroke-color': '#444',
7
+ '--vis-annotations-connector-stroke-width': '1px',
8
+ '--vis-annotations-connector-stroke-dasharray': 'none',
9
+ '--vis-annotations-subject-stroke-color': '#444',
10
+ '--vis-annotations-subject-fill-color': 'none',
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',
15
+ };
16
+ const root = css `
17
+ label: annotations-component;
18
+ `;
19
+ const variables = getCssVarNames(cssVarDefaults);
20
+ injectGlobalCssVariables(cssVarDefaults, root);
21
+ const annotation = css `
22
+ label: annotation;
23
+ `;
24
+ const annotationSubject = css `
25
+ label: annotationSubject;
26
+
27
+ line {
28
+ stroke: var(${variables.annotationsConnectorStrokeColor});
29
+ stroke-width: var(${variables.annotationsConnectorStrokeWidth});
30
+ stroke-dasharray: var(${variables.annotationsConnectorStrokeDasharray});
31
+ }
32
+
33
+ circle {
34
+ stroke: var(${variables.annotationsSubjectStrokeColor});
35
+ fill: var(${variables.annotationsSubjectFillColor});
36
+ stroke-dasharray: var(${variables.annotationsSubjectStrokeDasharray});
37
+ }
38
+ `;
39
+ const annotationContent = css `
40
+ label: annotationContent;
41
+ > text {
42
+ fill: var(--vis-annotations-text-color);
43
+ }
44
+ `;
45
+
46
+ export { annotation, annotationContent, annotationSubject, root, variables };
47
+ //# sourceMappingURL=style.js.map
@@ -0,0 +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-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;;;;;;;;;"}
@@ -0,0 +1,32 @@
1
+ import { LengthUnit } from "../../types/misc";
2
+ import { UnovisText, UnovisTextFrameOptions } from "../../types/text";
3
+ export declare type AnnotationItem = UnovisTextFrameOptions & {
4
+ content: string | UnovisText | UnovisText[];
5
+ subject?: AnnotationSubject;
6
+ x?: LengthUnit;
7
+ y?: LengthUnit;
8
+ width?: LengthUnit;
9
+ height?: LengthUnit;
10
+ cursor?: string;
11
+ };
12
+ export declare type AnnotationSubjectLocationXY = {
13
+ x: LengthUnit | (() => LengthUnit);
14
+ y: LengthUnit | (() => LengthUnit);
15
+ };
16
+ export declare type AnnotationSubjectStyle = {
17
+ /** Subject radius */
18
+ radius?: number;
19
+ /** Subject fill color */
20
+ fillColor?: string;
21
+ /** Subject stroke color */
22
+ strokeColor?: string;
23
+ /** Subject stroke-dasharray configuration */
24
+ strokeDasharray?: string;
25
+ /** Padding between the subject and the connector line */
26
+ padding?: number;
27
+ /** Connector line color */
28
+ connectorLineColor?: string;
29
+ /** Connector line stroke-dasharray configuration */
30
+ connectorLineStrokeDasharray?: string;
31
+ };
32
+ export declare type AnnotationSubject = AnnotationSubjectStyle & AnnotationSubjectLocationXY;
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -5,7 +5,7 @@ export interface AreaConfigInterface<Datum> extends XYComponentConfigInterface<D
5
5
  /** Area color accessor function. The whole data array will be passed as the first argument. Default: `undefined` */
6
6
  color?: ColorAccessor<Datum[]>;
7
7
  /** Curve type from the CurveType enum. Default: `CurveType.MonotoneX` */
8
- curveType?: CurveType;
8
+ curveType?: CurveType | string;
9
9
  /** Baseline value or accessor function. Default: `undefined` */
10
10
  baseline?: NumericAccessor<Datum>;
11
11
  /** Opacity value or accessor function. Default: `1` */
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sources":["../../../src/components/area/config.ts"],"sourcesContent":["import { XYComponentConfigInterface, XYComponentDefaultConfig } from 'core/xy-component/config'\n\n// Types\nimport { CurveType } from 'types/curve'\nimport { ColorAccessor, NumericAccessor, StringAccessor } from 'types/accessor'\n\nexport interface AreaConfigInterface<Datum> extends XYComponentConfigInterface<Datum> {\n /** Area color accessor function. The whole data array will be passed as the first argument. Default: `undefined` */\n color?: ColorAccessor<Datum[]>;\n /** Curve type from the CurveType enum. Default: `CurveType.MonotoneX` */\n curveType?: CurveType;\n /** Baseline value or accessor function. Default: `undefined` */\n baseline?: NumericAccessor<Datum>;\n /** Opacity value or accessor function. Default: `1` */\n opacity?: NumericAccessor<Datum[]>;\n /** Optional area cursor. String or accessor function. Default: `null` */\n cursor?: StringAccessor<Datum[]>;\n /** If an area is smaller than 1px, extend it to have 1px height.\n * This setting is useful when some of the area values are zeros or very small so visually they become\n * practically invisible, but you want to show that the data behind them exists and they're not just empty segments.\n * Default: `false` */\n minHeight1Px?: boolean;\n}\n\nexport const AreaDefaultConfig: AreaConfigInterface<unknown> = {\n ...XYComponentDefaultConfig,\n color: undefined,\n curveType: CurveType.MonotoneX,\n baseline: (): number => 0,\n opacity: 1,\n cursor: null,\n minHeight1Px: false,\n}\n"],"names":[],"mappings":";;;AAwBO,MAAM,iBAAiB,GAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACzB,wBAAwB,CAC3B,EAAA,EAAA,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,SAAS,CAAC,SAAS,EAC9B,QAAQ,EAAE,MAAc,CAAC,EACzB,OAAO,EAAE,CAAC,EACV,MAAM,EAAE,IAAI,EACZ,YAAY,EAAE,KAAK;;;;"}
1
+ {"version":3,"file":"config.js","sources":["../../../src/components/area/config.ts"],"sourcesContent":["import { XYComponentConfigInterface, XYComponentDefaultConfig } from 'core/xy-component/config'\n\n// Types\nimport { CurveType } from 'types/curve'\nimport { ColorAccessor, NumericAccessor, StringAccessor } from 'types/accessor'\n\nexport interface AreaConfigInterface<Datum> extends XYComponentConfigInterface<Datum> {\n /** Area color accessor function. The whole data array will be passed as the first argument. Default: `undefined` */\n color?: ColorAccessor<Datum[]>;\n /** Curve type from the CurveType enum. Default: `CurveType.MonotoneX` */\n curveType?: CurveType | string;\n /** Baseline value or accessor function. Default: `undefined` */\n baseline?: NumericAccessor<Datum>;\n /** Opacity value or accessor function. Default: `1` */\n opacity?: NumericAccessor<Datum[]>;\n /** Optional area cursor. String or accessor function. Default: `null` */\n cursor?: StringAccessor<Datum[]>;\n /** If an area is smaller than 1px, extend it to have 1px height.\n * This setting is useful when some of the area values are zeros or very small so visually they become\n * practically invisible, but you want to show that the data behind them exists and they're not just empty segments.\n * Default: `false` */\n minHeight1Px?: boolean;\n}\n\nexport const AreaDefaultConfig: AreaConfigInterface<unknown> = {\n ...XYComponentDefaultConfig,\n color: undefined,\n curveType: CurveType.MonotoneX,\n baseline: (): number => 0,\n opacity: 1,\n cursor: null,\n minHeight1Px: false,\n}\n"],"names":[],"mappings":";;;AAwBO,MAAM,iBAAiB,GAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACzB,wBAAwB,CAC3B,EAAA,EAAA,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,SAAS,CAAC,SAAS,EAC9B,QAAQ,EAAE,MAAc,CAAC,EACzB,OAAO,EAAE,CAAC,EACV,MAAM,EAAE,IAAI,EACZ,YAAY,EAAE,KAAK;;;;"}
@@ -21,6 +21,8 @@ class Area extends XYComponentCore {
21
21
  };
22
22
  if (config)
23
23
  this.setConfig(config);
24
+ // Determine if the provided chart should be stacked
25
+ this.stacked = Array.isArray(this.config.y);
24
26
  }
25
27
  _render(customDuration) {
26
28
  super._render(customDuration);
@@ -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 } 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]\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,S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M,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;;AAzGM,IAAS,CAAA,SAAA,GAAGC,KAAC;;;;"}
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,GA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,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;;;;"}
@@ -1,10 +1,12 @@
1
- import { BulletLegendItemInterface, BulletShape } from './types';
1
+ import { GenericAccessor } from "../../types/accessor";
2
+ import { BulletLegendItemInterface, BulletShape, BulletLegendOrientation } from './types';
2
3
  export interface BulletLegendConfigInterface {
3
4
  /** Legend items. Array of `BulletLegendItemInterface`:
4
5
  * ```
5
6
  * {
6
7
  * name: string | number;
7
8
  * color?: string;
9
+ * shape?: BulletShape;
8
10
  * inactive?: boolean;
9
11
  * hidden?: boolean;
10
12
  * pointer?: boolean;
@@ -22,7 +24,13 @@ export interface BulletLegendConfigInterface {
22
24
  labelMaxWidth?: string | null;
23
25
  /** Bullet shape size, mapped to the width and height CSS properties. Default: `null` */
24
26
  bulletSize?: string | null;
25
- /** Bullet shape: `BulletShape.Circle`, `BulletShape.Line` or `BulletShape.Square`. Default: `BulletShape.Circle` */
26
- bulletShape?: BulletShape;
27
+ /** Bullet shape enum value or accessor function. Default: `d => d.shape ?? BulletShape.Circle */
28
+ bulletShape?: GenericAccessor<BulletShape, BulletLegendItemInterface>;
29
+ /** Legend orientation. When set to `BulletLegendOrientation.Horizontal`, each legend item will
30
+ * start on a new line. Default: `BulletLegendOrientation.Horizontal` */
31
+ orientation?: BulletLegendOrientation | string;
32
+ /** If set to true, the legend will be rendered directly into the HTML element provided to the constructor
33
+ * without creating additional `div` element. Default: `false` */
34
+ renderIntoProvidedDomNode?: boolean;
27
35
  }
28
36
  export declare const BulletLegendDefaultConfig: BulletLegendConfigInterface;
@@ -1,6 +1,5 @@
1
- import { BulletShape } from './types.js';
1
+ import { BulletShape, BulletLegendOrientation } from './types.js';
2
2
 
3
- // Local Types
4
3
  const BulletLegendDefaultConfig = {
5
4
  items: [],
6
5
  labelClassName: '',
@@ -8,7 +7,9 @@ const BulletLegendDefaultConfig = {
8
7
  labelFontSize: null,
9
8
  labelMaxWidth: null,
10
9
  bulletSize: null,
11
- bulletShape: BulletShape.Circle,
10
+ bulletShape: d => { var _a; return (_a = d.shape) !== null && _a !== void 0 ? _a : BulletShape.Circle; },
11
+ orientation: BulletLegendOrientation.Horizontal,
12
+ renderIntoProvidedDomNode: false,
12
13
  };
13
14
 
14
15
  export { BulletLegendDefaultConfig };
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sources":["../../../src/components/bullet-legend/config.ts"],"sourcesContent":["// Local Types\nimport { BulletLegendItemInterface, BulletShape } from './types'\n\nexport interface BulletLegendConfigInterface {\n /** Legend items. Array of `BulletLegendItemInterface`:\n * ```\n * {\n * name: string | number;\n * color?: string;\n * inactive?: boolean;\n * hidden?: boolean;\n * pointer?: boolean;\n * }\n * ```\n * Default: `[]` */\n items: BulletLegendItemInterface[];\n /** Apply a specific class to the labels. Default: `''` */\n labelClassName?: string;\n /** Callback function for the legend item click. Default: `undefined` */\n onLegendItemClick?: ((d: BulletLegendItemInterface, i: number) => void);\n /** Label text (<span> element) font-size CSS. Default: `null` */\n labelFontSize?: string | null;\n /** Label text (<span> element) max-width CSS property. Default: `null` */\n labelMaxWidth?: string | null;\n /** Bullet shape size, mapped to the width and height CSS properties. Default: `null` */\n bulletSize?: string | null;\n /** Bullet shape: `BulletShape.Circle`, `BulletShape.Line` or `BulletShape.Square`. Default: `BulletShape.Circle` */\n bulletShape?: BulletShape;\n}\n\nexport const BulletLegendDefaultConfig: BulletLegendConfigInterface = {\n items: [],\n labelClassName: '',\n onLegendItemClick: undefined,\n labelFontSize: null,\n labelMaxWidth: null,\n bulletSize: null,\n bulletShape: BulletShape.Circle,\n}\n"],"names":[],"mappings":";;AAAA;AA8Ba,MAAA,yBAAyB,GAAgC;AACpE,IAAA,KAAK,EAAE,EAAE;AACT,IAAA,cAAc,EAAE,EAAE;AAClB,IAAA,iBAAiB,EAAE,SAAS;AAC5B,IAAA,aAAa,EAAE,IAAI;AACnB,IAAA,aAAa,EAAE,IAAI;AACnB,IAAA,UAAU,EAAE,IAAI;IAChB,WAAW,EAAE,WAAW,CAAC,MAAM;;;;;"}
1
+ {"version":3,"file":"config.js","sources":["../../../src/components/bullet-legend/config.ts"],"sourcesContent":["// Local Types\nimport { GenericAccessor } from 'types/accessor'\nimport { BulletLegendItemInterface, BulletShape, BulletLegendOrientation } from './types'\n\nexport interface BulletLegendConfigInterface {\n /** Legend items. Array of `BulletLegendItemInterface`:\n * ```\n * {\n * name: string | number;\n * color?: string;\n * shape?: BulletShape;\n * inactive?: boolean;\n * hidden?: boolean;\n * pointer?: boolean;\n * }\n * ```\n * Default: `[]` */\n items: BulletLegendItemInterface[];\n /** Apply a specific class to the labels. Default: `''` */\n labelClassName?: string;\n /** Callback function for the legend item click. Default: `undefined` */\n onLegendItemClick?: ((d: BulletLegendItemInterface, i: number) => void);\n /** Label text (<span> element) font-size CSS. Default: `null` */\n labelFontSize?: string | null;\n /** Label text (<span> element) max-width CSS property. Default: `null` */\n labelMaxWidth?: string | null;\n /** Bullet shape size, mapped to the width and height CSS properties. Default: `null` */\n bulletSize?: string | null;\n /** Bullet shape enum value or accessor function. Default: `d => d.shape ?? BulletShape.Circle */\n bulletShape?: GenericAccessor<BulletShape, BulletLegendItemInterface>;\n /** Legend orientation. When set to `BulletLegendOrientation.Horizontal`, each legend item will\n * start on a new line. Default: `BulletLegendOrientation.Horizontal` */\n orientation?: BulletLegendOrientation | string;\n /** If set to true, the legend will be rendered directly into the HTML element provided to the constructor\n * without creating additional `div` element. Default: `false` */\n renderIntoProvidedDomNode?: boolean;\n}\n\nexport const BulletLegendDefaultConfig: BulletLegendConfigInterface = {\n items: [],\n labelClassName: '',\n onLegendItemClick: undefined,\n labelFontSize: null,\n labelMaxWidth: null,\n bulletSize: null,\n bulletShape: d => d.shape ?? BulletShape.Circle,\n orientation: BulletLegendOrientation.Horizontal,\n renderIntoProvidedDomNode: false,\n}\n"],"names":[],"mappings":";;AAsCa,MAAA,yBAAyB,GAAgC;AACpE,IAAA,KAAK,EAAE,EAAE;AACT,IAAA,cAAc,EAAE,EAAE;AAClB,IAAA,iBAAiB,EAAE,SAAS;AAC5B,IAAA,aAAa,EAAE,IAAI;AACnB,IAAA,aAAa,EAAE,IAAI;AACnB,IAAA,UAAU,EAAE,IAAI;AAChB,IAAA,WAAW,EAAE,CAAC,cAAI,OAAA,CAAA,EAAA,GAAA,CAAC,CAAC,KAAK,MAAI,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAA,WAAW,CAAC,MAAM,CAAA,EAAA;IAC/C,WAAW,EAAE,uBAAuB,CAAC,UAAU;AAC/C,IAAA,yBAAyB,EAAE,KAAK;;;;;"}
@@ -6,7 +6,7 @@ export declare class BulletLegend {
6
6
  static selectors: typeof s;
7
7
  protected _defaultConfig: BulletLegendConfigInterface;
8
8
  config: BulletLegendConfigInterface;
9
- div: Selection<HTMLDivElement, unknown, null, undefined>;
9
+ div: Selection<HTMLElement, unknown, null, undefined>;
10
10
  element: HTMLElement;
11
11
  prevConfig: BulletLegendConfigInterface;
12
12
  protected _container: HTMLElement;
@@ -1,9 +1,11 @@
1
1
  import { select } from 'd3-selection';
2
+ import { cx } from '@emotion/css';
2
3
  import { merge } from '../../utils/data.js';
3
4
  import { BulletLegendDefaultConfig } from './config.js';
5
+ import { BulletLegendOrientation } from './types.js';
4
6
  import { createBullets, updateBullets } from './modules/shape.js';
5
7
  import * as style from './style.js';
6
- import { root, item, bullet, label, clickable } from './style.js';
8
+ import { root, item, itemVertical, clickable, bullet, label } from './style.js';
7
9
 
8
10
  class BulletLegend {
9
11
  constructor(element, config) {
@@ -11,10 +13,8 @@ class BulletLegend {
11
13
  this.config = this._defaultConfig;
12
14
  this._colorAccessor = (d) => d.color;
13
15
  this._container = element;
14
- // Create SVG element for visualizations
15
- this.div = select(this._container)
16
- .append('div')
17
- .attr('class', root);
16
+ this.div = (config === null || config === void 0 ? void 0 : config.renderIntoProvidedDomNode) ? select(this._container) : select(this._container).append('div');
17
+ this.div.attr('class', root);
18
18
  this.element = this.div.node();
19
19
  if (config)
20
20
  this.update(config);
@@ -26,28 +26,29 @@ class BulletLegend {
26
26
  }
27
27
  render() {
28
28
  const { config } = this;
29
- const legendItems = this.div.selectAll(`.${item}`)
30
- .data(config.items);
31
- const legendItemsEnter = legendItems.enter()
32
- .append('div')
33
- .attr('class', item)
29
+ const legendItems = this.div.selectAll(`.${item}`).data(config.items);
30
+ const legendItemsEnter = legendItems.enter().append('div')
31
+ .attr('class', d => cx(item, config.orientation === BulletLegendOrientation.Vertical && itemVertical, d.className))
34
32
  .on('click', this._onItemClick.bind(this));
35
- legendItemsEnter.append('span')
36
- .attr('class', bullet)
37
- .call(createBullets, config);
38
- legendItemsEnter.append('span')
39
- .attr('class', label)
40
- .classed(config.labelClassName, true)
41
- .style('max-width', config.labelMaxWidth)
42
- .style('font-size', config.labelFontSize);
43
33
  const legendItemsMerged = legendItemsEnter.merge(legendItems);
44
34
  legendItemsMerged
45
35
  .classed(clickable, d => !!config.onLegendItemClick && this._isItemClickable(d))
46
36
  .style('display', (d) => d.hidden ? 'none' : null);
37
+ // Bullet
38
+ legendItemsEnter.append('span')
39
+ .attr('class', bullet)
40
+ .call(createBullets);
47
41
  legendItemsMerged.select(`.${bullet}`)
48
- .style('min-width', config.bulletSize)
42
+ .style('width', config.bulletSize)
49
43
  .style('height', config.bulletSize)
44
+ .style('box-sizing', 'content-box')
50
45
  .call(updateBullets, this.config, this._colorAccessor);
46
+ // Labels
47
+ legendItemsEnter.append('span')
48
+ .attr('class', label)
49
+ .classed(config.labelClassName, true)
50
+ .style('max-width', config.labelMaxWidth)
51
+ .style('font-size', config.labelFontSize);
51
52
  legendItemsMerged.select(`.${label}`)
52
53
  .text((d) => d.name);
53
54
  legendItems.exit().remove();
@@ -63,7 +64,8 @@ class BulletLegend {
63
64
  onLegendItemClick(d, index);
64
65
  }
65
66
  destroy() {
66
- this.div.remove();
67
+ if (this.element !== this._container)
68
+ this.div.remove();
67
69
  }
68
70
  }
69
71
  BulletLegend.selectors = style;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/bullet-legend/index.ts"],"sourcesContent":["import { select, Selection } from 'd3-selection'\n\n// Utils\nimport { merge } from 'utils/data'\n\n// Config\nimport { BulletLegendDefaultConfig, BulletLegendConfigInterface } from './config'\n\n// Local Types\nimport { BulletLegendItemInterface } from './types'\n\n// Modules\nimport { createBullets, updateBullets } from './modules/shape'\n\n// Styles\nimport * as s from './style'\n\nexport class BulletLegend {\n static selectors = s\n protected _defaultConfig = BulletLegendDefaultConfig as BulletLegendConfigInterface\n public config: BulletLegendConfigInterface = this._defaultConfig\n\n div: Selection<HTMLDivElement, unknown, null, undefined>\n element: HTMLElement\n prevConfig: BulletLegendConfigInterface\n protected _container: HTMLElement\n\n private _colorAccessor = (d: BulletLegendItemInterface): string => d.color\n\n constructor (element: HTMLElement, config?: BulletLegendConfigInterface) {\n this._container = element\n\n // Create SVG element for visualizations\n this.div = select(this._container)\n .append('div')\n .attr('class', s.root)\n\n this.element = this.div.node()\n\n if (config) this.update(config)\n }\n\n update (config: BulletLegendConfigInterface): void {\n this.prevConfig = this.config\n this.config = merge(this._defaultConfig, config)\n this.render()\n }\n\n render (): void {\n const { config } = this\n const legendItems = this.div.selectAll<HTMLDivElement, unknown>(`.${s.item}`)\n .data(config.items)\n\n const legendItemsEnter = legendItems.enter()\n .append('div')\n .attr('class', s.item)\n .on('click', this._onItemClick.bind(this))\n\n legendItemsEnter.append('span')\n .attr('class', s.bullet)\n .call(createBullets, config)\n\n legendItemsEnter.append('span')\n .attr('class', s.label)\n .classed(config.labelClassName, true)\n .style('max-width', config.labelMaxWidth)\n .style('font-size', config.labelFontSize)\n\n const legendItemsMerged = legendItemsEnter.merge(legendItems)\n legendItemsMerged\n .classed(s.clickable, d => !!config.onLegendItemClick && this._isItemClickable(d))\n .style('display', (d: BulletLegendItemInterface) => d.hidden ? 'none' : null)\n\n legendItemsMerged.select<HTMLSpanElement>(`.${s.bullet}`)\n .style('min-width', config.bulletSize)\n .style('height', config.bulletSize)\n .call(updateBullets, this.config, this._colorAccessor)\n\n legendItemsMerged.select(`.${s.label}`)\n .text((d: BulletLegendItemInterface) => d.name)\n\n legendItems.exit().remove()\n }\n\n _isItemClickable (item: BulletLegendItemInterface): boolean {\n return item.pointer === undefined ? true : item.pointer\n }\n\n _onItemClick (event: MouseEvent, d: BulletLegendItemInterface): void {\n const { config: { onLegendItemClick } } = this\n\n const legendItems = this.div.selectAll(`.${s.item}`).nodes() as HTMLElement[]\n const index = legendItems.indexOf(event.currentTarget as HTMLElement)\n if (onLegendItemClick) onLegendItemClick(d, index)\n }\n\n public destroy (): void {\n this.div.remove()\n }\n}\n"],"names":["s.root","s.item","s.bullet","s.label","s.clickable","s"],"mappings":";;;;;;;MAiBa,YAAY,CAAA;IAYvB,WAAa,CAAA,OAAoB,EAAE,MAAoC,EAAA;QAV7D,IAAc,CAAA,cAAA,GAAG,yBAAwD,CAAA;AAC5E,QAAA,IAAA,CAAA,MAAM,GAAgC,IAAI,CAAC,cAAc,CAAA;QAOxD,IAAc,CAAA,cAAA,GAAG,CAAC,CAA4B,KAAa,CAAC,CAAC,KAAK,CAAA;AAGxE,QAAA,IAAI,CAAC,UAAU,GAAG,OAAO,CAAA;;QAGzB,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;aAC/B,MAAM,CAAC,KAAK,CAAC;AACb,aAAA,IAAI,CAAC,OAAO,EAAEA,IAAM,CAAC,CAAA;QAExB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;AAE9B,QAAA,IAAI,MAAM;AAAE,YAAA,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;KAChC;AAED,IAAA,MAAM,CAAE,MAAmC,EAAA;AACzC,QAAA,IAAI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AAA,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAA;KAClB;;AAhFM,YAAS,CAAA,SAAA,GAAGI,KAAC;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/components/bullet-legend/index.ts"],"sourcesContent":["import { select, Selection } from 'd3-selection'\nimport { cx } from '@emotion/css'\n\n// Utils\nimport { merge } from 'utils/data'\n\n// Config\nimport { BulletLegendDefaultConfig, BulletLegendConfigInterface } from './config'\n\n// Local Types\nimport { BulletLegendItemInterface, BulletLegendOrientation } from './types'\n\n// Modules\nimport { createBullets, updateBullets } from './modules/shape'\n\n// Styles\nimport * as s from './style'\n\nexport class BulletLegend {\n static selectors = s\n protected _defaultConfig = BulletLegendDefaultConfig as BulletLegendConfigInterface\n public config: BulletLegendConfigInterface = this._defaultConfig\n\n div: Selection<HTMLElement, unknown, null, undefined>\n element: HTMLElement\n prevConfig: BulletLegendConfigInterface\n protected _container: HTMLElement\n\n private _colorAccessor = (d: BulletLegendItemInterface): string => d.color\n\n constructor (element: HTMLElement, config?: BulletLegendConfigInterface) {\n this._container = element\n\n this.div = config?.renderIntoProvidedDomNode ? select(this._container) : select(this._container).append<HTMLElement>('div')\n this.div.attr('class', s.root)\n\n this.element = this.div.node()\n\n if (config) this.update(config)\n }\n\n update (config: BulletLegendConfigInterface): void {\n this.prevConfig = this.config\n this.config = merge(this._defaultConfig, config)\n this.render()\n }\n\n render (): void {\n const { config } = this\n\n const legendItems = this.div.selectAll<HTMLDivElement, unknown>(`.${s.item}`).data(config.items)\n\n const legendItemsEnter = legendItems.enter().append('div')\n .attr('class', d => cx(\n s.item,\n config.orientation === BulletLegendOrientation.Vertical && s.itemVertical,\n d.className)\n )\n .on('click', this._onItemClick.bind(this))\n\n const legendItemsMerged = legendItemsEnter.merge(legendItems)\n legendItemsMerged\n .classed(s.clickable, d => !!config.onLegendItemClick && this._isItemClickable(d))\n .style('display', (d: BulletLegendItemInterface) => d.hidden ? 'none' : null)\n\n // Bullet\n legendItemsEnter.append('span')\n .attr('class', s.bullet)\n .call(createBullets)\n\n legendItemsMerged.select<SVGElement>(`.${s.bullet}`)\n .style('width', config.bulletSize)\n .style('height', config.bulletSize)\n .style('box-sizing', 'content-box')\n .call(updateBullets, this.config, this._colorAccessor)\n\n // Labels\n legendItemsEnter.append('span')\n .attr('class', s.label)\n .classed(config.labelClassName, true)\n .style('max-width', config.labelMaxWidth)\n .style('font-size', config.labelFontSize)\n\n legendItemsMerged.select(`.${s.label}`)\n .text((d: BulletLegendItemInterface) => d.name)\n\n legendItems.exit().remove()\n }\n\n _isItemClickable (item: BulletLegendItemInterface): boolean {\n return item.pointer === undefined ? true : item.pointer\n }\n\n _onItemClick (event: MouseEvent, d: BulletLegendItemInterface): void {\n const { config: { onLegendItemClick } } = this\n\n const legendItems = this.div.selectAll(`.${s.item}`).nodes() as HTMLElement[]\n const index = legendItems.indexOf(event.currentTarget as HTMLElement)\n if (onLegendItemClick) onLegendItemClick(d, index)\n }\n\n public destroy (): void {\n if (this.element !== this._container) this.div.remove()\n }\n}\n"],"names":["s.root","s.item","s.itemVertical","s.clickable","s.bullet","s.label","s"],"mappings":";;;;;;;;;MAkBa,YAAY,CAAA;IAYvB,WAAa,CAAA,OAAoB,EAAE,MAAoC,EAAA;QAV7D,IAAc,CAAA,cAAA,GAAG,yBAAwD,CAAA;AAC5E,QAAA,IAAA,CAAA,MAAM,GAAgC,IAAI,CAAC,cAAc,CAAA;QAOxD,IAAc,CAAA,cAAA,GAAG,CAAC,CAA4B,KAAa,CAAC,CAAC,KAAK,CAAA;AAGxE,QAAA,IAAI,CAAC,UAAU,GAAG,OAAO,CAAA;AAEzB,QAAA,IAAI,CAAC,GAAG,GAAG,CAAA,MAAM,KAAN,IAAA,IAAA,MAAM,KAAN,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,MAAM,CAAE,yBAAyB,IAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,C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AA;KACxD;IAED,YAAY,CAAE,KAAiB,EAAE,CAA4B,EAAA;QAC3D,MAAM,EAAE,MAAM,EAAE,EAAE,iBAAiB,EAAE,EAAE,GAAG,IAAI,CAAA;AAE9C,QAAA,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAI,CAAA,EAAAJ,IAAM,CAAA,CAAE,CAAC,CAAC,KAAK,EAAmB,CAAA;QAC7E,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,aAA4B,CAAC,CAAA;AACrE,QAAA,IAAI,iBAAiB;AAAE,YAAA,iBAAiB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;KACnD;IAEM,OAAO,GAAA;AACZ,QAAA,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,UAAU;AAAE,YAAA,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAA;KACxD;;AApFM,YAAS,CAAA,SAAA,GAAGK,KAAC;;;;"}
@@ -2,5 +2,5 @@ import { Selection } from 'd3-selection';
2
2
  import { ColorAccessor } from "../../../types/accessor";
3
3
  import { BulletLegendConfigInterface } from '../config';
4
4
  import { BulletLegendItemInterface } from '../types';
5
- export declare function createBullets(container: Selection<HTMLSpanElement, BulletLegendItemInterface, HTMLDivElement, unknown>, config: BulletLegendConfigInterface): void;
6
- export declare function updateBullets(container: Selection<HTMLSpanElement, BulletLegendItemInterface, HTMLDivElement, unknown>, config: BulletLegendConfigInterface, colorAccessor: ColorAccessor<BulletLegendItemInterface>): void;
5
+ export declare function createBullets(container: Selection<HTMLSpanElement, BulletLegendItemInterface, HTMLElement, unknown>): void;
6
+ export declare function updateBullets(container: Selection<SVGElement, BulletLegendItemInterface, HTMLElement, unknown>, config: BulletLegendConfigInterface, colorAccessor: ColorAccessor<BulletLegendItemInterface>): void;