@fluentui/react-charting 5.23.59 → 5.23.60

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 (173) hide show
  1. package/CHANGELOG.json +40 -1
  2. package/CHANGELOG.md +15 -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 +26 -4
  12. package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  13. package/lib/components/DeclarativeChart/index.d.ts +0 -1
  14. package/lib/components/DeclarativeChart/index.js.map +1 -1
  15. package/lib/components/DonutChart/DonutChart.base.d.ts +3 -1
  16. package/lib/components/DonutChart/DonutChart.base.js +8 -2
  17. package/lib/components/DonutChart/DonutChart.base.js.map +1 -1
  18. package/lib/components/GaugeChart/GaugeChart.base.d.ts +3 -1
  19. package/lib/components/GaugeChart/GaugeChart.base.js +7 -1
  20. package/lib/components/GaugeChart/GaugeChart.base.js.map +1 -1
  21. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.d.ts +3 -1
  22. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js +7 -1
  23. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js.map +1 -1
  24. package/lib/components/HeatMapChart/HeatMapChart.base.d.ts +3 -1
  25. package/lib/components/HeatMapChart/HeatMapChart.base.js +8 -2
  26. package/lib/components/HeatMapChart/HeatMapChart.base.js.map +1 -1
  27. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.d.ts +3 -1
  28. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js +7 -1
  29. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js.map +1 -1
  30. package/lib/components/Legends/Legends.base.d.ts +8 -2
  31. package/lib/components/Legends/Legends.base.js +12 -1
  32. package/lib/components/Legends/Legends.base.js.map +1 -1
  33. package/lib/components/Legends/Legends.styles.d.ts +8 -0
  34. package/lib/components/Legends/Legends.styles.js +21 -8
  35. package/lib/components/Legends/Legends.styles.js.map +1 -1
  36. package/lib/components/Legends/Legends.types.d.ts +15 -1
  37. package/lib/components/Legends/Legends.types.js.map +1 -1
  38. package/lib/components/LineChart/LineChart.base.d.ts +3 -1
  39. package/lib/components/LineChart/LineChart.base.js +7 -1
  40. package/lib/components/LineChart/LineChart.base.js.map +1 -1
  41. package/lib/components/SankeyChart/SankeyChart.base.d.ts +2 -1
  42. package/lib/components/SankeyChart/SankeyChart.base.js +4 -0
  43. package/lib/components/SankeyChart/SankeyChart.base.js.map +1 -1
  44. package/lib/components/VerticalBarChart/VerticalBarChart.base.d.ts +3 -1
  45. package/lib/components/VerticalBarChart/VerticalBarChart.base.js +7 -1
  46. package/lib/components/VerticalBarChart/VerticalBarChart.base.js.map +1 -1
  47. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.base.d.ts +3 -1
  48. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +7 -1
  49. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
  50. package/lib/index.d.ts +2 -2
  51. package/lib/index.js.map +1 -1
  52. package/lib/types/IDataPoint.d.ts +10 -0
  53. package/lib/types/IDataPoint.js.map +1 -1
  54. package/lib/utilities/image-export-utils.d.ts +13 -0
  55. package/lib/{components/DeclarativeChart/imageExporter.js → utilities/image-export-utils.js} +65 -63
  56. package/lib/utilities/image-export-utils.js.map +1 -0
  57. package/lib/utilities/utilities.d.ts +2 -0
  58. package/lib/utilities/utilities.js +44 -0
  59. package/lib/utilities/utilities.js.map +1 -1
  60. package/lib-amd/components/AreaChart/AreaChart.base.d.ts +3 -1
  61. package/lib-amd/components/AreaChart/AreaChart.base.js +7 -2
  62. package/lib-amd/components/AreaChart/AreaChart.base.js.map +1 -1
  63. package/lib-amd/components/DeclarativeChart/DeclarativeChart.d.ts +1 -1
  64. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js +27 -4
  65. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  66. package/lib-amd/components/DeclarativeChart/index.d.ts +0 -1
  67. package/lib-amd/components/DeclarativeChart/index.js.map +1 -1
  68. package/lib-amd/components/DonutChart/DonutChart.base.d.ts +3 -1
  69. package/lib-amd/components/DonutChart/DonutChart.base.js +7 -2
  70. package/lib-amd/components/DonutChart/DonutChart.base.js.map +1 -1
  71. package/lib-amd/components/GaugeChart/GaugeChart.base.d.ts +3 -1
  72. package/lib-amd/components/GaugeChart/GaugeChart.base.js +7 -2
  73. package/lib-amd/components/GaugeChart/GaugeChart.base.js.map +1 -1
  74. package/lib-amd/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.d.ts +3 -1
  75. package/lib-amd/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js +7 -2
  76. package/lib-amd/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js.map +1 -1
  77. package/lib-amd/components/HeatMapChart/HeatMapChart.base.d.ts +3 -1
  78. package/lib-amd/components/HeatMapChart/HeatMapChart.base.js +7 -2
  79. package/lib-amd/components/HeatMapChart/HeatMapChart.base.js.map +1 -1
  80. package/lib-amd/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.d.ts +3 -1
  81. package/lib-amd/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js +7 -2
  82. package/lib-amd/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js.map +1 -1
  83. package/lib-amd/components/Legends/Legends.base.d.ts +8 -2
  84. package/lib-amd/components/Legends/Legends.base.js +12 -2
  85. package/lib-amd/components/Legends/Legends.base.js.map +1 -1
  86. package/lib-amd/components/Legends/Legends.styles.d.ts +8 -0
  87. package/lib-amd/components/Legends/Legends.styles.js +22 -9
  88. package/lib-amd/components/Legends/Legends.styles.js.map +1 -1
  89. package/lib-amd/components/Legends/Legends.types.d.ts +15 -1
  90. package/lib-amd/components/Legends/Legends.types.js.map +1 -1
  91. package/lib-amd/components/LineChart/LineChart.base.d.ts +3 -1
  92. package/lib-amd/components/LineChart/LineChart.base.js +7 -2
  93. package/lib-amd/components/LineChart/LineChart.base.js.map +1 -1
  94. package/lib-amd/components/SankeyChart/SankeyChart.base.d.ts +2 -1
  95. package/lib-amd/components/SankeyChart/SankeyChart.base.js +4 -1
  96. package/lib-amd/components/SankeyChart/SankeyChart.base.js.map +1 -1
  97. package/lib-amd/components/VerticalBarChart/VerticalBarChart.base.d.ts +3 -1
  98. package/lib-amd/components/VerticalBarChart/VerticalBarChart.base.js +7 -2
  99. package/lib-amd/components/VerticalBarChart/VerticalBarChart.base.js.map +1 -1
  100. package/lib-amd/components/VerticalStackedBarChart/VerticalStackedBarChart.base.d.ts +3 -1
  101. package/lib-amd/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +7 -2
  102. package/lib-amd/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
  103. package/lib-amd/index.d.ts +2 -2
  104. package/lib-amd/index.js.map +1 -1
  105. package/lib-amd/types/IDataPoint.d.ts +10 -0
  106. package/lib-amd/types/IDataPoint.js.map +1 -1
  107. package/lib-amd/utilities/image-export-utils.d.ts +13 -0
  108. package/lib-amd/{components/DeclarativeChart/imageExporter.js → utilities/image-export-utils.js} +69 -67
  109. package/lib-amd/utilities/image-export-utils.js.map +1 -0
  110. package/lib-amd/utilities/utilities.d.ts +2 -0
  111. package/lib-amd/utilities/utilities.js +47 -2
  112. package/lib-amd/utilities/utilities.js.map +1 -1
  113. package/lib-commonjs/components/AreaChart/AreaChart.base.d.ts +3 -1
  114. package/lib-commonjs/components/AreaChart/AreaChart.base.js +7 -1
  115. package/lib-commonjs/components/AreaChart/AreaChart.base.js.map +1 -1
  116. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.d.ts +1 -1
  117. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +26 -4
  118. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  119. package/lib-commonjs/components/DeclarativeChart/index.d.ts +0 -1
  120. package/lib-commonjs/components/DeclarativeChart/index.js.map +1 -1
  121. package/lib-commonjs/components/DonutChart/DonutChart.base.d.ts +3 -1
  122. package/lib-commonjs/components/DonutChart/DonutChart.base.js +7 -1
  123. package/lib-commonjs/components/DonutChart/DonutChart.base.js.map +1 -1
  124. package/lib-commonjs/components/GaugeChart/GaugeChart.base.d.ts +3 -1
  125. package/lib-commonjs/components/GaugeChart/GaugeChart.base.js +7 -1
  126. package/lib-commonjs/components/GaugeChart/GaugeChart.base.js.map +1 -1
  127. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.d.ts +3 -1
  128. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js +7 -1
  129. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js.map +1 -1
  130. package/lib-commonjs/components/HeatMapChart/HeatMapChart.base.d.ts +3 -1
  131. package/lib-commonjs/components/HeatMapChart/HeatMapChart.base.js +7 -1
  132. package/lib-commonjs/components/HeatMapChart/HeatMapChart.base.js.map +1 -1
  133. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.d.ts +3 -1
  134. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js +7 -1
  135. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js.map +1 -1
  136. package/lib-commonjs/components/Legends/Legends.base.d.ts +8 -2
  137. package/lib-commonjs/components/Legends/Legends.base.js +12 -1
  138. package/lib-commonjs/components/Legends/Legends.base.js.map +1 -1
  139. package/lib-commonjs/components/Legends/Legends.styles.d.ts +8 -0
  140. package/lib-commonjs/components/Legends/Legends.styles.js +22 -9
  141. package/lib-commonjs/components/Legends/Legends.styles.js.map +1 -1
  142. package/lib-commonjs/components/Legends/Legends.types.d.ts +15 -1
  143. package/lib-commonjs/components/Legends/Legends.types.js.map +1 -1
  144. package/lib-commonjs/components/LineChart/LineChart.base.d.ts +3 -1
  145. package/lib-commonjs/components/LineChart/LineChart.base.js +7 -1
  146. package/lib-commonjs/components/LineChart/LineChart.base.js.map +1 -1
  147. package/lib-commonjs/components/SankeyChart/SankeyChart.base.d.ts +2 -1
  148. package/lib-commonjs/components/SankeyChart/SankeyChart.base.js +4 -0
  149. package/lib-commonjs/components/SankeyChart/SankeyChart.base.js.map +1 -1
  150. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.base.d.ts +3 -1
  151. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.base.js +7 -1
  152. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.base.js.map +1 -1
  153. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.base.d.ts +3 -1
  154. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +7 -1
  155. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
  156. package/lib-commonjs/index.d.ts +2 -2
  157. package/lib-commonjs/index.js.map +1 -1
  158. package/lib-commonjs/types/IDataPoint.d.ts +10 -0
  159. package/lib-commonjs/types/IDataPoint.js.map +1 -1
  160. package/lib-commonjs/utilities/image-export-utils.d.ts +13 -0
  161. package/lib-commonjs/{components/DeclarativeChart/imageExporter.js → utilities/image-export-utils.js} +70 -67
  162. package/lib-commonjs/utilities/image-export-utils.js.map +1 -0
  163. package/lib-commonjs/utilities/utilities.d.ts +2 -0
  164. package/lib-commonjs/utilities/utilities.js +47 -1
  165. package/lib-commonjs/utilities/utilities.js.map +1 -1
  166. package/package.json +4 -4
  167. package/src/components/Legends/Legends.types.ts +20 -1
  168. package/lib/components/DeclarativeChart/imageExporter.d.ts +0 -10
  169. package/lib/components/DeclarativeChart/imageExporter.js.map +0 -1
  170. package/lib-amd/components/DeclarativeChart/imageExporter.d.ts +0 -10
  171. package/lib-amd/components/DeclarativeChart/imageExporter.js.map +0 -1
  172. package/lib-commonjs/components/DeclarativeChart/imageExporter.d.ts +0 -10
  173. 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,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toImage = void 0;
3
+ exports.cloneLegendsToSVG = exports.toImage = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var d3_selection_1 = require("d3-selection");
6
- var index_1 = require("../../utilities/index");
7
- function toImage(chartContainer, opts) {
6
+ var index_1 = require("./index");
7
+ var Legends_styles_1 = require("../components/Legends/Legends.styles");
8
+ function toImage(chartContainer, legendsToSvgCallback, isRTL, opts) {
9
+ if (isRTL === void 0) { isRTL = false; }
8
10
  if (opts === void 0) { opts = {}; }
9
11
  return new Promise(function (resolve, reject) {
10
12
  if (!chartContainer) {
@@ -12,7 +14,7 @@ function toImage(chartContainer, opts) {
12
14
  }
13
15
  try {
14
16
  var background = typeof opts.background === 'string' ? (0, index_1.resolveCSSVariables)(chartContainer, opts.background) : 'transparent';
15
- var svg = toSVG(chartContainer, background);
17
+ var svg = toSVG(chartContainer, legendsToSvgCallback, isRTL, background);
16
18
  var svgData = new XMLSerializer().serializeToString(svg.node);
17
19
  var svgDataUrl = 'data:image/svg+xml;base64,' + btoa(unescapePonyfill(encodeURIComponent(svgData)));
18
20
  svgToPng(svgDataUrl, {
@@ -31,7 +33,7 @@ function toImage(chartContainer, opts) {
31
33
  exports.toImage = toImage;
32
34
  var SVG_STYLE_PROPERTIES = ['display', 'fill', 'fill-opacity', 'opacity', 'stroke', 'stroke-width', 'transform'];
33
35
  var SVG_TEXT_STYLE_PROPERTIES = ['font-family', 'font-size', 'font-weight', 'text-anchor'];
34
- function toSVG(chartContainer, background) {
36
+ function toSVG(chartContainer, legendsToSvgCallback, isRTL, background) {
35
37
  var svg = chartContainer.querySelector('svg');
36
38
  if (!svg) {
37
39
  throw new Error('SVG not found');
@@ -44,17 +46,20 @@ function toSVG(chartContainer, background) {
44
46
  var clonedSvgElements = clonedSvg.node().getElementsByTagName('*');
45
47
  for (var i = 0; i < svgElements.length; i++) {
46
48
  if (svgElements[i].tagName.toLowerCase() === 'text') {
47
- copyStyle(tslib_1.__spreadArray(tslib_1.__spreadArray([], SVG_STYLE_PROPERTIES, true), SVG_TEXT_STYLE_PROPERTIES, true), svgElements[i], clonedSvgElements[i]);
49
+ (0, index_1.copyStyle)(tslib_1.__spreadArray(tslib_1.__spreadArray([], SVG_STYLE_PROPERTIES, true), SVG_TEXT_STYLE_PROPERTIES, true), svgElements[i], clonedSvgElements[i]);
48
50
  }
49
51
  else {
50
- copyStyle(SVG_STYLE_PROPERTIES, svgElements[i], clonedSvgElements[i]);
52
+ (0, index_1.copyStyle)(SVG_STYLE_PROPERTIES, svgElements[i], clonedSvgElements[i]);
51
53
  }
52
54
  }
53
55
  var _a = svg.getBoundingClientRect(), svgWidth = _a.width, svgHeight = _a.height;
54
- var legendGroup = cloneLegendsToSVG(chartContainer, svgWidth, svgHeight);
56
+ var legendGroup = typeof legendsToSvgCallback === 'function'
57
+ ? legendsToSvgCallback(svgWidth, isRTL)
58
+ : { node: null, width: 0, height: 0 };
55
59
  var w1 = Math.max(svgWidth, legendGroup.width);
56
60
  var h1 = svgHeight + legendGroup.height;
57
61
  if (legendGroup.node) {
62
+ (0, d3_selection_1.select)(legendGroup.node).attr('transform', "translate(0, ".concat(svgHeight, ")"));
58
63
  clonedSvg.append(function () { return legendGroup.node; });
59
64
  }
60
65
  clonedSvg
@@ -64,91 +69,102 @@ function toSVG(chartContainer, background) {
64
69
  .attr('width', w1)
65
70
  .attr('height', h1)
66
71
  .attr('fill', background);
67
- clonedSvg.attr('width', w1).attr('height', h1).attr('viewBox', "0 0 ".concat(w1, " ").concat(h1));
72
+ clonedSvg
73
+ .attr('width', w1)
74
+ .attr('height', h1)
75
+ .attr('viewBox', "0 0 ".concat(w1, " ").concat(h1))
76
+ .attr('direction', isRTL ? 'rtl' : 'ltr');
68
77
  return {
69
78
  node: clonedSvg.node(),
70
79
  width: w1,
71
80
  height: h1,
72
81
  };
73
82
  }
74
- var LEGEND_RECT_STYLE_PROPERTIES_MAP = {
75
- 'background-color': 'fill',
76
- 'border-color': 'stroke',
77
- };
78
83
  var LEGEND_TEXT_STYLE_PROPERTIES_MAP = {
79
84
  color: 'fill',
80
85
  'font-family': 'font-family',
81
86
  'font-size': 'font-size',
82
87
  'font-weight': 'font-weight',
83
- opacity: 'opacity',
84
88
  };
85
- function cloneLegendsToSVG(chartContainer, svgWidth, svgHeight) {
86
- var legendButtons = chartContainer.querySelectorAll("\n button[class^=\"legend-\"],\n [class^=\"legendContainer-\"] div[class^=\"overflowIndicationTextStyle-\"],\n [class^=\"legendsContainer-\"] div[class^=\"overflowIndicationTextStyle-\"]\n ");
87
- if (legendButtons.length === 0) {
89
+ function cloneLegendsToSVG(legends, svgWidth, config, legendContainer) {
90
+ if (legends.length === 0) {
88
91
  return {
89
92
  node: null,
90
93
  width: 0,
91
94
  height: 0,
92
95
  };
93
96
  }
97
+ var selectedLegends = config.selectedLegends, centerLegends = config.centerLegends, textClassName = config.textClassName, isRTL = config.isRTL;
94
98
  var legendGroup = (0, d3_selection_1.create)('svg:g');
95
- var legendX = 0;
96
- var legendY = 8;
99
+ var legendX = centerLegends ? 0 : Legends_styles_1.LEGEND_CONTAINER_MARGIN_START;
100
+ var legendY = Legends_styles_1.LEGEND_CONTAINER_MARGIN_TOP;
97
101
  var legendLine = [];
98
102
  var legendLines = [];
99
103
  var legendLineWidths = [];
104
+ var noLegendsSelected = Object.keys(selectedLegends).length === 0;
100
105
  var _loop_1 = function (i) {
101
- var legendWidth = legendButtons[i].getBoundingClientRect().width;
106
+ var textOffset = Legends_styles_1.LEGEND_PADDING + Legends_styles_1.LEGEND_SHAPE_SIZE + Legends_styles_1.LEGEND_SHAPE_MARGIN_END;
107
+ var legendText = (0, index_1.createMeasurementSpan)(legends[i].title, textClassName, legendContainer);
108
+ var legendWidth = textOffset + legendText.getBoundingClientRect().width + Legends_styles_1.LEGEND_PADDING;
102
109
  var legendItem = legendGroup.append('g');
103
- legendLine.push(legendItem);
110
+ legendLine.push({ elem: legendItem, width: legendWidth });
104
111
  if (legendX + legendWidth > svgWidth && legendLine.length > 1) {
105
112
  legendLine.pop();
106
113
  legendLines.push(legendLine);
107
114
  legendLineWidths.push(legendX);
108
- legendLine = [legendItem];
109
- legendX = 0;
110
- legendY += 32;
111
- }
112
- var legendText;
113
- var textOffset = 0;
114
- if (legendButtons[i].tagName.toLowerCase() === 'button') {
115
- var legendRect_1 = legendButtons[i].querySelector('[class^="rect"]');
116
- legendText = legendButtons[i].querySelector('[class^="text"]');
117
- legendItem
118
- .append('rect')
119
- .attr('x', legendX + 8)
120
- .attr('y', svgHeight + legendY + 8)
121
- .attr('width', 12)
122
- .attr('height', 12)
123
- .attr('stroke-width', 1)
124
- .call(function (selection) { return copyStyle(LEGEND_RECT_STYLE_PROPERTIES_MAP, legendRect_1, selection.node()); });
125
- textOffset = 28;
126
- }
127
- else {
128
- legendText = legendButtons[i];
129
- textOffset = 8;
115
+ legendLine = [{ elem: legendItem, width: legendWidth }];
116
+ legendX = centerLegends ? 0 : Legends_styles_1.LEGEND_CONTAINER_MARGIN_START;
117
+ legendY += Legends_styles_1.LEGEND_HEIGHT;
130
118
  }
119
+ var isLegendActive = selectedLegends[legends[i].title] || noLegendsSelected;
120
+ legendItem
121
+ .append('rect')
122
+ .attr('x', legendX + (isRTL ? legendWidth - Legends_styles_1.LEGEND_PADDING - Legends_styles_1.LEGEND_SHAPE_SIZE : Legends_styles_1.LEGEND_PADDING))
123
+ .attr('y', legendY + Legends_styles_1.LEGEND_PADDING)
124
+ .attr('width', Legends_styles_1.LEGEND_SHAPE_SIZE)
125
+ .attr('height', Legends_styles_1.LEGEND_SHAPE_SIZE)
126
+ .style('fill', isLegendActive ? legends[i].color : 'transparent')
127
+ .style('stroke-width', Legends_styles_1.LEGEND_SHAPE_BORDER)
128
+ .style('stroke', legends[i].color);
131
129
  legendItem
132
130
  .append('text')
133
- .attr('x', legendX + textOffset)
134
- .attr('y', svgHeight + legendY + 8)
131
+ .attr('x', legendX + (isRTL ? legendWidth - textOffset : textOffset))
132
+ .attr('y', legendY + Legends_styles_1.LEGEND_PADDING)
135
133
  .attr('dominant-baseline', 'hanging')
136
- .text(legendText.textContent)
137
- .call(function (selection) { return copyStyle(LEGEND_TEXT_STYLE_PROPERTIES_MAP, legendText, selection.node()); });
134
+ .style('opacity', isLegendActive ? 1 : Legends_styles_1.INACTIVE_LEGEND_TEXT_OPACITY)
135
+ .text(legends[i].title)
136
+ .call(function (selection) { return (0, index_1.copyStyle)(LEGEND_TEXT_STYLE_PROPERTIES_MAP, legendText, selection.node()); });
138
137
  legendX += legendWidth;
139
138
  };
140
- for (var i = 0; i < legendButtons.length; i++) {
139
+ for (var i = 0; i < legends.length; i++) {
141
140
  _loop_1(i);
142
141
  }
143
142
  legendLines.push(legendLine);
144
143
  legendLineWidths.push(legendX);
145
- legendY += 32;
146
- var centerLegends = true;
144
+ legendY += Legends_styles_1.LEGEND_HEIGHT;
147
145
  if (centerLegends) {
148
146
  legendLines.forEach(function (ln, idx) {
149
- var offsetX = Math.max((svgWidth - legendLineWidths[idx]) / 2, 0);
147
+ var lineOffsetX = Math.max((svgWidth - legendLineWidths[idx]) / 2, 0);
148
+ var remLineWidth = legendLineWidths[idx];
149
+ var itemOffsetX = 0;
150
150
  ln.forEach(function (item) {
151
- item.attr('transform', "translate(".concat(offsetX, ", 0)"));
151
+ var newOffsetX = lineOffsetX + (isRTL ? remLineWidth - item.width - itemOffsetX : 0);
152
+ item.elem.attr('transform', "translate(".concat(newOffsetX, ", 0)"));
153
+ remLineWidth -= item.width;
154
+ itemOffsetX += item.width;
155
+ });
156
+ });
157
+ }
158
+ else if (isRTL) {
159
+ var w1_1 = Math.max.apply(Math, tslib_1.__spreadArray([svgWidth], legendLineWidths, false));
160
+ legendLines.forEach(function (ln) {
161
+ var remLineWidth = w1_1 - Legends_styles_1.LEGEND_CONTAINER_MARGIN_START;
162
+ var itemOffsetX = Legends_styles_1.LEGEND_CONTAINER_MARGIN_START;
163
+ ln.forEach(function (item) {
164
+ var newOffsetX = remLineWidth - item.width - itemOffsetX;
165
+ item.elem.attr('transform', "translate(".concat(newOffsetX, ", 0)"));
166
+ remLineWidth -= item.width;
167
+ itemOffsetX += item.width;
152
168
  });
153
169
  });
154
170
  }
@@ -158,6 +174,7 @@ function cloneLegendsToSVG(chartContainer, svgWidth, svgHeight) {
158
174
  height: legendY,
159
175
  };
160
176
  }
177
+ exports.cloneLegendsToSVG = cloneLegendsToSVG;
161
178
  function svgToPng(svgDataUrl, opts) {
162
179
  if (opts === void 0) { opts = {}; }
163
180
  return new Promise(function (resolve, reject) {
@@ -223,18 +240,4 @@ function unescapePonyfill(str) {
223
240
  }
224
241
  return result;
225
242
  }
226
- function copyStyle(properties, fromEl, toEl) {
227
- var styles = getComputedStyle(fromEl);
228
- if (Array.isArray(properties)) {
229
- properties.forEach(function (prop) {
230
- (0, d3_selection_1.select)(toEl).style(prop, styles.getPropertyValue(prop));
231
- });
232
- }
233
- else {
234
- Object.entries(properties).forEach(function (_a) {
235
- var fromProp = _a[0], toProp = _a[1];
236
- (0, d3_selection_1.select)(toEl).style(toProp, styles.getPropertyValue(fromProp));
237
- });
238
- }
239
- }
240
- //# sourceMappingURL=imageExporter.js.map
243
+ //# 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":";;;;AAAA,6CAAiF;AACjF,iCAAgF;AAGhF,uEAS8C;AAE9C,SAAgB,OAAO,CACrB,cAA8C,EAC9C,oBAAgD,EAChD,KAAsB,EACtB,IAA8B;IAD9B,sBAAA,EAAA,aAAsB;IACtB,qBAAA,EAAA,SAA8B;IAE9B,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QACjC,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC,CAAC;QAC7D,CAAC;QAED,IAAI,CAAC;YACH,IAAM,UAAU,GACd,OAAO,IAAI,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAA,2BAAmB,EAAC,cAAc,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;YAC7G,IAAM,GAAG,GAAG,KAAK,CAAC,cAAc,EAAE,oBAAoB,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;YAE3E,IAAM,OAAO,GAAG,IAAI,aAAa,EAAE,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAChE,IAAM,UAAU,GAAG,4BAA4B,GAAG,IAAI,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAEtG,QAAQ,CAAC,UAAU,EAAE;gBACnB,KAAK,EAAE,IAAI,CAAC,KAAK,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C,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;oBAClD,KAAK,IAAI,CAAC,CAAC;oBACX,SAAS;gBACX,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;gBACnC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;oBACpB,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;oBAClD,KAAK,IAAI,CAAC,CAAC;oBACX,SAAS;gBACX,CAAC;YACH,CAAC;QACH,CAAC;QACD,MAAM,IAAI,GAAG,CAAC;IAChB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,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,7 +1,7 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- 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;
4
+ 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;
5
5
  var tslib_1 = require("tslib");
6
6
  var d3_axis_1 = require("d3-axis");
7
7
  var d3_array_1 = require("d3-array");
@@ -11,6 +11,7 @@ var d3_format_1 = require("d3-format");
11
11
  var d3_time_format_1 = require("d3-time-format");
12
12
  var d3_time_1 = require("d3-time");
13
13
  var d3_format_2 = require("d3-format");
14
+ var react_1 = require("@fluentui/react");
14
15
  var ChartTypes;
15
16
  (function (ChartTypes) {
16
17
  ChartTypes[ChartTypes["AreaChart"] = 0] = "AreaChart";
@@ -1220,4 +1221,49 @@ function resolveCSSVariables(chartContainer, styleRules) {
1220
1221
  });
1221
1222
  }
1222
1223
  exports.resolveCSSVariables = resolveCSSVariables;
1224
+ function copyStyle(properties, fromEl, toEl) {
1225
+ var styles = getComputedStyle(fromEl);
1226
+ if (Array.isArray(properties)) {
1227
+ properties.forEach(function (prop) {
1228
+ (0, d3_selection_1.select)(toEl).style(prop, styles.getPropertyValue(prop));
1229
+ });
1230
+ }
1231
+ else {
1232
+ Object.entries(properties).forEach(function (_a) {
1233
+ var fromProp = _a[0], toProp = _a[1];
1234
+ (0, d3_selection_1.select)(toEl).style(toProp, styles.getPropertyValue(fromProp));
1235
+ });
1236
+ }
1237
+ }
1238
+ exports.copyStyle = copyStyle;
1239
+ var MEASUREMENT_SPAN_STYLE = {
1240
+ position: 'absolute',
1241
+ visibility: 'hidden',
1242
+ top: '-20000px',
1243
+ left: 0,
1244
+ padding: 0,
1245
+ margin: 0,
1246
+ border: 'none',
1247
+ whiteSpace: 'pre',
1248
+ };
1249
+ var MEASUREMENT_SPAN_ID = (0, react_1.getId)('measurement_span_');
1250
+ var createMeasurementSpan = function (text, className, parentElement) {
1251
+ var measurementSpan = document.getElementById(MEASUREMENT_SPAN_ID);
1252
+ if (!measurementSpan) {
1253
+ measurementSpan = document.createElement('span');
1254
+ measurementSpan.setAttribute('id', MEASUREMENT_SPAN_ID);
1255
+ measurementSpan.setAttribute('aria-hidden', 'true');
1256
+ if (parentElement) {
1257
+ parentElement.appendChild(measurementSpan);
1258
+ }
1259
+ else {
1260
+ document.body.appendChild(measurementSpan);
1261
+ }
1262
+ }
1263
+ measurementSpan.setAttribute('class', className);
1264
+ Object.assign(measurementSpan.style, MEASUREMENT_SPAN_STYLE);
1265
+ measurementSpan.textContent = "".concat(text);
1266
+ return measurementSpan;
1267
+ };
1268
+ exports.createMeasurementSpan = createMeasurementSpan;
1223
1269
  //# sourceMappingURL=utilities.js.map