@fluentui/react-charting 5.24.39 → 5.25.1

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 (111) hide show
  1. package/CHANGELOG.json +75 -1
  2. package/CHANGELOG.md +30 -2
  3. package/dist/react-charting.d.ts +127 -0
  4. package/dist/react-charting.js +1 -1
  5. package/dist/react-charting.min.js +1 -1
  6. package/etc/react-charting.api.md +74 -0
  7. package/lib/components/CommonComponents/Annotations/ChartAnnotationLayer.d.ts +3 -0
  8. package/lib/components/CommonComponents/Annotations/ChartAnnotationLayer.js +496 -0
  9. package/lib/components/CommonComponents/Annotations/ChartAnnotationLayer.js.map +1 -0
  10. package/lib/components/CommonComponents/Annotations/ChartAnnotationLayer.styles.d.ts +28 -0
  11. package/lib/components/CommonComponents/Annotations/ChartAnnotationLayer.styles.js +111 -0
  12. package/lib/components/CommonComponents/Annotations/ChartAnnotationLayer.styles.js.map +1 -0
  13. package/lib/components/CommonComponents/Annotations/ChartAnnotationLayer.types.d.ts +52 -0
  14. package/lib/components/CommonComponents/Annotations/ChartAnnotationLayer.types.js +2 -0
  15. package/lib/components/CommonComponents/Annotations/ChartAnnotationLayer.types.js.map +1 -0
  16. package/lib/components/CommonComponents/CartesianChart.base.js +38 -46
  17. package/lib/components/CommonComponents/CartesianChart.base.js.map +1 -1
  18. package/lib/components/CommonComponents/CartesianChart.styles.js +9 -1
  19. package/lib/components/CommonComponents/CartesianChart.styles.js.map +1 -1
  20. package/lib/components/CommonComponents/CartesianChart.types.d.ts +17 -1
  21. package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
  22. package/lib/components/CommonComponents/index.d.ts +2 -0
  23. package/lib/components/CommonComponents/index.js +2 -0
  24. package/lib/components/CommonComponents/index.js.map +1 -1
  25. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +650 -76
  26. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  27. package/lib/index.d.ts +1 -1
  28. package/lib/index.js.map +1 -1
  29. package/lib/types/IChartAnnotation.d.ts +99 -0
  30. package/lib/types/IChartAnnotation.js +2 -0
  31. package/lib/types/IChartAnnotation.js.map +1 -0
  32. package/lib/types/IDataPoint.d.ts +4 -0
  33. package/lib/types/IDataPoint.js.map +1 -1
  34. package/lib/types/index.d.ts +1 -0
  35. package/lib/types/index.js +1 -0
  36. package/lib/types/index.js.map +1 -1
  37. package/lib/utilities/image-export-utils.js +55 -0
  38. package/lib/utilities/image-export-utils.js.map +1 -1
  39. package/lib/utilities/utilities.js +72 -20
  40. package/lib/utilities/utilities.js.map +1 -1
  41. package/lib-amd/components/CommonComponents/Annotations/ChartAnnotationLayer.d.ts +3 -0
  42. package/lib-amd/components/CommonComponents/Annotations/ChartAnnotationLayer.js +497 -0
  43. package/lib-amd/components/CommonComponents/Annotations/ChartAnnotationLayer.js.map +1 -0
  44. package/lib-amd/components/CommonComponents/Annotations/ChartAnnotationLayer.styles.d.ts +28 -0
  45. package/lib-amd/components/CommonComponents/Annotations/ChartAnnotationLayer.styles.js +119 -0
  46. package/lib-amd/components/CommonComponents/Annotations/ChartAnnotationLayer.styles.js.map +1 -0
  47. package/lib-amd/components/CommonComponents/Annotations/ChartAnnotationLayer.types.d.ts +52 -0
  48. package/lib-amd/components/CommonComponents/Annotations/ChartAnnotationLayer.types.js +5 -0
  49. package/lib-amd/components/CommonComponents/Annotations/ChartAnnotationLayer.types.js.map +1 -0
  50. package/lib-amd/components/CommonComponents/CartesianChart.base.js +38 -47
  51. package/lib-amd/components/CommonComponents/CartesianChart.base.js.map +1 -1
  52. package/lib-amd/components/CommonComponents/CartesianChart.styles.js +9 -1
  53. package/lib-amd/components/CommonComponents/CartesianChart.styles.js.map +1 -1
  54. package/lib-amd/components/CommonComponents/CartesianChart.types.d.ts +17 -1
  55. package/lib-amd/components/CommonComponents/CartesianChart.types.js.map +1 -1
  56. package/lib-amd/components/CommonComponents/index.d.ts +2 -0
  57. package/lib-amd/components/CommonComponents/index.js +3 -1
  58. package/lib-amd/components/CommonComponents/index.js.map +1 -1
  59. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js +650 -76
  60. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  61. package/lib-amd/index.d.ts +1 -1
  62. package/lib-amd/index.js.map +1 -1
  63. package/lib-amd/types/IChartAnnotation.d.ts +99 -0
  64. package/lib-amd/types/IChartAnnotation.js +5 -0
  65. package/lib-amd/types/IChartAnnotation.js.map +1 -0
  66. package/lib-amd/types/IDataPoint.d.ts +4 -0
  67. package/lib-amd/types/IDataPoint.js.map +1 -1
  68. package/lib-amd/types/index.d.ts +1 -0
  69. package/lib-amd/types/index.js +2 -1
  70. package/lib-amd/types/index.js.map +1 -1
  71. package/lib-amd/utilities/image-export-utils.js +55 -0
  72. package/lib-amd/utilities/image-export-utils.js.map +1 -1
  73. package/lib-amd/utilities/utilities.js +72 -20
  74. package/lib-amd/utilities/utilities.js.map +1 -1
  75. package/lib-commonjs/components/CommonComponents/Annotations/ChartAnnotationLayer.d.ts +3 -0
  76. package/lib-commonjs/components/CommonComponents/Annotations/ChartAnnotationLayer.js +499 -0
  77. package/lib-commonjs/components/CommonComponents/Annotations/ChartAnnotationLayer.js.map +1 -0
  78. package/lib-commonjs/components/CommonComponents/Annotations/ChartAnnotationLayer.styles.d.ts +28 -0
  79. package/lib-commonjs/components/CommonComponents/Annotations/ChartAnnotationLayer.styles.js +118 -0
  80. package/lib-commonjs/components/CommonComponents/Annotations/ChartAnnotationLayer.styles.js.map +1 -0
  81. package/lib-commonjs/components/CommonComponents/Annotations/ChartAnnotationLayer.types.d.ts +52 -0
  82. package/lib-commonjs/components/CommonComponents/Annotations/ChartAnnotationLayer.types.js +3 -0
  83. package/lib-commonjs/components/CommonComponents/Annotations/ChartAnnotationLayer.types.js.map +1 -0
  84. package/lib-commonjs/components/CommonComponents/CartesianChart.base.js +38 -46
  85. package/lib-commonjs/components/CommonComponents/CartesianChart.base.js.map +1 -1
  86. package/lib-commonjs/components/CommonComponents/CartesianChart.styles.js +9 -1
  87. package/lib-commonjs/components/CommonComponents/CartesianChart.styles.js.map +1 -1
  88. package/lib-commonjs/components/CommonComponents/CartesianChart.types.d.ts +17 -1
  89. package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
  90. package/lib-commonjs/components/CommonComponents/index.d.ts +2 -0
  91. package/lib-commonjs/components/CommonComponents/index.js +2 -0
  92. package/lib-commonjs/components/CommonComponents/index.js.map +1 -1
  93. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +650 -76
  94. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  95. package/lib-commonjs/index.d.ts +1 -1
  96. package/lib-commonjs/index.js.map +1 -1
  97. package/lib-commonjs/types/IChartAnnotation.d.ts +99 -0
  98. package/lib-commonjs/types/IChartAnnotation.js +3 -0
  99. package/lib-commonjs/types/IChartAnnotation.js.map +1 -0
  100. package/lib-commonjs/types/IDataPoint.d.ts +4 -0
  101. package/lib-commonjs/types/IDataPoint.js.map +1 -1
  102. package/lib-commonjs/types/index.d.ts +1 -0
  103. package/lib-commonjs/types/index.js +1 -0
  104. package/lib-commonjs/types/index.js.map +1 -1
  105. package/lib-commonjs/utilities/image-export-utils.js +55 -0
  106. package/lib-commonjs/utilities/image-export-utils.js.map +1 -1
  107. package/lib-commonjs/utilities/utilities.js +72 -20
  108. package/lib-commonjs/utilities/utilities.js.map +1 -1
  109. package/package.json +9 -9
  110. package/src/components/CommonComponents/Annotations/ChartAnnotationLayer.types.ts +58 -0
  111. package/src/components/CommonComponents/CartesianChart.types.ts +21 -0
@@ -39,6 +39,7 @@ export type AxisCategoryOrder = 'default' | 'data' | string[] | 'category ascend
39
39
  export type AxisProps = {
40
40
  tickStep?: number | string;
41
41
  tick0?: number | Date;
42
+ tickText?: string[];
42
43
  };
43
44
 
44
45
  // @public
@@ -47,6 +48,75 @@ export type AxisScaleType = 'default' | 'log';
47
48
  // @public
48
49
  export const CartesianChart: React_2.FunctionComponent<IModifiedCartesianChartProps>;
49
50
 
51
+ // @public (undocumented)
52
+ export interface ChartAnnotation {
53
+ accessibility?: ChartAnnotationAccessibilityProps;
54
+ connector?: ChartAnnotationConnectorProps;
55
+ coordinates: ChartAnnotationCoordinate;
56
+ data?: Record<string, unknown>;
57
+ id?: string;
58
+ layout?: ChartAnnotationLayoutProps;
59
+ style?: ChartAnnotationStyleProps;
60
+ text: string;
61
+ }
62
+
63
+ // @public (undocumented)
64
+ export interface ChartAnnotationAccessibilityProps {
65
+ ariaDescribedBy?: string;
66
+ ariaLabel?: string;
67
+ role?: string;
68
+ }
69
+
70
+ // @public (undocumented)
71
+ export type ChartAnnotationArrowHead = 'none' | 'start' | 'end' | 'both';
72
+
73
+ // @public (undocumented)
74
+ export interface ChartAnnotationConnectorProps {
75
+ arrow?: ChartAnnotationArrowHead;
76
+ dashArray?: string;
77
+ endPadding?: number;
78
+ startPadding?: number;
79
+ strokeColor?: string;
80
+ strokeWidth?: number;
81
+ }
82
+
83
+ // @public (undocumented)
84
+ export type ChartAnnotationCoordinate = {
85
+ type: 'data' | 'relative' | 'pixel';
86
+ x: number | string | Date;
87
+ y: number | string | Date;
88
+ yAxis?: 'primary' | 'secondary';
89
+ };
90
+
91
+ // @public (undocumented)
92
+ export interface ChartAnnotationLayoutProps {
93
+ // Warning: (ae-forgotten-export) The symbol "ChartAnnotationHorizontalAlign" needs to be exported by the entry point index.d.ts
94
+ align?: ChartAnnotationHorizontalAlign;
95
+ className?: string;
96
+ clipToBounds?: boolean;
97
+ maxWidth?: number;
98
+ offsetX?: number;
99
+ offsetY?: number;
100
+ // Warning: (ae-forgotten-export) The symbol "ChartAnnotationVerticalAlign" needs to be exported by the entry point index.d.ts
101
+ verticalAlign?: ChartAnnotationVerticalAlign;
102
+ }
103
+
104
+ // @public (undocumented)
105
+ export interface ChartAnnotationStyleProps {
106
+ backgroundColor?: string;
107
+ borderColor?: string;
108
+ borderRadius?: number;
109
+ borderStyle?: React_2.CSSProperties['borderStyle'];
110
+ borderWidth?: number;
111
+ boxShadow?: string;
112
+ className?: string;
113
+ fontSize?: string;
114
+ fontWeight?: React_2.CSSProperties['fontWeight'];
115
+ opacity?: number;
116
+ padding?: string;
117
+ textColor?: string;
118
+ }
119
+
50
120
  // @public
51
121
  export type ChartDataMode = 'default' | 'fraction' | 'percentage';
52
122
 
@@ -313,6 +383,7 @@ export interface IBasestate {
313
383
 
314
384
  // @public
315
385
  export interface ICartesianChartProps {
386
+ annotations?: ChartAnnotation[];
316
387
  calloutProps?: Partial<ICalloutProps>;
317
388
  // @deprecated
318
389
  chartLabel?: string;
@@ -395,6 +466,7 @@ export interface ICartesianChartStyleProps {
395
466
 
396
467
  // @public
397
468
  export interface ICartesianChartStyles {
469
+ annotationLayer?: IStyle;
398
470
  axisAnnotation?: IStyle;
399
471
  axisTitle?: IStyle;
400
472
  calloutBlockContainer?: IStyle;
@@ -411,6 +483,7 @@ export interface ICartesianChartStyles {
411
483
  hover?: IStyle;
412
484
  legendContainer?: IStyle;
413
485
  opacityChangeOnHover?: IStyle;
486
+ plotContainer?: IStyle;
414
487
  root?: IStyle;
415
488
  shapeStyles?: IStyle;
416
489
  svgTooltip?: IStyle;
@@ -1286,6 +1359,7 @@ export interface IMargins {
1286
1359
 
1287
1360
  // @public (undocumented)
1288
1361
  export interface IModifiedCartesianChartProps extends ICartesianChartProps {
1362
+ annotations?: ChartAnnotation[];
1289
1363
  barwidth?: number;
1290
1364
  calloutProps: Partial<ICalloutProps> & {
1291
1365
  isCalloutVisible: boolean;
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ import { IChartAnnotationLayerProps } from './ChartAnnotationLayer.types';
3
+ export declare const ChartAnnotationLayer: React.FC<IChartAnnotationLayerProps>;
@@ -0,0 +1,496 @@
1
+ import { __assign, __spreadArray } from "tslib";
2
+ import * as React from 'react';
3
+ import { classNamesFunction, css, getId } from '@fluentui/react/lib/Utilities';
4
+ import { applyOpacityToColor, DEFAULT_ANNOTATION_BACKGROUND_OPACITY, DEFAULT_CONNECTOR_ARROW, DEFAULT_CONNECTOR_END_PADDING, DEFAULT_CONNECTOR_START_PADDING, DEFAULT_CONNECTOR_STROKE_WIDTH, getDefaultConnectorStrokeColor, getStyles, } from './ChartAnnotationLayer.styles';
5
+ var getClassNames = classNamesFunction();
6
+ var DEFAULT_HORIZONTAL_ALIGN = 'center';
7
+ var DEFAULT_VERTICAL_ALIGN = 'middle';
8
+ var DEFAULT_FOREIGN_OBJECT_WIDTH = 180;
9
+ var DEFAULT_FOREIGN_OBJECT_HEIGHT = 60;
10
+ var MIN_ARROW_SIZE = 6;
11
+ var MAX_ARROW_SIZE = 24;
12
+ var ARROW_SIZE_SCALE = 0.35;
13
+ var MAX_SIMPLE_MARKUP_DEPTH = 5;
14
+ var CHAR_CODE_LESS_THAN = '<'.codePointAt(0);
15
+ var CHAR_CODE_GREATER_THAN = '>'.codePointAt(0);
16
+ var getAnnotationKey = function (annotation, index) {
17
+ var _a, _b;
18
+ return (_b = (_a = annotation.id) !== null && _a !== void 0 ? _a : (typeof annotation.text === 'string' || typeof annotation.text === 'number' ? String(annotation.text) : undefined)) !== null && _b !== void 0 ? _b : "annotation-".concat(index);
19
+ };
20
+ var decodeSimpleMarkupInput = function (input) {
21
+ var namedEntities = {
22
+ amp: '&',
23
+ quot: '"',
24
+ apos: "'",
25
+ nbsp: '\u00a0',
26
+ };
27
+ var withBasicEntitiesDecoded = input.replace(/&(#x?[0-9a-f]+|#\d+|[a-z][\w-]*);/gi, function (match, entity) {
28
+ var _a;
29
+ var lower = entity.toLowerCase();
30
+ if (lower === 'lt' || lower === 'gt') {
31
+ return "&".concat(lower, ";");
32
+ }
33
+ if (lower.startsWith('#')) {
34
+ var isHex = lower[1] === 'x';
35
+ var digits = lower.slice(isHex ? 2 : 1);
36
+ var codePoint = Number.parseInt(digits, isHex ? 16 : 10);
37
+ if (Number.isNaN(codePoint)) {
38
+ return match;
39
+ }
40
+ if (codePoint === CHAR_CODE_LESS_THAN) {
41
+ return '&lt;';
42
+ }
43
+ if (codePoint === CHAR_CODE_GREATER_THAN) {
44
+ return '&gt;';
45
+ }
46
+ return String.fromCodePoint(codePoint);
47
+ }
48
+ return (_a = namedEntities[lower]) !== null && _a !== void 0 ? _a : match;
49
+ });
50
+ return withBasicEntitiesDecoded.replace(/&lt;([^;]+)&gt;/gi, function (match, inner) {
51
+ var normalized = inner.trim().replace(/\s+/g, ' ');
52
+ var lower = normalized.toLowerCase();
53
+ switch (lower) {
54
+ case 'b':
55
+ return '<b>';
56
+ case '/b':
57
+ return '</b>';
58
+ case 'i':
59
+ return '<i>';
60
+ case '/i':
61
+ return '</i>';
62
+ case 'br':
63
+ case 'br/':
64
+ case 'br /':
65
+ return '<br />';
66
+ default:
67
+ return match;
68
+ }
69
+ });
70
+ };
71
+ var appendTextNode = function (nodes, text) {
72
+ if (text.length === 0) {
73
+ return;
74
+ }
75
+ var last = nodes[nodes.length - 1];
76
+ if (last && last.type === 'text') {
77
+ last.content += text;
78
+ }
79
+ else {
80
+ nodes.push({ type: 'text', content: text });
81
+ }
82
+ };
83
+ var serializeSimpleMarkup = function (nodes) {
84
+ return nodes
85
+ .map(function (node) {
86
+ if (node.type === 'text') {
87
+ return node.content;
88
+ }
89
+ if (node.type === 'br') {
90
+ return '<br />';
91
+ }
92
+ return "<".concat(node.tag, ">").concat(serializeSimpleMarkup(node.children), "</").concat(node.tag, ">");
93
+ })
94
+ .join('');
95
+ };
96
+ var parseSimpleMarkup = function (input) {
97
+ var _a, _b;
98
+ if (!input) {
99
+ return [];
100
+ }
101
+ var decodedInput = decodeSimpleMarkupInput(input);
102
+ var rootChildren = [];
103
+ var stack = [{ node: null }];
104
+ var currentChildren = function () { var _a, _b; return (_b = (_a = stack[stack.length - 1].node) === null || _a === void 0 ? void 0 : _a.children) !== null && _b !== void 0 ? _b : rootChildren; };
105
+ var tagRegex = /<\/?([a-z]+)\s*\/?\s*>/gi;
106
+ var lastIndex = 0;
107
+ var match;
108
+ while ((match = tagRegex.exec(decodedInput)) !== null) {
109
+ var fullMatch = match[0], rawTagName = match[1];
110
+ var tagName = rawTagName.toLowerCase();
111
+ var isClosing = fullMatch.startsWith('</');
112
+ var isSelfClosing = /\/\s*>$/.test(fullMatch);
113
+ appendTextNode(currentChildren(), decodedInput.slice(lastIndex, match.index));
114
+ lastIndex = match.index + fullMatch.length;
115
+ if (tagName === 'br' && !isClosing) {
116
+ currentChildren().push({ type: 'br' });
117
+ continue;
118
+ }
119
+ if ((tagName === 'b' || tagName === 'i') && !isSelfClosing) {
120
+ if (isClosing) {
121
+ var top_1 = stack[stack.length - 1].node;
122
+ if (stack.length > 1 && (top_1 === null || top_1 === void 0 ? void 0 : top_1.tag) === tagName) {
123
+ stack.pop();
124
+ }
125
+ else {
126
+ appendTextNode(currentChildren(), fullMatch);
127
+ }
128
+ }
129
+ else {
130
+ if (stack.length - 1 >= MAX_SIMPLE_MARKUP_DEPTH) {
131
+ appendTextNode(currentChildren(), fullMatch);
132
+ continue;
133
+ }
134
+ var elementNode = {
135
+ type: 'element',
136
+ tag: tagName,
137
+ children: [],
138
+ };
139
+ currentChildren().push(elementNode);
140
+ stack.push({ node: elementNode });
141
+ }
142
+ continue;
143
+ }
144
+ appendTextNode(currentChildren(), fullMatch);
145
+ }
146
+ appendTextNode(currentChildren(), decodedInput.slice(lastIndex));
147
+ while (stack.length > 1) {
148
+ var unclosed = stack.pop();
149
+ var elementNode = unclosed.node;
150
+ if (!elementNode) {
151
+ continue;
152
+ }
153
+ var parentChildren = (_b = (_a = stack[stack.length - 1].node) === null || _a === void 0 ? void 0 : _a.children) !== null && _b !== void 0 ? _b : rootChildren;
154
+ var lastChild = parentChildren[parentChildren.length - 1];
155
+ if (lastChild === elementNode) {
156
+ parentChildren.pop();
157
+ }
158
+ else {
159
+ var nodeIndex = parentChildren.indexOf(elementNode);
160
+ if (nodeIndex !== -1) {
161
+ parentChildren.splice(nodeIndex, 1);
162
+ }
163
+ }
164
+ appendTextNode(parentChildren, "<".concat(elementNode.tag, ">").concat(serializeSimpleMarkup(elementNode.children), "</").concat(elementNode.tag, ">"));
165
+ }
166
+ return rootChildren;
167
+ };
168
+ var simpleMarkupNodesToPlainText = function (nodes) {
169
+ return nodes
170
+ .map(function (node) {
171
+ if (node.type === 'text') {
172
+ return node.content;
173
+ }
174
+ if (node.type === 'br') {
175
+ return '\n';
176
+ }
177
+ return simpleMarkupNodesToPlainText(node.children);
178
+ })
179
+ .join('');
180
+ };
181
+ var renderSimpleMarkupNodeList = function (nodes, keyPrefix) {
182
+ return nodes.map(function (node, index) {
183
+ var key = "".concat(keyPrefix, "-").concat(index);
184
+ if (node.type === 'text') {
185
+ return React.createElement(React.Fragment, { key: key }, node.content);
186
+ }
187
+ if (node.type === 'br') {
188
+ return React.createElement("br", { key: key });
189
+ }
190
+ var Tag = node.tag === 'b' ? 'strong' : 'em';
191
+ return React.createElement.apply(React, __spreadArray([Tag, { key: key }], renderSimpleMarkupNodeList(node.children, key), false));
192
+ });
193
+ };
194
+ var renderSimpleMarkup = function (nodes, keyPrefix) {
195
+ var _a;
196
+ var rendered = renderSimpleMarkupNodeList(nodes, keyPrefix);
197
+ return rendered.length <= 1 ? (_a = rendered[0]) !== null && _a !== void 0 ? _a : null : rendered;
198
+ };
199
+ var normalizeBandOffset = function (scale, value) {
200
+ var position = scale === null || scale === void 0 ? void 0 : scale(value);
201
+ if (typeof position !== 'number' || Number.isNaN(position)) {
202
+ return undefined;
203
+ }
204
+ if (scale && typeof scale.bandwidth === 'function') {
205
+ return position + scale.bandwidth() / 2;
206
+ }
207
+ return position;
208
+ };
209
+ var clamp = function (value, min, max) { return Math.max(min, Math.min(max, value)); };
210
+ var createMeasurementSignature = function (annotationContentSignature, containerStyle, contentStyle, layoutClassName, styleClassName) {
211
+ return JSON.stringify({
212
+ annotationContentSignature: annotationContentSignature,
213
+ containerStyle: containerStyle,
214
+ contentStyle: contentStyle,
215
+ layoutClassName: layoutClassName !== null && layoutClassName !== void 0 ? layoutClassName : '',
216
+ styleClassName: styleClassName !== null && styleClassName !== void 0 ? styleClassName : '',
217
+ });
218
+ };
219
+ var resolveCoordinates = function (annotation, context) {
220
+ var _a, _b;
221
+ var coordinates = annotation.coordinates, layout = annotation.layout;
222
+ if (!coordinates) {
223
+ return undefined;
224
+ }
225
+ var offsetX = (_a = layout === null || layout === void 0 ? void 0 : layout.offsetX) !== null && _a !== void 0 ? _a : 0;
226
+ var offsetY = (_b = layout === null || layout === void 0 ? void 0 : layout.offsetY) !== null && _b !== void 0 ? _b : 0;
227
+ var anchor = { x: 0, y: 0 };
228
+ switch (coordinates.type) {
229
+ case 'data': {
230
+ var x = coordinates.x, y = coordinates.y, _c = coordinates.yAxis, yAxis = _c === void 0 ? 'primary' : _c;
231
+ var xScale = context.xScale;
232
+ var yScale = yAxis === 'secondary' ? context.yScaleSecondary : context.yScalePrimary;
233
+ if (!xScale || !yScale) {
234
+ return undefined;
235
+ }
236
+ var xValue = normalizeBandOffset(xScale, x instanceof Date ? x.getTime() : x);
237
+ var yValue = normalizeBandOffset(yScale, y instanceof Date ? y.getTime() : y);
238
+ if (typeof xValue !== 'number' || typeof yValue !== 'number') {
239
+ return undefined;
240
+ }
241
+ anchor.x = xValue;
242
+ anchor.y = yValue;
243
+ break;
244
+ }
245
+ case 'relative': {
246
+ if (typeof coordinates.x !== 'number' || typeof coordinates.y !== 'number') {
247
+ return undefined;
248
+ }
249
+ anchor.x = context.plotRect.x + context.plotRect.width * coordinates.x;
250
+ anchor.y = context.plotRect.y + context.plotRect.height * coordinates.y;
251
+ break;
252
+ }
253
+ case 'pixel': {
254
+ if (typeof coordinates.x !== 'number' || typeof coordinates.y !== 'number') {
255
+ return undefined;
256
+ }
257
+ anchor.x = context.plotRect.x + coordinates.x;
258
+ anchor.y = context.plotRect.y + coordinates.y;
259
+ break;
260
+ }
261
+ default:
262
+ return undefined;
263
+ }
264
+ var left = anchor.x + offsetX;
265
+ var top = anchor.y + offsetY;
266
+ if (layout === null || layout === void 0 ? void 0 : layout.clipToBounds) {
267
+ left = clamp(left, context.plotRect.x, context.plotRect.x + context.plotRect.width);
268
+ top = clamp(top, context.plotRect.y, context.plotRect.y + context.plotRect.height);
269
+ }
270
+ return {
271
+ anchor: anchor,
272
+ point: { x: left, y: top },
273
+ };
274
+ };
275
+ export var ChartAnnotationLayer = React.memo(function (props) {
276
+ var annotationsProp = props.annotations, theme = props.theme, context = props.context, className = props.className;
277
+ var classNames = getClassNames(getStyles, { theme: theme, className: className });
278
+ var idPrefix = React.useMemo(function () { return getId('chart-annotation'); }, []);
279
+ var _a = React.useState({}), measurements = _a[0], setMeasurements = _a[1];
280
+ var resolvedAnnotations = React.useMemo(function () {
281
+ return (annotationsProp !== null && annotationsProp !== void 0 ? annotationsProp : []).map(function (annotation, index) { return ({ annotation: annotation, key: getAnnotationKey(annotation, index) }); });
282
+ }, [annotationsProp]);
283
+ React.useEffect(function () {
284
+ setMeasurements(function (prev) {
285
+ if (resolvedAnnotations.length === 0) {
286
+ if (Object.keys(prev).length === 0) {
287
+ return prev;
288
+ }
289
+ return {};
290
+ }
291
+ var next = {};
292
+ resolvedAnnotations.forEach(function (_a) {
293
+ var key = _a.key;
294
+ if (prev[key]) {
295
+ next[key] = prev[key];
296
+ }
297
+ });
298
+ if (Object.keys(next).length === Object.keys(prev).length) {
299
+ var identical = true;
300
+ for (var _i = 0, _a = Object.keys(next); _i < _a.length; _i++) {
301
+ var key = _a[_i];
302
+ if (next[key] !== prev[key]) {
303
+ identical = false;
304
+ break;
305
+ }
306
+ }
307
+ if (identical) {
308
+ return prev;
309
+ }
310
+ }
311
+ return next;
312
+ });
313
+ }, [resolvedAnnotations]);
314
+ var updateMeasurement = React.useCallback(function (key, width, height, signature) {
315
+ setMeasurements(function (prev) {
316
+ var _a;
317
+ var prevEntry = prev[key];
318
+ if (prevEntry &&
319
+ prevEntry.signature === signature &&
320
+ Math.abs(prevEntry.width - width) < 0.5 &&
321
+ Math.abs(prevEntry.height - height) < 0.5) {
322
+ return prev;
323
+ }
324
+ if (width === 0 && height === 0) {
325
+ return prev;
326
+ }
327
+ return __assign(__assign({}, prev), (_a = {}, _a[key] = { width: width, height: height, signature: signature }, _a));
328
+ });
329
+ }, []);
330
+ var annotationForeignObjects = [];
331
+ var measurementElements = [];
332
+ var connectors = [];
333
+ resolvedAnnotations.forEach(function (_a) {
334
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12;
335
+ var annotation = _a.annotation, key = _a.key;
336
+ var resolved = resolveCoordinates(annotation, context);
337
+ if (!resolved) {
338
+ return;
339
+ }
340
+ var rawAnnotationText = annotation.text === undefined || annotation.text === null ? '' : String(annotation.text);
341
+ var annotationMarkupNodes = parseSimpleMarkup(rawAnnotationText);
342
+ var annotationMarkupSignature = JSON.stringify(annotationMarkupNodes);
343
+ var annotationPlainText = simpleMarkupNodesToPlainText(annotationMarkupNodes);
344
+ var layout = annotation.layout;
345
+ var horizontalAlign = (_b = layout === null || layout === void 0 ? void 0 : layout.align) !== null && _b !== void 0 ? _b : DEFAULT_HORIZONTAL_ALIGN;
346
+ var verticalAlign = (_c = layout === null || layout === void 0 ? void 0 : layout.verticalAlign) !== null && _c !== void 0 ? _c : DEFAULT_VERTICAL_ALIGN;
347
+ var backgroundOpacity = (_e = (_d = annotation.style) === null || _d === void 0 ? void 0 : _d.opacity) !== null && _e !== void 0 ? _e : DEFAULT_ANNOTATION_BACKGROUND_OPACITY;
348
+ var baseBackgroundColor = (_g = (_f = annotation.style) === null || _f === void 0 ? void 0 : _f.backgroundColor) !== null && _g !== void 0 ? _g : theme.semanticColors.bodyBackground;
349
+ var hasCustomBackground = ((_h = annotation.style) === null || _h === void 0 ? void 0 : _h.backgroundColor) !== undefined || ((_j = annotation.style) === null || _j === void 0 ? void 0 : _j.opacity) !== undefined;
350
+ var containerStyle = __assign(__assign({ maxWidth: layout === null || layout === void 0 ? void 0 : layout.maxWidth }, (hasCustomBackground && {
351
+ backgroundColor: applyOpacityToColor(baseBackgroundColor, backgroundOpacity),
352
+ })), { borderColor: (_k = annotation.style) === null || _k === void 0 ? void 0 : _k.borderColor, borderWidth: (_l = annotation.style) === null || _l === void 0 ? void 0 : _l.borderWidth, borderStyle: (_o = (_m = annotation.style) === null || _m === void 0 ? void 0 : _m.borderStyle) !== null && _o !== void 0 ? _o : (((_p = annotation.style) === null || _p === void 0 ? void 0 : _p.borderColor) ? 'solid' : undefined), borderRadius: (_q = annotation.style) === null || _q === void 0 ? void 0 : _q.borderRadius, padding: (_r = annotation.style) === null || _r === void 0 ? void 0 : _r.padding, boxShadow: (_s = annotation.style) === null || _s === void 0 ? void 0 : _s.boxShadow });
353
+ var contentStyle = {
354
+ color: (_t = annotation.style) === null || _t === void 0 ? void 0 : _t.textColor,
355
+ fontSize: (_u = annotation.style) === null || _u === void 0 ? void 0 : _u.fontSize,
356
+ fontWeight: (_v = annotation.style) === null || _v === void 0 ? void 0 : _v.fontWeight,
357
+ opacity: 1,
358
+ };
359
+ var measurementSignature = createMeasurementSignature(annotationMarkupSignature, containerStyle, contentStyle, layout === null || layout === void 0 ? void 0 : layout.className, (_w = annotation.style) === null || _w === void 0 ? void 0 : _w.className);
360
+ var measurementEntry = measurements[key];
361
+ var isMeasurementValid = (measurementEntry === null || measurementEntry === void 0 ? void 0 : measurementEntry.signature) === measurementSignature;
362
+ var measuredSize = isMeasurementValid ? measurementEntry : undefined;
363
+ var width = Math.max((_y = (_x = measuredSize === null || measuredSize === void 0 ? void 0 : measuredSize.width) !== null && _x !== void 0 ? _x : layout === null || layout === void 0 ? void 0 : layout.maxWidth) !== null && _y !== void 0 ? _y : DEFAULT_FOREIGN_OBJECT_WIDTH, 1);
364
+ var height = Math.max((_z = measuredSize === null || measuredSize === void 0 ? void 0 : measuredSize.height) !== null && _z !== void 0 ? _z : DEFAULT_FOREIGN_OBJECT_HEIGHT, 1);
365
+ var offsetX = horizontalAlign === 'center' ? -width / 2 : horizontalAlign === 'end' ? -width : 0;
366
+ var offsetY = verticalAlign === 'middle' ? -height / 2 : verticalAlign === 'bottom' ? -height : 0;
367
+ var baseTopLeftX = resolved.point.x + offsetX;
368
+ var baseTopLeftY = resolved.point.y + offsetY;
369
+ var usePlotBounds = (layout === null || layout === void 0 ? void 0 : layout.clipToBounds) !== false;
370
+ var viewportX = usePlotBounds ? context.plotRect.x : 0;
371
+ var viewportY = usePlotBounds ? context.plotRect.y : 0;
372
+ var viewportWidth = usePlotBounds ? context.plotRect.width : (_0 = context.svgRect.width) !== null && _0 !== void 0 ? _0 : 0;
373
+ var viewportHeight = usePlotBounds ? context.plotRect.height : (_1 = context.svgRect.height) !== null && _1 !== void 0 ? _1 : 0;
374
+ var maxTopLeftX = viewportWidth > 0 ? viewportX + viewportWidth - width : baseTopLeftX;
375
+ var maxTopLeftY = viewportHeight > 0 ? viewportY + viewportHeight - height : baseTopLeftY;
376
+ var topLeftX = viewportWidth > 0 ? clamp(baseTopLeftX, viewportX, Math.max(viewportX, maxTopLeftX)) : baseTopLeftX;
377
+ var topLeftY = viewportHeight > 0 ? clamp(baseTopLeftY, viewportY, Math.max(viewportY, maxTopLeftY)) : baseTopLeftY;
378
+ var displayPoint = {
379
+ x: topLeftX - offsetX,
380
+ y: topLeftY - offsetY,
381
+ };
382
+ if (annotation.connector) {
383
+ var startPadding = (_2 = annotation.connector.startPadding) !== null && _2 !== void 0 ? _2 : 12;
384
+ var endPadding = (_3 = annotation.connector.endPadding) !== null && _3 !== void 0 ? _3 : 0;
385
+ var minArrowClearance = 6;
386
+ var minDistance = Math.max(startPadding + endPadding + minArrowClearance, startPadding);
387
+ var dx = displayPoint.x - resolved.anchor.x;
388
+ var dy = displayPoint.y - resolved.anchor.y;
389
+ var distance = Math.sqrt(dx * dx + dy * dy);
390
+ if (distance < minDistance) {
391
+ var fallbackDirection = { x: 0, y: -1 };
392
+ var ux = distance === 0 ? fallbackDirection.x : dx / distance;
393
+ var uy = distance === 0 ? fallbackDirection.y : dy / distance;
394
+ var desiredDisplayX = resolved.anchor.x + ux * minDistance;
395
+ var desiredDisplayY = resolved.anchor.y + uy * minDistance;
396
+ var desiredTopLeftX = desiredDisplayX + offsetX;
397
+ var desiredTopLeftY = desiredDisplayY + offsetY;
398
+ desiredTopLeftX =
399
+ viewportWidth > 0 ? clamp(desiredTopLeftX, viewportX, Math.max(viewportX, maxTopLeftX)) : desiredTopLeftX;
400
+ desiredTopLeftY =
401
+ viewportHeight > 0 ? clamp(desiredTopLeftY, viewportY, Math.max(viewportY, maxTopLeftY)) : desiredTopLeftY;
402
+ topLeftX = desiredTopLeftX;
403
+ topLeftY = desiredTopLeftY;
404
+ displayPoint = {
405
+ x: topLeftX - offsetX,
406
+ y: topLeftY - offsetY,
407
+ };
408
+ }
409
+ }
410
+ var measurementStyle = __assign({ left: topLeftX, top: topLeftY, pointerEvents: 'none' }, containerStyle);
411
+ if (!isMeasurementValid) {
412
+ measurementElements.push(React.createElement("div", { key: "".concat(key, "-measurement"), ref: function (node) {
413
+ if (node) {
414
+ var rect = node.getBoundingClientRect();
415
+ if (rect.width !== 0 || rect.height !== 0) {
416
+ updateMeasurement(key, rect.width, rect.height, measurementSignature);
417
+ }
418
+ }
419
+ }, className: css(classNames.annotation, classNames.measurement, layout === null || layout === void 0 ? void 0 : layout.className, (_4 = annotation.style) === null || _4 === void 0 ? void 0 : _4.className), style: measurementStyle, "aria-hidden": true, "data-annotation-key": key, "data-chart-annotation-measurement": "true" },
420
+ React.createElement("div", { className: css(classNames.annotationContent, layout === null || layout === void 0 ? void 0 : layout.className, (_5 = annotation.style) === null || _5 === void 0 ? void 0 : _5.className), style: contentStyle }, renderSimpleMarkup(annotationMarkupNodes, "".concat(key, "-measurement")))));
421
+ }
422
+ annotationForeignObjects.push(React.createElement("foreignObject", { key: "".concat(key, "-annotation"), x: topLeftX, y: topLeftY, width: width, height: height, className: css(classNames.annotationForeignObject), "data-annotation-key": key },
423
+ React.createElement("div", { className: css(classNames.annotation, layout === null || layout === void 0 ? void 0 : layout.className, (_6 = annotation.style) === null || _6 === void 0 ? void 0 : _6.className), style: containerStyle, "data-annotation-key": key },
424
+ React.createElement("div", { className: css(classNames.annotationContent, (_7 = annotation.style) === null || _7 === void 0 ? void 0 : _7.className), style: contentStyle, role: (_9 = (_8 = annotation.accessibility) === null || _8 === void 0 ? void 0 : _8.role) !== null && _9 !== void 0 ? _9 : 'note', "aria-label": (_11 = (_10 = annotation.accessibility) === null || _10 === void 0 ? void 0 : _10.ariaLabel) !== null && _11 !== void 0 ? _11 : (annotationPlainText ? annotationPlainText : undefined), "aria-describedby": (_12 = annotation.accessibility) === null || _12 === void 0 ? void 0 : _12.ariaDescribedBy, "data-chart-annotation": "true", "data-annotation-key": key }, renderSimpleMarkup(annotationMarkupNodes, "".concat(key, "-content"))))));
425
+ if (annotation.connector) {
426
+ var _13 = annotation.connector, _14 = _13.startPadding, startPadding = _14 === void 0 ? DEFAULT_CONNECTOR_START_PADDING : _14, _15 = _13.endPadding, endPadding = _15 === void 0 ? DEFAULT_CONNECTOR_END_PADDING : _15, _16 = _13.strokeColor, strokeColor = _16 === void 0 ? getDefaultConnectorStrokeColor(theme) : _16, _17 = _13.strokeWidth, strokeWidth = _17 === void 0 ? DEFAULT_CONNECTOR_STROKE_WIDTH : _17, dashArray = _13.dashArray, _18 = _13.arrow, arrow = _18 === void 0 ? DEFAULT_CONNECTOR_ARROW : _18;
427
+ var dx = resolved.anchor.x - displayPoint.x;
428
+ var dy = resolved.anchor.y - displayPoint.y;
429
+ var distance = Math.sqrt(dx * dx + dy * dy) || 1;
430
+ var ux = dx / distance;
431
+ var uy = dy / distance;
432
+ var sizeBasis = Math.max(1, Math.min(width, height));
433
+ var proportionalSize = sizeBasis * ARROW_SIZE_SCALE;
434
+ var maxByPadding = startPadding > 0 ? startPadding * 1.25 : MAX_ARROW_SIZE;
435
+ var maxByDistance = distance * 0.6;
436
+ var markerSize = clamp(proportionalSize, MIN_ARROW_SIZE, Math.min(MAX_ARROW_SIZE, maxByPadding, maxByDistance));
437
+ var markerStrokeWidth = clamp(strokeWidth, 1, markerSize / 2);
438
+ var start = {
439
+ x: displayPoint.x + ux * startPadding,
440
+ y: displayPoint.y + uy * startPadding,
441
+ };
442
+ var end = {
443
+ x: resolved.anchor.x - ux * endPadding,
444
+ y: resolved.anchor.y - uy * endPadding,
445
+ };
446
+ connectors.push({
447
+ key: "".concat(key, "-connector"),
448
+ start: start,
449
+ end: end,
450
+ strokeColor: strokeColor,
451
+ strokeWidth: strokeWidth,
452
+ dashArray: dashArray,
453
+ arrow: arrow,
454
+ markerSize: markerSize,
455
+ markerStrokeWidth: markerStrokeWidth,
456
+ });
457
+ }
458
+ });
459
+ if (annotationForeignObjects.length === 0 && connectors.length === 0) {
460
+ return null;
461
+ }
462
+ var viewBoxWidth = context.svgRect.width || 1;
463
+ var viewBoxHeight = context.svgRect.height || 1;
464
+ var markerDefs = [];
465
+ var createMarkerId = function (color, position, size, markerStrokeWidth) {
466
+ var id = "".concat(idPrefix, "-").concat(position, "-").concat(markerDefs.length);
467
+ var refY = size / 2;
468
+ var refX = position === 'end' ? size : 0;
469
+ var pathEnd = "M0 0 L ".concat(size, " ").concat(refY, " L0 ").concat(size, " Z");
470
+ var pathStart = "M ".concat(size, " 0 L0 ").concat(refY, " L ").concat(size, " ").concat(size, " Z");
471
+ var path = position === 'end' ? pathEnd : pathStart;
472
+ markerDefs.push(React.createElement("marker", { key: id, id: id, markerWidth: size, markerHeight: size, viewBox: "0 0 ".concat(size, " ").concat(size), refX: refX, refY: refY, orient: "auto", markerUnits: "userSpaceOnUse" },
473
+ React.createElement("path", { d: path, fill: color, stroke: color, strokeWidth: markerStrokeWidth, strokeLinecap: "round", strokeLinejoin: "round" })));
474
+ return id;
475
+ };
476
+ var connectorElements = connectors.map(function (connector) {
477
+ var markerStart;
478
+ var markerEnd;
479
+ if (connector.arrow === 'start' || connector.arrow === 'both') {
480
+ markerStart = createMarkerId(connector.strokeColor, 'start', connector.markerSize, connector.markerStrokeWidth);
481
+ }
482
+ if (connector.arrow === 'end' || connector.arrow === 'both') {
483
+ markerEnd = createMarkerId(connector.strokeColor, 'end', connector.markerSize, connector.markerStrokeWidth);
484
+ }
485
+ return (React.createElement("line", { key: connector.key, x1: connector.start.x, y1: connector.start.y, x2: connector.end.x, y2: connector.end.y, stroke: connector.strokeColor, strokeWidth: connector.strokeWidth, strokeDasharray: connector.dashArray, strokeLinecap: "round", markerStart: markerStart ? "url(#".concat(markerStart, ")") : undefined, markerEnd: markerEnd ? "url(#".concat(markerEnd, ")") : undefined }));
486
+ });
487
+ var shouldRenderSvg = connectors.length > 0 || annotationForeignObjects.length > 0;
488
+ return (React.createElement("div", { className: classNames.root, role: "presentation", "data-chart-annotation-layer": "true" },
489
+ shouldRenderSvg && (React.createElement("svg", { className: classNames.connectorLayer, width: "100%", height: "100%", viewBox: "0 0 ".concat(viewBoxWidth, " ").concat(viewBoxHeight), preserveAspectRatio: "none", "data-chart-annotation-svg": "true" },
490
+ markerDefs.length > 0 && React.createElement("defs", null, markerDefs),
491
+ connectorElements.length > 0 && (React.createElement("g", { "aria-hidden": "true", className: classNames.connectorGroup }, connectorElements)),
492
+ annotationForeignObjects)),
493
+ measurementElements));
494
+ });
495
+ ChartAnnotationLayer.displayName = 'ChartAnnotationLayer';
496
+ //# sourceMappingURL=ChartAnnotationLayer.js.map