@semcore/d3-chart 3.60.0 → 3.60.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 (214) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/lib/cjs/Area.js +14 -12
  3. package/lib/cjs/Area.js.map +1 -1
  4. package/lib/cjs/Axis.js +17 -15
  5. package/lib/cjs/Axis.js.map +1 -1
  6. package/lib/cjs/Bar.js +19 -17
  7. package/lib/cjs/Bar.js.map +1 -1
  8. package/lib/cjs/Bubble.js +15 -13
  9. package/lib/cjs/Bubble.js.map +1 -1
  10. package/lib/cjs/CompactHorizontalBar.js +19 -17
  11. package/lib/cjs/CompactHorizontalBar.js.map +1 -1
  12. package/lib/cjs/Donut.js +12 -10
  13. package/lib/cjs/Donut.js.map +1 -1
  14. package/lib/cjs/Dots.js +11 -9
  15. package/lib/cjs/Dots.js.map +1 -1
  16. package/lib/cjs/HorizontalBar.js +19 -17
  17. package/lib/cjs/HorizontalBar.js.map +1 -1
  18. package/lib/cjs/Hover.js +6 -4
  19. package/lib/cjs/Hover.js.map +1 -1
  20. package/lib/cjs/Line.js +12 -10
  21. package/lib/cjs/Line.js.map +1 -1
  22. package/lib/cjs/Plot.js +6 -4
  23. package/lib/cjs/Plot.js.map +1 -1
  24. package/lib/cjs/Radar.js +22 -20
  25. package/lib/cjs/Radar.js.map +1 -1
  26. package/lib/cjs/RadialTree.js +15 -13
  27. package/lib/cjs/RadialTree.js.map +1 -1
  28. package/lib/cjs/Reference.js +15 -13
  29. package/lib/cjs/Reference.js.map +1 -1
  30. package/lib/cjs/ScatterPlot.js +12 -10
  31. package/lib/cjs/ScatterPlot.js.map +1 -1
  32. package/lib/cjs/Tooltip.js +12 -10
  33. package/lib/cjs/Tooltip.js.map +1 -1
  34. package/lib/cjs/Venn.js +12 -10
  35. package/lib/cjs/Venn.js.map +1 -1
  36. package/lib/cjs/a11y/PlotA11yModule.js +5 -3
  37. package/lib/cjs/a11y/PlotA11yModule.js.map +1 -1
  38. package/lib/cjs/a11y/PlotA11yView.js +5 -3
  39. package/lib/cjs/a11y/PlotA11yView.js.map +1 -1
  40. package/lib/cjs/component/ChartLegend/LegendFlex/LegendFlex.js +7 -5
  41. package/lib/cjs/component/ChartLegend/LegendFlex/LegendFlex.js.map +1 -1
  42. package/lib/cjs/component/ChartLegend/LegendItem/LegendItem.js +20 -18
  43. package/lib/cjs/component/ChartLegend/LegendItem/LegendItem.js.map +1 -1
  44. package/lib/cjs/component/ChartLegend/LegendTable/LegendTable.js +9 -7
  45. package/lib/cjs/component/ChartLegend/LegendTable/LegendTable.js.map +1 -1
  46. package/lib/es6/Area.js +14 -12
  47. package/lib/es6/Area.js.map +1 -1
  48. package/lib/es6/Axis.js +17 -15
  49. package/lib/es6/Axis.js.map +1 -1
  50. package/lib/es6/Bar.js +19 -17
  51. package/lib/es6/Bar.js.map +1 -1
  52. package/lib/es6/Bubble.js +15 -13
  53. package/lib/es6/Bubble.js.map +1 -1
  54. package/lib/es6/CompactHorizontalBar.js +19 -17
  55. package/lib/es6/CompactHorizontalBar.js.map +1 -1
  56. package/lib/es6/Donut.js +12 -10
  57. package/lib/es6/Donut.js.map +1 -1
  58. package/lib/es6/Dots.js +11 -9
  59. package/lib/es6/Dots.js.map +1 -1
  60. package/lib/es6/HorizontalBar.js +19 -17
  61. package/lib/es6/HorizontalBar.js.map +1 -1
  62. package/lib/es6/Hover.js +6 -4
  63. package/lib/es6/Hover.js.map +1 -1
  64. package/lib/es6/Line.js +12 -10
  65. package/lib/es6/Line.js.map +1 -1
  66. package/lib/es6/Plot.js +6 -4
  67. package/lib/es6/Plot.js.map +1 -1
  68. package/lib/es6/Radar.js +22 -20
  69. package/lib/es6/Radar.js.map +1 -1
  70. package/lib/es6/RadialTree.js +15 -13
  71. package/lib/es6/RadialTree.js.map +1 -1
  72. package/lib/es6/Reference.js +15 -13
  73. package/lib/es6/Reference.js.map +1 -1
  74. package/lib/es6/ScatterPlot.js +12 -10
  75. package/lib/es6/ScatterPlot.js.map +1 -1
  76. package/lib/es6/Tooltip.js +12 -10
  77. package/lib/es6/Tooltip.js.map +1 -1
  78. package/lib/es6/Venn.js +12 -10
  79. package/lib/es6/Venn.js.map +1 -1
  80. package/lib/es6/a11y/PlotA11yModule.js +5 -3
  81. package/lib/es6/a11y/PlotA11yModule.js.map +1 -1
  82. package/lib/es6/a11y/PlotA11yView.js +5 -3
  83. package/lib/es6/a11y/PlotA11yView.js.map +1 -1
  84. package/lib/es6/component/ChartLegend/LegendFlex/LegendFlex.js +7 -5
  85. package/lib/es6/component/ChartLegend/LegendFlex/LegendFlex.js.map +1 -1
  86. package/lib/es6/component/ChartLegend/LegendItem/LegendItem.js +20 -18
  87. package/lib/es6/component/ChartLegend/LegendItem/LegendItem.js.map +1 -1
  88. package/lib/es6/component/ChartLegend/LegendTable/LegendTable.js +9 -7
  89. package/lib/es6/component/ChartLegend/LegendTable/LegendTable.js.map +1 -1
  90. package/lib/esm/AnimatedClipPath.mjs +54 -0
  91. package/lib/esm/Area.mjs +189 -0
  92. package/lib/esm/Axis.mjs +406 -0
  93. package/lib/esm/Bar.mjs +201 -0
  94. package/lib/esm/Bubble.mjs +216 -0
  95. package/lib/esm/CompactHorizontalBar.mjs +518 -0
  96. package/lib/esm/Donut.mjs +415 -0
  97. package/lib/esm/Dots.mjs +120 -0
  98. package/lib/esm/GroupBar.mjs +94 -0
  99. package/lib/esm/HorizontalBar.mjs +181 -0
  100. package/lib/esm/Hover.mjs +217 -0
  101. package/lib/esm/Line.mjs +199 -0
  102. package/lib/esm/Pattern.mjs +520 -0
  103. package/lib/esm/Plot.mjs +137 -0
  104. package/lib/esm/Radar.mjs +706 -0
  105. package/lib/esm/RadialTree.mjs +565 -0
  106. package/lib/esm/Reference.mjs +243 -0
  107. package/lib/esm/ResponsiveContainer.mjs +99 -0
  108. package/lib/esm/ScatterPlot.mjs +194 -0
  109. package/lib/esm/StackBar.mjs +177 -0
  110. package/lib/esm/StackedArea.mjs +84 -0
  111. package/lib/esm/Tooltip.mjs +255 -0
  112. package/lib/esm/Venn.mjs +234 -0
  113. package/lib/esm/a11y/DataAccessibilityTable.mjs +100 -0
  114. package/lib/esm/a11y/PlotA11yModule.mjs +117 -0
  115. package/lib/esm/a11y/PlotA11yView.mjs +146 -0
  116. package/lib/esm/a11y/bezier.mjs +32 -0
  117. package/lib/esm/a11y/focus.mjs +44 -0
  118. package/lib/esm/a11y/hints.mjs +122 -0
  119. package/lib/esm/a11y/insights.mjs +700 -0
  120. package/lib/esm/a11y/intl.mjs +17 -0
  121. package/lib/esm/a11y/locale.mjs +39 -0
  122. package/lib/esm/a11y/serialize.mjs +363 -0
  123. package/lib/esm/a11y/summarize.mjs +14 -0
  124. package/lib/esm/a11y/translations/module/__intergalactic-dynamic-locales.mjs +33 -0
  125. package/lib/esm/a11y/translations/module/de.json.mjs +14 -0
  126. package/lib/esm/a11y/translations/module/en.json.mjs +14 -0
  127. package/lib/esm/a11y/translations/module/es.json.mjs +14 -0
  128. package/lib/esm/a11y/translations/module/fr.json.mjs +14 -0
  129. package/lib/esm/a11y/translations/module/it.json.mjs +14 -0
  130. package/lib/esm/a11y/translations/module/ja.json.mjs +14 -0
  131. package/lib/esm/a11y/translations/module/ko.json.mjs +14 -0
  132. package/lib/esm/a11y/translations/module/nl.json.mjs +14 -0
  133. package/lib/esm/a11y/translations/module/pl.json.mjs +14 -0
  134. package/lib/esm/a11y/translations/module/pt.json.mjs +14 -0
  135. package/lib/esm/a11y/translations/module/sv.json.mjs +14 -0
  136. package/lib/esm/a11y/translations/module/tr.json.mjs +14 -0
  137. package/lib/esm/a11y/translations/module/vi.json.mjs +14 -0
  138. package/lib/esm/a11y/translations/module/zh.json.mjs +14 -0
  139. package/lib/esm/a11y/translations/view/__intergalactic-dynamic-locales.mjs +33 -0
  140. package/lib/esm/a11y/translations/view/de.json.mjs +48 -0
  141. package/lib/esm/a11y/translations/view/en.json.mjs +48 -0
  142. package/lib/esm/a11y/translations/view/es.json.mjs +48 -0
  143. package/lib/esm/a11y/translations/view/fr.json.mjs +48 -0
  144. package/lib/esm/a11y/translations/view/it.json.mjs +48 -0
  145. package/lib/esm/a11y/translations/view/ja.json.mjs +48 -0
  146. package/lib/esm/a11y/translations/view/ko.json.mjs +48 -0
  147. package/lib/esm/a11y/translations/view/nl.json.mjs +48 -0
  148. package/lib/esm/a11y/translations/view/pl.json.mjs +48 -0
  149. package/lib/esm/a11y/translations/view/pt.json.mjs +48 -0
  150. package/lib/esm/a11y/translations/view/sv.json.mjs +48 -0
  151. package/lib/esm/a11y/translations/view/tr.json.mjs +48 -0
  152. package/lib/esm/a11y/translations/view/vi.json.mjs +48 -0
  153. package/lib/esm/a11y/translations/view/zh.json.mjs +48 -0
  154. package/lib/esm/color.mjs +127 -0
  155. package/lib/esm/component/Chart/AbstractChart.mjs +408 -0
  156. package/lib/esm/component/Chart/AreaChart.mjs +145 -0
  157. package/lib/esm/component/Chart/BarChart.mjs +240 -0
  158. package/lib/esm/component/Chart/BubbleChart.mjs +135 -0
  159. package/lib/esm/component/Chart/CigaretteChart.mjs +294 -0
  160. package/lib/esm/component/Chart/CompactHorizontalBarChart.mjs +113 -0
  161. package/lib/esm/component/Chart/DonutChart.mjs +113 -0
  162. package/lib/esm/component/Chart/HistogramChart.mjs +166 -0
  163. package/lib/esm/component/Chart/LineChart.mjs +131 -0
  164. package/lib/esm/component/Chart/RadarChart.mjs +115 -0
  165. package/lib/esm/component/Chart/ScatterPlotChart.mjs +144 -0
  166. package/lib/esm/component/Chart/VennChart.mjs +141 -0
  167. package/lib/esm/component/Chart/index.mjs +27 -0
  168. package/lib/esm/component/ChartLegend/BaseLegend.mjs +91 -0
  169. package/lib/esm/component/ChartLegend/LegendFlex/LegendFlex.mjs +86 -0
  170. package/lib/esm/component/ChartLegend/LegendFlex/legend-flex.shadow.css +12 -0
  171. package/lib/esm/component/ChartLegend/LegendItem/LegendItem.mjs +240 -0
  172. package/lib/esm/component/ChartLegend/LegendItem/LegendItem.type.mjs +4 -0
  173. package/lib/esm/component/ChartLegend/LegendItem/legend-item.shadow.css +129 -0
  174. package/lib/esm/component/ChartLegend/LegendTable/LegendTable.mjs +90 -0
  175. package/lib/esm/component/ChartLegend/LegendTable/legend-table.shadow.css +19 -0
  176. package/lib/esm/component/ChartLegend/index.mjs +5 -0
  177. package/lib/esm/component/Cigarette/Cigarette.mjs +139 -0
  178. package/lib/esm/component/StackGroupBar/StackGroupBar.mjs +141 -0
  179. package/lib/esm/createElement.mjs +104 -0
  180. package/lib/esm/index.mjs +70 -0
  181. package/lib/esm/style/area.shadow.css +50 -0
  182. package/lib/esm/style/axis.shadow.css +88 -0
  183. package/lib/esm/style/bar.shadow.css +66 -0
  184. package/lib/esm/style/bubble.shadow.css +64 -0
  185. package/lib/esm/style/donut.shadow.css +36 -0
  186. package/lib/esm/style/dot.shadow.css +27 -0
  187. package/lib/esm/style/hover.shadow.css +9 -0
  188. package/lib/esm/style/line.shadow.css +43 -0
  189. package/lib/esm/style/plot.shadow.css +19 -0
  190. package/lib/esm/style/plotA11yModule.shadow.css +12 -0
  191. package/lib/esm/style/plotA11yView.shadow.css +39 -0
  192. package/lib/esm/style/radar.shadow.css +80 -0
  193. package/lib/esm/style/radial-tree.shadow.css +54 -0
  194. package/lib/esm/style/reference.shadow.css +43 -0
  195. package/lib/esm/style/scatterplot.shadow.css +41 -0
  196. package/lib/esm/style/tooltip.shadow.css +42 -0
  197. package/lib/esm/style/venn.shadow.css +48 -0
  198. package/lib/esm/translations/__intergalactic-dynamic-locales.mjs +31 -0
  199. package/lib/esm/translations/en.json.mjs +12 -0
  200. package/lib/esm/translations/es.json.mjs +11 -0
  201. package/lib/esm/translations/fr.json.mjs +11 -0
  202. package/lib/esm/translations/it.json.mjs +11 -0
  203. package/lib/esm/translations/ja.json.mjs +11 -0
  204. package/lib/esm/translations/ko.json.mjs +11 -0
  205. package/lib/esm/translations/nl.json.mjs +11 -0
  206. package/lib/esm/translations/pl.json.mjs +11 -0
  207. package/lib/esm/translations/pt.json.mjs +11 -0
  208. package/lib/esm/translations/sv.json.mjs +11 -0
  209. package/lib/esm/translations/tr.json.mjs +11 -0
  210. package/lib/esm/translations/vi.json.mjs +11 -0
  211. package/lib/esm/translations/zh.json.mjs +11 -0
  212. package/lib/esm/utils.mjs +266 -0
  213. package/package.json +11 -11
  214. package/vite.config.ts +2 -0
@@ -0,0 +1,408 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
5
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
6
+ import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
7
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
8
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
9
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
10
+ import { sstyled, assignProps, Component } from "@semcore/core";
11
+ import { makeDataHintsContainer } from "../../a11y/hints.mjs";
12
+ import { interpolateValue } from "../../utils.mjs";
13
+ import React from "react";
14
+ import { callAllEventHandlers } from "@semcore/utils/lib/assignProps";
15
+ import { LegendFlex } from "../ChartLegend/LegendFlex/LegendFlex.mjs";
16
+ import { LegendTable } from "../ChartLegend/LegendTable/LegendTable.mjs";
17
+ import { Flex } from "@semcore/flex-box";
18
+ import Plot from "../../Plot.mjs";
19
+ import { YAxis, XAxis } from "../../Axis.mjs";
20
+ import { Text } from "@semcore/typography";
21
+ import { extractAriaProps } from "@semcore/utils/lib/ariaProps";
22
+ var AbstractChart = /* @__PURE__ */ function(_Component) {
23
+ _inherits(AbstractChart2, _Component);
24
+ var _super = _createSuper(AbstractChart2);
25
+ function AbstractChart2(props) {
26
+ var _this;
27
+ _classCallCheck(this, AbstractChart2);
28
+ _this = _super.call(this, props);
29
+ _defineProperty(_assertThisInitialized(_this), "plotPadding", 6);
30
+ _defineProperty(_assertThisInitialized(_this), "dataHints", makeDataHintsContainer());
31
+ _defineProperty(_assertThisInitialized(_this), "state", {
32
+ dataDefinitions: _this.getDefaultDataDefinitions(),
33
+ highlightedLine: -1,
34
+ withTrend: false
35
+ });
36
+ _this.setHighlightedLine = _this.setHighlightedLine.bind(_assertThisInitialized(_this));
37
+ _this.handleChangeVisible = _this.handleChangeVisible.bind(_assertThisInitialized(_this));
38
+ _this.handleMouseEnter = _this.handleMouseEnter.bind(_assertThisInitialized(_this));
39
+ _this.handleMouseLeave = _this.handleMouseLeave.bind(_assertThisInitialized(_this));
40
+ _this.resolveColor = _this.resolveColor.bind(_assertThisInitialized(_this));
41
+ _this.tooltipValueFormatter = _this.tooltipValueFormatter.bind(_assertThisInitialized(_this));
42
+ _this.handleWithTrendChange = _this.handleWithTrendChange.bind(_assertThisInitialized(_this));
43
+ return _this;
44
+ }
45
+ _createClass(AbstractChart2, [{
46
+ key: "componentDidUpdate",
47
+ value: function componentDidUpdate(prevProps) {
48
+ if (prevProps.data !== this.props.data || prevProps.legendProps !== this.props.legendProps) {
49
+ this.setState({
50
+ dataDefinitions: this.getDefaultDataDefinitions()
51
+ });
52
+ }
53
+ }
54
+ }, {
55
+ key: "getDefaultDataDefinitions",
56
+ value: function getDefaultDataDefinitions() {
57
+ var _this2 = this;
58
+ var _this$props = this.props, data = _this$props.data, legendProps = _this$props.legendProps;
59
+ return this.dataKeys.map(function(key, index) {
60
+ var _legendProps$legendMa, _legendData$label, _legendData$icon, _legendData$defaultCh;
61
+ var legendData = legendProps === null || legendProps === void 0 ? void 0 : (_legendProps$legendMa = legendProps.legendMap) === null || _legendProps$legendMa === void 0 ? void 0 : _legendProps$legendMa[key];
62
+ var dataDefinition = {
63
+ id: key,
64
+ label: (_legendData$label = legendData === null || legendData === void 0 ? void 0 : legendData.label) !== null && _legendData$label !== void 0 ? _legendData$label : key,
65
+ icon: (_legendData$icon = legendData === null || legendData === void 0 ? void 0 : legendData.icon) !== null && _legendData$icon !== void 0 ? _legendData$icon : void 0,
66
+ checked: (_legendData$defaultCh = legendData === null || legendData === void 0 ? void 0 : legendData.defaultChecked) !== null && _legendData$defaultCh !== void 0 ? _legendData$defaultCh : true,
67
+ color: _this2.resolveColor(key, index),
68
+ columns: []
69
+ };
70
+ if (legendData !== null && legendData !== void 0 && legendData.additionalInfo || legendData !== null && legendData !== void 0 && legendData.count) {
71
+ dataDefinition.additionalInfo = legendData.additionalInfo ? {
72
+ label: legendData.additionalInfo
73
+ } : legendData.count ? {
74
+ count: legendData.count
75
+ } : void 0;
76
+ }
77
+ if (legendData && "columns" in legendData) {
78
+ dataDefinition.columns = legendData.columns || [];
79
+ } else if (!Array.isArray(data)) {
80
+ var _value;
81
+ var value = void 0;
82
+ var dataValue = data[key];
83
+ if (data instanceof Map) {
84
+ dataValue = data.get(key);
85
+ }
86
+ if (dataValue !== interpolateValue) {
87
+ value = Number(dataValue);
88
+ }
89
+ var total = Object.values(data).reduce(function(sum, i) {
90
+ if (i !== interpolateValue) {
91
+ return sum + Number(i);
92
+ }
93
+ return sum;
94
+ }, 0);
95
+ var percent = value !== void 0 ? (value / total * 100).toFixed(2) : void 0;
96
+ dataDefinition.columns = [/* @__PURE__ */ React.createElement(Text, {
97
+ key: "".concat(key, "_percent"),
98
+ use: "secondary"
99
+ }, percent !== void 0 ? "".concat(percent, "%") : ""), /* @__PURE__ */ React.createElement(Text, {
100
+ key: "".concat(key, "_value"),
101
+ use: value ? "primary" : "secondary"
102
+ }, (_value = value) !== null && _value !== void 0 ? _value : "n/a")];
103
+ }
104
+ return dataDefinition;
105
+ });
106
+ }
107
+ }, {
108
+ key: "dataKeys",
109
+ get: function get() {
110
+ var _this$props2 = this.props, data = _this$props2.data, groupKey = _this$props2.groupKey;
111
+ var dataKeys;
112
+ if (Array.isArray(data) && groupKey) {
113
+ dataKeys = Object.keys(data[0]).filter(function(key) {
114
+ return key !== groupKey;
115
+ });
116
+ } else {
117
+ dataKeys = Object.keys(data);
118
+ }
119
+ return dataKeys;
120
+ }
121
+ }, {
122
+ key: "xTicks",
123
+ get: function get() {
124
+ var _this$asProps = this.asProps, data = _this$asProps.data, invertAxis = _this$asProps.invertAxis, xTicksCount = _this$asProps.xTicksCount, yTicksCount = _this$asProps.yTicksCount;
125
+ var scale = this.xScale;
126
+ if (Array.isArray(data) && "ticks" in scale) {
127
+ if (invertAxis && yTicksCount) {
128
+ return scale.ticks(yTicksCount);
129
+ } else if (xTicksCount) {
130
+ return scale.ticks(xTicksCount);
131
+ }
132
+ return void 0;
133
+ }
134
+ return void 0;
135
+ }
136
+ }, {
137
+ key: "yTicks",
138
+ get: function get() {
139
+ var _this$asProps2 = this.asProps, data = _this$asProps2.data, invertAxis = _this$asProps2.invertAxis, xTicksCount = _this$asProps2.xTicksCount, yTicksCount = _this$asProps2.yTicksCount;
140
+ var scale = this.yScale;
141
+ if (Array.isArray(data) && "ticks" in scale) {
142
+ if (invertAxis && xTicksCount) {
143
+ return scale.ticks(xTicksCount);
144
+ } else if (yTicksCount) {
145
+ return scale.ticks(yTicksCount);
146
+ }
147
+ return void 0;
148
+ }
149
+ return void 0;
150
+ }
151
+ }, {
152
+ key: "flatValues",
153
+ get: function get() {
154
+ var _this$asProps3 = this.asProps, data = _this$asProps3.data, groupKey = _this$asProps3.groupKey;
155
+ var values = Array.isArray(data) ? data : Object.values(data);
156
+ var flatValues = values.reduce(function(result, item) {
157
+ if (!groupKey && typeof item === "number") {
158
+ result.add(item);
159
+ } else {
160
+ Object.entries(item).forEach(function(_ref3) {
161
+ var _ref4 = _slicedToArray(_ref3, 2), key = _ref4[0], value = _ref4[1];
162
+ if (key !== groupKey && typeof value === "number") {
163
+ result.add(value);
164
+ }
165
+ });
166
+ }
167
+ return result;
168
+ }, /* @__PURE__ */ new Set());
169
+ return flatValues;
170
+ }
171
+ }, {
172
+ key: "maxStackedValue",
173
+ get: function get() {
174
+ var _this$asProps4 = this.asProps, data = _this$asProps4.data, groupKey = _this$asProps4.groupKey;
175
+ if (!Array.isArray(data)) {
176
+ var _max = Object.values(data).reduce(function(sum, val) {
177
+ if (typeof val === "number") {
178
+ sum = sum + val;
179
+ }
180
+ return sum;
181
+ }, 0);
182
+ return _max;
183
+ }
184
+ var max = data.reduce(function(max2, item) {
185
+ var barSum = Object.entries(item).reduce(function(sum, _ref5) {
186
+ var _ref6 = _slicedToArray(_ref5, 2), key = _ref6[0], val = _ref6[1];
187
+ if (key === groupKey) {
188
+ return sum;
189
+ }
190
+ if (typeof val === "number") {
191
+ return sum + val;
192
+ }
193
+ if (val instanceof Date && !Number.isNaN(val.getMilliseconds())) {
194
+ return sum + val.getMilliseconds();
195
+ }
196
+ return sum;
197
+ }, 0);
198
+ if (barSum > max2) {
199
+ max2 = barSum;
200
+ }
201
+ return max2;
202
+ }, 0);
203
+ return max;
204
+ }
205
+ }, {
206
+ key: "totalValue",
207
+ value: function totalValue(data) {
208
+ var dataDefinitions = this.state.dataDefinitions;
209
+ var total = dataDefinitions.reduce(function(sum, legendItem) {
210
+ var item = data[legendItem.id];
211
+ if (typeof item === "number") {
212
+ return sum + item;
213
+ }
214
+ if (item instanceof Date && !Number.isNaN(item.getMilliseconds())) {
215
+ return sum + item.getMilliseconds();
216
+ }
217
+ return sum;
218
+ }, 0);
219
+ return total;
220
+ }
221
+ }, {
222
+ key: "getValueScale",
223
+ value: function getValueScale(values) {
224
+ var max = Math.max.apply(Math, _toConsumableArray(values));
225
+ var min = Math.min.apply(Math, _toConsumableArray(values));
226
+ var avg = (max + min) / 2;
227
+ var count = Math.round(Math.log10(avg));
228
+ var valueScale = 100 / Math.pow(10, count);
229
+ return valueScale;
230
+ }
231
+ }, {
232
+ key: "setHighlightedLine",
233
+ value: function setHighlightedLine(index) {
234
+ this.setState({
235
+ highlightedLine: index
236
+ });
237
+ }
238
+ }, {
239
+ key: "handleChangeVisible",
240
+ value: function handleChangeVisible(id, isVisible) {
241
+ this.setState(function(prevState) {
242
+ var dataDefinitions = prevState.dataDefinitions.map(function(item) {
243
+ if (item.id === id) {
244
+ item.checked = isVisible;
245
+ }
246
+ return item;
247
+ });
248
+ return {
249
+ dataDefinitions
250
+ };
251
+ });
252
+ }
253
+ }, {
254
+ key: "handleWithTrendChange",
255
+ value: function handleWithTrendChange(isVisible) {
256
+ this.setState({
257
+ withTrend: isVisible
258
+ });
259
+ }
260
+ }, {
261
+ key: "handleMouseEnter",
262
+ value: function handleMouseEnter(id) {
263
+ this.setHighlightedLine(this.state.dataDefinitions.findIndex(function(line) {
264
+ return line.id === id;
265
+ }));
266
+ }
267
+ }, {
268
+ key: "handleMouseLeave",
269
+ value: function handleMouseLeave() {
270
+ this.setHighlightedLine(-1);
271
+ }
272
+ }, {
273
+ key: "resolveColor",
274
+ value: function resolveColor(id, index) {
275
+ var _this$props$colorMap$, _this$props$colorMap;
276
+ return (_this$props$colorMap$ = (_this$props$colorMap = this.props.colorMap) === null || _this$props$colorMap === void 0 ? void 0 : _this$props$colorMap[id]) !== null && _this$props$colorMap$ !== void 0 ? _this$props$colorMap$ : "chart-palette-order-".concat(index + 1);
277
+ }
278
+ }, {
279
+ key: "tooltipValueFormatter",
280
+ value: function tooltipValueFormatter(value) {
281
+ var tooltipValueFormatter2 = this.asProps.tooltipValueFormatter;
282
+ if (tooltipValueFormatter2) {
283
+ return tooltipValueFormatter2(value);
284
+ }
285
+ if (value === void 0 || value === interpolateValue) {
286
+ return "n/a";
287
+ }
288
+ if (value === null) {
289
+ return "0";
290
+ }
291
+ if (value instanceof Date) {
292
+ return value.toDateString();
293
+ }
294
+ return value.toString();
295
+ }
296
+ }, {
297
+ key: "defaultLegendProps",
298
+ value: function defaultLegendProps() {
299
+ return {
300
+ legendType: "Flex"
301
+ };
302
+ }
303
+ }, {
304
+ key: "renderLegend",
305
+ value: function renderLegend() {
306
+ var _lProps$direction;
307
+ var _this$asProps5 = this.asProps, legendProps = _this$asProps5.legendProps, direction = _this$asProps5.direction, showLegend = _this$asProps5.showLegend, patterns = _this$asProps5.patterns;
308
+ if (!showLegend || // we hide Legend for one item on chart except not manually set to show.
309
+ this.dataKeys.length === 1 && showLegend === true) {
310
+ return null;
311
+ }
312
+ var _this$state = this.state, dataDefinitions = _this$state.dataDefinitions, withTrend = _this$state.withTrend;
313
+ var lProps = _objectSpread(_objectSpread({}, this.defaultLegendProps()), legendProps);
314
+ var commonLegendProps = {
315
+ dataHints: this.dataHints,
316
+ items: dataDefinitions,
317
+ size: lProps.size,
318
+ shape: lProps.shape,
319
+ w: lProps.w,
320
+ h: lProps.h,
321
+ patterns,
322
+ direction: (_lProps$direction = lProps.direction) !== null && _lProps$direction !== void 0 ? _lProps$direction : direction === "row" || direction === "row-reverse" ? "column" : "row",
323
+ onChangeVisibleItem: lProps.disableSelectItems ? void 0 : callAllEventHandlers(lProps.onChangeVisibleItem, this.handleChangeVisible),
324
+ onMouseEnterItem: lProps.disableHoverItems ? void 0 : callAllEventHandlers(lProps.onMouseEnterItem, this.handleMouseEnter),
325
+ onMouseLeaveItem: lProps.disableHoverItems ? void 0 : callAllEventHandlers(lProps.onMouseLeaveItem, this.handleMouseLeave),
326
+ "aria-label": this.getLegendAriaLabel()
327
+ };
328
+ if (lProps.legendType === "Table") {
329
+ return /* @__PURE__ */ React.createElement(LegendTable, commonLegendProps);
330
+ }
331
+ if ("withTrend" in lProps) {
332
+ var flexLegendProps = _objectSpread(_objectSpread({}, commonLegendProps), {}, {
333
+ withTrend: true,
334
+ trendLabel: lProps.trendLabel,
335
+ trendIsVisible: withTrend,
336
+ onTrendIsVisibleChange: this.handleWithTrendChange
337
+ });
338
+ return /* @__PURE__ */ React.createElement(LegendFlex, flexLegendProps);
339
+ }
340
+ return /* @__PURE__ */ React.createElement(LegendFlex, commonLegendProps);
341
+ }
342
+ }, {
343
+ key: "renderAxis",
344
+ value: function renderAxis() {
345
+ var _this$asProps6 = this.asProps, invertAxis = _this$asProps6.invertAxis, showXAxis = _this$asProps6.showXAxis, showYAxis = _this$asProps6.showYAxis, data = _this$asProps6.data, axisXValueFormatter = _this$asProps6.axisXValueFormatter, axisYValueFormatter = _this$asProps6.axisYValueFormatter;
346
+ if (!Array.isArray(data)) {
347
+ return null;
348
+ }
349
+ var xTicks = this.xTicks;
350
+ var yTicks = this.yTicks;
351
+ var childrenX = axisXValueFormatter ? function(_ref7) {
352
+ var value = _ref7.value;
353
+ return {
354
+ children: axisXValueFormatter(value)
355
+ };
356
+ } : void 0;
357
+ var childrenY = axisYValueFormatter ? function(_ref8) {
358
+ var value = _ref8.value;
359
+ return {
360
+ children: axisYValueFormatter(value)
361
+ };
362
+ } : void 0;
363
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, showYAxis && /* @__PURE__ */ React.createElement(YAxis, null, yTicks ? /* @__PURE__ */ React.createElement(YAxis.Ticks, {
364
+ ticks: yTicks
365
+ }, childrenY) : /* @__PURE__ */ React.createElement(YAxis.Ticks, null, childrenY), invertAxis !== true && (yTicks ? /* @__PURE__ */ React.createElement(YAxis.Grid, {
366
+ ticks: yTicks
367
+ }) : /* @__PURE__ */ React.createElement(YAxis.Grid, null))), showXAxis && /* @__PURE__ */ React.createElement(XAxis, null, xTicks ? /* @__PURE__ */ React.createElement(XAxis.Ticks, {
368
+ ticks: xTicks
369
+ }, childrenX) : /* @__PURE__ */ React.createElement(XAxis.Ticks, null, childrenX), invertAxis === true && (xTicks ? /* @__PURE__ */ React.createElement(XAxis.Grid, {
370
+ ticks: xTicks
371
+ }) : /* @__PURE__ */ React.createElement(XAxis.Grid, null))));
372
+ }
373
+ }, {
374
+ key: "render",
375
+ value: function render() {
376
+ var _ref = this.asProps, _ref2;
377
+ var SChart = Flex;
378
+ var _this$asProps7 = this.asProps, styles = _this$asProps7.styles, plotWidth = _this$asProps7.plotWidth, plotHeight = _this$asProps7.plotHeight, data = _this$asProps7.data, patterns = _this$asProps7.patterns, a11yAltTextConfig = _this$asProps7.a11yAltTextConfig, duration = _this$asProps7.duration;
379
+ var _extractAriaProps = extractAriaProps(this.asProps), extractedAriaProps = _extractAriaProps.extractedAriaProps;
380
+ return _ref2 = sstyled(styles), /* @__PURE__ */ React.createElement(SChart, _ref2.cn("SChart", _objectSpread({}, assignProps({
381
+ "gap": 5,
382
+ "__excludeProps": ["data"],
383
+ "role": "group"
384
+ }, _ref))), this.renderLegend(), /* @__PURE__ */ React.createElement(Plot, _ref2.cn("Plot", _objectSpread({
385
+ "data": data,
386
+ "scale": [this.xScale, this.yScale],
387
+ "width": plotWidth,
388
+ "height": plotHeight,
389
+ "dataHints": this.dataHints,
390
+ "a11yAltTextConfig": a11yAltTextConfig,
391
+ "patterns": patterns,
392
+ "duration": duration
393
+ }, extractedAriaProps)), this.renderAxis(), this.renderTooltip(), this.renderChart()));
394
+ }
395
+ }]);
396
+ return AbstractChart2;
397
+ }(Component);
398
+ _defineProperty(AbstractChart, "style", {});
399
+ _defineProperty(AbstractChart, "defaultProps", {
400
+ direction: "column",
401
+ showXAxis: true,
402
+ showYAxis: true,
403
+ showTooltip: true,
404
+ showLegend: true
405
+ });
406
+ export {
407
+ AbstractChart
408
+ };
@@ -0,0 +1,145 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
+ import _get from "@babel/runtime/helpers/esm/get";
5
+ import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
6
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
7
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
8
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
9
+ import React from "react";
10
+ import createComponent from "@semcore/core";
11
+ import { scaleTime, scaleLinear } from "d3-scale";
12
+ import Area from "../../Area.mjs";
13
+ import StackedArea from "../../StackedArea.mjs";
14
+ import { HoverLine } from "../../Hover.mjs";
15
+ import { minMax } from "../../utils.mjs";
16
+ import { AbstractChart } from "./AbstractChart.mjs";
17
+ import { Flex, Box } from "@semcore/flex-box";
18
+ import { Text } from "@semcore/typography";
19
+ import { localizedMessages } from "../../translations/__intergalactic-dynamic-locales.mjs";
20
+ import i18nEnhance from "@semcore/utils/lib/enhances/i18nEnhance";
21
+ var AreaChartComponent = /* @__PURE__ */ function(_AbstractChart) {
22
+ _inherits(AreaChartComponent2, _AbstractChart);
23
+ var _super = _createSuper(AreaChartComponent2);
24
+ function AreaChartComponent2() {
25
+ _classCallCheck(this, AreaChartComponent2);
26
+ return _super.apply(this, arguments);
27
+ }
28
+ _createClass(AreaChartComponent2, [{
29
+ key: "xScale",
30
+ get: function get() {
31
+ var _this$asProps = this.asProps, xScale = _this$asProps.xScale, _this$asProps$marginY = _this$asProps.marginY, marginY = _this$asProps$marginY === void 0 ? 40 : _this$asProps$marginY, plotWidth = _this$asProps.plotWidth, data = _this$asProps.data, groupKey = _this$asProps.groupKey;
32
+ if (xScale) {
33
+ return xScale;
34
+ }
35
+ var testItem = data[0][groupKey];
36
+ var range = [marginY, plotWidth - this.plotPadding];
37
+ var domain = minMax(data, groupKey);
38
+ if (testItem instanceof Date && !Number.isNaN(testItem.getMilliseconds())) {
39
+ return scaleTime(domain, range);
40
+ }
41
+ return scaleLinear(domain, range);
42
+ }
43
+ }, {
44
+ key: "yScale",
45
+ get: function get() {
46
+ var _this$asProps2 = this.asProps, yScale = _this$asProps2.yScale, _this$asProps2$margin = _this$asProps2.marginX, marginX = _this$asProps2$margin === void 0 ? 24 : _this$asProps2$margin, plotHeight = _this$asProps2.plotHeight, stacked = _this$asProps2.stacked;
47
+ _this$asProps2.data;
48
+ _this$asProps2.groupKey;
49
+ if (yScale) {
50
+ return yScale;
51
+ }
52
+ var flatValues = _get(_getPrototypeOf(AreaChartComponent2.prototype), "flatValues", this);
53
+ var min = Math.min.apply(Math, _toConsumableArray(flatValues));
54
+ var max = stacked ? _get(_getPrototypeOf(AreaChartComponent2.prototype), "maxStackedValue", this) : Math.max.apply(Math, _toConsumableArray(flatValues));
55
+ return scaleLinear().range([plotHeight - marginX, this.plotPadding]).domain([min, max]);
56
+ }
57
+ }, {
58
+ key: "renderChart",
59
+ value: function renderChart() {
60
+ var _this$asProps3 = this.asProps, groupKey = _this$asProps3.groupKey, curve = _this$asProps3.curve, showDots = _this$asProps3.showDots, stacked = _this$asProps3.stacked;
61
+ var _this$state = this.state, dataDefinitions = _this$state.dataDefinitions, highlightedLine = _this$state.highlightedLine;
62
+ if (stacked) {
63
+ return /* @__PURE__ */ React.createElement(StackedArea, {
64
+ x: groupKey
65
+ }, dataDefinitions.map(function(item, index) {
66
+ return item.checked && /* @__PURE__ */ React.createElement(StackedArea.Area, {
67
+ x: groupKey,
68
+ y: item.id,
69
+ key: item.id,
70
+ color: item.color,
71
+ transparent: highlightedLine !== -1 && highlightedLine !== index,
72
+ curve
73
+ }, showDots && /* @__PURE__ */ React.createElement(StackedArea.Area.Dots, {
74
+ display: true
75
+ }));
76
+ }));
77
+ }
78
+ return dataDefinitions.map(function(item, index) {
79
+ return item.checked && /* @__PURE__ */ React.createElement(Area, {
80
+ x: groupKey,
81
+ y: item.id,
82
+ key: item.id,
83
+ color: item.color,
84
+ transparent: highlightedLine !== -1 && highlightedLine !== index,
85
+ curve
86
+ }, showDots && /* @__PURE__ */ React.createElement(Area.Dots, {
87
+ display: true
88
+ }));
89
+ });
90
+ }
91
+ }, {
92
+ key: "renderTooltip",
93
+ value: function renderTooltip() {
94
+ var _this = this;
95
+ var _this$asProps4 = this.asProps, data = _this$asProps4.data, groupKey = _this$asProps4.groupKey, showTotalInTooltip = _this$asProps4.showTotalInTooltip, showTooltip = _this$asProps4.showTooltip;
96
+ var dataDefinitions = this.state.dataDefinitions;
97
+ if (!showTooltip) {
98
+ return null;
99
+ }
100
+ return /* @__PURE__ */ React.createElement(HoverLine.Tooltip, {
101
+ x: groupKey,
102
+ wMin: 100
103
+ }, function(_ref) {
104
+ var _dataItem$groupKey;
105
+ var xIndex = _ref.xIndex;
106
+ var dataItem = data[xIndex];
107
+ var total = _this.totalValue(dataItem);
108
+ return {
109
+ children: /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(HoverLine.Tooltip.Title, null, (_dataItem$groupKey = dataItem[groupKey]) === null || _dataItem$groupKey === void 0 ? void 0 : _dataItem$groupKey.toString()), dataDefinitions.map(function(item) {
110
+ return item.checked && /* @__PURE__ */ React.createElement(Flex, {
111
+ justifyContent: "space-between",
112
+ key: item.id
113
+ }, /* @__PURE__ */ React.createElement(HoverLine.Tooltip.Dot, {
114
+ mr: 4,
115
+ color: item.color
116
+ }, item.label), /* @__PURE__ */ React.createElement(Text, {
117
+ bold: true
118
+ }, _this.tooltipValueFormatter(dataItem[item.id])));
119
+ }), showTotalInTooltip === true && /* @__PURE__ */ React.createElement(Flex, {
120
+ mt: 2,
121
+ justifyContent: "space-between"
122
+ }, /* @__PURE__ */ React.createElement(Box, {
123
+ mr: 4
124
+ }, "Total"), /* @__PURE__ */ React.createElement(Text, {
125
+ bold: true
126
+ }, total)))
127
+ };
128
+ });
129
+ }
130
+ }, {
131
+ key: "getLegendAriaLabel",
132
+ value: function getLegendAriaLabel() {
133
+ return this.asProps.getI18nText("legendForChart", {
134
+ chartType: "Area"
135
+ });
136
+ }
137
+ }]);
138
+ return AreaChartComponent2;
139
+ }(AbstractChart);
140
+ _defineProperty(AreaChartComponent, "displayName", "Chart.Area");
141
+ _defineProperty(AreaChartComponent, "enhance", [i18nEnhance(localizedMessages)]);
142
+ var AreaChart = createComponent(AreaChartComponent);
143
+ export {
144
+ AreaChart
145
+ };