@fluentui/react-charting 5.23.59 → 5.23.61

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 (179) hide show
  1. package/CHANGELOG.json +55 -1
  2. package/CHANGELOG.md +24 -2
  3. package/dist/react-charting.d.ts +17 -1
  4. package/dist/react-charting.js +1 -1
  5. package/dist/react-charting.min.js +1 -1
  6. package/etc/react-charting.api.md +4 -0
  7. package/lib/components/AreaChart/AreaChart.base.d.ts +3 -1
  8. package/lib/components/AreaChart/AreaChart.base.js +8 -2
  9. package/lib/components/AreaChart/AreaChart.base.js.map +1 -1
  10. package/lib/components/DeclarativeChart/DeclarativeChart.d.ts +1 -1
  11. package/lib/components/DeclarativeChart/DeclarativeChart.js +36 -8
  12. package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  13. package/lib/components/DeclarativeChart/PlotlySchema.d.ts +1 -0
  14. package/lib/components/DeclarativeChart/PlotlySchema.js.map +1 -1
  15. package/lib/components/DeclarativeChart/index.d.ts +0 -1
  16. package/lib/components/DeclarativeChart/index.js.map +1 -1
  17. package/lib/components/DonutChart/DonutChart.base.d.ts +3 -1
  18. package/lib/components/DonutChart/DonutChart.base.js +8 -2
  19. package/lib/components/DonutChart/DonutChart.base.js.map +1 -1
  20. package/lib/components/GaugeChart/GaugeChart.base.d.ts +3 -1
  21. package/lib/components/GaugeChart/GaugeChart.base.js +7 -1
  22. package/lib/components/GaugeChart/GaugeChart.base.js.map +1 -1
  23. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.d.ts +3 -1
  24. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js +7 -1
  25. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js.map +1 -1
  26. package/lib/components/HeatMapChart/HeatMapChart.base.d.ts +3 -1
  27. package/lib/components/HeatMapChart/HeatMapChart.base.js +8 -2
  28. package/lib/components/HeatMapChart/HeatMapChart.base.js.map +1 -1
  29. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.d.ts +3 -1
  30. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js +7 -1
  31. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js.map +1 -1
  32. package/lib/components/Legends/Legends.base.d.ts +8 -2
  33. package/lib/components/Legends/Legends.base.js +12 -1
  34. package/lib/components/Legends/Legends.base.js.map +1 -1
  35. package/lib/components/Legends/Legends.styles.d.ts +8 -0
  36. package/lib/components/Legends/Legends.styles.js +21 -8
  37. package/lib/components/Legends/Legends.styles.js.map +1 -1
  38. package/lib/components/Legends/Legends.types.d.ts +15 -1
  39. package/lib/components/Legends/Legends.types.js.map +1 -1
  40. package/lib/components/LineChart/LineChart.base.d.ts +3 -1
  41. package/lib/components/LineChart/LineChart.base.js +7 -1
  42. package/lib/components/LineChart/LineChart.base.js.map +1 -1
  43. package/lib/components/SankeyChart/SankeyChart.base.d.ts +2 -1
  44. package/lib/components/SankeyChart/SankeyChart.base.js +4 -0
  45. package/lib/components/SankeyChart/SankeyChart.base.js.map +1 -1
  46. package/lib/components/VerticalBarChart/VerticalBarChart.base.d.ts +3 -1
  47. package/lib/components/VerticalBarChart/VerticalBarChart.base.js +7 -1
  48. package/lib/components/VerticalBarChart/VerticalBarChart.base.js.map +1 -1
  49. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.base.d.ts +3 -1
  50. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +7 -1
  51. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
  52. package/lib/index.d.ts +2 -2
  53. package/lib/index.js.map +1 -1
  54. package/lib/types/IDataPoint.d.ts +10 -0
  55. package/lib/types/IDataPoint.js.map +1 -1
  56. package/lib/utilities/image-export-utils.d.ts +13 -0
  57. package/lib/{components/DeclarativeChart/imageExporter.js → utilities/image-export-utils.js} +65 -63
  58. package/lib/utilities/image-export-utils.js.map +1 -0
  59. package/lib/utilities/utilities.d.ts +2 -0
  60. package/lib/utilities/utilities.js +44 -0
  61. package/lib/utilities/utilities.js.map +1 -1
  62. package/lib-amd/components/AreaChart/AreaChart.base.d.ts +3 -1
  63. package/lib-amd/components/AreaChart/AreaChart.base.js +7 -2
  64. package/lib-amd/components/AreaChart/AreaChart.base.js.map +1 -1
  65. package/lib-amd/components/DeclarativeChart/DeclarativeChart.d.ts +1 -1
  66. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js +37 -8
  67. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  68. package/lib-amd/components/DeclarativeChart/PlotlySchema.d.ts +1 -0
  69. package/lib-amd/components/DeclarativeChart/PlotlySchema.js.map +1 -1
  70. package/lib-amd/components/DeclarativeChart/index.d.ts +0 -1
  71. package/lib-amd/components/DeclarativeChart/index.js.map +1 -1
  72. package/lib-amd/components/DonutChart/DonutChart.base.d.ts +3 -1
  73. package/lib-amd/components/DonutChart/DonutChart.base.js +7 -2
  74. package/lib-amd/components/DonutChart/DonutChart.base.js.map +1 -1
  75. package/lib-amd/components/GaugeChart/GaugeChart.base.d.ts +3 -1
  76. package/lib-amd/components/GaugeChart/GaugeChart.base.js +7 -2
  77. package/lib-amd/components/GaugeChart/GaugeChart.base.js.map +1 -1
  78. package/lib-amd/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.d.ts +3 -1
  79. package/lib-amd/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js +7 -2
  80. package/lib-amd/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js.map +1 -1
  81. package/lib-amd/components/HeatMapChart/HeatMapChart.base.d.ts +3 -1
  82. package/lib-amd/components/HeatMapChart/HeatMapChart.base.js +7 -2
  83. package/lib-amd/components/HeatMapChart/HeatMapChart.base.js.map +1 -1
  84. package/lib-amd/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.d.ts +3 -1
  85. package/lib-amd/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js +7 -2
  86. package/lib-amd/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js.map +1 -1
  87. package/lib-amd/components/Legends/Legends.base.d.ts +8 -2
  88. package/lib-amd/components/Legends/Legends.base.js +12 -2
  89. package/lib-amd/components/Legends/Legends.base.js.map +1 -1
  90. package/lib-amd/components/Legends/Legends.styles.d.ts +8 -0
  91. package/lib-amd/components/Legends/Legends.styles.js +22 -9
  92. package/lib-amd/components/Legends/Legends.styles.js.map +1 -1
  93. package/lib-amd/components/Legends/Legends.types.d.ts +15 -1
  94. package/lib-amd/components/Legends/Legends.types.js.map +1 -1
  95. package/lib-amd/components/LineChart/LineChart.base.d.ts +3 -1
  96. package/lib-amd/components/LineChart/LineChart.base.js +7 -2
  97. package/lib-amd/components/LineChart/LineChart.base.js.map +1 -1
  98. package/lib-amd/components/SankeyChart/SankeyChart.base.d.ts +2 -1
  99. package/lib-amd/components/SankeyChart/SankeyChart.base.js +4 -1
  100. package/lib-amd/components/SankeyChart/SankeyChart.base.js.map +1 -1
  101. package/lib-amd/components/VerticalBarChart/VerticalBarChart.base.d.ts +3 -1
  102. package/lib-amd/components/VerticalBarChart/VerticalBarChart.base.js +7 -2
  103. package/lib-amd/components/VerticalBarChart/VerticalBarChart.base.js.map +1 -1
  104. package/lib-amd/components/VerticalStackedBarChart/VerticalStackedBarChart.base.d.ts +3 -1
  105. package/lib-amd/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +7 -2
  106. package/lib-amd/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
  107. package/lib-amd/index.d.ts +2 -2
  108. package/lib-amd/index.js.map +1 -1
  109. package/lib-amd/types/IDataPoint.d.ts +10 -0
  110. package/lib-amd/types/IDataPoint.js.map +1 -1
  111. package/lib-amd/utilities/image-export-utils.d.ts +13 -0
  112. package/lib-amd/{components/DeclarativeChart/imageExporter.js → utilities/image-export-utils.js} +69 -67
  113. package/lib-amd/utilities/image-export-utils.js.map +1 -0
  114. package/lib-amd/utilities/utilities.d.ts +2 -0
  115. package/lib-amd/utilities/utilities.js +47 -2
  116. package/lib-amd/utilities/utilities.js.map +1 -1
  117. package/lib-commonjs/components/AreaChart/AreaChart.base.d.ts +3 -1
  118. package/lib-commonjs/components/AreaChart/AreaChart.base.js +7 -1
  119. package/lib-commonjs/components/AreaChart/AreaChart.base.js.map +1 -1
  120. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.d.ts +1 -1
  121. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +36 -8
  122. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  123. package/lib-commonjs/components/DeclarativeChart/PlotlySchema.d.ts +1 -0
  124. package/lib-commonjs/components/DeclarativeChart/PlotlySchema.js.map +1 -1
  125. package/lib-commonjs/components/DeclarativeChart/index.d.ts +0 -1
  126. package/lib-commonjs/components/DeclarativeChart/index.js.map +1 -1
  127. package/lib-commonjs/components/DonutChart/DonutChart.base.d.ts +3 -1
  128. package/lib-commonjs/components/DonutChart/DonutChart.base.js +7 -1
  129. package/lib-commonjs/components/DonutChart/DonutChart.base.js.map +1 -1
  130. package/lib-commonjs/components/GaugeChart/GaugeChart.base.d.ts +3 -1
  131. package/lib-commonjs/components/GaugeChart/GaugeChart.base.js +7 -1
  132. package/lib-commonjs/components/GaugeChart/GaugeChart.base.js.map +1 -1
  133. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.d.ts +3 -1
  134. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js +7 -1
  135. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js.map +1 -1
  136. package/lib-commonjs/components/HeatMapChart/HeatMapChart.base.d.ts +3 -1
  137. package/lib-commonjs/components/HeatMapChart/HeatMapChart.base.js +7 -1
  138. package/lib-commonjs/components/HeatMapChart/HeatMapChart.base.js.map +1 -1
  139. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.d.ts +3 -1
  140. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js +7 -1
  141. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js.map +1 -1
  142. package/lib-commonjs/components/Legends/Legends.base.d.ts +8 -2
  143. package/lib-commonjs/components/Legends/Legends.base.js +12 -1
  144. package/lib-commonjs/components/Legends/Legends.base.js.map +1 -1
  145. package/lib-commonjs/components/Legends/Legends.styles.d.ts +8 -0
  146. package/lib-commonjs/components/Legends/Legends.styles.js +22 -9
  147. package/lib-commonjs/components/Legends/Legends.styles.js.map +1 -1
  148. package/lib-commonjs/components/Legends/Legends.types.d.ts +15 -1
  149. package/lib-commonjs/components/Legends/Legends.types.js.map +1 -1
  150. package/lib-commonjs/components/LineChart/LineChart.base.d.ts +3 -1
  151. package/lib-commonjs/components/LineChart/LineChart.base.js +7 -1
  152. package/lib-commonjs/components/LineChart/LineChart.base.js.map +1 -1
  153. package/lib-commonjs/components/SankeyChart/SankeyChart.base.d.ts +2 -1
  154. package/lib-commonjs/components/SankeyChart/SankeyChart.base.js +4 -0
  155. package/lib-commonjs/components/SankeyChart/SankeyChart.base.js.map +1 -1
  156. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.base.d.ts +3 -1
  157. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.base.js +7 -1
  158. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.base.js.map +1 -1
  159. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.base.d.ts +3 -1
  160. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +7 -1
  161. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
  162. package/lib-commonjs/index.d.ts +2 -2
  163. package/lib-commonjs/index.js.map +1 -1
  164. package/lib-commonjs/types/IDataPoint.d.ts +10 -0
  165. package/lib-commonjs/types/IDataPoint.js.map +1 -1
  166. package/lib-commonjs/utilities/image-export-utils.d.ts +13 -0
  167. package/lib-commonjs/{components/DeclarativeChart/imageExporter.js → utilities/image-export-utils.js} +70 -67
  168. package/lib-commonjs/utilities/image-export-utils.js.map +1 -0
  169. package/lib-commonjs/utilities/utilities.d.ts +2 -0
  170. package/lib-commonjs/utilities/utilities.js +47 -1
  171. package/lib-commonjs/utilities/utilities.js.map +1 -1
  172. package/package.json +4 -4
  173. package/src/components/Legends/Legends.types.ts +20 -1
  174. package/lib/components/DeclarativeChart/imageExporter.d.ts +0 -10
  175. package/lib/components/DeclarativeChart/imageExporter.js.map +0 -1
  176. package/lib-amd/components/DeclarativeChart/imageExporter.d.ts +0 -10
  177. package/lib-amd/components/DeclarativeChart/imageExporter.js.map +0 -1
  178. package/lib-commonjs/components/DeclarativeChart/imageExporter.d.ts +0 -10
  179. package/lib-commonjs/components/DeclarativeChart/imageExporter.js.map +0 -1
@@ -0,0 +1,13 @@
1
+ import { IImageExportOptions } from '../types/index';
2
+ import { ILegend, ILegendContainer } from '../Legends';
3
+ export declare function toImage(chartContainer: HTMLElement | null | undefined, legendsToSvgCallback?: ILegendContainer['toSVG'], isRTL?: boolean, opts?: IImageExportOptions): Promise<string>;
4
+ export declare function cloneLegendsToSVG(legends: ILegend[], svgWidth: number, config: {
5
+ selectedLegends: Record<string, boolean>;
6
+ centerLegends: boolean;
7
+ textClassName: string;
8
+ isRTL: boolean;
9
+ }, legendContainer?: HTMLElement | null): {
10
+ node: SVGGElement | null;
11
+ width: number;
12
+ height: number;
13
+ };
@@ -1,8 +1,9 @@
1
- define(["require", "exports", "tslib", "d3-selection", "../../utilities/index"], function (require, exports, tslib_1, d3_selection_1, index_1) {
1
+ define(["require", "exports", "tslib", "d3-selection", "./index", "../components/Legends/Legends.styles"], function (require, exports, tslib_1, d3_selection_1, index_1, Legends_styles_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.toImage = void 0;
5
- function toImage(chartContainer, opts) {
4
+ exports.cloneLegendsToSVG = exports.toImage = void 0;
5
+ function toImage(chartContainer, legendsToSvgCallback, isRTL, opts) {
6
+ if (isRTL === void 0) { isRTL = false; }
6
7
  if (opts === void 0) { opts = {}; }
7
8
  return new Promise(function (resolve, reject) {
8
9
  if (!chartContainer) {
@@ -10,7 +11,7 @@ define(["require", "exports", "tslib", "d3-selection", "../../utilities/index"],
10
11
  }
11
12
  try {
12
13
  var background = typeof opts.background === 'string' ? (0, index_1.resolveCSSVariables)(chartContainer, opts.background) : 'transparent';
13
- var svg = toSVG(chartContainer, background);
14
+ var svg = toSVG(chartContainer, legendsToSvgCallback, isRTL, background);
14
15
  var svgData = new XMLSerializer().serializeToString(svg.node);
15
16
  var svgDataUrl = 'data:image/svg+xml;base64,' + btoa(unescapePonyfill(encodeURIComponent(svgData)));
16
17
  svgToPng(svgDataUrl, {
@@ -29,7 +30,7 @@ define(["require", "exports", "tslib", "d3-selection", "../../utilities/index"],
29
30
  exports.toImage = toImage;
30
31
  var SVG_STYLE_PROPERTIES = ['display', 'fill', 'fill-opacity', 'opacity', 'stroke', 'stroke-width', 'transform'];
31
32
  var SVG_TEXT_STYLE_PROPERTIES = ['font-family', 'font-size', 'font-weight', 'text-anchor'];
32
- function toSVG(chartContainer, background) {
33
+ function toSVG(chartContainer, legendsToSvgCallback, isRTL, background) {
33
34
  var svg = chartContainer.querySelector('svg');
34
35
  if (!svg) {
35
36
  throw new Error('SVG not found');
@@ -42,17 +43,20 @@ define(["require", "exports", "tslib", "d3-selection", "../../utilities/index"],
42
43
  var clonedSvgElements = clonedSvg.node().getElementsByTagName('*');
43
44
  for (var i = 0; i < svgElements.length; i++) {
44
45
  if (svgElements[i].tagName.toLowerCase() === 'text') {
45
- copyStyle(tslib_1.__spreadArray(tslib_1.__spreadArray([], SVG_STYLE_PROPERTIES, true), SVG_TEXT_STYLE_PROPERTIES, true), svgElements[i], clonedSvgElements[i]);
46
+ (0, index_1.copyStyle)(tslib_1.__spreadArray(tslib_1.__spreadArray([], SVG_STYLE_PROPERTIES, true), SVG_TEXT_STYLE_PROPERTIES, true), svgElements[i], clonedSvgElements[i]);
46
47
  }
47
48
  else {
48
- copyStyle(SVG_STYLE_PROPERTIES, svgElements[i], clonedSvgElements[i]);
49
+ (0, index_1.copyStyle)(SVG_STYLE_PROPERTIES, svgElements[i], clonedSvgElements[i]);
49
50
  }
50
51
  }
51
52
  var _a = svg.getBoundingClientRect(), svgWidth = _a.width, svgHeight = _a.height;
52
- var legendGroup = cloneLegendsToSVG(chartContainer, svgWidth, svgHeight);
53
+ var legendGroup = typeof legendsToSvgCallback === 'function'
54
+ ? legendsToSvgCallback(svgWidth, isRTL)
55
+ : { node: null, width: 0, height: 0 };
53
56
  var w1 = Math.max(svgWidth, legendGroup.width);
54
57
  var h1 = svgHeight + legendGroup.height;
55
58
  if (legendGroup.node) {
59
+ (0, d3_selection_1.select)(legendGroup.node).attr('transform', "translate(0, ".concat(svgHeight, ")"));
56
60
  clonedSvg.append(function () { return legendGroup.node; });
57
61
  }
58
62
  clonedSvg
@@ -62,91 +66,102 @@ define(["require", "exports", "tslib", "d3-selection", "../../utilities/index"],
62
66
  .attr('width', w1)
63
67
  .attr('height', h1)
64
68
  .attr('fill', background);
65
- clonedSvg.attr('width', w1).attr('height', h1).attr('viewBox', "0 0 ".concat(w1, " ").concat(h1));
69
+ clonedSvg
70
+ .attr('width', w1)
71
+ .attr('height', h1)
72
+ .attr('viewBox', "0 0 ".concat(w1, " ").concat(h1))
73
+ .attr('direction', isRTL ? 'rtl' : 'ltr');
66
74
  return {
67
75
  node: clonedSvg.node(),
68
76
  width: w1,
69
77
  height: h1,
70
78
  };
71
79
  }
72
- var LEGEND_RECT_STYLE_PROPERTIES_MAP = {
73
- 'background-color': 'fill',
74
- 'border-color': 'stroke',
75
- };
76
80
  var LEGEND_TEXT_STYLE_PROPERTIES_MAP = {
77
81
  color: 'fill',
78
82
  'font-family': 'font-family',
79
83
  'font-size': 'font-size',
80
84
  'font-weight': 'font-weight',
81
- opacity: 'opacity',
82
85
  };
83
- function cloneLegendsToSVG(chartContainer, svgWidth, svgHeight) {
84
- var legendButtons = chartContainer.querySelectorAll("\n button[class^=\"legend-\"],\n [class^=\"legendContainer-\"] div[class^=\"overflowIndicationTextStyle-\"],\n [class^=\"legendsContainer-\"] div[class^=\"overflowIndicationTextStyle-\"]\n ");
85
- if (legendButtons.length === 0) {
86
+ function cloneLegendsToSVG(legends, svgWidth, config, legendContainer) {
87
+ if (legends.length === 0) {
86
88
  return {
87
89
  node: null,
88
90
  width: 0,
89
91
  height: 0,
90
92
  };
91
93
  }
94
+ var selectedLegends = config.selectedLegends, centerLegends = config.centerLegends, textClassName = config.textClassName, isRTL = config.isRTL;
92
95
  var legendGroup = (0, d3_selection_1.create)('svg:g');
93
- var legendX = 0;
94
- var legendY = 8;
96
+ var legendX = centerLegends ? 0 : Legends_styles_1.LEGEND_CONTAINER_MARGIN_START;
97
+ var legendY = Legends_styles_1.LEGEND_CONTAINER_MARGIN_TOP;
95
98
  var legendLine = [];
96
99
  var legendLines = [];
97
100
  var legendLineWidths = [];
101
+ var noLegendsSelected = Object.keys(selectedLegends).length === 0;
98
102
  var _loop_1 = function (i) {
99
- var legendWidth = legendButtons[i].getBoundingClientRect().width;
103
+ var textOffset = Legends_styles_1.LEGEND_PADDING + Legends_styles_1.LEGEND_SHAPE_SIZE + Legends_styles_1.LEGEND_SHAPE_MARGIN_END;
104
+ var legendText = (0, index_1.createMeasurementSpan)(legends[i].title, textClassName, legendContainer);
105
+ var legendWidth = textOffset + legendText.getBoundingClientRect().width + Legends_styles_1.LEGEND_PADDING;
100
106
  var legendItem = legendGroup.append('g');
101
- legendLine.push(legendItem);
107
+ legendLine.push({ elem: legendItem, width: legendWidth });
102
108
  if (legendX + legendWidth > svgWidth && legendLine.length > 1) {
103
109
  legendLine.pop();
104
110
  legendLines.push(legendLine);
105
111
  legendLineWidths.push(legendX);
106
- legendLine = [legendItem];
107
- legendX = 0;
108
- legendY += 32;
109
- }
110
- var legendText;
111
- var textOffset = 0;
112
- if (legendButtons[i].tagName.toLowerCase() === 'button') {
113
- var legendRect_1 = legendButtons[i].querySelector('[class^="rect"]');
114
- legendText = legendButtons[i].querySelector('[class^="text"]');
115
- legendItem
116
- .append('rect')
117
- .attr('x', legendX + 8)
118
- .attr('y', svgHeight + legendY + 8)
119
- .attr('width', 12)
120
- .attr('height', 12)
121
- .attr('stroke-width', 1)
122
- .call(function (selection) { return copyStyle(LEGEND_RECT_STYLE_PROPERTIES_MAP, legendRect_1, selection.node()); });
123
- textOffset = 28;
124
- }
125
- else {
126
- legendText = legendButtons[i];
127
- textOffset = 8;
112
+ legendLine = [{ elem: legendItem, width: legendWidth }];
113
+ legendX = centerLegends ? 0 : Legends_styles_1.LEGEND_CONTAINER_MARGIN_START;
114
+ legendY += Legends_styles_1.LEGEND_HEIGHT;
128
115
  }
116
+ var isLegendActive = selectedLegends[legends[i].title] || noLegendsSelected;
117
+ legendItem
118
+ .append('rect')
119
+ .attr('x', legendX + (isRTL ? legendWidth - Legends_styles_1.LEGEND_PADDING - Legends_styles_1.LEGEND_SHAPE_SIZE : Legends_styles_1.LEGEND_PADDING))
120
+ .attr('y', legendY + Legends_styles_1.LEGEND_PADDING)
121
+ .attr('width', Legends_styles_1.LEGEND_SHAPE_SIZE)
122
+ .attr('height', Legends_styles_1.LEGEND_SHAPE_SIZE)
123
+ .style('fill', isLegendActive ? legends[i].color : 'transparent')
124
+ .style('stroke-width', Legends_styles_1.LEGEND_SHAPE_BORDER)
125
+ .style('stroke', legends[i].color);
129
126
  legendItem
130
127
  .append('text')
131
- .attr('x', legendX + textOffset)
132
- .attr('y', svgHeight + legendY + 8)
128
+ .attr('x', legendX + (isRTL ? legendWidth - textOffset : textOffset))
129
+ .attr('y', legendY + Legends_styles_1.LEGEND_PADDING)
133
130
  .attr('dominant-baseline', 'hanging')
134
- .text(legendText.textContent)
135
- .call(function (selection) { return copyStyle(LEGEND_TEXT_STYLE_PROPERTIES_MAP, legendText, selection.node()); });
131
+ .style('opacity', isLegendActive ? 1 : Legends_styles_1.INACTIVE_LEGEND_TEXT_OPACITY)
132
+ .text(legends[i].title)
133
+ .call(function (selection) { return (0, index_1.copyStyle)(LEGEND_TEXT_STYLE_PROPERTIES_MAP, legendText, selection.node()); });
136
134
  legendX += legendWidth;
137
135
  };
138
- for (var i = 0; i < legendButtons.length; i++) {
136
+ for (var i = 0; i < legends.length; i++) {
139
137
  _loop_1(i);
140
138
  }
141
139
  legendLines.push(legendLine);
142
140
  legendLineWidths.push(legendX);
143
- legendY += 32;
144
- var centerLegends = true;
141
+ legendY += Legends_styles_1.LEGEND_HEIGHT;
145
142
  if (centerLegends) {
146
143
  legendLines.forEach(function (ln, idx) {
147
- var offsetX = Math.max((svgWidth - legendLineWidths[idx]) / 2, 0);
144
+ var lineOffsetX = Math.max((svgWidth - legendLineWidths[idx]) / 2, 0);
145
+ var remLineWidth = legendLineWidths[idx];
146
+ var itemOffsetX = 0;
148
147
  ln.forEach(function (item) {
149
- item.attr('transform', "translate(".concat(offsetX, ", 0)"));
148
+ var newOffsetX = lineOffsetX + (isRTL ? remLineWidth - item.width - itemOffsetX : 0);
149
+ item.elem.attr('transform', "translate(".concat(newOffsetX, ", 0)"));
150
+ remLineWidth -= item.width;
151
+ itemOffsetX += item.width;
152
+ });
153
+ });
154
+ }
155
+ else if (isRTL) {
156
+ var w1_1 = Math.max.apply(Math, tslib_1.__spreadArray([svgWidth], legendLineWidths, false));
157
+ legendLines.forEach(function (ln) {
158
+ var remLineWidth = w1_1 - Legends_styles_1.LEGEND_CONTAINER_MARGIN_START;
159
+ var itemOffsetX = Legends_styles_1.LEGEND_CONTAINER_MARGIN_START;
160
+ ln.forEach(function (item) {
161
+ var newOffsetX = remLineWidth - item.width - itemOffsetX;
162
+ item.elem.attr('transform', "translate(".concat(newOffsetX, ", 0)"));
163
+ remLineWidth -= item.width;
164
+ itemOffsetX += item.width;
150
165
  });
151
166
  });
152
167
  }
@@ -156,6 +171,7 @@ define(["require", "exports", "tslib", "d3-selection", "../../utilities/index"],
156
171
  height: legendY,
157
172
  };
158
173
  }
174
+ exports.cloneLegendsToSVG = cloneLegendsToSVG;
159
175
  function svgToPng(svgDataUrl, opts) {
160
176
  if (opts === void 0) { opts = {}; }
161
177
  return new Promise(function (resolve, reject) {
@@ -221,19 +237,5 @@ define(["require", "exports", "tslib", "d3-selection", "../../utilities/index"],
221
237
  }
222
238
  return result;
223
239
  }
224
- function copyStyle(properties, fromEl, toEl) {
225
- var styles = getComputedStyle(fromEl);
226
- if (Array.isArray(properties)) {
227
- properties.forEach(function (prop) {
228
- (0, d3_selection_1.select)(toEl).style(prop, styles.getPropertyValue(prop));
229
- });
230
- }
231
- else {
232
- Object.entries(properties).forEach(function (_a) {
233
- var fromProp = _a[0], toProp = _a[1];
234
- (0, d3_selection_1.select)(toEl).style(toProp, styles.getPropertyValue(fromProp));
235
- });
236
- }
237
- }
238
240
  });
239
- //# sourceMappingURL=imageExporter.js.map
241
+ //# sourceMappingURL=image-export-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-export-utils.js","sourceRoot":"../src/","sources":["utilities/image-export-utils.ts"],"names":[],"mappings":";;;;IAeA,SAAgB,OAAO,CACrB,cAA8C,EAC9C,oBAAgD,EAChD,KAAsB,EACtB,IAA8B;QAD9B,sBAAA,EAAA,aAAsB;QACtB,qBAAA,EAAA,SAA8B;QAE9B,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;YACjC,IAAI,CAAC,cAAc,EAAE,CAAC;gBACpB,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC,CAAC;YAC7D,CAAC;YAED,IAAI,CAAC;gBACH,IAAM,UAAU,GACd,OAAO,IAAI,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAA,2BAAmB,EAAC,cAAc,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAA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,CAAC;QACR,IAAI,IAAI,CAAC;QACT,OAAO,KAAK,GAAG,MAAM,EAAE,CAAC;YACtB,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;YAC1B,IAAI,GAAG,KAAK,GAAG,EAAE,CAAC;gBAChB,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC;oBAC9B,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;oBACvC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;wBACpB,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;wBAClD,KAAK,IAAI,CAAC,CAAC;wBACX,SAAS;oBACX,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;oBACnC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;wBACpB,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;wBAClD,KAAK,IAAI,CAAC,CAAC;wBACX,SAAS;oBACX,CAAC;gBACH,CAAC;YACH,CAAC;YACD,MAAM,IAAI,GAAG,CAAC;QAChB,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC","sourcesContent":["import { create as d3Create, select as d3Select, Selection } from 'd3-selection';\nimport { copyStyle, createMeasurementSpan, resolveCSSVariables } from './index';\nimport { IImageExportOptions } from '../types/index';\nimport { ILegend, ILegendContainer } from '../Legends';\nimport {\n LEGEND_CONTAINER_MARGIN_TOP,\n LEGEND_CONTAINER_MARGIN_START,\n LEGEND_PADDING,\n LEGEND_HEIGHT,\n LEGEND_SHAPE_BORDER,\n LEGEND_SHAPE_SIZE,\n LEGEND_SHAPE_MARGIN_END,\n INACTIVE_LEGEND_TEXT_OPACITY,\n} from '../components/Legends/Legends.styles';\n\nexport function toImage(\n chartContainer: HTMLElement | null | undefined,\n legendsToSvgCallback?: ILegendContainer['toSVG'],\n isRTL: boolean = false,\n opts: IImageExportOptions = {},\n): Promise<string> {\n return new Promise((resolve, reject) => {\n if (!chartContainer) {\n return reject(new Error('Chart container is not defined'));\n }\n\n try {\n const background =\n typeof opts.background === 'string' ? resolveCSSVariables(chartContainer, opts.background) : 'transparent';\n const svg = toSVG(chartContainer, legendsToSvgCallback, isRTL, background);\n\n const svgData = new XMLSerializer().serializeToString(svg.node);\n const svgDataUrl = 'data:image/svg+xml;base64,' + btoa(unescapePonyfill(encodeURIComponent(svgData)));\n\n svgToPng(svgDataUrl, {\n width: opts.width || svg.width,\n height: opts.height || svg.height,\n scale: opts.scale,\n })\n .then(resolve)\n .catch(reject);\n } catch (err) {\n return reject(err);\n }\n });\n}\n\nconst SVG_STYLE_PROPERTIES = ['display', 'fill', 'fill-opacity', 'opacity', 'stroke', 'stroke-width', 'transform'];\nconst SVG_TEXT_STYLE_PROPERTIES = ['font-family', 'font-size', 'font-weight', 'text-anchor'];\n\nfunction toSVG(\n chartContainer: HTMLElement,\n legendsToSvgCallback: ILegendContainer['toSVG'] | undefined,\n isRTL: boolean,\n background: string,\n) {\n const svg = chartContainer.querySelector<SVGSVGElement>('svg');\n if (!svg) {\n throw new Error('SVG not found');\n }\n\n const clonedSvg = d3Select(svg.cloneNode(true) as SVGSVGElement)\n .attr('width', null)\n .attr('height', null)\n .attr('viewBox', null);\n const svgElements = svg.getElementsByTagName('*');\n const clonedSvgElements = clonedSvg.node()!.getElementsByTagName('*');\n\n for (let i = 0; i < svgElements.length; i++) {\n if (svgElements[i].tagName.toLowerCase() === 'text') {\n copyStyle([...SVG_STYLE_PROPERTIES, ...SVG_TEXT_STYLE_PROPERTIES], svgElements[i], clonedSvgElements[i]);\n } else {\n copyStyle(SVG_STYLE_PROPERTIES, svgElements[i], clonedSvgElements[i]);\n }\n }\n\n const { width: svgWidth, height: svgHeight } = svg.getBoundingClientRect();\n const legendGroup =\n typeof legendsToSvgCallback === 'function'\n ? legendsToSvgCallback(svgWidth, isRTL)\n : { node: null, width: 0, height: 0 };\n const w1 = Math.max(svgWidth, legendGroup.width);\n const h1 = svgHeight + legendGroup.height;\n\n if (legendGroup.node) {\n d3Select(legendGroup.node).attr('transform', `translate(0, ${svgHeight})`);\n clonedSvg.append(() => legendGroup.node);\n }\n clonedSvg\n .insert('rect', ':first-child')\n .attr('x', 0)\n .attr('y', 0)\n .attr('width', w1)\n .attr('height', h1)\n .attr('fill', background);\n clonedSvg\n .attr('width', w1)\n .attr('height', h1)\n .attr('viewBox', `0 0 ${w1} ${h1}`)\n .attr('direction', isRTL ? 'rtl' : 'ltr');\n\n return {\n node: clonedSvg.node()!,\n width: w1,\n height: h1,\n };\n}\n\nconst LEGEND_TEXT_STYLE_PROPERTIES_MAP = {\n color: 'fill',\n 'font-family': 'font-family',\n 'font-size': 'font-size',\n 'font-weight': 'font-weight',\n};\n\nexport function cloneLegendsToSVG(\n legends: ILegend[],\n svgWidth: number,\n config: {\n selectedLegends: Record<string, boolean>;\n centerLegends: boolean;\n textClassName: string;\n isRTL: boolean;\n },\n legendContainer?: HTMLElement | null,\n) {\n if (legends.length === 0) {\n return {\n node: null,\n width: 0,\n height: 0,\n };\n }\n\n const { selectedLegends, centerLegends, textClassName, isRTL } = config;\n const legendGroup = d3Create<SVGGElement>('svg:g');\n let legendX = centerLegends ? 0 : LEGEND_CONTAINER_MARGIN_START;\n let legendY = LEGEND_CONTAINER_MARGIN_TOP;\n let legendLine: { elem: Selection<SVGGElement, unknown, null, undefined>; width: number }[] = [];\n const legendLines: (typeof legendLine)[] = [];\n const legendLineWidths: number[] = [];\n const noLegendsSelected = Object.keys(selectedLegends).length === 0;\n\n for (let i = 0; i < legends.length; i++) {\n const textOffset = LEGEND_PADDING + LEGEND_SHAPE_SIZE + LEGEND_SHAPE_MARGIN_END;\n const legendText = createMeasurementSpan(legends[i].title, textClassName, legendContainer);\n const legendWidth = textOffset + legendText.getBoundingClientRect().width + LEGEND_PADDING;\n const legendItem = legendGroup.append('g');\n\n legendLine.push({ elem: legendItem, width: legendWidth });\n if (legendX + legendWidth > svgWidth && legendLine.length > 1) {\n legendLine.pop();\n legendLines.push(legendLine);\n legendLineWidths.push(legendX);\n\n legendLine = [{ elem: legendItem, width: legendWidth }];\n legendX = centerLegends ? 0 : LEGEND_CONTAINER_MARGIN_START;\n legendY += LEGEND_HEIGHT;\n }\n\n const isLegendActive = selectedLegends[legends[i].title] || noLegendsSelected;\n\n legendItem\n .append('rect')\n .attr('x', legendX + (isRTL ? legendWidth - LEGEND_PADDING - LEGEND_SHAPE_SIZE : LEGEND_PADDING))\n .attr('y', legendY + LEGEND_PADDING)\n .attr('width', LEGEND_SHAPE_SIZE)\n .attr('height', LEGEND_SHAPE_SIZE)\n .style('fill', isLegendActive ? legends[i].color : 'transparent')\n .style('stroke-width', LEGEND_SHAPE_BORDER)\n .style('stroke', legends[i].color);\n\n legendItem\n .append('text')\n .attr('x', legendX + (isRTL ? legendWidth - textOffset : textOffset))\n .attr('y', legendY + LEGEND_PADDING)\n .attr('dominant-baseline', 'hanging')\n .style('opacity', isLegendActive ? 1 : INACTIVE_LEGEND_TEXT_OPACITY)\n .text(legends[i].title)\n .call(selection => copyStyle(LEGEND_TEXT_STYLE_PROPERTIES_MAP, legendText, selection.node()!));\n\n legendX += legendWidth;\n }\n\n legendLines.push(legendLine);\n legendLineWidths.push(legendX);\n legendY += LEGEND_HEIGHT;\n\n if (centerLegends) {\n legendLines.forEach((ln, idx) => {\n const lineOffsetX = Math.max((svgWidth - legendLineWidths[idx]) / 2, 0);\n let remLineWidth = legendLineWidths[idx];\n let itemOffsetX = 0;\n ln.forEach(item => {\n const newOffsetX = lineOffsetX + (isRTL ? remLineWidth - item.width - itemOffsetX : 0);\n item.elem.attr('transform', `translate(${newOffsetX}, 0)`);\n remLineWidth -= item.width;\n itemOffsetX += item.width;\n });\n });\n } else if (isRTL) {\n const w1 = Math.max(svgWidth, ...legendLineWidths);\n legendLines.forEach(ln => {\n let remLineWidth = w1 - LEGEND_CONTAINER_MARGIN_START;\n let itemOffsetX = LEGEND_CONTAINER_MARGIN_START;\n ln.forEach(item => {\n const newOffsetX = remLineWidth - item.width - itemOffsetX;\n item.elem.attr('transform', `translate(${newOffsetX}, 0)`);\n remLineWidth -= item.width;\n itemOffsetX += item.width;\n });\n });\n }\n\n return {\n node: legendGroup.node(),\n width: Math.max(...legendLineWidths),\n height: legendY,\n };\n}\n\nfunction svgToPng(svgDataUrl: string, opts: IImageExportOptions = {}): Promise<string> {\n return new Promise((resolve, reject) => {\n const scale = opts.scale || 1;\n const w0 = opts.width || 300;\n const h0 = opts.height || 150;\n const w1 = scale * w0;\n const h1 = scale * h0;\n\n const canvas = document.createElement('canvas');\n const img = new Image();\n\n canvas.width = w1;\n canvas.height = h1;\n\n img.onload = function () {\n const ctx = canvas.getContext('2d');\n if (!ctx) {\n return reject(new Error('Canvas context is null'));\n }\n\n ctx.clearRect(0, 0, w1, h1);\n ctx.drawImage(img, 0, 0, w1, h1);\n\n const imgData = canvas.toDataURL('image/png');\n resolve(imgData);\n };\n\n img.onerror = function (err) {\n reject(err);\n };\n\n img.src = svgDataUrl;\n });\n}\n\nconst hex2 = /^[\\da-f]{2}$/i;\nconst hex4 = /^[\\da-f]{4}$/i;\n\n/**\n * A ponyfill for the deprecated `unescape` method, taken from the `core-js` library.\n *\n * Source: {@link https://github.com/zloirock/core-js/blob/167136f479d3b8519953f2e4c534ecdd1031d3cf/packages/core-js/modules/es.unescape.js core-js/packages/core-js/modules/es.unescape.js}\n */\nfunction unescapePonyfill(str: string) {\n let result = '';\n const length = str.length;\n let index = 0;\n let chr;\n let part;\n while (index < length) {\n chr = str.charAt(index++);\n if (chr === '%') {\n if (str.charAt(index) === 'u') {\n part = str.slice(index + 1, index + 5);\n if (hex4.exec(part)) {\n result += String.fromCharCode(parseInt(part, 16));\n index += 5;\n continue;\n }\n } else {\n part = str.slice(index, index + 2);\n if (hex2.exec(part)) {\n result += String.fromCharCode(parseInt(part, 16));\n index += 2;\n continue;\n }\n }\n }\n result += chr;\n }\n return result;\n}\n"]}
@@ -413,4 +413,6 @@ export declare const formatDate: (date: Date, useUTC?: boolean) => string;
413
413
  export declare function getSecureProps(props?: Record<string, any>): Record<string, any>;
414
414
  export declare function areArraysEqual(arr1?: string[], arr2?: string[]): boolean;
415
415
  export declare function resolveCSSVariables(chartContainer: HTMLElement, styleRules: string): string;
416
+ export declare function copyStyle(properties: string[] | Record<string, string>, fromEl: Element, toEl: Element): void;
417
+ export declare const createMeasurementSpan: (text: string | number, className: string, parentElement?: HTMLElement | null) => HTMLElement;
416
418
  export {};
@@ -1,8 +1,8 @@
1
- define(["require", "exports", "tslib", "d3-axis", "d3-array", "d3-scale", "d3-selection", "d3-format", "d3-time-format", "d3-time", "d3-format"], function (require, exports, tslib_1, d3_axis_1, d3_array_1, d3_scale_1, d3_selection_1, d3_format_1, d3_time_format_1, d3_time_1, d3_format_2) {
1
+ define(["require", "exports", "tslib", "d3-axis", "d3-array", "d3-scale", "d3-selection", "d3-format", "d3-time-format", "d3-time", "d3-format", "@fluentui/react"], function (require, exports, tslib_1, d3_axis_1, d3_array_1, d3_scale_1, d3_selection_1, d3_format_1, d3_time_format_1, d3_time_1, d3_format_2, react_1) {
2
2
  "use strict";
3
3
  var _a;
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.resolveCSSVariables = exports.areArraysEqual = exports.getSecureProps = exports.formatDate = exports.isScalePaddingDefined = exports.getScalePadding = exports.getBarWidth = exports.formatValueWithSIPrefix = exports.wrapTextInsideDonut = exports.rotateXAxisLabels = exports.convertToLocaleString = exports.getAccessibleDataObject = exports.pointTypes = exports.CustomPoints = exports.Points = exports.getTypeOfAxis = exports.findHBCWANumericMinMaxOfY = exports.findVerticalNumericMinMaxOfY = exports.findVSBCNumericMinMaxOfY = exports.findNumericMinMaxOfY = exports.domainRageOfVerticalNumeric = exports.domainRangeOfDateForAreaLineVerticalBarChart = exports.domainRangeOfVSBCNumeric = exports.domainRangeOfXStringAxis = exports.domainRangeOfNumericForHorizontalBarChartWithAxis = exports.domainRangeOfNumericForAreaChart = exports.getXAxisType = exports.tooltipOfXAxislabels = exports.calculateLongestLabelWidth = exports.wrapContent = exports.createYAxisLabels = exports.createWrapOfXLabels = exports.silceOrAppendToArray = exports.getUnique = exports.calloutData = exports.createStringYAxis = exports.createStringYAxisForHorizontalBarChartWithAxis = exports.createNumericYAxis = exports.createYAxisForHorizontalBarChartWithAxis = exports.prepareDatapoints = exports.createStringXAxis = exports.createDateXAxis = exports.createNumericXAxis = exports.YAxisType = exports.XAxisTypes = exports.ChartTypes = void 0;
5
+ exports.createMeasurementSpan = exports.copyStyle = exports.resolveCSSVariables = exports.areArraysEqual = exports.getSecureProps = exports.formatDate = exports.isScalePaddingDefined = exports.getScalePadding = exports.getBarWidth = exports.formatValueWithSIPrefix = exports.wrapTextInsideDonut = exports.rotateXAxisLabels = exports.convertToLocaleString = exports.getAccessibleDataObject = exports.pointTypes = exports.CustomPoints = exports.Points = exports.getTypeOfAxis = exports.findHBCWANumericMinMaxOfY = exports.findVerticalNumericMinMaxOfY = exports.findVSBCNumericMinMaxOfY = exports.findNumericMinMaxOfY = exports.domainRageOfVerticalNumeric = exports.domainRangeOfDateForAreaLineVerticalBarChart = exports.domainRangeOfVSBCNumeric = exports.domainRangeOfXStringAxis = exports.domainRangeOfNumericForHorizontalBarChartWithAxis = exports.domainRangeOfNumericForAreaChart = exports.getXAxisType = exports.tooltipOfXAxislabels = exports.calculateLongestLabelWidth = exports.wrapContent = exports.createYAxisLabels = exports.createWrapOfXLabels = exports.silceOrAppendToArray = exports.getUnique = exports.calloutData = exports.createStringYAxis = exports.createStringYAxisForHorizontalBarChartWithAxis = exports.createNumericYAxis = exports.createYAxisForHorizontalBarChartWithAxis = exports.prepareDatapoints = exports.createStringXAxis = exports.createDateXAxis = exports.createNumericXAxis = exports.YAxisType = exports.XAxisTypes = exports.ChartTypes = void 0;
6
6
  var ChartTypes;
7
7
  (function (ChartTypes) {
8
8
  ChartTypes[ChartTypes["AreaChart"] = 0] = "AreaChart";
@@ -1212,5 +1212,50 @@ define(["require", "exports", "tslib", "d3-axis", "d3-array", "d3-scale", "d3-se
1212
1212
  });
1213
1213
  }
1214
1214
  exports.resolveCSSVariables = resolveCSSVariables;
1215
+ function copyStyle(properties, fromEl, toEl) {
1216
+ var styles = getComputedStyle(fromEl);
1217
+ if (Array.isArray(properties)) {
1218
+ properties.forEach(function (prop) {
1219
+ (0, d3_selection_1.select)(toEl).style(prop, styles.getPropertyValue(prop));
1220
+ });
1221
+ }
1222
+ else {
1223
+ Object.entries(properties).forEach(function (_a) {
1224
+ var fromProp = _a[0], toProp = _a[1];
1225
+ (0, d3_selection_1.select)(toEl).style(toProp, styles.getPropertyValue(fromProp));
1226
+ });
1227
+ }
1228
+ }
1229
+ exports.copyStyle = copyStyle;
1230
+ var MEASUREMENT_SPAN_STYLE = {
1231
+ position: 'absolute',
1232
+ visibility: 'hidden',
1233
+ top: '-20000px',
1234
+ left: 0,
1235
+ padding: 0,
1236
+ margin: 0,
1237
+ border: 'none',
1238
+ whiteSpace: 'pre',
1239
+ };
1240
+ var MEASUREMENT_SPAN_ID = (0, react_1.getId)('measurement_span_');
1241
+ var createMeasurementSpan = function (text, className, parentElement) {
1242
+ var measurementSpan = document.getElementById(MEASUREMENT_SPAN_ID);
1243
+ if (!measurementSpan) {
1244
+ measurementSpan = document.createElement('span');
1245
+ measurementSpan.setAttribute('id', MEASUREMENT_SPAN_ID);
1246
+ measurementSpan.setAttribute('aria-hidden', 'true');
1247
+ if (parentElement) {
1248
+ parentElement.appendChild(measurementSpan);
1249
+ }
1250
+ else {
1251
+ document.body.appendChild(measurementSpan);
1252
+ }
1253
+ }
1254
+ measurementSpan.setAttribute('class', className);
1255
+ Object.assign(measurementSpan.style, MEASUREMENT_SPAN_STYLE);
1256
+ measurementSpan.textContent = "".concat(text);
1257
+ return measurementSpan;
1258
+ };
1259
+ exports.createMeasurementSpan = createMeasurementSpan;
1215
1260
  });
1216
1261
  //# sourceMappingURL=utilities.js.map