@semcore/d3-chart 16.5.0 → 16.6.0-prerelease.2
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.
- package/CHANGELOG.md +13 -0
- package/lib/cjs/Area.js +11 -11
- package/lib/cjs/Axis.js +15 -15
- package/lib/cjs/Bar.js +16 -16
- package/lib/cjs/Bubble.js +20 -15
- package/lib/cjs/Bubble.js.map +1 -1
- package/lib/cjs/CompactHorizontalBar.js +16 -16
- package/lib/cjs/Donut.js +9 -9
- package/lib/cjs/Dots.js +8 -8
- package/lib/cjs/HorizontalBar.js +16 -16
- package/lib/cjs/Hover.js +3 -3
- package/lib/cjs/Line.js +9 -9
- package/lib/cjs/Plot.js +3 -3
- package/lib/cjs/Radar.js +19 -19
- package/lib/cjs/RadialTree.js +12 -12
- package/lib/cjs/Reference.js +12 -12
- package/lib/cjs/ScatterPlot.js +9 -9
- package/lib/cjs/Tooltip.js +9 -9
- package/lib/cjs/Venn.js +9 -9
- package/lib/cjs/a11y/PlotA11yModule.js +2 -2
- package/lib/cjs/a11y/PlotA11yView.js +2 -2
- package/lib/cjs/component/Chart/AbstractChart.js +9 -23
- package/lib/cjs/component/Chart/AbstractChart.js.map +1 -1
- package/lib/cjs/component/Chart/CigaretteChart.js +252 -90
- package/lib/cjs/component/Chart/CigaretteChart.js.map +1 -1
- package/lib/cjs/component/Chart/CigaretteChart.type.js.map +1 -1
- package/lib/cjs/component/ChartLegend/LegendFlex/LegendFlex.js +4 -4
- package/lib/cjs/component/ChartLegend/LegendItem/LegendItem.js +17 -17
- package/lib/cjs/component/ChartLegend/LegendTable/LegendTable.js +6 -6
- package/lib/cjs/style/bubble.shadow.css +4 -0
- package/lib/cjs/utils.js +3 -2
- package/lib/cjs/utils.js.map +1 -1
- package/lib/es6/Area.js +11 -11
- package/lib/es6/Axis.js +15 -15
- package/lib/es6/Bar.js +16 -16
- package/lib/es6/Bubble.js +20 -15
- package/lib/es6/Bubble.js.map +1 -1
- package/lib/es6/CompactHorizontalBar.js +16 -16
- package/lib/es6/Donut.js +9 -9
- package/lib/es6/Dots.js +8 -8
- package/lib/es6/HorizontalBar.js +16 -16
- package/lib/es6/Hover.js +3 -3
- package/lib/es6/Line.js +9 -9
- package/lib/es6/Plot.js +3 -3
- package/lib/es6/Radar.js +19 -19
- package/lib/es6/RadialTree.js +12 -12
- package/lib/es6/Reference.js +12 -12
- package/lib/es6/ScatterPlot.js +9 -9
- package/lib/es6/Tooltip.js +9 -9
- package/lib/es6/Venn.js +9 -9
- package/lib/es6/a11y/PlotA11yModule.js +2 -2
- package/lib/es6/a11y/PlotA11yView.js +2 -2
- package/lib/es6/component/Chart/AbstractChart.js +9 -23
- package/lib/es6/component/Chart/AbstractChart.js.map +1 -1
- package/lib/es6/component/Chart/CigaretteChart.js +254 -92
- package/lib/es6/component/Chart/CigaretteChart.js.map +1 -1
- package/lib/es6/component/Chart/CigaretteChart.type.js.map +1 -1
- package/lib/es6/component/ChartLegend/LegendFlex/LegendFlex.js +4 -4
- package/lib/es6/component/ChartLegend/LegendItem/LegendItem.js +17 -17
- package/lib/es6/component/ChartLegend/LegendTable/LegendTable.js +6 -6
- package/lib/es6/style/bubble.shadow.css +4 -0
- package/lib/es6/utils.js +3 -2
- package/lib/es6/utils.js.map +1 -1
- package/lib/esm/Area.mjs +12 -12
- package/lib/esm/Axis.mjs +16 -16
- package/lib/esm/Bar.mjs +17 -17
- package/lib/esm/Bubble.mjs +20 -17
- package/lib/esm/CompactHorizontalBar.mjs +17 -17
- package/lib/esm/Donut.mjs +10 -10
- package/lib/esm/Dots.mjs +9 -9
- package/lib/esm/HorizontalBar.mjs +17 -17
- package/lib/esm/Hover.mjs +4 -4
- package/lib/esm/Line.mjs +10 -10
- package/lib/esm/Plot.mjs +4 -4
- package/lib/esm/Radar.mjs +20 -20
- package/lib/esm/RadialTree.mjs +13 -13
- package/lib/esm/Reference.mjs +13 -13
- package/lib/esm/ScatterPlot.mjs +10 -10
- package/lib/esm/Tooltip.mjs +10 -10
- package/lib/esm/Venn.mjs +10 -10
- package/lib/esm/a11y/PlotA11yModule.mjs +3 -3
- package/lib/esm/a11y/PlotA11yView.mjs +3 -3
- package/lib/esm/component/Chart/AbstractChart.mjs +10 -24
- package/lib/esm/component/Chart/CigaretteChart.mjs +210 -61
- package/lib/esm/component/ChartLegend/LegendFlex/LegendFlex.mjs +5 -5
- package/lib/esm/component/ChartLegend/LegendItem/LegendItem.mjs +18 -18
- package/lib/esm/component/ChartLegend/LegendTable/LegendTable.mjs +7 -7
- package/lib/esm/style/bubble.shadow.css +4 -0
- package/lib/esm/utils.mjs +2 -2
- package/lib/types/component/Chart/AbstractChart.d.ts +4 -7
- package/lib/types/component/Chart/CigaretteChart.type.d.ts +7 -4
- package/package.json +6 -6
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
4
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
5
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
6
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
5
7
|
import _callSuper from "@babel/runtime/helpers/esm/callSuper";
|
|
@@ -9,34 +11,75 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
9
11
|
import { createComponent, sstyled, assignProps } from "@semcore/core";
|
|
10
12
|
import i18nEnhance from "@semcore/core/lib/utils/enhances/i18nEnhance";
|
|
11
13
|
import resolveColorEnhance from "@semcore/core/lib/utils/enhances/resolveColorEnhance";
|
|
14
|
+
import trottle from "@semcore/core/lib/utils/rafTrottle";
|
|
12
15
|
import uniqueIDEnhancement from "@semcore/core/lib/utils/uniqueID";
|
|
13
16
|
import Divider from "@semcore/divider";
|
|
14
17
|
import { Box, Flex } from "@semcore/flex-box";
|
|
15
18
|
import { Text } from "@semcore/typography";
|
|
16
|
-
import {
|
|
19
|
+
import { scaleLinear, scaleThreshold } from "d3-scale";
|
|
17
20
|
import React from "react";
|
|
18
21
|
import Plot from "../../Plot.mjs";
|
|
19
22
|
import { HoverRect } from "../../Hover.mjs";
|
|
20
|
-
import { interpolateValue,
|
|
23
|
+
import { interpolateValue, eventToPoint } from "../../utils.mjs";
|
|
21
24
|
import { NOT_A_VALUE, AbstractChart } from "./AbstractChart.mjs";
|
|
22
25
|
import AnimatedClipPath from "../../AnimatedClipPath.mjs";
|
|
23
26
|
import { localizedMessages } from "../../translations/__intergalactic-dynamic-locales.mjs";
|
|
24
27
|
import Cigarette from "../Cigarette/Cigarette.mjs";
|
|
25
|
-
var
|
|
28
|
+
var DEFAULT_MINIMAL_BAR_WIDTH = 2;
|
|
29
|
+
var DEFAULT_GAP = 2;
|
|
26
30
|
var CigaretteChartComponent = /* @__PURE__ */ (function(_AbstractChart) {
|
|
27
|
-
function CigaretteChartComponent2() {
|
|
31
|
+
function CigaretteChartComponent2(props) {
|
|
28
32
|
var _this;
|
|
29
33
|
_classCallCheck(this, CigaretteChartComponent2);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
_this = _callSuper(this, CigaretteChartComponent2, [].concat(args));
|
|
34
|
+
_this = _callSuper(this, CigaretteChartComponent2, [props]);
|
|
35
|
+
_defineProperty(_this, "plotRef", /* @__PURE__ */ React.createRef());
|
|
34
36
|
_defineProperty(_this, "plotPadding", 0);
|
|
35
37
|
_defineProperty(_this, "offset", 0);
|
|
38
|
+
_defineProperty(_this, "onPlotMouseMove", trottle(function(event) {
|
|
39
|
+
if (!_this.plotRef.current) return;
|
|
40
|
+
var _eventToPoint = eventToPoint(event, _this.plotRef.current), _eventToPoint2 = _slicedToArray(_eventToPoint, 2), pX = _eventToPoint2[0], pY = _eventToPoint2[1];
|
|
41
|
+
_this.setState(function(prevState) {
|
|
42
|
+
return {
|
|
43
|
+
pX,
|
|
44
|
+
pY
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
}));
|
|
48
|
+
_defineProperty(_this, "onPlotMouseLeave", trottle(function() {
|
|
49
|
+
_this.setState(function(prevState) {
|
|
50
|
+
return {
|
|
51
|
+
pX: null,
|
|
52
|
+
pY: null
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
}));
|
|
56
|
+
_this.state = _objectSpread(_objectSpread({}, _this.state), {}, {
|
|
57
|
+
pX: null,
|
|
58
|
+
pY: null
|
|
59
|
+
});
|
|
36
60
|
return _this;
|
|
37
61
|
}
|
|
38
62
|
_inherits(CigaretteChartComponent2, _AbstractChart);
|
|
39
63
|
return _createClass(CigaretteChartComponent2, [{
|
|
64
|
+
key: "activeDataDefinitions",
|
|
65
|
+
get: function get() {
|
|
66
|
+
var dataDefinitions = this.state.dataDefinitions;
|
|
67
|
+
return dataDefinitions.filter(function(_ref7) {
|
|
68
|
+
var checked = _ref7.checked;
|
|
69
|
+
return checked;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}, {
|
|
73
|
+
key: "activePositiveDataDefinitions",
|
|
74
|
+
get: function get() {
|
|
75
|
+
var data = this.asProps.data;
|
|
76
|
+
return this.activeDataDefinitions.filter(function(_ref8) {
|
|
77
|
+
var id = _ref8.id;
|
|
78
|
+
var itemValue = data[id];
|
|
79
|
+
return typeof itemValue === "number" && itemValue > 0;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
40
83
|
key: "resolveColor",
|
|
41
84
|
value: function resolveColor(id, index) {
|
|
42
85
|
var _this$props$colorMap$, _this$props$colorMap;
|
|
@@ -59,37 +102,122 @@ var CigaretteChartComponent = /* @__PURE__ */ (function(_AbstractChart) {
|
|
|
59
102
|
w: "fit-content"
|
|
60
103
|
};
|
|
61
104
|
}
|
|
105
|
+
}, {
|
|
106
|
+
key: "totalValue",
|
|
107
|
+
value: function totalValue() {
|
|
108
|
+
var data = this.asProps.data;
|
|
109
|
+
return this.activeDataDefinitions.reduce(function(acc, _ref9) {
|
|
110
|
+
var id = _ref9.id;
|
|
111
|
+
var itemValue = data[id];
|
|
112
|
+
if (typeof itemValue === "number") {
|
|
113
|
+
acc += itemValue;
|
|
114
|
+
}
|
|
115
|
+
return acc;
|
|
116
|
+
}, 0);
|
|
117
|
+
}
|
|
118
|
+
}, {
|
|
119
|
+
key: "computeCigaretteItems",
|
|
120
|
+
value: function computeCigaretteItems() {
|
|
121
|
+
var _this$asProps = this.asProps, plotWidth = _this$asProps.plotWidth, plotHeight = _this$asProps.plotHeight, data = _this$asProps.data, invertAxis = _this$asProps.invertAxis, minimalBarWidth = _this$asProps.minimalBarWidth;
|
|
122
|
+
var dataDefinitions = invertAxis ? this.activeDataDefinitions : _toConsumableArray(this.activeDataDefinitions).reverse();
|
|
123
|
+
var count = this.activePositiveDataDefinitions.length;
|
|
124
|
+
var totalGapWidth = DEFAULT_GAP * Math.max(0, count - 1);
|
|
125
|
+
var availableSpace = Math.max(0, (invertAxis ? plotWidth : plotHeight) - totalGapWidth);
|
|
126
|
+
var totalValue = this.totalValue();
|
|
127
|
+
var dataDefinitionsItemSize = dataDefinitions.map(function(_ref0) {
|
|
128
|
+
var id = _ref0.id;
|
|
129
|
+
if (totalValue === 0) {
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
var itemValue = data[id];
|
|
133
|
+
if (typeof itemValue !== "number") return 0;
|
|
134
|
+
return itemValue / totalValue * availableSpace;
|
|
135
|
+
});
|
|
136
|
+
var result = dataDefinitions.map(function(dd, index) {
|
|
137
|
+
return _objectSpread(_objectSpread({}, dd), {}, {
|
|
138
|
+
value: data[dd.id],
|
|
139
|
+
dataWidth: dataDefinitionsItemSize[index],
|
|
140
|
+
visualWidth: dataDefinitionsItemSize[index],
|
|
141
|
+
isMinVisible: false
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
var smallItems = result.filter(function(r) {
|
|
145
|
+
var value = r.value, dataWidth = r.dataWidth;
|
|
146
|
+
if (typeof value !== "number") return false;
|
|
147
|
+
return value > 0 && dataWidth < minimalBarWidth;
|
|
148
|
+
});
|
|
149
|
+
if (smallItems.length === 0) return result;
|
|
150
|
+
var extraNeeded = 0;
|
|
151
|
+
var _iterator = _createForOfIteratorHelper(smallItems), _step;
|
|
152
|
+
try {
|
|
153
|
+
for (_iterator.s(); !(_step = _iterator.n()).done; ) {
|
|
154
|
+
var smallItem = _step.value;
|
|
155
|
+
extraNeeded += minimalBarWidth - smallItem.dataWidth;
|
|
156
|
+
smallItem.visualWidth = minimalBarWidth;
|
|
157
|
+
smallItem.isMinVisible = true;
|
|
158
|
+
}
|
|
159
|
+
} catch (err) {
|
|
160
|
+
_iterator.e(err);
|
|
161
|
+
} finally {
|
|
162
|
+
_iterator.f();
|
|
163
|
+
}
|
|
164
|
+
var donors = result.filter(function(r) {
|
|
165
|
+
return !r.isMinVisible && r.dataWidth > minimalBarWidth;
|
|
166
|
+
});
|
|
167
|
+
var donorCapacity = donors.reduce(function(s, d) {
|
|
168
|
+
return s + (d.dataWidth - minimalBarWidth);
|
|
169
|
+
}, 0);
|
|
170
|
+
var _iterator2 = _createForOfIteratorHelper(donors), _step2;
|
|
171
|
+
try {
|
|
172
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done; ) {
|
|
173
|
+
var donor = _step2.value;
|
|
174
|
+
var available = donor.dataWidth - minimalBarWidth;
|
|
175
|
+
var share = available / donorCapacity;
|
|
176
|
+
var taken = share * extraNeeded;
|
|
177
|
+
donor.visualWidth = donor.dataWidth - taken;
|
|
178
|
+
}
|
|
179
|
+
} catch (err) {
|
|
180
|
+
_iterator2.e(err);
|
|
181
|
+
} finally {
|
|
182
|
+
_iterator2.f();
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
62
186
|
}, {
|
|
63
187
|
key: "xScale",
|
|
64
188
|
get: function get() {
|
|
65
|
-
var
|
|
66
|
-
return
|
|
189
|
+
var plotWidth = this.asProps.plotWidth;
|
|
190
|
+
return scaleLinear([0, plotWidth]);
|
|
67
191
|
}
|
|
68
192
|
}, {
|
|
69
193
|
key: "yScale",
|
|
70
194
|
get: function get() {
|
|
71
|
-
var
|
|
72
|
-
return
|
|
195
|
+
var plotHeight = this.asProps.plotHeight;
|
|
196
|
+
return scaleLinear([plotHeight, 0]);
|
|
73
197
|
}
|
|
74
198
|
}, {
|
|
75
199
|
key: "renderChart",
|
|
76
200
|
value: function renderChart() {
|
|
77
201
|
var _this2 = this;
|
|
78
|
-
var _this$
|
|
202
|
+
var _this$asProps2 = this.asProps, invertAxis = _this$asProps2.invertAxis, data = _this$asProps2.data, uid = _this$asProps2.uid, duration = _this$asProps2.duration, patterns = _this$asProps2.patterns, plotHeight = _this$asProps2.plotHeight, plotWidth = _this$asProps2.plotWidth, onClick = _this$asProps2.onClick;
|
|
79
203
|
var _this$state = this.state, dataDefinitions = _this$state.dataDefinitions, highlightedLine = _this$state.highlightedLine;
|
|
80
204
|
this.offset = 0;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
205
|
+
var items = this.computeCigaretteItems();
|
|
206
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, items.map(function(item, index) {
|
|
207
|
+
var visualWidth = item.visualWidth, id = item.id;
|
|
208
|
+
var value = data[id];
|
|
209
|
+
if (value === interpolateValue || value === null) {
|
|
84
210
|
return null;
|
|
85
211
|
}
|
|
86
|
-
var
|
|
87
|
-
var
|
|
88
|
-
var
|
|
89
|
-
var
|
|
90
|
-
var x = index === 0 ? 0 : _this2.offset;
|
|
212
|
+
var height = invertAxis ? plotHeight - DEFAULT_GAP * 2 : plotWidth - DEFAULT_GAP * 2;
|
|
213
|
+
var width = visualWidth;
|
|
214
|
+
var y = DEFAULT_GAP;
|
|
215
|
+
var x = _this2.offset;
|
|
91
216
|
var r = height < 28 ? 2 : 4;
|
|
92
|
-
_this2.offset
|
|
217
|
+
_this2.offset += visualWidth;
|
|
218
|
+
if (index < items.length - 1) {
|
|
219
|
+
_this2.offset += DEFAULT_GAP;
|
|
220
|
+
}
|
|
93
221
|
return /* @__PURE__ */ React.createElement(Cigarette, {
|
|
94
222
|
key: item.id,
|
|
95
223
|
dataKey: item.id,
|
|
@@ -122,8 +250,8 @@ var CigaretteChartComponent = /* @__PURE__ */ (function(_AbstractChart) {
|
|
|
122
250
|
key: "renderTooltip",
|
|
123
251
|
value: function renderTooltip() {
|
|
124
252
|
var _ref = this.asProps, _this3 = this;
|
|
125
|
-
var _this$
|
|
126
|
-
var
|
|
253
|
+
var _this$asProps3 = this.asProps, data = _this$asProps3.data, invertAxis = _this$asProps3.invertAxis, tooltipTitle = _this$asProps3.tooltipTitle, tooltipViewType = _this$asProps3.tooltipViewType, showPercentValueInTooltip = _this$asProps3.showPercentValueInTooltip, styles = _this$asProps3.styles, showTooltip = _this$asProps3.showTooltip;
|
|
254
|
+
var _this$state2 = this.state, dataDefinitions = _this$state2.dataDefinitions, pX = _this$state2.pX, pY = _this$state2.pY;
|
|
127
255
|
var STooltipChildrenWrapper = Box;
|
|
128
256
|
if (!showTooltip) {
|
|
129
257
|
return null;
|
|
@@ -132,18 +260,22 @@ var CigaretteChartComponent = /* @__PURE__ */ (function(_AbstractChart) {
|
|
|
132
260
|
x: invertAxis ? "" : void 0,
|
|
133
261
|
y: invertAxis ? void 0 : "",
|
|
134
262
|
wMin: 100,
|
|
135
|
-
hideHoverLine: true
|
|
263
|
+
hideHoverLine: true,
|
|
264
|
+
xIndex: pX !== null ? this.visualScale(pX) : void 0,
|
|
265
|
+
yIndex: pY !== null ? this.visualScale(pY) : void 0
|
|
136
266
|
}, function(tooltipProps) {
|
|
137
267
|
var _ref4;
|
|
138
268
|
var dataKey = invertAxis ? tooltipProps.xIndex : tooltipProps.yIndex;
|
|
139
|
-
var showPercentColumn = showPercentValueInTooltip && _this3.totalValue(
|
|
269
|
+
var showPercentColumn = showPercentValueInTooltip && _this3.totalValue() !== 0;
|
|
140
270
|
if (tooltipViewType === "single") {
|
|
141
271
|
var _ref3;
|
|
142
272
|
var item = dataDefinitions.find(function(dataDefItem) {
|
|
143
273
|
return dataDefItem.id === dataKey;
|
|
144
274
|
});
|
|
145
275
|
if (!item) {
|
|
146
|
-
return
|
|
276
|
+
return {
|
|
277
|
+
children: null
|
|
278
|
+
};
|
|
147
279
|
}
|
|
148
280
|
return {
|
|
149
281
|
children: (_ref3 = sstyled(styles), /* @__PURE__ */ React.createElement(STooltipChildrenWrapper, _ref3.cn("STooltipChildrenWrapper", _objectSpread({}, assignProps({
|
|
@@ -190,14 +322,30 @@ var CigaretteChartComponent = /* @__PURE__ */ (function(_AbstractChart) {
|
|
|
190
322
|
};
|
|
191
323
|
});
|
|
192
324
|
}
|
|
325
|
+
}, {
|
|
326
|
+
key: "percentValue",
|
|
327
|
+
value: function percentValue(data, key) {
|
|
328
|
+
var percentFormatter = this.asProps.percentFormatter;
|
|
329
|
+
var total = this.totalValue();
|
|
330
|
+
var value = data[key];
|
|
331
|
+
if (typeof value === "number" && total !== 0) {
|
|
332
|
+
var rawPercent = 100 * value / total;
|
|
333
|
+
var formattedPercent = percentFormatter ? percentFormatter(rawPercent) : Math.round(rawPercent);
|
|
334
|
+
return "".concat(formattedPercent, "%");
|
|
335
|
+
}
|
|
336
|
+
if (value === null) {
|
|
337
|
+
return "0%";
|
|
338
|
+
}
|
|
339
|
+
return NOT_A_VALUE;
|
|
340
|
+
}
|
|
193
341
|
}, {
|
|
194
342
|
key: "renderTooltipTotalLine",
|
|
195
343
|
value: function renderTooltipTotalLine(dataItem) {
|
|
196
|
-
var _this$
|
|
344
|
+
var _this$asProps4 = this.asProps, showTotalInTooltip = _this$asProps4.showTotalInTooltip, showPercentValueInTooltip = _this$asProps4.showPercentValueInTooltip;
|
|
197
345
|
if (!showTotalInTooltip) {
|
|
198
346
|
return null;
|
|
199
347
|
}
|
|
200
|
-
var total = this.totalValue(
|
|
348
|
+
var total = this.totalValue();
|
|
201
349
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Box, {
|
|
202
350
|
mt: 2,
|
|
203
351
|
mr: 2
|
|
@@ -222,7 +370,7 @@ var CigaretteChartComponent = /* @__PURE__ */ (function(_AbstractChart) {
|
|
|
222
370
|
value: function render() {
|
|
223
371
|
var _ref2 = this.asProps, _ref6;
|
|
224
372
|
var SChart = Flex;
|
|
225
|
-
var _this$
|
|
373
|
+
var _this$asProps5 = this.asProps, styles = _this$asProps5.styles, plotWidth = _this$asProps5.plotWidth, plotHeight = _this$asProps5.plotHeight, data = _this$asProps5.data, patterns = _this$asProps5.patterns, invertAxis = _this$asProps5.invertAxis, a11yAltTextConfig = _this$asProps5.a11yAltTextConfig;
|
|
226
374
|
var header = this.renderHeader();
|
|
227
375
|
if (invertAxis) {
|
|
228
376
|
var _ref5;
|
|
@@ -233,26 +381,32 @@ var CigaretteChartComponent = /* @__PURE__ */ (function(_AbstractChart) {
|
|
|
233
381
|
}, _ref2))), /* @__PURE__ */ React.createElement(Flex, _ref5.cn("Flex", {
|
|
234
382
|
"direction": "column"
|
|
235
383
|
}), header, /* @__PURE__ */ React.createElement(Plot, _ref5.cn("Plot", {
|
|
384
|
+
"ref": this.plotRef,
|
|
236
385
|
"data": data,
|
|
237
386
|
"scale": [this.xScale, this.yScale],
|
|
238
387
|
"width": plotWidth,
|
|
239
388
|
"height": plotHeight,
|
|
240
389
|
"dataHints": this.dataHints,
|
|
241
390
|
"patterns": patterns,
|
|
242
|
-
"a11yAltTextConfig": a11yAltTextConfig
|
|
391
|
+
"a11yAltTextConfig": a11yAltTextConfig,
|
|
392
|
+
"onMouseMove": this.onPlotMouseMove,
|
|
393
|
+
"onMouseLeave": this.onPlotMouseLeave
|
|
243
394
|
}), this.renderTooltip(), this.renderChart())), this.renderLegend());
|
|
244
395
|
}
|
|
245
396
|
return _ref6 = sstyled(styles), /* @__PURE__ */ React.createElement(SChart, _ref6.cn("SChart", _objectSpread({}, assignProps({
|
|
246
397
|
"gap": 6,
|
|
247
398
|
"__excludeProps": ["onClick", "data"]
|
|
248
399
|
}, _ref2))), /* @__PURE__ */ React.createElement(Plot, _ref6.cn("Plot", {
|
|
400
|
+
"ref": this.plotRef,
|
|
249
401
|
"data": data,
|
|
250
402
|
"scale": [this.xScale, this.yScale],
|
|
251
403
|
"width": plotWidth,
|
|
252
404
|
"height": plotHeight,
|
|
253
405
|
"dataHints": this.dataHints,
|
|
254
406
|
"patterns": patterns,
|
|
255
|
-
"a11yAltTextConfig": a11yAltTextConfig
|
|
407
|
+
"a11yAltTextConfig": a11yAltTextConfig,
|
|
408
|
+
"onMouseMove": this.onPlotMouseMove,
|
|
409
|
+
"onMouseLeave": this.onPlotMouseLeave
|
|
256
410
|
}), this.renderTooltip(), this.renderChart()), /* @__PURE__ */ React.createElement(Flex, _ref6.cn("Flex", {
|
|
257
411
|
"direction": "column",
|
|
258
412
|
"gap": 2
|
|
@@ -266,35 +420,29 @@ var CigaretteChartComponent = /* @__PURE__ */ (function(_AbstractChart) {
|
|
|
266
420
|
});
|
|
267
421
|
}
|
|
268
422
|
}, {
|
|
269
|
-
key: "
|
|
423
|
+
key: "visualScale",
|
|
270
424
|
get: function get() {
|
|
271
|
-
var
|
|
272
|
-
var
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
425
|
+
var cigaretteItems = this.computeCigaretteItems();
|
|
426
|
+
var _cigaretteItems$reduc = cigaretteItems.reduce(function(acc, _ref1, index) {
|
|
427
|
+
var id = _ref1.id, visualWidth = _ref1.visualWidth;
|
|
428
|
+
var range2 = acc.range, domain2 = acc.domain;
|
|
429
|
+
if (visualWidth) {
|
|
430
|
+
range2.push(id);
|
|
431
|
+
if (domain2.length === 0) {
|
|
432
|
+
domain2.push(visualWidth + DEFAULT_GAP);
|
|
433
|
+
return acc;
|
|
434
|
+
}
|
|
435
|
+
if (index !== cigaretteItems.length - 1) {
|
|
436
|
+
var lastAddedDomain = domain2[domain2.length - 1];
|
|
437
|
+
domain2.push(lastAddedDomain + visualWidth + DEFAULT_GAP);
|
|
438
|
+
}
|
|
278
439
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
var _this$asProps5 = this.asProps, plotWidth = _this$asProps5.plotWidth, plotHeight = _this$asProps5.plotHeight, invertAxis = _this$asProps5.invertAxis;
|
|
286
|
-
var range = invertAxis ? [plotHeight, 0] : [0, plotWidth];
|
|
287
|
-
return scaleBand([0], range);
|
|
288
|
-
}
|
|
289
|
-
}, {
|
|
290
|
-
key: "valueScale",
|
|
291
|
-
get: function get() {
|
|
292
|
-
var _this$asProps6 = this.asProps, plotWidth = _this$asProps6.plotWidth, plotHeight = _this$asProps6.plotHeight, invertAxis = _this$asProps6.invertAxis;
|
|
293
|
-
var max = 0;
|
|
294
|
-
this.selectedData.forEach(function(value) {
|
|
295
|
-
max = max + value;
|
|
296
|
-
});
|
|
297
|
-
return scaleLinear().range(invertAxis ? [0, plotWidth] : [plotHeight, 0]).domain([0, max]);
|
|
440
|
+
return acc;
|
|
441
|
+
}, {
|
|
442
|
+
range: [],
|
|
443
|
+
domain: []
|
|
444
|
+
}), range = _cigaretteItems$reduc.range, domain = _cigaretteItems$reduc.domain;
|
|
445
|
+
return scaleThreshold(domain, range);
|
|
298
446
|
}
|
|
299
447
|
}]);
|
|
300
448
|
})(AbstractChart);
|
|
@@ -313,7 +461,8 @@ _defineProperty(CigaretteChartComponent, "defaultProps", function(props) {
|
|
|
313
461
|
duration: 500,
|
|
314
462
|
plotWidth: !invertAxis && !props.plotWidth ? 44 : props.plotWidth,
|
|
315
463
|
plotHeight: invertAxis && !props.plotHeight ? 28 : props.plotHeight,
|
|
316
|
-
showPercentValueInTooltip: false
|
|
464
|
+
showPercentValueInTooltip: false,
|
|
465
|
+
minimalBarWidth: DEFAULT_MINIMAL_BAR_WIDTH
|
|
317
466
|
};
|
|
318
467
|
});
|
|
319
468
|
_defineProperty(CigaretteChartComponent, "enhance", [resolveColorEnhance(), uniqueIDEnhancement(), i18nEnhance(localizedMessages)]);
|
|
@@ -18,14 +18,14 @@ var style = (
|
|
|
18
18
|
/*__reshadow_css_start__*/
|
|
19
19
|
(sstyled.insert(
|
|
20
20
|
/*__inner_css_start__*/
|
|
21
|
-
".
|
|
21
|
+
".___SLegendFlex_bsbfx_gg_._direction_row_bsbfx_gg_{align-items:flex-start;align-content:flex-start;flex-wrap:wrap;gap:8px 16px}.___SLegendFlex_bsbfx_gg_._direction_column_bsbfx_gg_{align-items:flex-start;flex-wrap:wrap;gap:8px}",
|
|
22
22
|
/*__inner_css_end__*/
|
|
23
|
-
"
|
|
23
|
+
"bsbfx_gg_"
|
|
24
24
|
), /*__reshadow_css_end__*/
|
|
25
25
|
{
|
|
26
|
-
"__SLegendFlex": "
|
|
27
|
-
"_direction_row": "
|
|
28
|
-
"_direction_column": "
|
|
26
|
+
"__SLegendFlex": "___SLegendFlex_bsbfx_gg_",
|
|
27
|
+
"_direction_row": "_direction_row_bsbfx_gg_",
|
|
28
|
+
"_direction_column": "_direction_column_bsbfx_gg_"
|
|
29
29
|
})
|
|
30
30
|
);
|
|
31
31
|
var LegendFlexRoot = /* @__PURE__ */ (function(_BaseLegend) {
|
|
@@ -21,27 +21,27 @@ var style = (
|
|
|
21
21
|
/*__reshadow_css_start__*/
|
|
22
22
|
(sstyled.insert(
|
|
23
23
|
/*__inner_css_start__*/
|
|
24
|
-
'.
|
|
24
|
+
'.___SLegendItem_ah6rb_gg_{min-width:0;align-items:flex-start}@media (hover:hover){.___SLegendItem_ah6rb_gg_:hover{cursor:pointer}.___SLegendItem_ah6rb_gg_.__disabled_ah6rb_gg_:hover{cursor:default}}.___SPointShape_ah6rb_gg_.__color_ah6rb_gg_{background-color:var(--color_ah6rb);margin-right:8px;flex-shrink:0}.___SPointShape_ah6rb_gg_._shape_Circle_ah6rb_gg_._size_l_ah6rb_gg_{width:16px;height:16px;border-radius:8px;margin-top:4px}.___SPointShape_ah6rb_gg_._shape_Circle_ah6rb_gg_._size_m_ah6rb_gg_{width:12px;height:12px;border-radius:6px;margin-top:4px}.___SPointShape_ah6rb_gg_._shape_Line_ah6rb_gg_._size_l_ah6rb_gg_{width:16px;height:4px;border-radius:3px;margin-top:9px}.___SPointShape_ah6rb_gg_._shape_Line_ah6rb_gg_._size_m_ah6rb_gg_{width:12px;height:4px;border-radius:3px;margin-top:8px}.___SPointShape_ah6rb_gg_._shape_Square_ah6rb_gg_._size_l_ah6rb_gg_{width:16px;height:16px;border-radius:2px;margin-top:4px}.___SPointShape_ah6rb_gg_._shape_Square_ah6rb_gg_._size_m_ah6rb_gg_{width:12px;height:12px;border-radius:2px;margin-top:4px}.___SPointShape_ah6rb_gg_._shape_Pattern_ah6rb_gg_{background-color:transparent;margin-right:4px}.___SIcon_ah6rb_gg_{line-height:0;margin-right:4px}.___SIcon_ah6rb_gg_._size_l_ah6rb_gg_{margin-top:4px}.___SIcon_ah6rb_gg_._size_m_ah6rb_gg_{margin-top:2px}.___SLabel_ah6rb_gg_{min-width:0}.___SAdditionalLabel_ah6rb_gg_._size_l_ah6rb_gg_,.___SCount_ah6rb_gg_._size_l_ah6rb_gg_,.___SLabel_ah6rb_gg_._size_l_ah6rb_gg_{font-size:var(--intergalactic-fs-300, 16px);line-height:var(--intergalactic-lh-300, 150%)}.___SAdditionalLabel_ah6rb_gg_._size_m_ah6rb_gg_,.___SCount_ah6rb_gg_._size_m_ah6rb_gg_,.___SLabel_ah6rb_gg_._size_m_ah6rb_gg_{font-size:var(--intergalactic-fs-200, 14px);line-height:var(--intergalactic-lh-200, 142%)}.___SAdditionalLabel_ah6rb_gg_,.___SCount_ah6rb_gg_{margin-left:4px}.___SAdditionalLabel_ah6rb_gg_{white-space:nowrap;display:flex;align-items:flex-start}.___SAdditionalLabel_ah6rb_gg_::before{content:"";display:inline-block;background-color:var(--intergalactic-text-secondary, #6c6e79);height:4px;width:4px;border-radius:2px;margin-right:4px}.___SAdditionalLabel_ah6rb_gg_._size_l_ah6rb_gg_::before{margin-top:10px}.___SAdditionalLabel_ah6rb_gg_._size_m_ah6rb_gg_::before{margin-top:8px}.___SPatternSymbol_ah6rb_gg_{transform:scale(.8)}',
|
|
25
25
|
/*__inner_css_end__*/
|
|
26
|
-
"
|
|
26
|
+
"ah6rb_gg_"
|
|
27
27
|
), /*__reshadow_css_end__*/
|
|
28
28
|
{
|
|
29
|
-
"__SLegendItem": "
|
|
30
|
-
"_disabled": "
|
|
31
|
-
"__SPointShape": "
|
|
32
|
-
"_color": "
|
|
33
|
-
"--color": "--
|
|
34
|
-
"_shape_Circle": "
|
|
35
|
-
"_size_l": "
|
|
36
|
-
"_size_m": "
|
|
37
|
-
"_shape_Line": "
|
|
38
|
-
"_shape_Square": "
|
|
39
|
-
"_shape_Pattern": "
|
|
40
|
-
"__SIcon": "
|
|
41
|
-
"__SLabel": "
|
|
42
|
-
"__SAdditionalLabel": "
|
|
43
|
-
"__SCount": "
|
|
44
|
-
"__SPatternSymbol": "
|
|
29
|
+
"__SLegendItem": "___SLegendItem_ah6rb_gg_",
|
|
30
|
+
"_disabled": "__disabled_ah6rb_gg_",
|
|
31
|
+
"__SPointShape": "___SPointShape_ah6rb_gg_",
|
|
32
|
+
"_color": "__color_ah6rb_gg_",
|
|
33
|
+
"--color": "--color_ah6rb",
|
|
34
|
+
"_shape_Circle": "_shape_Circle_ah6rb_gg_",
|
|
35
|
+
"_size_l": "_size_l_ah6rb_gg_",
|
|
36
|
+
"_size_m": "_size_m_ah6rb_gg_",
|
|
37
|
+
"_shape_Line": "_shape_Line_ah6rb_gg_",
|
|
38
|
+
"_shape_Square": "_shape_Square_ah6rb_gg_",
|
|
39
|
+
"_shape_Pattern": "_shape_Pattern_ah6rb_gg_",
|
|
40
|
+
"__SIcon": "___SIcon_ah6rb_gg_",
|
|
41
|
+
"__SLabel": "___SLabel_ah6rb_gg_",
|
|
42
|
+
"__SAdditionalLabel": "___SAdditionalLabel_ah6rb_gg_",
|
|
43
|
+
"__SCount": "___SCount_ah6rb_gg_",
|
|
44
|
+
"__SPatternSymbol": "___SPatternSymbol_ah6rb_gg_"
|
|
45
45
|
})
|
|
46
46
|
);
|
|
47
47
|
var enhance = [resolveColorEnhance(), uniqueIDEnhancement()];
|
|
@@ -14,16 +14,16 @@ var style = (
|
|
|
14
14
|
/*__reshadow_css_start__*/
|
|
15
15
|
(sstyled.insert(
|
|
16
16
|
/*__inner_css_start__*/
|
|
17
|
-
'.
|
|
17
|
+
'.___SLegendTable_nfmvg_gg_.__columns-count_nfmvg_gg_{font-feature-settings:"tnum";font-variant-numeric:tabular-nums;display:grid;grid-template-columns:auto .2fr;align-items:center;height:-moz-fit-content;height:fit-content;grid-column-gap:16px;grid-row-gap:8px}.___SColumnItem_nfmvg_gg_._size_l_nfmvg_gg_{font-size:var(--intergalactic-fs-300, 16px);text-align:right}.___SColumnItem_nfmvg_gg_._size_m_nfmvg_gg_{font-size:var(--intergalactic-fs-200, 14px);text-align:right}',
|
|
18
18
|
/*__inner_css_end__*/
|
|
19
|
-
"
|
|
19
|
+
"nfmvg_gg_"
|
|
20
20
|
), /*__reshadow_css_end__*/
|
|
21
21
|
{
|
|
22
|
-
"__SLegendTable": "
|
|
23
|
-
"_columns-count": "__columns-
|
|
24
|
-
"__SColumnItem": "
|
|
25
|
-
"_size_l": "
|
|
26
|
-
"_size_m": "
|
|
22
|
+
"__SLegendTable": "___SLegendTable_nfmvg_gg_",
|
|
23
|
+
"_columns-count": "__columns-count_nfmvg_gg_",
|
|
24
|
+
"__SColumnItem": "___SColumnItem_nfmvg_gg_",
|
|
25
|
+
"_size_l": "_size_l_nfmvg_gg_",
|
|
26
|
+
"_size_m": "_size_m_nfmvg_gg_"
|
|
27
27
|
})
|
|
28
28
|
);
|
|
29
29
|
var LegendTableRoot = /* @__PURE__ */ (function(_BaseLegend) {
|
package/lib/esm/utils.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
5
5
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
6
6
|
import EventEmitter from "@semcore/core/lib/utils/eventEmitter";
|
|
7
7
|
import { extent, bisector } from "d3-array";
|
|
8
|
-
import { scaleSqrt,
|
|
8
|
+
import { scaleSqrt, scaleQuantize, scaleBand } from "d3-scale";
|
|
9
9
|
var eventToPoint = function eventToPoint2(event, svgRoot) {
|
|
10
10
|
var node = event.currentTarget || event.target;
|
|
11
11
|
var rect = svgRoot.getBoundingClientRect();
|
|
@@ -240,7 +240,7 @@ var calculateBubbleDomain = function calculateBubbleDomain2(data, key, range) {
|
|
|
240
240
|
var maxValueShift = valueScale(maxestValue) * pixelRatio;
|
|
241
241
|
min -= minValueShift * 2;
|
|
242
242
|
max += maxValueShift * 2;
|
|
243
|
-
return [min, max];
|
|
243
|
+
return [Math.floor(min), Math.floor(max)];
|
|
244
244
|
};
|
|
245
245
|
var PlotEventEmitter = EventEmitter;
|
|
246
246
|
export {
|
|
@@ -5,7 +5,7 @@ import type { BaseChartProps, BaseLegendProps, ListData, ObjectData } from './Ab
|
|
|
5
5
|
import type { HoverLine, HoverRect } from '../..';
|
|
6
6
|
import { interpolateValue } from '../../utils';
|
|
7
7
|
import type { LegendItem } from '../ChartLegend/LegendItem/LegendItem.type';
|
|
8
|
-
type ChartState = {
|
|
8
|
+
export type ChartState = {
|
|
9
9
|
dataDefinitions: Array<LegendItem & {
|
|
10
10
|
columns: React.ReactNode[];
|
|
11
11
|
}>;
|
|
@@ -13,7 +13,7 @@ type ChartState = {
|
|
|
13
13
|
withTrend: boolean;
|
|
14
14
|
};
|
|
15
15
|
export declare const NOT_A_VALUE = "n/a";
|
|
16
|
-
export declare abstract class AbstractChart<
|
|
16
|
+
export declare abstract class AbstractChart<Data extends ListData | ObjectData, Props extends BaseChartProps<Data>, Enhancers extends readonly ((...args: any[]) => any)[] = [], State extends ChartState = ChartState, DefaultProps = {}> extends Component<Props, {}, State, Enhancers, DefaultProps> {
|
|
17
17
|
static style: {
|
|
18
18
|
[key: string]: string;
|
|
19
19
|
};
|
|
@@ -23,9 +23,8 @@ export declare abstract class AbstractChart<D extends ListData | ObjectData, T e
|
|
|
23
23
|
*/
|
|
24
24
|
protected plotPadding: number;
|
|
25
25
|
protected dataHints: import("../../a11y/hints").DataStructureHints;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
componentDidUpdate(prevProps: T): void;
|
|
26
|
+
constructor(props: Props);
|
|
27
|
+
componentDidUpdate(prevProps: Props): void;
|
|
29
28
|
protected getDefaultDataDefinitions(): Array<LegendItem & {
|
|
30
29
|
columns: React.ReactNode[];
|
|
31
30
|
}>;
|
|
@@ -40,7 +39,6 @@ export declare abstract class AbstractChart<D extends ListData | ObjectData, T e
|
|
|
40
39
|
protected get flatValues(): Set<number>;
|
|
41
40
|
protected get maxStackedValue(): number;
|
|
42
41
|
protected totalValue(data: ObjectData): number;
|
|
43
|
-
protected percentValue(data: ObjectData, key: string): string;
|
|
44
42
|
protected getValueScale(values: number[]): number;
|
|
45
43
|
protected setHighlightedLine(index: number): void;
|
|
46
44
|
protected handleChangeVisible(id: string, isVisible: boolean): void;
|
|
@@ -59,4 +57,3 @@ export declare abstract class AbstractChart<D extends ListData | ObjectData, T e
|
|
|
59
57
|
protected renderTooltipTotalLine<D extends ObjectData>(dataItem: D): React.JSX.Element | null;
|
|
60
58
|
render(): React.ReactNode;
|
|
61
59
|
}
|
|
62
|
-
export {};
|
|
@@ -2,8 +2,8 @@ import type { Intergalactic } from '@semcore/core';
|
|
|
2
2
|
import type React from 'react';
|
|
3
3
|
import type { BaseChartProps } from './AbstractChart.type';
|
|
4
4
|
import type { interpolateValue } from '../../utils';
|
|
5
|
-
type
|
|
6
|
-
export type CigaretteChartData = Record<
|
|
5
|
+
export type CigaretteChartDataKey = string;
|
|
6
|
+
export type CigaretteChartData = Record<CigaretteChartDataKey, number | typeof interpolateValue>;
|
|
7
7
|
export type CigaretteChartProps = Intergalactic.InternalTypings.EfficientOmit<BaseChartProps<CigaretteChartData>, 'xScale' | 'yScale'> & {
|
|
8
8
|
/** Title text displayed in the tooltip */
|
|
9
9
|
tooltipTitle?: string;
|
|
@@ -11,12 +11,15 @@ export type CigaretteChartProps = Intergalactic.InternalTypings.EfficientOmit<Ba
|
|
|
11
11
|
tooltipViewType?: 'all' | 'single';
|
|
12
12
|
/** Show percent value in tooltip */
|
|
13
13
|
showPercentValueInTooltip?: boolean;
|
|
14
|
+
/** Custom percent formatter. */
|
|
15
|
+
percentFormatter?: (value: number) => number;
|
|
14
16
|
/** Header content for the chart */
|
|
15
17
|
header?: React.ReactNode;
|
|
16
18
|
/** Animation duration in milliseconds */
|
|
17
19
|
duration?: number;
|
|
18
20
|
/** Click handler that receives the data key and event */
|
|
19
|
-
onClick?: (key:
|
|
21
|
+
onClick?: (key: CigaretteChartDataKey, event: React.SyntheticEvent) => void;
|
|
22
|
+
/** Minimal bar width in pixels. Default is `2`. */
|
|
23
|
+
minimalBarWidth?: number;
|
|
20
24
|
};
|
|
21
25
|
export type CigaretteChartType = Intergalactic.Component<'div', CigaretteChartProps>;
|
|
22
|
-
export {};
|