sea-chart 2.0.31 → 2.0.32

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.
@@ -69,7 +69,7 @@ const TypesDialog = _ref => {
69
69
  }, [onChange, selectedType, onToggle]);
70
70
  const handleFilterTypes = (0, _react.useCallback)(() => {
71
71
  if (hideTypeToggle) {
72
- const newChartTypes = _constants.CHART_TYPES.filter(item => ['Histogram', 'Bar_chart', 'Line_chart', 'Area', 'Pie_chart', 'Scatter_chart', 'Combination_chart', 'Map', 'Heat_map', 'Facet_chart'].includes(item.name));
72
+ const newChartTypes = _constants.CHART_TYPES.filter(item => ['Histogram', 'Bar_chart', 'Line_chart', 'Area', 'Pie_chart', 'Scatter_chart', 'Combination_chart', 'Map', 'Heat_map', 'Facet_chart', 'Gauge'].includes(item.name));
73
73
  return newChartTypes;
74
74
  }
75
75
  return _constants.CHART_TYPES;
@@ -1106,6 +1106,7 @@ class ChartComponent extends _react.Component {
1106
1106
  });
1107
1107
  };
1108
1108
  this.getLegendR = chart => {
1109
+ if (!chart) return 3;
1109
1110
  const {
1110
1111
  config
1111
1112
  } = chart;
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+ var _react = _interopRequireDefault(require("react"));
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+ var _lodashEs = require("lodash-es");
12
+ var d3 = _interopRequireWildcard(require("d3"));
13
+ var _constants = require("../../constants");
14
+ var _utils = require("../../utils");
15
+ var _tooltip = _interopRequireDefault(require("../../components/tooltip"));
16
+ var _chartComponent = _interopRequireDefault(require("./chart-component"));
17
+ class Dashboard extends _chartComponent.default {
18
+ constructor(props) {
19
+ super(props);
20
+ this.handleResize = () => {
21
+ this.destroyChart();
22
+ this.createChart();
23
+ this.drawChart();
24
+ };
25
+ this.createChart = () => {
26
+ const {
27
+ chart
28
+ } = this.props;
29
+ const initConfig = {
30
+ insertPadding: 30
31
+ };
32
+ this.initChart(this.container, chart === null || chart === void 0 ? void 0 : chart.id, initConfig);
33
+ };
34
+ this.drawChart = () => {
35
+ const {
36
+ result: data,
37
+ customRender
38
+ } = this.props;
39
+ this.draw(data);
40
+ (0, _utils.isFunction)(customRender) && customRender(this.chart);
41
+ };
42
+ this.draw = data => {
43
+ const {
44
+ width: chartWidth,
45
+ height: chartHeight,
46
+ insertPadding
47
+ } = this.chartBoundingClientRect;
48
+ const value = Number(data) * 100;
49
+ const formatValue = value >= 100 ? 100 : value.toFixed(1);
50
+ const innerRadius = Math.min(chartWidth, chartHeight) / 2 * 0.7;
51
+ const outerRadius = Math.min(chartWidth, chartHeight) / 2 * 0.75;
52
+ const startAngle = -(Math.PI / 2 + 0.5);
53
+ const endAngle = Math.PI / 2 + 0.5;
54
+
55
+ // Ring and Arc
56
+ const arc = d3.arc().innerRadius(innerRadius).outerRadius(outerRadius).startAngle(startAngle).endAngle(endAngle);
57
+ const xScale = d3.scaleLinear().domain([0, 100]).range([startAngle, endAngle]);
58
+
59
+ // Draw Ring
60
+ this.chart.append('g').attr('class', 'content-wrapper').append('path').attr('class', 'completed-path').attr('opacity', 1).attr('fill', '#1890FF').attr('d', () => arc()).call(g => {
61
+ var _g$node$parentNode;
62
+ const {
63
+ width,
64
+ height
65
+ } = (_g$node$parentNode = g.node().parentNode) === null || _g$node$parentNode === void 0 ? void 0 : _g$node$parentNode.getBoundingClientRect();
66
+ const left = width / 2 + insertPadding;
67
+ const top = height / 2 + insertPadding;
68
+ const offsetX = (chartWidth - insertPadding - insertPadding - width) / 2;
69
+ const offsetY = (chartHeight - insertPadding - insertPadding - height) / 2;
70
+ d3.select(g.node().parentNode).attr('transform', "translate(".concat(left + offsetX, ", ").concat(top + offsetY, ")"));
71
+
72
+ // Draw uncompleted path
73
+ if (formatValue < 100) {
74
+ const unCompletedStartAngle = xScale(formatValue);
75
+ this.drawUncompletedPath(g.node().parentNode, innerRadius, outerRadius, unCompletedStartAngle, endAngle);
76
+ }
77
+
78
+ // Draw ticks
79
+ this.drawTicks(left, offsetX, top, offsetY, startAngle, endAngle, arc);
80
+
81
+ // Draw pointer
82
+ this.drawPointer(g.node().parentNode, xScale, formatValue);
83
+
84
+ // Draw total
85
+ this.drawTotal(g.node().parentNode, formatValue);
86
+ });
87
+ };
88
+ this.drawTicks = (left, offsetX, top, offsetY, startAngle, endAngle, arc) => {
89
+ const {
90
+ globalTheme
91
+ } = this.props;
92
+ const theme = _constants.CHART_THEME_COLOR[globalTheme];
93
+ const ticks = Array.from({
94
+ length: 51
95
+ }, (_, i) => i);
96
+ const lineInnerRadius = arc.innerRadius()();
97
+ const x = d3.scaleBand().domain(ticks).range([startAngle, endAngle]).paddingInner(1).paddingOuter(0);
98
+ this.chart.append('g').attr('class', 'ticks-line-wrapper').attr('transform', "translate(".concat(left + offsetX, ", ").concat(top + offsetY, ")")).selectAll().data(x.domain()).join('g').attr('transform', (d, index) => {
99
+ return "\n rotate(".concat(x(d) * 180 / Math.PI - 90, ")\n translate(").concat(lineInnerRadius, ",0)\n ");
100
+ }).attr('data-value', d => d).call(g => {
101
+ g.nodes().forEach(group => {
102
+ const value = Number(group.getAttribute('data-value'));
103
+ // line
104
+ d3.select(group).append('line').attr('x2', () => value % 5 === 0 ? -15 : -10).attr('stroke', () => value % 5 === 0 ? '#CBCBCB' : '#545454');
105
+
106
+ // text
107
+ if (value % 5 === 0) {
108
+ const text = value / 5;
109
+ const rotateVal = ((x(value) + x.bandwidth() / 2) * 180 / Math.PI - 90) * -1; // -1 is Rotate the text
110
+ d3.select(group).append('text').attr('transform', () => {
111
+ if (x(value) <= -(Math.PI / 4)) {
112
+ return "translate(-25,-5) rotate(".concat(rotateVal, ")");
113
+ }
114
+ if (x(value) <= 0) {
115
+ return "translate(-30,-5) rotate(".concat(rotateVal, ")");
116
+ }
117
+ if (x(value) <= Math.PI / 4) {
118
+ return "translate(-30,-2) rotate(".concat(rotateVal, ")");
119
+ }
120
+ if (x(value) <= Math.PI) {
121
+ return "translate(-30,3) rotate(".concat(rotateVal, ")");
122
+ }
123
+ }).text(text).attr('fill', theme.textColor);
124
+ }
125
+ });
126
+ });
127
+ };
128
+ this.drawPointer = (wrapper, xScale, formatValue) => {
129
+ const rotate = xScale(formatValue) * 180 / Math.PI;
130
+
131
+ // Circle
132
+ d3.select(wrapper).append('g').attr('class', 'pointer-circle-wrapper').append('circle').attr('cx', 0).attr('cy', 0).attr('r', 10).attr('fill', 'white').attr('stroke', '#1890FF').attr('stroke-width', 5);
133
+
134
+ // Pointer
135
+ d3.select(wrapper).append('g').attr('class', 'pointer-wrapper').append('rect').attr('x', -2).attr('y', -78).attr('width', 6).attr('height', 70).attr('fill', '#1890FF').attr('rx', 3).attr('transform', () => {
136
+ return "rotate(".concat(rotate, ")");
137
+ });
138
+ };
139
+ this.drawUncompletedPath = (wrapper, innerRadius, outerRadius, startAngle, endAngle) => {
140
+ const uncompletedArc = d3.arc().innerRadius(innerRadius).outerRadius(outerRadius).startAngle(startAngle).endAngle(endAngle);
141
+ d3.select(wrapper).append('path').attr('class', 'uncompleted-path').attr('opacity', 1).attr('d', () => uncompletedArc()).attr('fill', '#CBCBCB');
142
+ };
143
+ this.drawTotal = (wrapper, formatValue) => {
144
+ const {
145
+ chart,
146
+ globalTheme
147
+ } = this.props;
148
+ const {
149
+ name
150
+ } = chart.config;
151
+ const theme = _constants.CHART_THEME_COLOR[globalTheme];
152
+ const {
153
+ height: chartHeight
154
+ } = this.chartBoundingClientRect;
155
+ const totalWrapper = d3.select(wrapper).append('g').attr('class', 'total-wrapper');
156
+ // title
157
+ totalWrapper.append('text').attr('fill', '#545454').attr('font-size', chartHeight > 240 ? 20 : 12).text(name).attr('dy', 50).call(g => {
158
+ const {
159
+ width
160
+ } = g.node().getBoundingClientRect();
161
+ g.attr('dx', "".concat(-(width / 2)));
162
+ });
163
+
164
+ // total
165
+ totalWrapper.append('text').attr('fill', theme.textColor).attr('font-size', chartHeight > 240 ? 36 : 16).text("".concat(formatValue, "%")).attr('dx', -10).attr('dy', 90).call(g => {
166
+ const {
167
+ width
168
+ } = g.node().getBoundingClientRect();
169
+ g.attr('dx', "".concat(-(width / 2)));
170
+ });
171
+ };
172
+ this.chart = null;
173
+ this.state = {
174
+ tooltipData: null,
175
+ toolTipPosition: null
176
+ };
177
+ }
178
+ componentDidMount() {
179
+ this.createChart();
180
+ this.drawChart();
181
+ this.debouncedHandleResize = (0, _lodashEs.debounce)(this.handleResize, 300);
182
+ window.addEventListener('resize', this.debouncedHandleResize);
183
+ }
184
+ componentDidUpdate(prevProps) {
185
+ super.componentDidUpdate(prevProps);
186
+ if (_utils.BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
187
+ this.destroyChart();
188
+ this.createChart();
189
+ this.drawChart();
190
+ }
191
+ }
192
+ componentWillUnmount() {
193
+ this.destroyChart();
194
+ window.removeEventListener('resize', this.debouncedHandleResize);
195
+ }
196
+ render() {
197
+ const {
198
+ tooltipData,
199
+ toolTipPosition
200
+ } = this.state;
201
+ return /*#__PURE__*/_react.default.createElement("div", {
202
+ ref: ref => this.container = ref,
203
+ className: "sea-chart-container"
204
+ }, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
205
+ tooltipData: tooltipData,
206
+ toolTipPosition: toolTipPosition,
207
+ chart: this.chart
208
+ }));
209
+ }
210
+ }
211
+ Dashboard.propTypes = {
212
+ canvasStyle: _propTypes.default.object,
213
+ chart: _propTypes.default.object,
214
+ groupbyColumn: _propTypes.default.object,
215
+ summaryColumn: _propTypes.default.object,
216
+ result: _propTypes.default.number,
217
+ tables: _propTypes.default.array,
218
+ globalTheme: _propTypes.default.string,
219
+ chartColorTheme: _propTypes.default.string,
220
+ toggleRecords: _propTypes.default.func,
221
+ customRender: _propTypes.default.func
222
+ };
223
+ var _default = exports.default = Dashboard;
@@ -36,6 +36,7 @@ var _mapWorld = _interopRequireDefault(require("./map-world"));
36
36
  var _mapWorldBubble = _interopRequireDefault(require("./map-world-bubble"));
37
37
  var _heatMap = _interopRequireDefault(require("./heat-map"));
38
38
  var _mirror = _interopRequireDefault(require("./mirror"));
39
+ var _dashboard = _interopRequireDefault(require("./dashboard"));
39
40
  var _trend = _interopRequireDefault(require("./trend"));
40
41
  var _tableElement = _interopRequireDefault(require("./table-element"));
41
42
  const Wrapper = _ref => {
@@ -295,6 +296,12 @@ const Wrapper = _ref => {
295
296
  canvasStyle: canvasStyle
296
297
  }));
297
298
  }
299
+ case _constants.CHART_TYPE.DASHBOARD:
300
+ {
301
+ return /*#__PURE__*/_react.default.createElement(_dashboard.default, Object.assign({}, baseProps, {
302
+ canvasStyle: canvasStyle
303
+ }));
304
+ }
298
305
  case _constants.CHART_TYPE.BASIC_NUMBER_CARD:
299
306
  {
300
307
  return /*#__PURE__*/_react.default.createElement(_basicNumberCard.default, Object.assign({}, baseProps, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "2.0.31",
3
+ "version": "2.0.32",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@dnd-kit/core": "^6.1.0",