onesight-charts 2.0.2 → 2.0.4
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/README.md +1 -1
- package/dist/onesight-charts.min.css +1 -1
- package/dist/onesight-charts.min.js +1 -1
- package/es/components/gauge/demo/base.js +41 -0
- package/es/components/gauge/index.js +371 -0
- package/es/components/gauge/style.scss +67 -0
- package/es/components/vertical-stacked-bar/index.js +32 -0
- package/es/index.js +1 -0
- package/lib/components/gauge/demo/base.js +40 -0
- package/lib/components/gauge/index.js +264 -0
- package/lib/components/gauge/style.scss +67 -0
- package/lib/components/vertical-stacked-bar/index.js +25 -0
- package/lib/index.js +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Gauge from "../index";
|
|
3
|
+
function App() {
|
|
4
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
5
|
+
style: {
|
|
6
|
+
display: 'flex',
|
|
7
|
+
gap: 24,
|
|
8
|
+
flexWrap: 'wrap'
|
|
9
|
+
}
|
|
10
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
11
|
+
style: {
|
|
12
|
+
width: 360,
|
|
13
|
+
height: 322
|
|
14
|
+
}
|
|
15
|
+
}, /*#__PURE__*/React.createElement(Gauge, {
|
|
16
|
+
value: 12
|
|
17
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
18
|
+
style: {
|
|
19
|
+
width: 360,
|
|
20
|
+
height: 322
|
|
21
|
+
}
|
|
22
|
+
}, /*#__PURE__*/React.createElement(Gauge, {
|
|
23
|
+
value: -68
|
|
24
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
25
|
+
style: {
|
|
26
|
+
width: 360,
|
|
27
|
+
height: 322
|
|
28
|
+
}
|
|
29
|
+
}, /*#__PURE__*/React.createElement(Gauge, {
|
|
30
|
+
value: 85
|
|
31
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
32
|
+
style: {
|
|
33
|
+
width: 360,
|
|
34
|
+
height: 322
|
|
35
|
+
}
|
|
36
|
+
}, /*#__PURE__*/React.createElement(Gauge, {
|
|
37
|
+
value: 0,
|
|
38
|
+
showInfo: false
|
|
39
|
+
})));
|
|
40
|
+
}
|
|
41
|
+
export default App;
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { Tooltip } from 'antd';
|
|
9
|
+
import "./style.scss";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 仪表盘 Gauge
|
|
13
|
+
* 一个纯展示型的组件:接收 -100 ~ 100 之间的分值,
|
|
14
|
+
* 用半环形仪表盘 + 指针 + 底部标签展示情绪/得分。
|
|
15
|
+
*/
|
|
16
|
+
function Gauge(props) {
|
|
17
|
+
var _props$width = props.width,
|
|
18
|
+
width = _props$width === void 0 ? '100%' : _props$width,
|
|
19
|
+
_props$height = props.height,
|
|
20
|
+
height = _props$height === void 0 ? '100%' : _props$height,
|
|
21
|
+
_props$value = props.value,
|
|
22
|
+
value = _props$value === void 0 ? 0 : _props$value,
|
|
23
|
+
_props$min = props.min,
|
|
24
|
+
min = _props$min === void 0 ? -100 : _props$min,
|
|
25
|
+
_props$max = props.max,
|
|
26
|
+
max = _props$max === void 0 ? 100 : _props$max,
|
|
27
|
+
_props$positiveThresh = props.positiveThreshold,
|
|
28
|
+
positiveThreshold = _props$positiveThresh === void 0 ? 0 : _props$positiveThresh,
|
|
29
|
+
_props$negativeThresh = props.negativeThreshold,
|
|
30
|
+
negativeThreshold = _props$negativeThresh === void 0 ? 0 : _props$negativeThresh,
|
|
31
|
+
label = props.label,
|
|
32
|
+
_props$showTag = props.showTag,
|
|
33
|
+
showTag = _props$showTag === void 0 ? true : _props$showTag,
|
|
34
|
+
_props$showInfo = props.showInfo,
|
|
35
|
+
showInfo = _props$showInfo === void 0 ? true : _props$showInfo,
|
|
36
|
+
colorProp = props.colors,
|
|
37
|
+
onInfoClick = props.onInfoClick,
|
|
38
|
+
_props$tip = props.tip,
|
|
39
|
+
tip = _props$tip === void 0 ? '' : _props$tip;
|
|
40
|
+
var colors = _objectSpread({
|
|
41
|
+
negative: '#EF7B7B',
|
|
42
|
+
positive: '#4CBFA6',
|
|
43
|
+
neutral: '#9CA3AF',
|
|
44
|
+
arcMiddle: '#ECECEC',
|
|
45
|
+
tick: '#D4D4D4',
|
|
46
|
+
pointer: '#D2D3D7'
|
|
47
|
+
}, colorProp || {});
|
|
48
|
+
|
|
49
|
+
// 数值处理
|
|
50
|
+
var clamped = Math.max(min, Math.min(max, Number(value) || 0));
|
|
51
|
+
// 指针角度:min -> -90°,max -> +90°
|
|
52
|
+
var pointerAngle = (clamped - min) / (max - min) * 180 - 90;
|
|
53
|
+
|
|
54
|
+
// 情绪判定
|
|
55
|
+
var mood = getMood(clamped, positiveThreshold, negativeThreshold, colors);
|
|
56
|
+
var displayLabel = label !== null && label !== void 0 ? label : mood.label;
|
|
57
|
+
|
|
58
|
+
// 数值颜色
|
|
59
|
+
var valueColor = clamped > 0 ? colors.positive : clamped < 0 ? colors.negative : colors.neutral;
|
|
60
|
+
|
|
61
|
+
// 坐标常量
|
|
62
|
+
var VB_W = 400;
|
|
63
|
+
var VB_H = 230;
|
|
64
|
+
var CX = 200;
|
|
65
|
+
var CY = 210;
|
|
66
|
+
var OUTER_R = 180;
|
|
67
|
+
var INNER_R = 152;
|
|
68
|
+
var EMOJI_R = (OUTER_R + INNER_R) / 2;
|
|
69
|
+
|
|
70
|
+
// 极坐标 -> 直角坐标(0° 指向正上,顺时针为正)
|
|
71
|
+
var pt = function pt(r, deg) {
|
|
72
|
+
var rad = deg * Math.PI / 180;
|
|
73
|
+
return {
|
|
74
|
+
x: CX + r * Math.sin(rad),
|
|
75
|
+
y: CY - r * Math.cos(rad)
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// 半环形路径
|
|
80
|
+
var so = pt(OUTER_R, -90);
|
|
81
|
+
var eo = pt(OUTER_R, 90);
|
|
82
|
+
var si = pt(INNER_R, -90);
|
|
83
|
+
var ei = pt(INNER_R, 90);
|
|
84
|
+
var arcPath = "M ".concat(so.x, " ").concat(so.y, " ") + "A ".concat(OUTER_R, " ").concat(OUTER_R, " 0 0 1 ").concat(eo.x, " ").concat(eo.y, " ") + "L ".concat(ei.x, " ").concat(ei.y, " ") + "A ".concat(INNER_R, " ").concat(INNER_R, " 0 0 0 ").concat(si.x, " ").concat(si.y, " Z");
|
|
85
|
+
|
|
86
|
+
// 刻度
|
|
87
|
+
var TICK_COUNT = 31;
|
|
88
|
+
var EMOJI_ANGLES = [-60, 0, 60];
|
|
89
|
+
var ticks = [];
|
|
90
|
+
var _loop = function _loop() {
|
|
91
|
+
var angle = -90 + i * 180 / (TICK_COUNT - 1);
|
|
92
|
+
// 表情附近让出空间
|
|
93
|
+
if (EMOJI_ANGLES.some(function (a) {
|
|
94
|
+
return Math.abs(angle - a) < 7;
|
|
95
|
+
})) return 1; // continue
|
|
96
|
+
var p1 = pt(INNER_R - 4, angle);
|
|
97
|
+
var p2 = pt(INNER_R - 14, angle);
|
|
98
|
+
ticks.push({
|
|
99
|
+
p1: p1,
|
|
100
|
+
p2: p2,
|
|
101
|
+
key: i
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
for (var i = 0; i < TICK_COUNT; i++) {
|
|
105
|
+
if (_loop()) continue;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 三个表情位置
|
|
109
|
+
var emojis = [{
|
|
110
|
+
angle: -60,
|
|
111
|
+
mood: 'sad'
|
|
112
|
+
}, {
|
|
113
|
+
angle: 0,
|
|
114
|
+
mood: 'neutral'
|
|
115
|
+
}, {
|
|
116
|
+
angle: 60,
|
|
117
|
+
mood: 'happy'
|
|
118
|
+
}];
|
|
119
|
+
var label0Pos = pt(EMOJI_R - 28, 0);
|
|
120
|
+
var labelMinPos = pt(OUTER_R, -90);
|
|
121
|
+
var labelMaxPos = pt(OUTER_R, 90);
|
|
122
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
123
|
+
className: "onesight-gauge",
|
|
124
|
+
style: {
|
|
125
|
+
width: width,
|
|
126
|
+
height: height
|
|
127
|
+
}
|
|
128
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
129
|
+
className: "onesight-gauge__inner"
|
|
130
|
+
}, /*#__PURE__*/React.createElement("svg", {
|
|
131
|
+
viewBox: "0 0 ".concat(VB_W, " ").concat(VB_H),
|
|
132
|
+
preserveAspectRatio: "xMidYMid meet",
|
|
133
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
134
|
+
className: "onesight-gauge__svg"
|
|
135
|
+
}, /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement("linearGradient", {
|
|
136
|
+
id: "onesight-gauge-arc",
|
|
137
|
+
x1: "0",
|
|
138
|
+
y1: "0",
|
|
139
|
+
x2: "1",
|
|
140
|
+
y2: "0"
|
|
141
|
+
}, /*#__PURE__*/React.createElement("stop", {
|
|
142
|
+
offset: "0%",
|
|
143
|
+
stopColor: colors.negative
|
|
144
|
+
}), /*#__PURE__*/React.createElement("stop", {
|
|
145
|
+
offset: "18%",
|
|
146
|
+
stopColor: colors.negative
|
|
147
|
+
}), /*#__PURE__*/React.createElement("stop", {
|
|
148
|
+
offset: "38%",
|
|
149
|
+
stopColor: "#F5C7C7"
|
|
150
|
+
}), /*#__PURE__*/React.createElement("stop", {
|
|
151
|
+
offset: "50%",
|
|
152
|
+
stopColor: colors.arcMiddle
|
|
153
|
+
}), /*#__PURE__*/React.createElement("stop", {
|
|
154
|
+
offset: "62%",
|
|
155
|
+
stopColor: "#BFE3D8"
|
|
156
|
+
}), /*#__PURE__*/React.createElement("stop", {
|
|
157
|
+
offset: "82%",
|
|
158
|
+
stopColor: colors.positive
|
|
159
|
+
}), /*#__PURE__*/React.createElement("stop", {
|
|
160
|
+
offset: "100%",
|
|
161
|
+
stopColor: colors.positive
|
|
162
|
+
}))), /*#__PURE__*/React.createElement("path", {
|
|
163
|
+
d: arcPath,
|
|
164
|
+
fill: "url(#onesight-gauge-arc)"
|
|
165
|
+
}), ticks.map(function (t) {
|
|
166
|
+
return /*#__PURE__*/React.createElement("line", {
|
|
167
|
+
key: t.key,
|
|
168
|
+
x1: t.p1.x,
|
|
169
|
+
y1: t.p1.y,
|
|
170
|
+
x2: t.p2.x,
|
|
171
|
+
y2: t.p2.y,
|
|
172
|
+
stroke: colors.tick,
|
|
173
|
+
strokeWidth: 1.5,
|
|
174
|
+
strokeLinecap: "round"
|
|
175
|
+
});
|
|
176
|
+
}), emojis.map(function (e) {
|
|
177
|
+
var c = pt(EMOJI_R, e.angle);
|
|
178
|
+
return /*#__PURE__*/React.createElement(MoodFace, {
|
|
179
|
+
key: e.mood,
|
|
180
|
+
mood: e.mood,
|
|
181
|
+
size: 18,
|
|
182
|
+
color: '#ffffff',
|
|
183
|
+
x: c.x - 10,
|
|
184
|
+
y: c.y - 10
|
|
185
|
+
});
|
|
186
|
+
}), /*#__PURE__*/React.createElement("text", {
|
|
187
|
+
// x={labelMinPos.x + 16}
|
|
188
|
+
x: 72
|
|
189
|
+
// y={labelMinPos.y + 20}
|
|
190
|
+
,
|
|
191
|
+
y: 214,
|
|
192
|
+
fill: colors.negative,
|
|
193
|
+
fontSize: "14",
|
|
194
|
+
fontWeight: "500",
|
|
195
|
+
textAnchor: "middle"
|
|
196
|
+
}, min), /*#__PURE__*/React.createElement("text", {
|
|
197
|
+
x: CX,
|
|
198
|
+
y: label0Pos.y,
|
|
199
|
+
fill: "#666",
|
|
200
|
+
fontSize: "14",
|
|
201
|
+
textAnchor: "middle"
|
|
202
|
+
}, "0"), /*#__PURE__*/React.createElement("text", {
|
|
203
|
+
x: 322,
|
|
204
|
+
y: 214,
|
|
205
|
+
fill: colors.positive,
|
|
206
|
+
fontSize: "14",
|
|
207
|
+
fontWeight: "500",
|
|
208
|
+
textAnchor: "middle"
|
|
209
|
+
}, max), /*#__PURE__*/React.createElement("g", {
|
|
210
|
+
transform: "rotate(".concat(pointerAngle, " ").concat(CX, " ").concat(CY, ")")
|
|
211
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
212
|
+
d: "M ".concat(CX - 4, " ").concat(CY - 79, " ") + "A 4 4 0 0 1 ".concat(CX + 4, " ").concat(CY - 79, " ") + "L ".concat(CX + 11, " ").concat(CY, " ") + "L ".concat(CX - 11, " ").concat(CY, " Z"),
|
|
213
|
+
fill: colors.pointer
|
|
214
|
+
}), /*#__PURE__*/React.createElement("circle", {
|
|
215
|
+
cx: 200,
|
|
216
|
+
cy: 208,
|
|
217
|
+
r: 11,
|
|
218
|
+
fill: colors.pointer
|
|
219
|
+
}), /*#__PURE__*/React.createElement("circle", {
|
|
220
|
+
cx: CX,
|
|
221
|
+
cy: 208,
|
|
222
|
+
r: 5.5,
|
|
223
|
+
fill: "#ffffff"
|
|
224
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
|
225
|
+
className: "onesight-gauge__value",
|
|
226
|
+
style: {
|
|
227
|
+
color: valueColor
|
|
228
|
+
}
|
|
229
|
+
}, clamped), showTag && /*#__PURE__*/React.createElement("div", {
|
|
230
|
+
className: "onesight-gauge__tag",
|
|
231
|
+
style: {
|
|
232
|
+
borderColor: mood.color,
|
|
233
|
+
color: mood.color,
|
|
234
|
+
backgroundColor: withAlpha(mood.color, 0.08)
|
|
235
|
+
}
|
|
236
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
237
|
+
className: "onesight-gauge__tag-icon"
|
|
238
|
+
}, /*#__PURE__*/React.createElement(MoodFace, {
|
|
239
|
+
mood: mood.face,
|
|
240
|
+
size: 16
|
|
241
|
+
})), /*#__PURE__*/React.createElement("span", {
|
|
242
|
+
className: "onesight-gauge__tag-label"
|
|
243
|
+
}, displayLabel), showInfo && /*#__PURE__*/React.createElement(Tooltip, {
|
|
244
|
+
title: tip
|
|
245
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
246
|
+
className: "onesight-gauge__tag-info",
|
|
247
|
+
onClick: onInfoClick,
|
|
248
|
+
role: onInfoClick ? 'button' : undefined
|
|
249
|
+
}, /*#__PURE__*/React.createElement(InfoIcon, {
|
|
250
|
+
color: mood.color
|
|
251
|
+
}))))));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/* ------------ 内部小组件 ------------ */
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* 三种情绪表情的默认填充色与 path 数据(14x14 视口)
|
|
258
|
+
*/
|
|
259
|
+
var MOOD_FACE_CONFIG = {
|
|
260
|
+
happy: {
|
|
261
|
+
fill: '#1DA9A0',
|
|
262
|
+
d: 'M7,0 C10.8654,0 14,3.1339 14,7 C14,10.8661 10.8654,14 7,14 C3.1346,14 0,10.8661 0,7 C0,3.1339 3.1346,0 7,0 Z M9.8875,8.52684 L4.1125,8.52684 C3.8094,8.52684 3.577,8.81594 3.6603,9.10714 C4.0453,10.44414 5.3928,11.43254 7,11.43254 C8.6072,11.43254 9.9547,10.44414 10.3397,9.10714 C10.423,8.81594 10.1906,8.52684 9.8875,8.52684 Z M4.59606,4.67124 C4.11866,4.67124 3.73086,5.05764 3.73086,5.53574 C3.73086,6.01314 4.11866,6.40024 4.59606,6.40024 C5.07346,6.40024 5.46056,6.01314 5.46056,5.53574 C5.46056,5.05764 5.07346,4.67124 4.59606,4.67124 Z M9.40443,4.67124 C8.92633,4.67124 8.53923,5.05764 8.53923,5.53574 C8.53923,6.01314 8.92633,6.40024 9.40443,6.40024 C9.88113,6.40024 10.26893,6.01314 10.26893,5.53574 C10.26893,5.05764 9.88113,4.67124 9.40443,4.67124 Z'
|
|
263
|
+
},
|
|
264
|
+
sad: {
|
|
265
|
+
fill: '#EE6666',
|
|
266
|
+
d: 'M7,0 C10.8661,0 14,3.1339 14,7 C14,10.8661 10.8661,14 7,14 C3.1346,14 0,10.8661 0,7 C0,3.1339 3.1346,0 7,0 Z M7.82369,8.19399 C6.32919,7.88249 4.76749,8.45789 3.83439,9.65839 C3.66849,9.87189 3.70699,10.17989 3.92049,10.34649 C4.13469,10.51169 4.44199,10.47459 4.60789,10.25969 C5.31349,9.35249 6.49789,8.91779 7.62279,9.15299 C8.32279,9.29929 8.95069,9.69199 9.39169,10.25969 C9.48829,10.38429 9.63319,10.4494007 9.77949,10.4494007 C9.88379,10.4494007 9.99019,10.41579 10.07979,10.34649 C10.29259,10.17989 10.33179,9.87259 10.16589,9.65839 C9.58209,8.90729 8.74979,8.38719 7.82369,8.19399 Z M4.59669,4.67124 C4.11859,4.67124 3.73149,5.05764 3.73149,5.53574 C3.73149,6.01314 4.11859,6.40024 4.59669,6.40024 C5.07339,6.40024 5.46119,6.01314 5.46119,5.53574 C5.46119,5.05764 5.07339,4.67124 4.59669,4.67124 Z M9.40443,4.67124 C8.92633,4.67124 8.53923,5.05764 8.53923,5.53574 C8.53923,6.01314 8.92633,6.40024 9.40443,6.40024 C9.88113,6.40024 10.26893,6.01314 10.26893,5.53574 C10.26893,5.05764 9.88113,4.67124 9.40443,4.67124 Z'
|
|
267
|
+
},
|
|
268
|
+
neutral: {
|
|
269
|
+
fill: '#CCCCCC',
|
|
270
|
+
d: 'M7,0 C10.8661,0 14,3.1339 14,7 C14,10.8661 10.8661,14 7,14 C3.1346,14 0,10.8661 0,7 C0,3.1339 3.1346,0 7,0 Z M9.17728,9.41962 L4.82328,9.41962 C4.51458,9.41962 4.26328,9.67022 4.26328,9.97962 C4.26328,10.28902 4.51458,10.53962 4.82328,10.53962 L9.17728,10.53962 C9.48598,10.53962 9.73728,10.28902 9.73728,9.97962 C9.73728,9.67022 9.48598,9.41962 9.17728,9.41962 Z M4.59676,4.67124 C4.11866,4.67124 3.73156,5.05764 3.73156,5.53574 C3.73156,6.01314 4.11866,6.40024 4.59676,6.40024 C5.07416,6.40024 5.46126,6.01314 5.46126,5.53574 C5.46126,5.05764 5.07416,4.67124 4.59676,4.67124 Z M9.40443,4.67124 C8.92633,4.67124 8.53923,5.05764 8.53923,5.53574 C8.53923,6.01314 8.92633,6.40024 9.40443,6.40024 C9.88183,6.40024 10.26893,6.01314 10.26893,5.53574 C10.26893,5.05764 9.88183,4.67124 9.40443,4.67124 Z'
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* 情绪表情组件
|
|
276
|
+
*
|
|
277
|
+
* @param {'happy'|'sad'|'neutral'} mood 情绪类型
|
|
278
|
+
* @param {number} [size=16] 渲染尺寸(像素)
|
|
279
|
+
* @param {string} [color] 覆盖默认填充色,不传则使用 MOOD_FACE_CONFIG 中的默认色
|
|
280
|
+
* @param {number} [x] svg 元素 x 坐标(嵌入到外层 svg 中时使用)
|
|
281
|
+
* @param {number} [y] svg 元素 y 坐标(嵌入到外层 svg 中时使用)
|
|
282
|
+
*/
|
|
283
|
+
function MoodFace(_ref) {
|
|
284
|
+
var mood = _ref.mood,
|
|
285
|
+
_ref$size = _ref.size,
|
|
286
|
+
size = _ref$size === void 0 ? 16 : _ref$size,
|
|
287
|
+
color = _ref.color,
|
|
288
|
+
x = _ref.x,
|
|
289
|
+
y = _ref.y;
|
|
290
|
+
var cfg = MOOD_FACE_CONFIG[mood] || MOOD_FACE_CONFIG.neutral;
|
|
291
|
+
var fill = color || cfg.fill;
|
|
292
|
+
var svgProps = {
|
|
293
|
+
width: size,
|
|
294
|
+
height: size,
|
|
295
|
+
viewBox: '0 0 14 14',
|
|
296
|
+
'aria-hidden': true
|
|
297
|
+
};
|
|
298
|
+
if (x !== undefined) svgProps.x = x;
|
|
299
|
+
if (y !== undefined) svgProps.y = y;
|
|
300
|
+
return /*#__PURE__*/React.createElement("svg", svgProps, /*#__PURE__*/React.createElement("g", {
|
|
301
|
+
stroke: "none",
|
|
302
|
+
strokeWidth: "1",
|
|
303
|
+
fill: "none",
|
|
304
|
+
fillRule: "evenodd"
|
|
305
|
+
}, /*#__PURE__*/React.createElement("g", {
|
|
306
|
+
fill: fill
|
|
307
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
308
|
+
d: cfg.d
|
|
309
|
+
}))));
|
|
310
|
+
}
|
|
311
|
+
function InfoIcon(_ref2) {
|
|
312
|
+
var color = _ref2.color;
|
|
313
|
+
return /*#__PURE__*/React.createElement("svg", {
|
|
314
|
+
width: "14",
|
|
315
|
+
height: "14",
|
|
316
|
+
viewBox: "0 0 14 14",
|
|
317
|
+
"aria-hidden": "true"
|
|
318
|
+
}, /*#__PURE__*/React.createElement("circle", {
|
|
319
|
+
cx: "7",
|
|
320
|
+
cy: "7",
|
|
321
|
+
r: "6",
|
|
322
|
+
stroke: color,
|
|
323
|
+
strokeWidth: "1.1",
|
|
324
|
+
fill: "none"
|
|
325
|
+
}), /*#__PURE__*/React.createElement("circle", {
|
|
326
|
+
cx: "7",
|
|
327
|
+
cy: "4.3",
|
|
328
|
+
r: "0.9",
|
|
329
|
+
fill: color
|
|
330
|
+
}), /*#__PURE__*/React.createElement("line", {
|
|
331
|
+
x1: "7",
|
|
332
|
+
y1: "6.4",
|
|
333
|
+
x2: "7",
|
|
334
|
+
y2: "10.2",
|
|
335
|
+
stroke: color,
|
|
336
|
+
strokeWidth: "1.2",
|
|
337
|
+
strokeLinecap: "round"
|
|
338
|
+
}));
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/* ------------ 工具函数 ------------ */
|
|
342
|
+
|
|
343
|
+
function getMood(v, posT, negT, colors) {
|
|
344
|
+
if (v > posT) return {
|
|
345
|
+
label: '积极',
|
|
346
|
+
color: colors.positive,
|
|
347
|
+
face: 'happy'
|
|
348
|
+
};
|
|
349
|
+
if (v < negT) return {
|
|
350
|
+
label: '消极',
|
|
351
|
+
color: colors.negative,
|
|
352
|
+
face: 'sad'
|
|
353
|
+
};
|
|
354
|
+
return {
|
|
355
|
+
label: '中性',
|
|
356
|
+
color: colors.neutral,
|
|
357
|
+
face: 'neutral'
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function withAlpha(hex, alpha) {
|
|
361
|
+
var h = String(hex || '').replace('#', '');
|
|
362
|
+
if (h.length === 3) h = h.split('').map(function (c) {
|
|
363
|
+
return c + c;
|
|
364
|
+
}).join('');
|
|
365
|
+
if (h.length !== 6) return hex;
|
|
366
|
+
var r = parseInt(h.substring(0, 2), 16);
|
|
367
|
+
var g = parseInt(h.substring(2, 4), 16);
|
|
368
|
+
var b = parseInt(h.substring(4, 6), 16);
|
|
369
|
+
return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(alpha, ")");
|
|
370
|
+
}
|
|
371
|
+
export default Gauge;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
.onesight-gauge {
|
|
2
|
+
width: 100%;
|
|
3
|
+
height: 100%;
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
justify-content: center;
|
|
7
|
+
|
|
8
|
+
&__inner {
|
|
9
|
+
width: 100%;
|
|
10
|
+
max-width: 640px;
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
align-items: center;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
&__svg {
|
|
17
|
+
width: 100%;
|
|
18
|
+
height: auto;
|
|
19
|
+
display: block;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
&__value {
|
|
23
|
+
margin-top: 4px;
|
|
24
|
+
font-size: 28px;
|
|
25
|
+
font-weight: 700;
|
|
26
|
+
line-height: 1;
|
|
27
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&__tag {
|
|
31
|
+
margin-top: 12px;
|
|
32
|
+
display: inline-flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
gap: 6px;
|
|
35
|
+
padding: 3px 10px 3px 4px;
|
|
36
|
+
border: 1px solid;
|
|
37
|
+
border-radius: 999px;
|
|
38
|
+
font-size: 13px;
|
|
39
|
+
line-height: 1;
|
|
40
|
+
|
|
41
|
+
&-icon {
|
|
42
|
+
width: 20px;
|
|
43
|
+
height: 20px;
|
|
44
|
+
border-radius: 50%;
|
|
45
|
+
display: inline-flex;
|
|
46
|
+
align-items: center;
|
|
47
|
+
justify-content: center;
|
|
48
|
+
flex-shrink: 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&-label {
|
|
52
|
+
font-weight: 500;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
&-info {
|
|
56
|
+
display: inline-flex;
|
|
57
|
+
align-items: center;
|
|
58
|
+
cursor: pointer;
|
|
59
|
+
opacity: 0.85;
|
|
60
|
+
transition: opacity 0.2s;
|
|
61
|
+
|
|
62
|
+
&:hover {
|
|
63
|
+
opacity: 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -919,6 +919,38 @@ function VerticalStackedBar(props) {
|
|
|
919
919
|
dataIndex: event.dataIndex
|
|
920
920
|
});
|
|
921
921
|
currentIndex = event.dataIndex;
|
|
922
|
+
|
|
923
|
+
// 首次 showTip 后 ECharts 才会创建 tooltip DOM
|
|
924
|
+
// 给 tooltip DOM 绑定一次鼠标进出事件:
|
|
925
|
+
// - 鼠标进入自定义 tooltip 时,隐藏 axisPointer 阴影
|
|
926
|
+
// - 鼠标离开时,ECharts 会自行隐藏 tooltip,同时把阴影也置为透明
|
|
927
|
+
setTimeout(function () {
|
|
928
|
+
var chartDom = myChart.getDom();
|
|
929
|
+
var parentElement = (chartDom === null || chartDom === void 0 ? void 0 : chartDom.parentElement) || chartDom;
|
|
930
|
+
var tooltipEl = parentElement === null || parentElement === void 0 ? void 0 : parentElement.querySelector(".".concat(tooltipClassNameRef.current));
|
|
931
|
+
if (tooltipEl && !tooltipEl.dataset.axisPointerBound) {
|
|
932
|
+
tooltipEl.addEventListener('mouseenter', function () {
|
|
933
|
+
toggleAxisPointer(myChart, false);
|
|
934
|
+
});
|
|
935
|
+
tooltipEl.addEventListener('mouseleave', function () {
|
|
936
|
+
toggleAxisPointer(myChart, false);
|
|
937
|
+
myChart.dispatchAction({
|
|
938
|
+
type: 'hideTip'
|
|
939
|
+
});
|
|
940
|
+
myChart.dispatchAction({
|
|
941
|
+
type: 'downplay',
|
|
942
|
+
dataIndex: currentIndex
|
|
943
|
+
});
|
|
944
|
+
});
|
|
945
|
+
tooltipEl.dataset.axisPointerBound = 'true';
|
|
946
|
+
}
|
|
947
|
+
}, 0);
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
// tooltip 隐藏时,重置 axisPointer 阴影为透明,避免残留
|
|
951
|
+
myChart.off('hideTip');
|
|
952
|
+
myChart.on('hideTip', function () {
|
|
953
|
+
toggleAxisPointer(myChart, false);
|
|
922
954
|
});
|
|
923
955
|
myChart.setOption(option, true);
|
|
924
956
|
|
package/es/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export { default as Pie } from "./components/pie";
|
|
|
7
7
|
export { default as RadioTabs } from "./components/radio-tabs";
|
|
8
8
|
export { default as StackedBar } from "./components/stacked-bar";
|
|
9
9
|
export { default as StandardCustomLine } from "./components/standard-custom-line";
|
|
10
|
+
export { default as Gauge } from "./components/gauge";
|
|
10
11
|
export { default as StandardLine } from "./components/standard-line";
|
|
11
12
|
export { default as VerticalStackedBar } from "./components/vertical-stacked-bar";
|
|
12
13
|
export { default as WordCloud } from "./components/word-cloud";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/components/gauge/demo/base.jsx
|
|
30
|
+
var base_exports = {};
|
|
31
|
+
__export(base_exports, {
|
|
32
|
+
default: () => base_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(base_exports);
|
|
35
|
+
var import_react = __toESM(require("react"));
|
|
36
|
+
var import__ = __toESM(require("../index"));
|
|
37
|
+
function App() {
|
|
38
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", gap: 24, flexWrap: "wrap" } }, /* @__PURE__ */ import_react.default.createElement("div", { style: { width: 360, height: 322 } }, /* @__PURE__ */ import_react.default.createElement(import__.default, { value: 12 })), /* @__PURE__ */ import_react.default.createElement("div", { style: { width: 360, height: 322 } }, /* @__PURE__ */ import_react.default.createElement(import__.default, { value: -68 })), /* @__PURE__ */ import_react.default.createElement("div", { style: { width: 360, height: 322 } }, /* @__PURE__ */ import_react.default.createElement(import__.default, { value: 85 })), /* @__PURE__ */ import_react.default.createElement("div", { style: { width: 360, height: 322 } }, /* @__PURE__ */ import_react.default.createElement(import__.default, { value: 0, showInfo: false })));
|
|
39
|
+
}
|
|
40
|
+
var base_default = App;
|