jmchart 1.2.17 → 1.2.19
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/dist/jmchart.amd.js +634 -63
- package/dist/jmchart.cjs.js +634 -63
- package/dist/jmchart.esm.js +634 -63
- package/dist/jmchart.iife.js +634 -63
- package/dist/jmchart.system.js +634 -63
- package/package.json +2 -2
- package/src/series/gaugeSeries.js +7 -2
package/dist/jmchart.esm.js
CHANGED
|
@@ -150,11 +150,13 @@ const colorKeywords = {
|
|
|
150
150
|
darkseagreen: "#8fbc8f",
|
|
151
151
|
darkslateblue: "#483d8b",
|
|
152
152
|
darkslategray: "#2f4f4f",
|
|
153
|
+
darkslategrey: "#2f4f4f",
|
|
153
154
|
darkturquoise: "#00ced1",
|
|
154
155
|
darkviolet: "#9400d3",
|
|
155
156
|
deeppink: "#ff1493",
|
|
156
157
|
deepskyblue: "#00bfff",
|
|
157
158
|
dimgray: "#696969",
|
|
159
|
+
dimgrey: "#696969",
|
|
158
160
|
dodgerblue: "#1e90ff",
|
|
159
161
|
firebrick: "#b22222",
|
|
160
162
|
floralwhite: "#fffaf0",
|
|
@@ -189,6 +191,7 @@ const colorKeywords = {
|
|
|
189
191
|
lightseagreen: "#20b2aa",
|
|
190
192
|
lightskyblue: "#87cefa",
|
|
191
193
|
lightslategray: "#778899",
|
|
194
|
+
lightslategrey: "#778899",
|
|
192
195
|
lightsteelblue: "#b0c4de",
|
|
193
196
|
lightyellow: "#ffffe0",
|
|
194
197
|
lime: "#00ff00",
|
|
@@ -229,6 +232,7 @@ const colorKeywords = {
|
|
|
229
232
|
powderblue: "#b0e0e6",
|
|
230
233
|
purple: "#800080",
|
|
231
234
|
red: "#ff0000",
|
|
235
|
+
rebeccapurple: "#663399",
|
|
232
236
|
rosybrown: "#bc8f8f",
|
|
233
237
|
royalblue: "#4169e1",
|
|
234
238
|
saddlebrown: "#8b4513",
|
|
@@ -241,6 +245,7 @@ const colorKeywords = {
|
|
|
241
245
|
skyblue: "#87ceeb",
|
|
242
246
|
slateblue: "#6a5acd",
|
|
243
247
|
slategray: "#708090",
|
|
248
|
+
slategrey: "#708090",
|
|
244
249
|
snow: "#fffafa",
|
|
245
250
|
springgreen: "#00ff7f",
|
|
246
251
|
steelblue: "#4682b4",
|
|
@@ -255,7 +260,37 @@ const colorKeywords = {
|
|
|
255
260
|
whitesmoke: "#f5f5f5",
|
|
256
261
|
yellow: "#ffff00",
|
|
257
262
|
yellowgreen: "#9acd32",
|
|
258
|
-
transparent: "rgba(0,0,0,0)"
|
|
263
|
+
transparent: "rgba(0,0,0,0)",
|
|
264
|
+
// grey 别名(已有 darkslategrey/lightslategrey/slategrey/dimgrey)
|
|
265
|
+
// 以下为 CSS 系统颜色
|
|
266
|
+
activeborder: "#bfcaca",
|
|
267
|
+
activecaption: "#000080",
|
|
268
|
+
appworkspace: "#ababab",
|
|
269
|
+
background: "#636363",
|
|
270
|
+
buttonface: "#c0c0c0",
|
|
271
|
+
buttonhighlight: "#dedede",
|
|
272
|
+
buttonshadow: "#808080",
|
|
273
|
+
buttontext: "#000000",
|
|
274
|
+
captiontext: "#000000",
|
|
275
|
+
graytext: "#808080",
|
|
276
|
+
highlight: "#b3d4fc",
|
|
277
|
+
highlighttext: "#000000",
|
|
278
|
+
inactiveborder: "#d4d0c8",
|
|
279
|
+
inactivecaption: "#bfbbb0",
|
|
280
|
+
inactivecaptiontext: "#545454",
|
|
281
|
+
infobackground: "#fbfcc5",
|
|
282
|
+
infotext: "#000000",
|
|
283
|
+
menu: "#c0c0c0",
|
|
284
|
+
menutext: "#000000",
|
|
285
|
+
scrollbar: "#c0c0c0",
|
|
286
|
+
threeddarkshadow: "#696969",
|
|
287
|
+
threedface: "#c0c0c0",
|
|
288
|
+
threedhighlight: "#dfdfdf",
|
|
289
|
+
threedlightshadow: "#dcdcdc",
|
|
290
|
+
threedshadow: "#808080",
|
|
291
|
+
window: "#ffffff",
|
|
292
|
+
windowframe: "#646464",
|
|
293
|
+
windowtext: "#000000"
|
|
259
294
|
};
|
|
260
295
|
|
|
261
296
|
/**
|
|
@@ -1091,28 +1126,65 @@ class jmGradient {
|
|
|
1091
1126
|
d = location.radius * 2;
|
|
1092
1127
|
}
|
|
1093
1128
|
if(!d) {
|
|
1094
|
-
d = Math.min(location.width,location.height);
|
|
1129
|
+
d = Math.min(location.width || 0, location.height || 0);
|
|
1095
1130
|
}
|
|
1131
|
+
if(d <= 0) {
|
|
1132
|
+
d = Math.max(bounds.width || 0, bounds.height || 0, 100);
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
const width = bounds.width || d;
|
|
1136
|
+
const height = bounds.height || d;
|
|
1096
1137
|
|
|
1097
|
-
//let offsetLine = 1;//渐变长度或半径
|
|
1098
|
-
//处理百分比参数
|
|
1099
1138
|
if(jmUtils.checkPercent(x1)) {
|
|
1100
|
-
x1 = jmUtils.percentToNumber(x1) *
|
|
1139
|
+
x1 = jmUtils.percentToNumber(x1) * width;
|
|
1140
|
+
}
|
|
1141
|
+
else if(typeof x1 === 'number' && x1 >= 0 && x1 <= 1) {
|
|
1142
|
+
x1 = x1 * width;
|
|
1143
|
+
}
|
|
1144
|
+
else if(typeof x1 === 'string') {
|
|
1145
|
+
const num = parseFloat(x1);
|
|
1146
|
+
if(!isNaN(num)) x1 = num;
|
|
1101
1147
|
}
|
|
1102
1148
|
if(jmUtils.checkPercent(x2)) {
|
|
1103
|
-
x2 = jmUtils.percentToNumber(x2) *
|
|
1149
|
+
x2 = jmUtils.percentToNumber(x2) * width;
|
|
1150
|
+
}
|
|
1151
|
+
else if(typeof x2 === 'number' && x2 >= 0 && x2 <= 1) {
|
|
1152
|
+
x2 = x2 * width;
|
|
1153
|
+
}
|
|
1154
|
+
else if(typeof x2 === 'string') {
|
|
1155
|
+
const num = parseFloat(x2);
|
|
1156
|
+
if(!isNaN(num)) x2 = num;
|
|
1104
1157
|
}
|
|
1105
1158
|
if(jmUtils.checkPercent(y1)) {
|
|
1106
|
-
y1 = jmUtils.percentToNumber(y1) *
|
|
1159
|
+
y1 = jmUtils.percentToNumber(y1) * height;
|
|
1160
|
+
}
|
|
1161
|
+
else if(typeof y1 === 'number' && y1 >= 0 && y1 <= 1) {
|
|
1162
|
+
y1 = y1 * height;
|
|
1163
|
+
}
|
|
1164
|
+
else if(typeof y1 === 'string') {
|
|
1165
|
+
const num = parseFloat(y1);
|
|
1166
|
+
if(!isNaN(num)) y1 = num;
|
|
1107
1167
|
}
|
|
1108
1168
|
if(jmUtils.checkPercent(y2)) {
|
|
1109
|
-
y2 = jmUtils.percentToNumber(y2) *
|
|
1110
|
-
}
|
|
1169
|
+
y2 = jmUtils.percentToNumber(y2) * height;
|
|
1170
|
+
}
|
|
1171
|
+
else if(typeof y2 === 'number' && y2 >= 0 && y2 <= 1) {
|
|
1172
|
+
y2 = y2 * height;
|
|
1173
|
+
}
|
|
1174
|
+
else if(typeof y2 === 'string') {
|
|
1175
|
+
const num = parseFloat(y2);
|
|
1176
|
+
if(!isNaN(num)) y2 = num;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
x1 = Number(x1) || 0;
|
|
1180
|
+
y1 = Number(y1) || 0;
|
|
1181
|
+
x2 = Number(x2) || 0;
|
|
1182
|
+
y2 = Number(y2) || 0;
|
|
1111
1183
|
|
|
1112
|
-
let sx1 =
|
|
1113
|
-
let sy1 =
|
|
1114
|
-
let sx2 =
|
|
1115
|
-
let sy2 =
|
|
1184
|
+
let sx1 = x1 + (bounds.left || 0);
|
|
1185
|
+
let sy1 = y1 + (bounds.top || 0);
|
|
1186
|
+
let sx2 = x2 + (bounds.left || 0);
|
|
1187
|
+
let sy2 = y2 + (bounds.top || 0);
|
|
1116
1188
|
if(this.type === 'linear') {
|
|
1117
1189
|
if(control.mode === 'webgl' && control.webglControl) {
|
|
1118
1190
|
// WebGL 着色器中 v_text_coord 是绝对坐标,需要传递绝对坐标
|
|
@@ -1126,24 +1198,47 @@ class jmGradient {
|
|
|
1126
1198
|
else if(this.type === 'radial') {
|
|
1127
1199
|
let r1 = this.r1||0;
|
|
1128
1200
|
let r2 = this.r2;
|
|
1201
|
+
|
|
1202
|
+
if(d <= 0) {
|
|
1203
|
+
d = Math.max(bounds.width || 0, bounds.height || 0, 1);
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1129
1206
|
if(jmUtils.checkPercent(r1)) {
|
|
1130
1207
|
r1 = jmUtils.percentToNumber(r1);
|
|
1131
1208
|
r1 = d * r1;
|
|
1132
1209
|
}
|
|
1210
|
+
else if(typeof r1 === 'number' && r1 >= 0 && r1 <= 1) {
|
|
1211
|
+
r1 = r1 * d;
|
|
1212
|
+
}
|
|
1213
|
+
else if(typeof r1 === 'string') {
|
|
1214
|
+
r1 = parseFloat(r1) || 0;
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1133
1217
|
if(jmUtils.checkPercent(r2)) {
|
|
1134
1218
|
r2 = jmUtils.percentToNumber(r2);
|
|
1135
1219
|
r2 = d * r2;
|
|
1136
1220
|
}
|
|
1221
|
+
else if(typeof r2 === 'number' && r2 >= 0 && r2 <= 1) {
|
|
1222
|
+
r2 = r2 * d;
|
|
1223
|
+
}
|
|
1224
|
+
else if(typeof r2 === 'string') {
|
|
1225
|
+
r2 = parseFloat(r2);
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
if(r2 === undefined || r2 === null || isNaN(Number(r2)) || Number(r2) <= 0) {
|
|
1229
|
+
r2 = d / 2;
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
r1 = Number(r1) || 0;
|
|
1233
|
+
r2 = Number(r2) || d / 2;
|
|
1234
|
+
|
|
1137
1235
|
if(control.mode === 'webgl' && control.webglControl) {
|
|
1138
|
-
// WebGL 着色器中 v_text_coord 是绝对坐标,需要传递绝对坐标
|
|
1139
1236
|
gradient = control.webglControl.createRadialGradient(sx1, sy1, r1, sx2, sy2, r2, bounds);
|
|
1140
1237
|
gradient.key = this.toString();
|
|
1141
1238
|
}
|
|
1142
|
-
//offsetLine = Math.abs(r2 - r1);//二圆半径差
|
|
1143
1239
|
else if(context.createRadialGradient) {
|
|
1144
1240
|
gradient = context.createRadialGradient(sx1, sy1, r1, sx2, sy2, r2);
|
|
1145
1241
|
}
|
|
1146
|
-
//小程序的接口特殊
|
|
1147
1242
|
else if(context.createCircularGradient) {
|
|
1148
1243
|
gradient = context.createCircularGradient(sx1, sy1, r2);
|
|
1149
1244
|
}
|
|
@@ -1166,67 +1261,539 @@ class jmGradient {
|
|
|
1166
1261
|
}
|
|
1167
1262
|
|
|
1168
1263
|
/**
|
|
1169
|
-
*
|
|
1170
|
-
*
|
|
1171
|
-
* linear-gradient
|
|
1172
|
-
*
|
|
1264
|
+
* 解析渐变字符串
|
|
1265
|
+
* 支持的格式:
|
|
1266
|
+
* - linear-gradient(180deg, #8b5cf6 0%, #6366f1 50%, #4f46e5 100%)
|
|
1267
|
+
* - linear-gradient(to top, red, blue)
|
|
1268
|
+
* - linear-gradient(to right bottom, red, blue)
|
|
1269
|
+
* - linear-gradient(45deg, red, blue)
|
|
1270
|
+
* - linear-gradient(0.5turn, red, blue)
|
|
1271
|
+
* - radial-gradient(circle, red, blue)
|
|
1272
|
+
* - radial-gradient(ellipse at top, red, blue)
|
|
1173
1273
|
*
|
|
1174
1274
|
* @method fromString
|
|
1175
1275
|
* @for jmGradient
|
|
1176
|
-
* @
|
|
1276
|
+
* @param {string} s 渐变字符串
|
|
1177
1277
|
*/
|
|
1178
1278
|
fromString(s) {
|
|
1179
|
-
if(!s)
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
const
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1279
|
+
if(!s) {
|
|
1280
|
+
console.warn('jmGradient: 渐变字符串为空');
|
|
1281
|
+
return;
|
|
1282
|
+
}
|
|
1283
|
+
// 使用 [\s\S] 匹配任意字符(包括换行符),支持多行渐变字符串
|
|
1284
|
+
const gradientMatch = s.match(/(linear|radial)-gradient\s*\(\s*([\s\S]+)\)/i);
|
|
1285
|
+
if(!gradientMatch || gradientMatch.length < 3) {
|
|
1286
|
+
console.warn('jmGradient: 无效的渐变字符串格式: "' + s + '"');
|
|
1287
|
+
return;
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
const type = gradientMatch[1].toLowerCase();
|
|
1291
|
+
if(type !== 'linear' && type !== 'radial') {
|
|
1292
|
+
console.warn('jmGradient: 不支持的渐变类型 "' + type + '",仅支持 linear 和 radial');
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
this.type = type;
|
|
1297
|
+
const content = jmUtils.trim(gradientMatch[2]);
|
|
1298
|
+
|
|
1299
|
+
const splitIndex = this._findSplitIndex(content);
|
|
1300
|
+
if(splitIndex < 0) {
|
|
1301
|
+
console.warn('jmGradient: 无法解析渐变内容: "' + content + '"');
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
const params = content.substring(0, splitIndex).trim();
|
|
1306
|
+
const colorPart = content.substring(splitIndex + 1).trim();
|
|
1307
|
+
|
|
1308
|
+
if(!colorPart) {
|
|
1309
|
+
console.warn('jmGradient: 未找到颜色停止点');
|
|
1310
|
+
return;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
if(this.type === 'linear') {
|
|
1314
|
+
this._parseLinearParams(params);
|
|
1315
|
+
}
|
|
1316
|
+
else {
|
|
1317
|
+
this._parseRadialParams(params);
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
const colorCount = this._parseColorStops(colorPart);
|
|
1321
|
+
if(colorCount === 0) {
|
|
1322
|
+
console.warn('jmGradient: 未找到有效的颜色停止点: "' + colorPart + '"');
|
|
1323
|
+
}
|
|
1324
|
+
else if(colorCount < 2) {
|
|
1325
|
+
console.warn('jmGradient: 颜色停止点至少需要2个,当前只有 ' + colorCount + ' 个');
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
/**
|
|
1330
|
+
* 找到参数和颜色的分割位置(第一个不在括号内的逗号)
|
|
1331
|
+
* @param {string} content 内容字符串
|
|
1332
|
+
* @returns {number} 分割位置索引
|
|
1333
|
+
*/
|
|
1334
|
+
_findSplitIndex(content) {
|
|
1335
|
+
let depth = 0;
|
|
1336
|
+
|
|
1337
|
+
for(let i = 0; i < content.length; i++) {
|
|
1338
|
+
const char = content[i];
|
|
1339
|
+
if(char === '(') {
|
|
1340
|
+
depth++;
|
|
1190
1341
|
}
|
|
1191
|
-
else {
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1342
|
+
else if(char === ')') {
|
|
1343
|
+
depth--;
|
|
1344
|
+
}
|
|
1345
|
+
else if(char === ',' && depth === 0) {
|
|
1346
|
+
return i;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
return -1;
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
/**
|
|
1354
|
+
* 验证渐变配置是否有效
|
|
1355
|
+
* @returns {boolean} 是否有效
|
|
1356
|
+
*/
|
|
1357
|
+
isValid() {
|
|
1358
|
+
if(!this.type) return false;
|
|
1359
|
+
if(this.type === 'linear') {
|
|
1360
|
+
return typeof this.x1 !== 'undefined' ||
|
|
1361
|
+
typeof this.x2 !== 'undefined' ||
|
|
1362
|
+
typeof this._angle !== 'undefined';
|
|
1363
|
+
}
|
|
1364
|
+
if(this.type === 'radial') {
|
|
1365
|
+
return this.stops && this.stops.length >= 2;
|
|
1366
|
+
}
|
|
1367
|
+
return false;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
/**
|
|
1371
|
+
* 解析线性渐变参数
|
|
1372
|
+
* @param {string} params 参数字符串
|
|
1373
|
+
*/
|
|
1374
|
+
_parseLinearParams(params) {
|
|
1375
|
+
const trimmed = jmUtils.trim(params);
|
|
1376
|
+
|
|
1377
|
+
if(trimmed.startsWith('to ')) {
|
|
1378
|
+
const direction = trimmed.substring(3).toLowerCase().trim();
|
|
1379
|
+
const dir = this._directionToAngle(direction);
|
|
1380
|
+
this._angle = dir.angle;
|
|
1381
|
+
this.x1 = dir.x1;
|
|
1382
|
+
this.y1 = dir.y1;
|
|
1383
|
+
this.x2 = dir.x2;
|
|
1384
|
+
this.y2 = dir.y2;
|
|
1385
|
+
}
|
|
1386
|
+
else if(this._hasAngleUnit(trimmed)) {
|
|
1387
|
+
const angle = this._parseAngle(trimmed);
|
|
1388
|
+
this._angle = angle;
|
|
1389
|
+
const coords = this._angleToCoords(angle);
|
|
1390
|
+
this.x1 = coords.x1;
|
|
1391
|
+
this.y1 = coords.y1;
|
|
1392
|
+
this.x2 = coords.x2;
|
|
1393
|
+
this.y2 = coords.y2;
|
|
1394
|
+
}
|
|
1395
|
+
else if(trimmed.startsWith('at ')) {
|
|
1396
|
+
const radialMatch = trimmed.match(/at\s+(.+)/i);
|
|
1397
|
+
if(radialMatch) {
|
|
1398
|
+
this._parseRadialParams(trimmed);
|
|
1196
1399
|
}
|
|
1197
1400
|
}
|
|
1198
|
-
//径向渐变
|
|
1199
1401
|
else {
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
this.
|
|
1203
|
-
this.
|
|
1402
|
+
const parts = trimmed.split(/\s+/);
|
|
1403
|
+
if(parts.length >= 4) {
|
|
1404
|
+
this.x1 = parts[0];
|
|
1405
|
+
this.y1 = parts[1];
|
|
1406
|
+
this.x2 = parts[2];
|
|
1407
|
+
this.y2 = parts[3];
|
|
1204
1408
|
}
|
|
1205
|
-
else {
|
|
1206
|
-
this.x1 =
|
|
1207
|
-
this.y1 =
|
|
1208
|
-
this.
|
|
1209
|
-
this.
|
|
1210
|
-
|
|
1211
|
-
|
|
1409
|
+
else if(parts.length === 2) {
|
|
1410
|
+
this.x1 = 0;
|
|
1411
|
+
this.y1 = 0;
|
|
1412
|
+
this.x2 = parts[0];
|
|
1413
|
+
this.y2 = parts[1];
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
/**
|
|
1419
|
+
* 解析径向渐变参数
|
|
1420
|
+
* @param {string} params 参数字符串
|
|
1421
|
+
*/
|
|
1422
|
+
_parseRadialParams(params) {
|
|
1423
|
+
const trimmed = jmUtils.trim(params);
|
|
1424
|
+
|
|
1425
|
+
this.shape = 'ellipse';
|
|
1426
|
+
this.position = { x: '50%', y: '50%' };
|
|
1427
|
+
|
|
1428
|
+
const atMatch = trimmed.match(/^(.+?)\s+at\s+(.+)$/i);
|
|
1429
|
+
if(atMatch) {
|
|
1430
|
+
const shapePart = jmUtils.trim(atMatch[1]);
|
|
1431
|
+
const posPart = jmUtils.trim(atMatch[2]);
|
|
1432
|
+
this._parseRadialShape(shapePart);
|
|
1433
|
+
this._parseRadialPosition(posPart);
|
|
1434
|
+
}
|
|
1435
|
+
else if(trimmed.startsWith('circle') || trimmed.startsWith('ellipse')) {
|
|
1436
|
+
this._parseRadialShape(trimmed);
|
|
1437
|
+
this.x1 = '50%';
|
|
1438
|
+
this.y1 = '50%';
|
|
1439
|
+
this.x2 = '50%';
|
|
1440
|
+
this.y2 = '50%';
|
|
1441
|
+
}
|
|
1442
|
+
else {
|
|
1443
|
+
const parts = trimmed.split(/\s+/);
|
|
1444
|
+
if(parts.length >= 3) {
|
|
1445
|
+
this.x1 = parts[0];
|
|
1446
|
+
this.y1 = parts[1];
|
|
1447
|
+
this.r1 = parts[2];
|
|
1448
|
+
}
|
|
1449
|
+
if(parts.length >= 6) {
|
|
1450
|
+
this.x2 = parts[3];
|
|
1451
|
+
this.y2 = parts[4];
|
|
1452
|
+
this.r2 = parts[5];
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
if(this.x1 === undefined && this.y1 === undefined) {
|
|
1457
|
+
this.x1 = '50%';
|
|
1458
|
+
this.y1 = '50%';
|
|
1459
|
+
}
|
|
1460
|
+
if(this.x2 === undefined && this.y2 === undefined) {
|
|
1461
|
+
this.x2 = '50%';
|
|
1462
|
+
this.y2 = '50%';
|
|
1463
|
+
}
|
|
1464
|
+
if(this.r2 === undefined) {
|
|
1465
|
+
this.r2 = '50%';
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
/**
|
|
1470
|
+
* 解析径向渐变形状
|
|
1471
|
+
* @param {string} shapePart 形状描述
|
|
1472
|
+
*/
|
|
1473
|
+
_parseRadialShape(shapePart) {
|
|
1474
|
+
if(shapePart.startsWith('circle')) {
|
|
1475
|
+
this.shape = 'circle';
|
|
1476
|
+
const sizeMatch = shapePart.match(/circle\s*\(\s*([^)]+)\s*\)/i);
|
|
1477
|
+
if(sizeMatch) {
|
|
1478
|
+
this.r2 = jmUtils.trim(sizeMatch[1]);
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
else if(shapePart.startsWith('ellipse')) {
|
|
1482
|
+
this.shape = 'ellipse';
|
|
1483
|
+
const sizeMatch = shapePart.match(/ellipse\s*\(\s*([^)]+)\s*\)/i);
|
|
1484
|
+
if(sizeMatch) {
|
|
1485
|
+
const sizes = jmUtils.trim(sizeMatch[1]).split(/\s+/);
|
|
1486
|
+
if(sizes.length >= 2) {
|
|
1487
|
+
this.rx = sizes[0];
|
|
1488
|
+
this.ry = sizes[1];
|
|
1489
|
+
}
|
|
1212
1490
|
}
|
|
1213
1491
|
}
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
/**
|
|
1495
|
+
* 解析径向渐变位置
|
|
1496
|
+
* @param {string} posPart 位置描述
|
|
1497
|
+
*/
|
|
1498
|
+
_parseRadialPosition(posPart) {
|
|
1499
|
+
const parts = posPart.split(/\s+/);
|
|
1500
|
+
if(parts.length >= 2) {
|
|
1501
|
+
this.x1 = parts[0];
|
|
1502
|
+
this.y1 = parts[1];
|
|
1503
|
+
this.x2 = parts[0];
|
|
1504
|
+
this.y2 = parts[1];
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
/**
|
|
1509
|
+
* 解析颜色停止点
|
|
1510
|
+
* @param {string} colorPart 颜色部分字符串
|
|
1511
|
+
* @returns {number} 成功解析的颜色数量
|
|
1512
|
+
*/
|
|
1513
|
+
_parseColorStops(colorPart) {
|
|
1514
|
+
if(!colorPart) {
|
|
1515
|
+
return 0;
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
const stops = this._splitColorStops(colorPart);
|
|
1519
|
+
let lastOffset = -1;
|
|
1520
|
+
let colorCount = 0;
|
|
1521
|
+
|
|
1522
|
+
for(let i = 0; i < stops.length; i++) {
|
|
1523
|
+
const stop = jmUtils.trim(stops[i]);
|
|
1524
|
+
if(!stop) continue;
|
|
1525
|
+
|
|
1526
|
+
const parsed = this._parseSingleColorStop(stop);
|
|
1527
|
+
if(!parsed) {
|
|
1528
|
+
continue;
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
let { color, offset } = parsed;
|
|
1532
|
+
|
|
1533
|
+
if(color === 'transparent') {
|
|
1534
|
+
color = 'rgba(0,0,0,0)';
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
if(!this._isValidColor(color)) {
|
|
1538
|
+
console.warn('jmGradient: 无效的颜色格式 "' + color + '"');
|
|
1539
|
+
continue;
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
const normalizedOffset = this._normalizeOffset(offset);
|
|
1543
|
+
let finalOffset = normalizedOffset;
|
|
1544
|
+
|
|
1545
|
+
if(finalOffset === null) {
|
|
1546
|
+
if(i === 0) {
|
|
1547
|
+
finalOffset = 0;
|
|
1548
|
+
}
|
|
1549
|
+
else if(i === stops.length - 1) {
|
|
1550
|
+
finalOffset = 1;
|
|
1551
|
+
}
|
|
1552
|
+
else {
|
|
1553
|
+
const nextOffset = this._findNextOffset(stops, i);
|
|
1554
|
+
if(nextOffset !== null) {
|
|
1555
|
+
finalOffset = (lastOffset + nextOffset) / 2;
|
|
1226
1556
|
}
|
|
1557
|
+
else {
|
|
1558
|
+
finalOffset = Math.min(1, lastOffset + (1 - lastOffset) / (stops.length - i));
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
if(finalOffset !== null) {
|
|
1564
|
+
if(finalOffset < 0 || finalOffset > 1) {
|
|
1565
|
+
console.warn('jmGradient: 颜色偏移量 ' + finalOffset + ' 超出有效范围 [0, 1],将调整为有效范围');
|
|
1566
|
+
finalOffset = Math.max(0, Math.min(1, finalOffset));
|
|
1567
|
+
}
|
|
1568
|
+
lastOffset = finalOffset;
|
|
1569
|
+
this.addStop(finalOffset, color);
|
|
1570
|
+
colorCount++;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
return colorCount;
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
/**
|
|
1578
|
+
* 分割颜色停止点字符串
|
|
1579
|
+
* @param {string} colorPart 颜色部分字符串
|
|
1580
|
+
* @returns {string[]} 颜色停止点数组
|
|
1581
|
+
*/
|
|
1582
|
+
_splitColorStops(colorPart) {
|
|
1583
|
+
const stops = [];
|
|
1584
|
+
let depth = 0;
|
|
1585
|
+
let current = '';
|
|
1586
|
+
|
|
1587
|
+
for(let i = 0; i < colorPart.length; i++) {
|
|
1588
|
+
const char = colorPart[i];
|
|
1589
|
+
if(char === '(') {
|
|
1590
|
+
depth++;
|
|
1591
|
+
current += char;
|
|
1592
|
+
}
|
|
1593
|
+
else if(char === ')') {
|
|
1594
|
+
depth--;
|
|
1595
|
+
current += char;
|
|
1596
|
+
}
|
|
1597
|
+
else if(char === ',' && depth === 0) {
|
|
1598
|
+
stops.push(current.trim());
|
|
1599
|
+
current = '';
|
|
1600
|
+
}
|
|
1601
|
+
else {
|
|
1602
|
+
current += char;
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
if(current.trim()) {
|
|
1607
|
+
stops.push(current.trim());
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
return stops;
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
/**
|
|
1614
|
+
* 解析单个颜色停止点
|
|
1615
|
+
* @param {string} stop 单个颜色停止点字符串
|
|
1616
|
+
* @returns {object|null} {color, offset} 或 null
|
|
1617
|
+
*/
|
|
1618
|
+
_parseSingleColorStop(stop) {
|
|
1619
|
+
const hexMatch = stop.match(/^(#[a-fA-F0-9]{3,8})\s*(\d+(?:\.\d+)?%?)?$/i);
|
|
1620
|
+
if(hexMatch) {
|
|
1621
|
+
return { color: hexMatch[1], offset: hexMatch[2] || null };
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
const rgbaMatch = stop.match(/^(rgba?\s*\([^)]+\))\s*(\d+(?:\.\d+)?%?)?$/i);
|
|
1625
|
+
if(rgbaMatch) {
|
|
1626
|
+
return { color: rgbaMatch[1], offset: rgbaMatch[2] || null };
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
const hslaMatch = stop.match(/^(hsla?\s*\([^)]+\))\s*(\d+(?:\.\d+)?%?)?$/i);
|
|
1630
|
+
if(hslaMatch) {
|
|
1631
|
+
return { color: hslaMatch[1], offset: hslaMatch[2] || null };
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
const namedMatch = stop.match(/^([a-zA-Z]+)\s*(\d+(?:\.\d+)?%?)?$/i);
|
|
1635
|
+
if(namedMatch && this._isValidColor(namedMatch[1])) {
|
|
1636
|
+
return { color: namedMatch[1], offset: namedMatch[2] || null };
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
return null;
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
/**
|
|
1643
|
+
* 查找下一个有偏移量的颜色停止点
|
|
1644
|
+
* @param {string[]} stops 颜色停止点数组
|
|
1645
|
+
* @param {number} currentIndex 当前索引
|
|
1646
|
+
* @returns {number|null} 下一个偏移量或null
|
|
1647
|
+
*/
|
|
1648
|
+
_findNextOffset(stops, currentIndex) {
|
|
1649
|
+
for(let i = currentIndex + 1; i < stops.length; i++) {
|
|
1650
|
+
const parsed = this._parseSingleColorStop(jmUtils.trim(stops[i]));
|
|
1651
|
+
if(parsed && parsed.offset) {
|
|
1652
|
+
return this._normalizeOffset(parsed.offset);
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
return null;
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
/**
|
|
1659
|
+
* 验证颜色格式是否有效
|
|
1660
|
+
* @param {string} color 颜色字符串
|
|
1661
|
+
* @returns {boolean} 是否有效
|
|
1662
|
+
*/
|
|
1663
|
+
_isValidColor(color) {
|
|
1664
|
+
if(!color) return false;
|
|
1665
|
+
|
|
1666
|
+
const hexPattern = /^#([a-fA-F0-9]{3,8})$/;
|
|
1667
|
+
if(hexPattern.test(color)) return true;
|
|
1668
|
+
|
|
1669
|
+
// 支持 rgba(r,g,b,a) 和 rgba(r, g, b, a) 等各种空格格式
|
|
1670
|
+
const rgbPattern = /^rgba?\s*\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*(,\s*[\d.]+\s*)?\)$/i;
|
|
1671
|
+
if(rgbPattern.test(color)) return true;
|
|
1672
|
+
|
|
1673
|
+
const hslPattern = /^hsla?\s*\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*(,\s*[\d.]+\s*)?\)$/i;
|
|
1674
|
+
if(hslPattern.test(color)) return true;
|
|
1675
|
+
|
|
1676
|
+
// 使用 jmUtils 中的完整 CSS 颜色关键字表
|
|
1677
|
+
if(colorKeywords && colorKeywords[color.toLowerCase()]) return true;
|
|
1678
|
+
|
|
1679
|
+
// 宽松处理:符合 CSS 关键字命名规则的字符串也视为有效颜色
|
|
1680
|
+
// (纯字母,可能在运行时被浏览器或其他环境解析)
|
|
1681
|
+
if(/^[a-zA-Z]+$/.test(color)) return true;
|
|
1682
|
+
|
|
1683
|
+
return false;
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
/**
|
|
1687
|
+
* 标准化偏移值
|
|
1688
|
+
* @param {string} offset 偏移字符串
|
|
1689
|
+
* @returns {number|null} 0-1之间的数值或null
|
|
1690
|
+
*/
|
|
1691
|
+
_normalizeOffset(offset) {
|
|
1692
|
+
if(!offset) return null;
|
|
1693
|
+
offset = jmUtils.trim(offset);
|
|
1694
|
+
if(offset.endsWith('%')) {
|
|
1695
|
+
return parseFloat(offset) / 100;
|
|
1696
|
+
}
|
|
1697
|
+
const num = parseFloat(offset);
|
|
1698
|
+
if(isNaN(num)) return null;
|
|
1699
|
+
if(num > 1) {
|
|
1700
|
+
return num / 100;
|
|
1701
|
+
}
|
|
1702
|
+
return num;
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
/**
|
|
1706
|
+
* 检查字符串是否包含角度单位
|
|
1707
|
+
* @param {string} str 待检查字符串
|
|
1708
|
+
* @returns {boolean}
|
|
1709
|
+
*/
|
|
1710
|
+
_hasAngleUnit(str) {
|
|
1711
|
+
return /^-?\d+(\.\d+)?\s*(deg|rad|grad|turn)$/i.test(str);
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
/**
|
|
1715
|
+
* 解析角度值
|
|
1716
|
+
* @param {string} angleStr 角度字符串
|
|
1717
|
+
* @returns {number} 弧度值
|
|
1718
|
+
*/
|
|
1719
|
+
_parseAngle(angleStr) {
|
|
1720
|
+
angleStr = jmUtils.trim(angleStr);
|
|
1721
|
+
const match = angleStr.match(/^(-?\d+(\.\d+)?)\s*(deg|rad|grad|turn)?$/i);
|
|
1722
|
+
if(!match) return 0;
|
|
1723
|
+
|
|
1724
|
+
let value = parseFloat(match[1]);
|
|
1725
|
+
const unit = (match[3] || 'deg').toLowerCase();
|
|
1726
|
+
|
|
1727
|
+
switch(unit) {
|
|
1728
|
+
case 'deg':
|
|
1729
|
+
return value * Math.PI / 180;
|
|
1730
|
+
case 'rad':
|
|
1731
|
+
return value;
|
|
1732
|
+
case 'grad':
|
|
1733
|
+
return value * Math.PI / 200;
|
|
1734
|
+
case 'turn':
|
|
1735
|
+
return value * 2 * Math.PI;
|
|
1736
|
+
default:
|
|
1737
|
+
return value * Math.PI / 180;
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
/**
|
|
1742
|
+
* 将角度转换为起点和终点坐标
|
|
1743
|
+
* @param {number} angle 弧度值
|
|
1744
|
+
* @returns {object} 坐标对象
|
|
1745
|
+
*/
|
|
1746
|
+
_angleToCoords(angle) {
|
|
1747
|
+
const x = Math.cos(angle);
|
|
1748
|
+
const y = -Math.sin(angle);
|
|
1749
|
+
|
|
1750
|
+
return {
|
|
1751
|
+
x1: Math.round((0.5 - x * 0.5) * 1000) / 1000,
|
|
1752
|
+
y1: Math.round((0.5 + y * 0.5) * 1000) / 1000,
|
|
1753
|
+
x2: Math.round((0.5 + x * 0.5) * 1000) / 1000,
|
|
1754
|
+
y2: Math.round((0.5 - y * 0.5) * 1000) / 1000
|
|
1755
|
+
};
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
/**
|
|
1759
|
+
* 将方向关键词转换为角度和坐标
|
|
1760
|
+
* @param {string} direction 方向描述
|
|
1761
|
+
* @returns {object} 包含angle和坐标的对象
|
|
1762
|
+
*/
|
|
1763
|
+
_directionToAngle(direction) {
|
|
1764
|
+
const directions = {
|
|
1765
|
+
'to top': { angle: 0, x1: '50%', y1: '100%', x2: '50%', y2: '0%' },
|
|
1766
|
+
'to bottom': { angle: Math.PI, x1: '50%', y1: '0%', x2: '50%', y2: '100%' },
|
|
1767
|
+
'to left': { angle: -Math.PI / 2, x1: '100%', y1: '50%', x2: '0%', y2: '50%' },
|
|
1768
|
+
'to right': { angle: Math.PI / 2, x1: '0%', y1: '50%', x2: '100%', y2: '50%' },
|
|
1769
|
+
'to top left': { angle: -Math.PI * 3 / 4, x1: '100%', y1: '100%', x2: '0%', y2: '0%' },
|
|
1770
|
+
'to top right': { angle: -Math.PI / 4, x1: '0%', y1: '100%', x2: '100%', y2: '0%' },
|
|
1771
|
+
'to bottom left': { angle: Math.PI * 3 / 4, x1: '100%', y1: '0%', x2: '0%', y2: '100%' },
|
|
1772
|
+
'to bottom right': { angle: Math.PI / 4, x1: '0%', y1: '0%', x2: '100%', y2: '100%' },
|
|
1773
|
+
'top': { angle: 0, x1: '50%', y1: '100%', x2: '50%', y2: '0%' },
|
|
1774
|
+
'bottom': { angle: Math.PI, x1: '50%', y1: '0%', x2: '50%', y2: '100%' },
|
|
1775
|
+
'left': { angle: -Math.PI / 2, x1: '100%', y1: '50%', x2: '0%', y2: '50%' },
|
|
1776
|
+
'right': { angle: Math.PI / 2, x1: '0%', y1: '50%', x2: '100%', y2: '50%' }
|
|
1777
|
+
};
|
|
1778
|
+
|
|
1779
|
+
const dir = directions[direction];
|
|
1780
|
+
if(dir) {
|
|
1781
|
+
return dir;
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
const keywordMatch = direction.match(/to\s+(top|bottom|left|right)/i);
|
|
1785
|
+
if(keywordMatch) {
|
|
1786
|
+
const mainDir = keywordMatch[1].toLowerCase();
|
|
1787
|
+
const secDir = direction.replace(keywordMatch[0], '').trim();
|
|
1788
|
+
if(secDir) {
|
|
1789
|
+
const combined = `to ${mainDir} ${secDir}`;
|
|
1790
|
+
if(directions[combined]) {
|
|
1791
|
+
return directions[combined];
|
|
1227
1792
|
}
|
|
1228
1793
|
}
|
|
1229
1794
|
}
|
|
1795
|
+
|
|
1796
|
+
return { angle: 0, x1: '50%', y1: '100%', x2: '50%', y2: '0%' };
|
|
1230
1797
|
}
|
|
1231
1798
|
|
|
1232
1799
|
/**
|
|
@@ -12889,7 +13456,7 @@ class jmGaugeSeries extends jmSeries {
|
|
|
12889
13456
|
x: labelX,
|
|
12890
13457
|
y: labelY
|
|
12891
13458
|
},
|
|
12892
|
-
text: value.toString()
|
|
13459
|
+
text: Number(value.toFixed(2)).toString()
|
|
12893
13460
|
});
|
|
12894
13461
|
this.addShape(tickLabel);
|
|
12895
13462
|
}
|
|
@@ -12943,6 +13510,10 @@ class jmGaugeSeries extends jmSeries {
|
|
|
12943
13510
|
* 创建仪表盘值标签
|
|
12944
13511
|
*/
|
|
12945
13512
|
createGaugeValueLabel(centerX, centerY, radius, value) {
|
|
13513
|
+
// 使用 itemLabelFormat 格式化,如果没有则默认最多保留2位小数
|
|
13514
|
+
const text = this.option.itemLabelFormat ? this.option.itemLabelFormat.call(this, {
|
|
13515
|
+
yValue: value
|
|
13516
|
+
}) : Number(value.toFixed(2)).toString();
|
|
12946
13517
|
const valueLabel = this.graph.createShape('label', {
|
|
12947
13518
|
style: {
|
|
12948
13519
|
fill: this.style.valueColor || '#333',
|
|
@@ -12955,7 +13526,7 @@ class jmGaugeSeries extends jmSeries {
|
|
|
12955
13526
|
x: centerX,
|
|
12956
13527
|
y: centerY + radius * 0.3
|
|
12957
13528
|
},
|
|
12958
|
-
text:
|
|
13529
|
+
text: text
|
|
12959
13530
|
});
|
|
12960
13531
|
this.addShape(valueLabel);
|
|
12961
13532
|
if (this.style.unit) {
|