@visactor/vchart-extension 2.0.0-alpha.1 → 2.0.0-alpha.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/build/index.js +3074 -19
- package/build/index.min.js +2 -2
- package/cjs/charts/axis-3d/log-axis.js +1 -2
- package/cjs/charts/axis-3d/time-axis.js +2 -1
- package/cjs/charts/bar-3d/series-spec-transformer.js +2 -1
- package/cjs/charts/conversion-funnel/conversion-funnel-transformer.js +0 -1
- package/cjs/charts/conversion-funnel/interface.js +1 -1
- package/cjs/charts/conversion-funnel/util.js +1 -1
- package/cjs/charts/funnel-3d/chart.js +1 -1
- package/cjs/charts/funnel-3d/constant.js +1 -1
- package/cjs/charts/funnel-3d/index.js +1 -1
- package/cjs/charts/funnel-3d/interface.js +1 -1
- package/cjs/charts/funnel-3d/series-spec-transformer.js +1 -1
- package/cjs/charts/funnel-3d/series.js +1 -1
- package/cjs/charts/funnel-3d/theme.js +1 -1
- package/cjs/charts/histogram-3d/chart.js +1 -1
- package/cjs/charts/histogram-3d/index.js +1 -1
- package/cjs/charts/histogram-3d/interface.js +1 -1
- package/cjs/charts/image-cloud/image-cloud-transformer.js +1 -1
- package/cjs/charts/image-cloud/image-cloud.js +1 -2
- package/cjs/charts/image-cloud/index.js +1 -1
- package/cjs/charts/image-cloud/interface.js +1 -1
- package/cjs/charts/pictogram/element-highlight-by-graphic-name.js +1 -1
- package/cjs/charts/pictogram/element-select-by-graphic-name.js +1 -1
- package/cjs/charts/pictogram/index.js +1 -1
- package/cjs/charts/pictogram/interface.js +1 -1
- package/cjs/charts/pictogram/pictogram-transformer.js +1 -1
- package/cjs/components/bar-link/bar-link.js +1 -1
- package/cjs/components/bar-link/constant.js +1 -1
- package/cjs/components/bar-link/index.js +1 -1
- package/cjs/components/bar-link/type.js +1 -1
- package/cjs/components/bar-link/util.js +1 -1
- package/cjs/components/map-label/index.js +1 -1
- package/cjs/components/map-label/layout.js +1 -1
- package/cjs/components/map-label/map-label-transformer.js +1 -1
- package/cjs/components/map-label/map-label.js +1 -1
- package/cjs/components/map-label/theme.js +1 -1
- package/cjs/components/map-label/type.js +1 -1
- package/cjs/components/series-break/constant.js +2 -1
- package/cjs/components/series-break/index.js +1 -1
- package/cjs/components/series-break/series-break.js +1 -1
- package/cjs/components/series-break/type.js +1 -1
- package/cjs/components/series-break/util.js +1 -1
- package/cjs/components/series-label/constant.js +1 -1
- package/cjs/components/series-label/index.js +1 -1
- package/cjs/components/series-label/series-label.js +1 -1
- package/cjs/components/series-label/type.js +1 -1
- package/cjs/components/series-label/util.js +1 -1
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +2 -1
- package/cjs/index.js.map +1 -1
- package/esm/charts/axis-3d/log-axis.js +1 -2
- package/esm/charts/axis-3d/time-axis.js +2 -1
- package/esm/charts/bar-3d/series-spec-transformer.js +2 -1
- package/esm/charts/conversion-funnel/conversion-funnel-transformer.js +1 -2
- package/esm/charts/conversion-funnel/interface.js +1 -1
- package/esm/charts/conversion-funnel/util.js +1 -1
- package/esm/charts/funnel-3d/chart.js +1 -1
- package/esm/charts/funnel-3d/constant.js +1 -1
- package/esm/charts/funnel-3d/index.js +1 -1
- package/esm/charts/funnel-3d/interface.js +1 -1
- package/esm/charts/funnel-3d/series-spec-transformer.js +1 -1
- package/esm/charts/funnel-3d/series.js +1 -1
- package/esm/charts/funnel-3d/theme.js +1 -1
- package/esm/charts/histogram-3d/chart.js +1 -1
- package/esm/charts/histogram-3d/index.js +1 -1
- package/esm/charts/histogram-3d/interface.js +1 -1
- package/esm/charts/image-cloud/image-cloud-transformer.js +1 -1
- package/esm/charts/image-cloud/image-cloud.js +1 -2
- package/esm/charts/image-cloud/index.js +1 -1
- package/esm/charts/image-cloud/interface.js +1 -1
- package/esm/charts/pictogram/element-highlight-by-graphic-name.js +1 -1
- package/esm/charts/pictogram/element-select-by-graphic-name.js +1 -1
- package/esm/charts/pictogram/index.js +1 -1
- package/esm/charts/pictogram/interface.js +1 -1
- package/esm/charts/pictogram/pictogram-transformer.js +1 -1
- package/esm/components/bar-link/bar-link.js +1 -1
- package/esm/components/bar-link/constant.js +1 -1
- package/esm/components/bar-link/index.js +1 -1
- package/esm/components/bar-link/type.js +1 -1
- package/esm/components/bar-link/util.js +1 -1
- package/esm/components/map-label/index.js +1 -1
- package/esm/components/map-label/layout.js +1 -1
- package/esm/components/map-label/map-label-transformer.js +1 -1
- package/esm/components/map-label/map-label.js +1 -1
- package/esm/components/map-label/theme.js +1 -1
- package/esm/components/map-label/type.js +1 -1
- package/esm/components/series-break/constant.js +2 -1
- package/esm/components/series-break/index.js +1 -1
- package/esm/components/series-break/series-break.js +1 -1
- package/esm/components/series-break/type.js +1 -1
- package/esm/components/series-break/util.js +1 -1
- package/esm/components/series-label/constant.js +1 -1
- package/esm/components/series-label/index.js +1 -1
- package/esm/components/series-label/series-label.js +1 -1
- package/esm/components/series-label/type.js +1 -1
- package/esm/components/series-label/util.js +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/index.js +4 -0
- package/esm/index.js.map +1 -1
- package/package.json +3 -3
package/build/index.js
CHANGED
|
@@ -1071,6 +1071,180 @@
|
|
|
1071
1071
|
return 0;
|
|
1072
1072
|
}
|
|
1073
1073
|
|
|
1074
|
+
const tagNameToType = {
|
|
1075
|
+
svg: "group",
|
|
1076
|
+
rect: "rect",
|
|
1077
|
+
line: "rule",
|
|
1078
|
+
polygon: "polygon",
|
|
1079
|
+
path: "path",
|
|
1080
|
+
polyline: "line",
|
|
1081
|
+
g: "group",
|
|
1082
|
+
circle: "arc",
|
|
1083
|
+
ellipse: "arc"
|
|
1084
|
+
},
|
|
1085
|
+
validTagName = Object.keys(tagNameToType),
|
|
1086
|
+
validGroupNode = ["g", "svg", "text", "tspan", "switch"],
|
|
1087
|
+
validTextAttributes = ["font-size", "font-family", "font-weight", "font-style", "text-align", "text-anchor"],
|
|
1088
|
+
validCircleAttributes = ["cx", "cy", "r"],
|
|
1089
|
+
validEllipseAttributes = ["cx", "cy", "rx", "ry"],
|
|
1090
|
+
validLineAttributes = ["x1", "x2", "y1", "y2"],
|
|
1091
|
+
validAttributes = ["visibility", "x", "y", "width", "height", "d", "points", "stroke", "stroke-width", "fill", "fill-opacity", "stroke-opacity", ...validTextAttributes, ...validCircleAttributes, ...validEllipseAttributes, ...validLineAttributes],
|
|
1092
|
+
validInheritAttributes = ["visible", "fill", "stroke", "stroke-width", "fill-opacity", "stroke-opacity", ...validTextAttributes],
|
|
1093
|
+
numberReg = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
|
|
1094
|
+
function splitNumberSequence(rawStr) {
|
|
1095
|
+
return rawStr.match(numberReg) || [];
|
|
1096
|
+
}
|
|
1097
|
+
const svgParser = function (data) {
|
|
1098
|
+
let option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1099
|
+
let parser = option.customDOMParser;
|
|
1100
|
+
if (parser || (null === window || void 0 === window ? void 0 : window.DOMParser) && (parser = svg => new DOMParser().parseFromString(svg, "text/xml")), !parser) throw new Error("No Available DOMParser!");
|
|
1101
|
+
const svg = parser(data);
|
|
1102
|
+
let node = 9 === svg.nodeType ? svg.firstChild : svg;
|
|
1103
|
+
for (; node && ("svg" !== node.nodeName.toLowerCase() || 1 !== node.nodeType);) node = node.nextSibling;
|
|
1104
|
+
if (node) {
|
|
1105
|
+
return parseSvgNode(node);
|
|
1106
|
+
}
|
|
1107
|
+
return null;
|
|
1108
|
+
};
|
|
1109
|
+
let idx = 0;
|
|
1110
|
+
function parseSvgNode(svg) {
|
|
1111
|
+
let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1112
|
+
const elements = [],
|
|
1113
|
+
root = parseNode(svg, null);
|
|
1114
|
+
let width = parseFloat(svg.getAttribute("width") || opt.width),
|
|
1115
|
+
height = parseFloat(svg.getAttribute("height") || opt.height);
|
|
1116
|
+
!vutils.isValidNumber(width) && (width = null), !vutils.isValidNumber(height) && (height = null);
|
|
1117
|
+
const viewBox = svg.getAttribute("viewBox");
|
|
1118
|
+
let viewBoxRect;
|
|
1119
|
+
if (viewBox) {
|
|
1120
|
+
const viewBoxArr = splitNumberSequence(viewBox);
|
|
1121
|
+
if (viewBoxArr.length >= 4 && (viewBoxRect = {
|
|
1122
|
+
x: parseFloat(viewBoxArr[0] || 0),
|
|
1123
|
+
y: parseFloat(viewBoxArr[1] || 0),
|
|
1124
|
+
width: parseFloat(viewBoxArr[2]),
|
|
1125
|
+
height: parseFloat(viewBoxArr[3])
|
|
1126
|
+
}, width || height)) {
|
|
1127
|
+
const boundingRect = {
|
|
1128
|
+
x: 0,
|
|
1129
|
+
y: 0,
|
|
1130
|
+
width: width,
|
|
1131
|
+
height: height
|
|
1132
|
+
},
|
|
1133
|
+
scaleX = boundingRect.width / viewBoxRect.width,
|
|
1134
|
+
scaleY = boundingRect.height / viewBoxRect.height,
|
|
1135
|
+
scale = Math.min(scaleX, scaleY),
|
|
1136
|
+
transLateX = -(viewBoxRect.x + viewBoxRect.width / 2) * scale + (boundingRect.x + boundingRect.width / 2),
|
|
1137
|
+
transLateY = -(viewBoxRect.y + viewBoxRect.height / 2) * scale + (boundingRect.y + boundingRect.height / 2),
|
|
1138
|
+
viewBoxTransform = new vutils.Matrix().translate(transLateX, transLateY).scale(scale, scale);
|
|
1139
|
+
root.transform = viewBoxTransform;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
return traverse(svg, root, elements), {
|
|
1143
|
+
root: root,
|
|
1144
|
+
width: width,
|
|
1145
|
+
height: height,
|
|
1146
|
+
elements: elements,
|
|
1147
|
+
viewBoxRect: viewBoxRect
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
function parseInheritAttributes(parsedElement) {
|
|
1151
|
+
let inheritedAttrs;
|
|
1152
|
+
const {
|
|
1153
|
+
parent: parent,
|
|
1154
|
+
attributes: attributes
|
|
1155
|
+
} = parsedElement,
|
|
1156
|
+
parse = parent => parent ? validInheritAttributes.reduce((acc, attrName) => {
|
|
1157
|
+
const camelAttrName = vutils.toCamelCase(attrName);
|
|
1158
|
+
return vutils.isValid(parent[camelAttrName]) && (acc[camelAttrName] = parent[camelAttrName]), acc;
|
|
1159
|
+
}, {}) : {};
|
|
1160
|
+
return parent ? (parent._inheritStyle || (parent._inheritStyle = parse(parent.attributes)), inheritedAttrs = vutils.merge({}, parent._inheritStyle, parse(attributes))) : inheritedAttrs = parse(attributes), inheritedAttrs;
|
|
1161
|
+
}
|
|
1162
|
+
function parseAttributes(el) {
|
|
1163
|
+
var _a, _b, _c;
|
|
1164
|
+
const attrs = {},
|
|
1165
|
+
attributes = null !== (_a = el.attributes) && void 0 !== _a ? _a : {},
|
|
1166
|
+
style = null !== (_b = el.style) && void 0 !== _b ? _b : {};
|
|
1167
|
+
for (let i = 0; i < validAttributes.length; i++) {
|
|
1168
|
+
const attrName = validAttributes[i],
|
|
1169
|
+
attrValue = vutils.isValid(style[attrName]) && "" !== style[attrName] ? style[attrName] : null === (_c = attributes[attrName]) || void 0 === _c ? void 0 : _c.value;
|
|
1170
|
+
vutils.isValid(attrValue) && (attrs[vutils.toCamelCase(attrName)] = isNaN(+attrValue) ? attrValue : parseFloat(attrValue));
|
|
1171
|
+
}
|
|
1172
|
+
return "none" === style.display && (attrs.visible = !1), ["fontSize", "strokeWidth", "width", "height"].forEach(attr => {
|
|
1173
|
+
const attrValue = attrs[attr];
|
|
1174
|
+
vutils.isString(attrs[attr]) && (attrs[attr] = parseFloat(attrValue));
|
|
1175
|
+
}), attrs;
|
|
1176
|
+
}
|
|
1177
|
+
function parseNode(node, parent) {
|
|
1178
|
+
var _a, _b, _c, _d, _e;
|
|
1179
|
+
const tagName = null === (_a = node.tagName) || void 0 === _a ? void 0 : _a.toLowerCase();
|
|
1180
|
+
if (3 === node.nodeType || "text" === tagName || "tspan" === tagName) return parseText(node, parent);
|
|
1181
|
+
if (!validTagName.includes(tagName)) return null;
|
|
1182
|
+
const parsed = {
|
|
1183
|
+
tagName: tagName,
|
|
1184
|
+
graphicType: tagNameToType[tagName],
|
|
1185
|
+
attributes: parseAttributes(node),
|
|
1186
|
+
parent: parent,
|
|
1187
|
+
name: null !== (_b = node.getAttribute("name")) && void 0 !== _b ? _b : null === (_c = null == parent ? void 0 : parent.attributes) || void 0 === _c ? void 0 : _c.name,
|
|
1188
|
+
id: null !== (_d = node.getAttribute("id")) && void 0 !== _d ? _d : `${tagName}-${idx++}`,
|
|
1189
|
+
transform: parseTransform(node)
|
|
1190
|
+
};
|
|
1191
|
+
return parsed._inheritStyle = parseInheritAttributes(parsed), parent && !vutils.isValid(parsed.name) && (parsed._nameFromParent = null !== (_e = parent.name) && void 0 !== _e ? _e : parent._nameFromParent), parsed;
|
|
1192
|
+
}
|
|
1193
|
+
function parseText(node, parent) {
|
|
1194
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1195
|
+
if (!parent) return null;
|
|
1196
|
+
const tagName = null === (_a = node.tagName) || void 0 === _a ? void 0 : _a.toLowerCase();
|
|
1197
|
+
if (!tagName && "group" !== parent.graphicType) return null;
|
|
1198
|
+
const nodeAsGroup = "text" === tagName || "tspan" === tagName,
|
|
1199
|
+
elType = nodeAsGroup ? "group" : "text",
|
|
1200
|
+
value = nodeAsGroup || null === (_b = node.textContent) || void 0 === _b ? void 0 : _b.replace(/\n/g, " ").replace(/\s+/g, " ");
|
|
1201
|
+
if (" " === value) return null;
|
|
1202
|
+
let parsed;
|
|
1203
|
+
return parsed = nodeAsGroup ? {
|
|
1204
|
+
tagName: tagName,
|
|
1205
|
+
graphicType: elType,
|
|
1206
|
+
attributes: parseAttributes(node),
|
|
1207
|
+
parent: parent,
|
|
1208
|
+
name: node.getAttribute("name"),
|
|
1209
|
+
id: null !== (_c = node.getAttribute("id")) && void 0 !== _c ? _c : `${tagName}-${idx++}`,
|
|
1210
|
+
transform: parseTransform(node),
|
|
1211
|
+
value: value
|
|
1212
|
+
} : {
|
|
1213
|
+
tagName: tagName,
|
|
1214
|
+
graphicType: "text",
|
|
1215
|
+
attributes: parseAttributes(node),
|
|
1216
|
+
parent: parent,
|
|
1217
|
+
name: null == parent ? void 0 : parent.name,
|
|
1218
|
+
id: null !== (_e = null === (_d = node.getAttribute) || void 0 === _d ? void 0 : _d.call(node, "id")) && void 0 !== _e ? _e : `${tagName}-${idx++}`,
|
|
1219
|
+
value: value
|
|
1220
|
+
}, parsed._inheritStyle = parseInheritAttributes(parsed), vutils.isValid(parsed.name) || (parsed._nameFromParent = null !== (_f = parent.name) && void 0 !== _f ? _f : parent._nameFromParent), nodeAsGroup ? parent._textGroupStyle ? parsed._textGroupStyle = vutils.merge({}, parent._textGroupStyle, parseAttributes(node)) : parsed._textGroupStyle = parseAttributes(node) : parsed.attributes = parsed._inheritStyle, parsed;
|
|
1221
|
+
}
|
|
1222
|
+
function parseTransform(node) {
|
|
1223
|
+
var _a, _b;
|
|
1224
|
+
const transforms = null === (_a = node.transform) || void 0 === _a ? void 0 : _a.baseVal;
|
|
1225
|
+
if (!transforms) return null;
|
|
1226
|
+
const matrix = null === (_b = transforms.consolidate()) || void 0 === _b ? void 0 : _b.matrix;
|
|
1227
|
+
if (!matrix) return null;
|
|
1228
|
+
const {
|
|
1229
|
+
a: a,
|
|
1230
|
+
b: b,
|
|
1231
|
+
c: c,
|
|
1232
|
+
d: d,
|
|
1233
|
+
e: e,
|
|
1234
|
+
f: f
|
|
1235
|
+
} = matrix;
|
|
1236
|
+
return new vutils.Matrix(a, b, c, d, e, f);
|
|
1237
|
+
}
|
|
1238
|
+
function traverse(node, parsedParent) {
|
|
1239
|
+
let result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
1240
|
+
var _a;
|
|
1241
|
+
if (!node) return;
|
|
1242
|
+
let parseResult;
|
|
1243
|
+
"svg" !== node.nodeName && (parseResult = parseNode(node, parsedParent)), parseResult && result.push(parseResult);
|
|
1244
|
+
let child = validGroupNode.includes(null === (_a = node.tagName) || void 0 === _a ? void 0 : _a.toLocaleLowerCase()) ? node.firstChild : null;
|
|
1245
|
+
for (; child;) traverse(child, null != parseResult ? parseResult : parsedParent, result), child = child.nextSibling;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1074
1248
|
let idIndex = 0;
|
|
1075
1249
|
const maxId = 1e8;
|
|
1076
1250
|
function getUUID() {
|
|
@@ -1078,6 +1252,88 @@
|
|
|
1078
1252
|
return idIndex > maxId && (idIndex = 0), prefix + "_" + idIndex++;
|
|
1079
1253
|
}
|
|
1080
1254
|
|
|
1255
|
+
class DataSet {
|
|
1256
|
+
constructor(options) {
|
|
1257
|
+
var _a;
|
|
1258
|
+
let name;
|
|
1259
|
+
this.options = options, this.isDataSet = !0, this.transformMap = {}, this.parserMap = {}, this.dataViewMap = {}, this.target = new vutils.EventEmitter(), name = (null == options ? void 0 : options.name) ? options.name : getUUID("dataset"), this.name = name, this._logger = null !== (_a = null == options ? void 0 : options.logger) && void 0 !== _a ? _a : vutils.Logger.getInstance();
|
|
1260
|
+
}
|
|
1261
|
+
setLogger(logger) {
|
|
1262
|
+
this._logger = logger;
|
|
1263
|
+
}
|
|
1264
|
+
getDataView(name) {
|
|
1265
|
+
return this.dataViewMap[name];
|
|
1266
|
+
}
|
|
1267
|
+
setDataView(name, dataView) {
|
|
1268
|
+
var _a;
|
|
1269
|
+
this.dataViewMap[name] && (null === (_a = this._logger) || void 0 === _a || _a.error(`Error: dataView ${name} 之前已存在,请重新命名`)), this.dataViewMap[name] = dataView;
|
|
1270
|
+
}
|
|
1271
|
+
removeDataView(name) {
|
|
1272
|
+
this.dataViewMap[name] = null, delete this.dataViewMap[name];
|
|
1273
|
+
}
|
|
1274
|
+
registerParser(name, parser) {
|
|
1275
|
+
var _a;
|
|
1276
|
+
this.parserMap[name] && (null === (_a = this._logger) || void 0 === _a || _a.warn(`Warn: transform ${name} 之前已注册,执行覆盖逻辑`)), this.parserMap[name] = parser;
|
|
1277
|
+
}
|
|
1278
|
+
removeParser(name) {
|
|
1279
|
+
this.parserMap[name] = null, delete this.parserMap[name];
|
|
1280
|
+
}
|
|
1281
|
+
getParser(name) {
|
|
1282
|
+
return this.parserMap[name] || this.parserMap.default;
|
|
1283
|
+
}
|
|
1284
|
+
registerTransform(name, transform) {
|
|
1285
|
+
var _a;
|
|
1286
|
+
this.transformMap[name] && (null === (_a = this._logger) || void 0 === _a || _a.warn(`Warn: transform ${name} 之前已注册,执行覆盖逻辑`)), this.transformMap[name] = transform;
|
|
1287
|
+
}
|
|
1288
|
+
removeTransform(name) {
|
|
1289
|
+
this.transformMap[name] = null, delete this.transformMap[name];
|
|
1290
|
+
}
|
|
1291
|
+
getTransform(name) {
|
|
1292
|
+
return this.transformMap[name];
|
|
1293
|
+
}
|
|
1294
|
+
multipleDataViewAddListener(list, event, call) {
|
|
1295
|
+
this._callMap || (this._callMap = new Map());
|
|
1296
|
+
let callAd = this._callMap.get(call);
|
|
1297
|
+
callAd || (callAd = () => {
|
|
1298
|
+
list.some(l => l.isRunning) || call();
|
|
1299
|
+
}), list.forEach(l => {
|
|
1300
|
+
l.target.addListener(event, callAd);
|
|
1301
|
+
}), this._callMap.set(call, callAd);
|
|
1302
|
+
}
|
|
1303
|
+
allDataViewAddListener(event, call) {
|
|
1304
|
+
this.multipleDataViewAddListener(Object.values(this.dataViewMap), event, call);
|
|
1305
|
+
}
|
|
1306
|
+
multipleDataViewRemoveListener(list, event, call) {
|
|
1307
|
+
if (this._callMap) {
|
|
1308
|
+
const callAd = this._callMap.get(call);
|
|
1309
|
+
callAd && list.forEach(l => {
|
|
1310
|
+
l.target.removeListener(event, callAd);
|
|
1311
|
+
}), this._callMap.delete(call);
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
multipleDataViewUpdateInParse(newData) {
|
|
1315
|
+
newData.forEach(d => {
|
|
1316
|
+
var _a;
|
|
1317
|
+
return null === (_a = this.getDataView(d.name)) || void 0 === _a ? void 0 : _a.markRunning();
|
|
1318
|
+
}), newData.forEach(d => {
|
|
1319
|
+
var _a;
|
|
1320
|
+
return null === (_a = this.getDataView(d.name)) || void 0 === _a ? void 0 : _a.parseNewData(d.data, d.options);
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
multipleDataViewUpdateInRawData(newData) {
|
|
1324
|
+
newData.forEach(d => {
|
|
1325
|
+
var _a;
|
|
1326
|
+
return null === (_a = this.getDataView(d.name)) || void 0 === _a ? void 0 : _a.markRunning();
|
|
1327
|
+
}), newData.forEach(d => {
|
|
1328
|
+
var _a;
|
|
1329
|
+
return null === (_a = this.getDataView(d.name)) || void 0 === _a ? void 0 : _a.updateRawData(d.data, d.options);
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
destroy() {
|
|
1333
|
+
this.transformMap = null, this.parserMap = null, this.dataViewMap = null, this._callMap = null, this.target.removeAllListeners();
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1081
1337
|
class DataView {
|
|
1082
1338
|
constructor(dataSet, options) {
|
|
1083
1339
|
var _this = this;
|
|
@@ -6352,7 +6608,7 @@
|
|
|
6352
6608
|
}
|
|
6353
6609
|
}
|
|
6354
6610
|
|
|
6355
|
-
function circle(ctx, r, x, y, z) {
|
|
6611
|
+
function circle$1(ctx, r, x, y, z) {
|
|
6356
6612
|
return z ? ctx.arc(x, y, r, 0, vutils.tau, !1, z) : ctx.arc(x, y, r, 0, vutils.tau), !1;
|
|
6357
6613
|
}
|
|
6358
6614
|
class CircleSymbol extends BaseSymbol {
|
|
@@ -6360,17 +6616,17 @@
|
|
|
6360
6616
|
super(...arguments), this.type = "circle", this.pathStr = "M0.5,0A0.5,0.5,0,1,1,-0.5,0A0.5,0.5,0,1,1,0.5,0";
|
|
6361
6617
|
}
|
|
6362
6618
|
draw(ctx, size, x, y, z) {
|
|
6363
|
-
return circle(ctx, this.parseSize(size) / 2, x, y, z);
|
|
6619
|
+
return circle$1(ctx, this.parseSize(size) / 2, x, y, z);
|
|
6364
6620
|
}
|
|
6365
6621
|
drawOffset(ctx, size, x, y, offset, z) {
|
|
6366
|
-
return circle(ctx, this.parseSize(size) / 2 + offset, x, y, z);
|
|
6622
|
+
return circle$1(ctx, this.parseSize(size) / 2 + offset, x, y, z);
|
|
6367
6623
|
}
|
|
6368
6624
|
drawToSvgPath(size, x, y, z) {
|
|
6369
6625
|
const r = this.parseSize(size) / 2;
|
|
6370
6626
|
return `M ${x - r}, ${y} a ${r},${r} 0 1,0 ${2 * r},0 a ${r},${r} 0 1,0 -${2 * r},0`;
|
|
6371
6627
|
}
|
|
6372
6628
|
}
|
|
6373
|
-
var circle$
|
|
6629
|
+
var circle$2 = new CircleSymbol();
|
|
6374
6630
|
|
|
6375
6631
|
function cross(ctx, r, x, y, z) {
|
|
6376
6632
|
return ctx.moveTo(-3 * r + x, -r + y, z), ctx.lineTo(-r + x, -r + y, z), ctx.lineTo(-r + x, -3 * r + y, z), ctx.lineTo(r + x, -3 * r + y, z), ctx.lineTo(r + x, -r + y, z), ctx.lineTo(3 * r + x, -r + y, z), ctx.lineTo(3 * r + x, r + y, z), ctx.lineTo(r + x, r + y, z), ctx.lineTo(r + x, 3 * r + y, z), ctx.lineTo(-r + x, 3 * r + y, z), ctx.lineTo(-r + x, r + y, z), ctx.lineTo(-3 * r + x, r + y, z), ctx.closePath(), !0;
|
|
@@ -6391,7 +6647,7 @@
|
|
|
6391
6647
|
}
|
|
6392
6648
|
var cross$1 = new CrossSymbol();
|
|
6393
6649
|
|
|
6394
|
-
function diamond(ctx, r, x, y, z) {
|
|
6650
|
+
function diamond$1(ctx, r, x, y, z) {
|
|
6395
6651
|
return ctx.moveTo(x, y - r, z), ctx.lineTo(r + x, y, z), ctx.lineTo(x, y + r, z), ctx.lineTo(x - r, y, z), ctx.closePath(), !0;
|
|
6396
6652
|
}
|
|
6397
6653
|
class DiamondSymbol extends BaseSymbol {
|
|
@@ -6399,18 +6655,18 @@
|
|
|
6399
6655
|
super(...arguments), this.type = "diamond", this.pathStr = "M-0.5,0L0,-0.5L0.5,0L0,0.5Z";
|
|
6400
6656
|
}
|
|
6401
6657
|
draw(ctx, size, x, y, z) {
|
|
6402
|
-
return diamond(ctx, this.parseSize(size) / 2, x, y, z);
|
|
6658
|
+
return diamond$1(ctx, this.parseSize(size) / 2, x, y, z);
|
|
6403
6659
|
}
|
|
6404
6660
|
drawFitDir(ctx, size, x, y, z) {
|
|
6405
|
-
return diamond(ctx, this.parseSize(size) / 2, x, y, z);
|
|
6661
|
+
return diamond$1(ctx, this.parseSize(size) / 2, x, y, z);
|
|
6406
6662
|
}
|
|
6407
6663
|
drawOffset(ctx, size, x, y, offset, z) {
|
|
6408
|
-
return diamond(ctx, this.parseSize(size) / 2 + offset, x, y, z);
|
|
6664
|
+
return diamond$1(ctx, this.parseSize(size) / 2 + offset, x, y, z);
|
|
6409
6665
|
}
|
|
6410
6666
|
}
|
|
6411
|
-
var diamond$
|
|
6667
|
+
var diamond$2 = new DiamondSymbol();
|
|
6412
6668
|
|
|
6413
|
-
function square(ctx, r, x, y) {
|
|
6669
|
+
function square$2(ctx, r, x, y) {
|
|
6414
6670
|
const wh = 2 * r;
|
|
6415
6671
|
return ctx.rect(x - r, y - r, wh, wh), !1;
|
|
6416
6672
|
}
|
|
@@ -6419,13 +6675,13 @@
|
|
|
6419
6675
|
super(...arguments), this.type = "square", this.pathStr = "M-0.5,-0.5h1v1h-1Z";
|
|
6420
6676
|
}
|
|
6421
6677
|
draw(ctx, size, x, y) {
|
|
6422
|
-
return square(ctx, this.parseSize(size) / 2, x, y);
|
|
6678
|
+
return square$2(ctx, this.parseSize(size) / 2, x, y);
|
|
6423
6679
|
}
|
|
6424
6680
|
drawOffset(ctx, size, x, y, offset) {
|
|
6425
|
-
return square(ctx, this.parseSize(size) / 2 + offset, x, y);
|
|
6681
|
+
return square$2(ctx, this.parseSize(size) / 2 + offset, x, y);
|
|
6426
6682
|
}
|
|
6427
6683
|
}
|
|
6428
|
-
var square$
|
|
6684
|
+
var square$3 = new SquareSymbol();
|
|
6429
6685
|
|
|
6430
6686
|
function trianglUpOffset(ctx, r, x, y) {
|
|
6431
6687
|
let offset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
@@ -6449,12 +6705,12 @@
|
|
|
6449
6705
|
super(...arguments), this.type = "triangle";
|
|
6450
6706
|
}
|
|
6451
6707
|
}
|
|
6452
|
-
var triangle = new TriangleSymbol();
|
|
6708
|
+
var triangle$1 = new TriangleSymbol();
|
|
6453
6709
|
|
|
6454
6710
|
const kr = Math.sin(Math.PI / 10) / Math.sin(7 * Math.PI / 10),
|
|
6455
6711
|
kx = Math.sin(vutils.tau / 10) * kr,
|
|
6456
6712
|
ky = -Math.cos(vutils.tau / 10) * kr;
|
|
6457
|
-
function star(ctx, r, transX, transY) {
|
|
6713
|
+
function star$1(ctx, r, transX, transY) {
|
|
6458
6714
|
const x = kx * r,
|
|
6459
6715
|
y = ky * r;
|
|
6460
6716
|
ctx.moveTo(transX, -r + transY), ctx.lineTo(x + transX, y + transY);
|
|
@@ -6471,13 +6727,13 @@
|
|
|
6471
6727
|
super(...arguments), this.type = "star", this.pathStr = "M0 -1L0.22451398828979266 -0.3090169943749474L0.9510565162951535 -0.30901699437494745L0.3632712640026804 0.1180339887498948L0.5877852522924732 0.8090169943749473L8.326672684688674e-17 0.3819660112501051L-0.587785252292473 0.8090169943749476L-0.3632712640026804 0.11803398874989487L-0.9510565162951536 -0.30901699437494723L-0.22451398828979274 -0.30901699437494734Z";
|
|
6472
6728
|
}
|
|
6473
6729
|
draw(ctx, size, transX, transY) {
|
|
6474
|
-
return star(ctx, this.parseSize(size) / 2, transX, transY);
|
|
6730
|
+
return star$1(ctx, this.parseSize(size) / 2, transX, transY);
|
|
6475
6731
|
}
|
|
6476
6732
|
drawOffset(ctx, size, transX, transY, offset) {
|
|
6477
|
-
return star(ctx, this.parseSize(size) / 2 + offset, transX, transY);
|
|
6733
|
+
return star$1(ctx, this.parseSize(size) / 2 + offset, transX, transY);
|
|
6478
6734
|
}
|
|
6479
6735
|
}
|
|
6480
|
-
var star$
|
|
6736
|
+
var star$2 = new StarSymbol();
|
|
6481
6737
|
|
|
6482
6738
|
const sqrt3$1 = vutils.sqrt(3);
|
|
6483
6739
|
function arrow(ctx, r, transX, transY) {
|
|
@@ -6843,7 +7099,7 @@
|
|
|
6843
7099
|
}
|
|
6844
7100
|
}
|
|
6845
7101
|
|
|
6846
|
-
const builtinSymbols = [circle$
|
|
7102
|
+
const builtinSymbols = [circle$2, cross$1, diamond$2, square$3, thinTriangle$1, triangle$1, star$2, arrow$1, wedge$1, stroke$1, wye$1, triangleLeft, triangleRight, triangleUp, triangleDown, arrow2Left$1, arrow2Right$1, arrow2Up$1, arrow2Down$1, rect, lineV$1, lineH$1, close$1];
|
|
6847
7103
|
const builtinSymbolsMap = {};
|
|
6848
7104
|
builtinSymbols.forEach(symbol => {
|
|
6849
7105
|
builtinSymbolsMap[symbol.type] = symbol;
|
|
@@ -16985,6 +17241,2793 @@
|
|
|
16985
17241
|
vchart.Factory.registerChart(RangeColumn3dChart.type, RangeColumn3dChart);
|
|
16986
17242
|
};
|
|
16987
17243
|
|
|
17244
|
+
const PICTOGRAM_CHART_TYPE = 'pictogram';
|
|
17245
|
+
const PICTOGRAM_SERIES_TYPE = 'pictogram';
|
|
17246
|
+
const ELEMENT_HIGHLIGHT_BY_GRPHIC_NAME = 'element-highlight-by-graphic-name';
|
|
17247
|
+
const ELEMENT_SELECT_BY_GRPHIC_NAME = 'element-select-by-graphic-name';
|
|
17248
|
+
var PictogramMarkNameEnum;
|
|
17249
|
+
(function (PictogramMarkNameEnum) {
|
|
17250
|
+
PictogramMarkNameEnum["pictogram"] = "pictogram";
|
|
17251
|
+
})(PictogramMarkNameEnum || (PictogramMarkNameEnum = {}));
|
|
17252
|
+
const PictogramSeriesMark = Object.assign(Object.assign({}, vchart.baseSeriesMark), { ["pictogram"]: { name: "pictogram", type: "group" } });
|
|
17253
|
+
|
|
17254
|
+
class PictogramChartSpecTransformer extends vchart.BaseChartSpecTransformer {
|
|
17255
|
+
_isValidSeries(type) {
|
|
17256
|
+
return type === PICTOGRAM_SERIES_TYPE;
|
|
17257
|
+
}
|
|
17258
|
+
_getDefaultSeriesSpec(spec) {
|
|
17259
|
+
return super._getDefaultSeriesSpec(spec, [
|
|
17260
|
+
'type',
|
|
17261
|
+
'nameField',
|
|
17262
|
+
'valueField',
|
|
17263
|
+
'svg',
|
|
17264
|
+
'pictogram',
|
|
17265
|
+
'defaultFillColor'
|
|
17266
|
+
]);
|
|
17267
|
+
}
|
|
17268
|
+
transformSpec(spec) {
|
|
17269
|
+
super.transformSpec(spec);
|
|
17270
|
+
spec.region.forEach((r) => {
|
|
17271
|
+
r.coordinate = 'geo';
|
|
17272
|
+
});
|
|
17273
|
+
super.transformSeriesSpec(spec);
|
|
17274
|
+
}
|
|
17275
|
+
}
|
|
17276
|
+
|
|
17277
|
+
const svgSourceMap = new Map();
|
|
17278
|
+
let svgDataSet;
|
|
17279
|
+
function initSVGDataSet() {
|
|
17280
|
+
if (svgDataSet) {
|
|
17281
|
+
return;
|
|
17282
|
+
}
|
|
17283
|
+
svgDataSet = new DataSet();
|
|
17284
|
+
vchart.registerDataSetInstanceParser(svgDataSet, 'svg', svgParser);
|
|
17285
|
+
}
|
|
17286
|
+
function registerSVGSource(key, source) {
|
|
17287
|
+
if (svgSourceMap.has(key)) {
|
|
17288
|
+
vchart.warn(`svg source key of '${key}' already exists, will be overwritten.`);
|
|
17289
|
+
}
|
|
17290
|
+
initSVGDataSet();
|
|
17291
|
+
const dataView = new DataView(svgDataSet);
|
|
17292
|
+
dataView.parse(source, {
|
|
17293
|
+
type: 'svg'
|
|
17294
|
+
});
|
|
17295
|
+
svgSourceMap.set(key, dataView);
|
|
17296
|
+
}
|
|
17297
|
+
function unregisterSVGSource(key) {
|
|
17298
|
+
if (!svgSourceMap.has(key)) {
|
|
17299
|
+
vchart.warn(`map type of '${key}' does not exists.`);
|
|
17300
|
+
return;
|
|
17301
|
+
}
|
|
17302
|
+
svgSourceMap.delete(key);
|
|
17303
|
+
}
|
|
17304
|
+
function getSVGSource(type) {
|
|
17305
|
+
return svgSourceMap.get(type);
|
|
17306
|
+
}
|
|
17307
|
+
function clearSVGSource() {
|
|
17308
|
+
svgSourceMap.clear();
|
|
17309
|
+
svgDataSet = null;
|
|
17310
|
+
}
|
|
17311
|
+
|
|
17312
|
+
class PictogramSeriesSpecTransformer extends vchart.BaseSeriesSpecTransformer {
|
|
17313
|
+
_getDefaultSpecFromChart(chartSpec) {
|
|
17314
|
+
var _a, _b, _c;
|
|
17315
|
+
const spec = (_a = super._getDefaultSpecFromChart(chartSpec)) !== null && _a !== void 0 ? _a : {};
|
|
17316
|
+
const svg = chartSpec.svg;
|
|
17317
|
+
const elements = (_c = (_b = svgSourceMap.get(svg)) === null || _b === void 0 ? void 0 : _b.latestData) === null || _c === void 0 ? void 0 : _c.elements;
|
|
17318
|
+
if (elements && elements.length) {
|
|
17319
|
+
const names = elements.map(e => e.name).filter(n => vutils.isValid(n));
|
|
17320
|
+
names.forEach(name => {
|
|
17321
|
+
if (chartSpec[name]) {
|
|
17322
|
+
spec[name] = chartSpec[name];
|
|
17323
|
+
}
|
|
17324
|
+
});
|
|
17325
|
+
}
|
|
17326
|
+
return spec;
|
|
17327
|
+
}
|
|
17328
|
+
}
|
|
17329
|
+
|
|
17330
|
+
class PictogramSeriesTooltipHelper extends vchart.BaseSeriesTooltipHelper {
|
|
17331
|
+
constructor() {
|
|
17332
|
+
super(...arguments);
|
|
17333
|
+
this.dimensionTooltipTitleCallback = (datum) => {
|
|
17334
|
+
var _a;
|
|
17335
|
+
const series = this.series;
|
|
17336
|
+
return (_a = this._getDimensionData(datum)) !== null && _a !== void 0 ? _a : series.getDatumName(datum);
|
|
17337
|
+
};
|
|
17338
|
+
this.markTooltipValueCallback = (datum, params) => {
|
|
17339
|
+
const { measureFields } = this._seriesCacheInfo;
|
|
17340
|
+
if (measureFields[0] && datum.data) {
|
|
17341
|
+
return datum.data[measureFields[0]];
|
|
17342
|
+
}
|
|
17343
|
+
};
|
|
17344
|
+
this.markTooltipKeyCallback = (datum) => {
|
|
17345
|
+
var _a;
|
|
17346
|
+
return (_a = datum.data) === null || _a === void 0 ? void 0 : _a[this.series.getDimensionField()[0]];
|
|
17347
|
+
};
|
|
17348
|
+
}
|
|
17349
|
+
}
|
|
17350
|
+
|
|
17351
|
+
const type$1 = 'element-highlight-by-graphic-name';
|
|
17352
|
+
class ElementHighlightByGraphicName extends vchart.ElementHighlight {
|
|
17353
|
+
constructor() {
|
|
17354
|
+
super(...arguments);
|
|
17355
|
+
this.type = type$1;
|
|
17356
|
+
this.handleStart = (e) => {
|
|
17357
|
+
if (e && e.item && this.isGraphicInMark(e.item)) {
|
|
17358
|
+
const shouldStart = this.options.shouldStart ? this.options.shouldStart(e) : this._filterByName(e);
|
|
17359
|
+
if (shouldStart) {
|
|
17360
|
+
const itemKey = this._parseTargetKey(e);
|
|
17361
|
+
this.start(itemKey);
|
|
17362
|
+
}
|
|
17363
|
+
}
|
|
17364
|
+
};
|
|
17365
|
+
this.handleReset = (e) => {
|
|
17366
|
+
if (e && e.item && this.isGraphicInMark(e.item)) {
|
|
17367
|
+
this.reset();
|
|
17368
|
+
}
|
|
17369
|
+
};
|
|
17370
|
+
}
|
|
17371
|
+
_filterByName(e) {
|
|
17372
|
+
var _a;
|
|
17373
|
+
const name = (_a = e === null || e === void 0 ? void 0 : e.node) === null || _a === void 0 ? void 0 : _a.name;
|
|
17374
|
+
return !!name;
|
|
17375
|
+
}
|
|
17376
|
+
_parseTargetKey(e) {
|
|
17377
|
+
return e.node.name;
|
|
17378
|
+
}
|
|
17379
|
+
start(itemKey) {
|
|
17380
|
+
if (vutils.isNil(itemKey)) {
|
|
17381
|
+
return;
|
|
17382
|
+
}
|
|
17383
|
+
const { interaction, highlightState, blurState } = this.options;
|
|
17384
|
+
const statedGraphics = interaction.getStatedGraphics(this);
|
|
17385
|
+
const newStatedGraphics = [];
|
|
17386
|
+
this.getMarks().forEach(m => {
|
|
17387
|
+
var _a;
|
|
17388
|
+
(_a = m.getGraphics()) === null || _a === void 0 ? void 0 : _a.forEach(g => {
|
|
17389
|
+
if (g.name === itemKey) {
|
|
17390
|
+
newStatedGraphics.push(g);
|
|
17391
|
+
}
|
|
17392
|
+
});
|
|
17393
|
+
});
|
|
17394
|
+
interaction.updateStates(this, newStatedGraphics, statedGraphics, highlightState, blurState);
|
|
17395
|
+
interaction.setStatedGraphics(this, newStatedGraphics);
|
|
17396
|
+
}
|
|
17397
|
+
reset() {
|
|
17398
|
+
const { highlightState, blurState, interaction } = this.options;
|
|
17399
|
+
interaction.clearAllStatesOfTrigger(this, highlightState, blurState);
|
|
17400
|
+
interaction.setStatedGraphics(this, []);
|
|
17401
|
+
}
|
|
17402
|
+
}
|
|
17403
|
+
ElementHighlightByGraphicName.type = type$1;
|
|
17404
|
+
const registerElementHighlightByGraphicName = () => {
|
|
17405
|
+
vchart.Factory.registerInteractionTrigger(ElementHighlightByGraphicName.type, ElementHighlightByGraphicName);
|
|
17406
|
+
};
|
|
17407
|
+
|
|
17408
|
+
const type = 'element-select-by-graphic-name';
|
|
17409
|
+
class ElementSelectByGraphicName extends vchart.ElementSelect {
|
|
17410
|
+
constructor() {
|
|
17411
|
+
super(...arguments);
|
|
17412
|
+
this.type = type;
|
|
17413
|
+
}
|
|
17414
|
+
start(markGraphic) {
|
|
17415
|
+
const name = markGraphic === null || markGraphic === void 0 ? void 0 : markGraphic.name;
|
|
17416
|
+
if (name) {
|
|
17417
|
+
this.getMarks().forEach(mark => {
|
|
17418
|
+
var _a;
|
|
17419
|
+
(_a = mark.getGraphics()) === null || _a === void 0 ? void 0 : _a.forEach(g => {
|
|
17420
|
+
if (g.name === name) {
|
|
17421
|
+
super.start(g);
|
|
17422
|
+
}
|
|
17423
|
+
});
|
|
17424
|
+
});
|
|
17425
|
+
}
|
|
17426
|
+
}
|
|
17427
|
+
}
|
|
17428
|
+
ElementSelectByGraphicName.type = type;
|
|
17429
|
+
const registerElementSelectByGraphicName = () => {
|
|
17430
|
+
vchart.Factory.registerInteractionTrigger(ElementSelectByGraphicName.type, ElementSelectByGraphicName);
|
|
17431
|
+
};
|
|
17432
|
+
|
|
17433
|
+
function isValidStrokeOrFill(attr) {
|
|
17434
|
+
var _a;
|
|
17435
|
+
return vutils.isValid(attr) && attr !== 'none' && !((_a = attr.includes) === null || _a === void 0 ? void 0 : _a.call(attr, 'url'));
|
|
17436
|
+
}
|
|
17437
|
+
const getLineWidth = (attributes) => {
|
|
17438
|
+
const strokeWidth = parseFloat(attributes.strokeWidth);
|
|
17439
|
+
if (!isNaN(strokeWidth)) {
|
|
17440
|
+
return strokeWidth;
|
|
17441
|
+
}
|
|
17442
|
+
const stroke = attributes.stroke;
|
|
17443
|
+
return stroke && isValidStrokeOrFill(stroke) ? 1 : 0;
|
|
17444
|
+
};
|
|
17445
|
+
const getFill = (attributes, defaultFill) => {
|
|
17446
|
+
var _a;
|
|
17447
|
+
const fill = (_a = attributes.fill) !== null && _a !== void 0 ? _a : defaultFill;
|
|
17448
|
+
return fill && isValidStrokeOrFill(fill) ? fill : undefined;
|
|
17449
|
+
};
|
|
17450
|
+
const getStroke = (attributes, defaultStroke) => {
|
|
17451
|
+
var _a;
|
|
17452
|
+
const stroke = (_a = attributes.stroke) !== null && _a !== void 0 ? _a : defaultStroke;
|
|
17453
|
+
return stroke && isValidStrokeOrFill(stroke) ? stroke : false;
|
|
17454
|
+
};
|
|
17455
|
+
const commonAttributes = (attributes) => {
|
|
17456
|
+
return Object.assign(Object.assign({}, attributes), { x: parseFloat(attributes.x) || undefined, y: parseFloat(attributes.y) || undefined, fillStrokeOrder: false, fill: getFill(attributes), lineWidth: getLineWidth(attributes), stroke: getStroke(attributes) });
|
|
17457
|
+
};
|
|
17458
|
+
const graphicAttributeTransform = {
|
|
17459
|
+
group: (attributes) => {
|
|
17460
|
+
const common = commonAttributes(attributes);
|
|
17461
|
+
return Object.assign(Object.assign({}, common), { visibleAll: common.visible !== false });
|
|
17462
|
+
},
|
|
17463
|
+
rule: (attributes) => {
|
|
17464
|
+
return Object.assign(Object.assign({}, commonAttributes(attributes)), { x: parseFloat(attributes.x1), y: parseFloat(attributes.y1), x1: parseFloat(attributes.x2), y1: parseFloat(attributes.y2) });
|
|
17465
|
+
},
|
|
17466
|
+
rect: (attributes) => {
|
|
17467
|
+
return Object.assign(Object.assign({}, commonAttributes(attributes)), { fill: getFill(attributes, '#000'), width: parseFloat(attributes.width), height: parseFloat(attributes.height) });
|
|
17468
|
+
},
|
|
17469
|
+
polygon: (attributes) => {
|
|
17470
|
+
return Object.assign(Object.assign({}, commonAttributes(attributes)), { fill: getFill(attributes, '#000'), points: attributes.points
|
|
17471
|
+
.trim()
|
|
17472
|
+
.split(/\s+/)
|
|
17473
|
+
.map((pair) => {
|
|
17474
|
+
const [x, y] = pair.split(',').map(Number);
|
|
17475
|
+
return { x, y };
|
|
17476
|
+
}) });
|
|
17477
|
+
},
|
|
17478
|
+
line: (attributes) => {
|
|
17479
|
+
return Object.assign(Object.assign({}, commonAttributes(attributes)), { points: attributes.points
|
|
17480
|
+
.trim()
|
|
17481
|
+
.split(/\s+/)
|
|
17482
|
+
.map((pair) => {
|
|
17483
|
+
const [x, y] = pair.split(',').map(Number);
|
|
17484
|
+
return { x, y };
|
|
17485
|
+
}) });
|
|
17486
|
+
},
|
|
17487
|
+
path: (attributes) => {
|
|
17488
|
+
return Object.assign(Object.assign({}, commonAttributes(attributes)), { path: attributes.d, fillStrokeOrder: false, fill: getFill(attributes, '#000') });
|
|
17489
|
+
},
|
|
17490
|
+
arc: (attributes) => {
|
|
17491
|
+
var _a;
|
|
17492
|
+
return Object.assign(Object.assign({}, commonAttributes(attributes)), { outerRadius: (_a = attributes.r) !== null && _a !== void 0 ? _a : attributes.ry, x: parseFloat(attributes.cx), y: parseFloat(attributes.cy), startAngle: 0, endAngle: Math.PI * 2, scaleX: parseFloat(attributes.rx) / parseFloat(attributes.ry) || 1, fill: getFill(attributes, '#000') });
|
|
17493
|
+
},
|
|
17494
|
+
text: (attributes, value) => {
|
|
17495
|
+
var _a, _b;
|
|
17496
|
+
return Object.assign(Object.assign({}, commonAttributes(attributes)), { text: value, textAlign: (_a = attributes.textAlign) !== null && _a !== void 0 ? _a : 'left', textBaseLine: (_b = attributes.textAnchor) !== null && _b !== void 0 ? _b : 'middle', anchor: [0, 0], fill: getFill(attributes, '#000') });
|
|
17497
|
+
}
|
|
17498
|
+
};
|
|
17499
|
+
const pictogram = (data) => {
|
|
17500
|
+
var _a, _b;
|
|
17501
|
+
if (!data || !data[0]) {
|
|
17502
|
+
return {};
|
|
17503
|
+
}
|
|
17504
|
+
const { elements } = data[0].latestData;
|
|
17505
|
+
if (elements && elements.length) {
|
|
17506
|
+
elements.forEach((el, index) => {
|
|
17507
|
+
var _a;
|
|
17508
|
+
el[vchart.DEFAULT_DATA_INDEX] = index;
|
|
17509
|
+
el._uniqueId = `${el.id}-${index}`;
|
|
17510
|
+
el.data = undefined;
|
|
17511
|
+
const { graphicType: type, transform } = el;
|
|
17512
|
+
const finalAttributes = {
|
|
17513
|
+
visible: el.attributes.visibility !== 'hidden' && el.attributes.visibility !== 'collapse'
|
|
17514
|
+
};
|
|
17515
|
+
if (el.graphicType === 'text') {
|
|
17516
|
+
vutils.merge(finalAttributes, el._inheritStyle, (_a = el.parent) === null || _a === void 0 ? void 0 : _a._textGroupStyle, el.attributes);
|
|
17517
|
+
}
|
|
17518
|
+
else if (el.graphicType !== 'group') {
|
|
17519
|
+
vutils.merge(finalAttributes, el._inheritStyle, el.attributes);
|
|
17520
|
+
}
|
|
17521
|
+
if (graphicAttributeTransform[type]) {
|
|
17522
|
+
el._finalAttributes = graphicAttributeTransform[type](finalAttributes, el.value);
|
|
17523
|
+
}
|
|
17524
|
+
else {
|
|
17525
|
+
el._finalAttributes = finalAttributes;
|
|
17526
|
+
}
|
|
17527
|
+
if (transform) {
|
|
17528
|
+
el._finalAttributes.postMatrix = Object.assign({}, transform);
|
|
17529
|
+
}
|
|
17530
|
+
});
|
|
17531
|
+
const texts = elements.filter(el => el.tagName === 'text');
|
|
17532
|
+
for (let i = 0; i < texts.length; i++) {
|
|
17533
|
+
const textId = texts[i]._uniqueId;
|
|
17534
|
+
const children = elements.filter(el => {
|
|
17535
|
+
let result = false;
|
|
17536
|
+
let parent = el.parent;
|
|
17537
|
+
while (parent) {
|
|
17538
|
+
if (parent._uniqueId === textId) {
|
|
17539
|
+
result = true;
|
|
17540
|
+
break;
|
|
17541
|
+
}
|
|
17542
|
+
parent = parent.parent;
|
|
17543
|
+
}
|
|
17544
|
+
return result;
|
|
17545
|
+
});
|
|
17546
|
+
if (children && children.length) {
|
|
17547
|
+
const startX = (_b = (_a = texts[i]._textGroupStyle) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : 0;
|
|
17548
|
+
let curX = startX;
|
|
17549
|
+
for (let j = 0; j < children.length; j++) {
|
|
17550
|
+
const currentChild = children[j];
|
|
17551
|
+
if (currentChild.graphicType === 'group') {
|
|
17552
|
+
curX = startX;
|
|
17553
|
+
}
|
|
17554
|
+
else if (currentChild.value) {
|
|
17555
|
+
if (currentChild.parent._textGroupStyle.x === undefined) {
|
|
17556
|
+
const lastText = children
|
|
17557
|
+
.slice(0, j)
|
|
17558
|
+
.reverse()
|
|
17559
|
+
.find(c => c.graphicType === 'text' && c.value);
|
|
17560
|
+
if (lastText) {
|
|
17561
|
+
const width = vchart.measureText(lastText.value, lastText._finalAttributes).width;
|
|
17562
|
+
curX += width;
|
|
17563
|
+
}
|
|
17564
|
+
currentChild._finalAttributes.x = curX;
|
|
17565
|
+
}
|
|
17566
|
+
}
|
|
17567
|
+
}
|
|
17568
|
+
}
|
|
17569
|
+
}
|
|
17570
|
+
}
|
|
17571
|
+
return elements;
|
|
17572
|
+
};
|
|
17573
|
+
|
|
17574
|
+
class PictogramSeries extends vchart.GeoSeries {
|
|
17575
|
+
constructor() {
|
|
17576
|
+
super(...arguments);
|
|
17577
|
+
this.type = PICTOGRAM_SERIES_TYPE;
|
|
17578
|
+
this._idToMark = new Map();
|
|
17579
|
+
}
|
|
17580
|
+
setAttrFromSpec() {
|
|
17581
|
+
var _a, _b, _c;
|
|
17582
|
+
super.setAttrFromSpec();
|
|
17583
|
+
this.svg = this._spec.svg;
|
|
17584
|
+
this._nameField = this._spec.nameField;
|
|
17585
|
+
this._valueField = this._spec.valueField;
|
|
17586
|
+
if (!this.svg) {
|
|
17587
|
+
(_a = this._option) === null || _a === void 0 ? void 0 : _a.onError(`svg source is not specified !`);
|
|
17588
|
+
}
|
|
17589
|
+
this._parsedSvgResult = (_b = getSVGSource(this.svg)) === null || _b === void 0 ? void 0 : _b.latestData;
|
|
17590
|
+
if (!this._parsedSvgResult) {
|
|
17591
|
+
(_c = this._option) === null || _c === void 0 ? void 0 : _c.onError(`'${this.svg}' is not registered !`);
|
|
17592
|
+
}
|
|
17593
|
+
}
|
|
17594
|
+
getDatumCenter(datum) {
|
|
17595
|
+
return [Number.NaN, Number.NaN];
|
|
17596
|
+
}
|
|
17597
|
+
getDatumName(datum) {
|
|
17598
|
+
return datum.name || datum._nameFromParent;
|
|
17599
|
+
}
|
|
17600
|
+
getMarksWithoutRoot() {
|
|
17601
|
+
return this.getMarks().filter(m => m.name && !m.name.includes('seriesGroup') && !m.name.includes('root') && m !== this._pictogramMark);
|
|
17602
|
+
}
|
|
17603
|
+
_buildMarkAttributeContext() {
|
|
17604
|
+
super._buildMarkAttributeContext();
|
|
17605
|
+
this._markAttributeContext.getTransformMatrix = this.getRootMatrix.bind(this);
|
|
17606
|
+
this._markAttributeContext.coordToPosition = this.coordToPosition.bind(this);
|
|
17607
|
+
this._markAttributeContext.dataToPosition = this.dataToPosition.bind(this);
|
|
17608
|
+
}
|
|
17609
|
+
_defaultHoverConfig(finalHoverSpec) {
|
|
17610
|
+
return {
|
|
17611
|
+
type: ELEMENT_HIGHLIGHT_BY_GRPHIC_NAME,
|
|
17612
|
+
trigger: finalHoverSpec.trigger,
|
|
17613
|
+
triggerOff: 'pointerout',
|
|
17614
|
+
blurState: vchart.STATE_VALUE_ENUM.STATE_HOVER_REVERSE,
|
|
17615
|
+
highlightState: vchart.STATE_VALUE_ENUM.STATE_HOVER
|
|
17616
|
+
};
|
|
17617
|
+
}
|
|
17618
|
+
_defaultSelectConfig(finalSelectSpec) {
|
|
17619
|
+
const isMultiple = finalSelectSpec.mode === 'multiple';
|
|
17620
|
+
const triggerOff = vutils.isValid(finalSelectSpec.triggerOff)
|
|
17621
|
+
? finalSelectSpec.triggerOff
|
|
17622
|
+
: isMultiple
|
|
17623
|
+
? ['empty', 'self']
|
|
17624
|
+
: ['empty', finalSelectSpec.trigger];
|
|
17625
|
+
return {
|
|
17626
|
+
type: ELEMENT_SELECT_BY_GRPHIC_NAME,
|
|
17627
|
+
trigger: finalSelectSpec.trigger,
|
|
17628
|
+
triggerOff: triggerOff,
|
|
17629
|
+
reverseState: vchart.STATE_VALUE_ENUM.STATE_SELECTED_REVERSE,
|
|
17630
|
+
state: vchart.STATE_VALUE_ENUM.STATE_SELECTED,
|
|
17631
|
+
isMultiple
|
|
17632
|
+
};
|
|
17633
|
+
}
|
|
17634
|
+
initMark() {
|
|
17635
|
+
var _a;
|
|
17636
|
+
this._pictogramMark = this._createMark(PictogramSeries.mark.pictogram, {
|
|
17637
|
+
groupKey: this.getDimensionField()[0],
|
|
17638
|
+
isSeriesMark: true,
|
|
17639
|
+
skipBeforeLayouted: true
|
|
17640
|
+
}, {
|
|
17641
|
+
morph: vchart.shouldMarkDoMorph(this._spec, PictogramSeries.mark.pictogram.name)
|
|
17642
|
+
});
|
|
17643
|
+
if (!this._pictogramMark) {
|
|
17644
|
+
return;
|
|
17645
|
+
}
|
|
17646
|
+
this._pictogramMark.setData(this._mapViewData);
|
|
17647
|
+
this._pictogramMark.setUserId(PictogramSeries.mark.pictogram.name);
|
|
17648
|
+
for (const element of this._mapViewData.getDataView().latestData) {
|
|
17649
|
+
const { graphicType: type, name, parent, id, _nameFromParent, _uniqueId } = element;
|
|
17650
|
+
const mark = this._createMark({ type, name: name !== null && name !== void 0 ? name : _nameFromParent }, {
|
|
17651
|
+
groupKey: _uniqueId,
|
|
17652
|
+
isSeriesMark: false,
|
|
17653
|
+
skipBeforeLayouted: true,
|
|
17654
|
+
parent: (_a = this._idToMark.get(parent === null || parent === void 0 ? void 0 : parent._uniqueId)) !== null && _a !== void 0 ? _a : this._pictogramMark
|
|
17655
|
+
}, {
|
|
17656
|
+
morph: vchart.shouldMarkDoMorph(this._spec, PictogramSeries.mark.pictogram.name)
|
|
17657
|
+
});
|
|
17658
|
+
if (mark) {
|
|
17659
|
+
mark.setData(this._mapViewData);
|
|
17660
|
+
mark.setUserId(_uniqueId);
|
|
17661
|
+
this._idToMark.set(_uniqueId, mark);
|
|
17662
|
+
if (mark.type !== 'group') {
|
|
17663
|
+
mark.setMarkConfig({ graphicName: mark.name });
|
|
17664
|
+
}
|
|
17665
|
+
mark.setTransform([
|
|
17666
|
+
{
|
|
17667
|
+
type: 'filter',
|
|
17668
|
+
callback: (datum) => {
|
|
17669
|
+
return datum._uniqueId === _uniqueId;
|
|
17670
|
+
}
|
|
17671
|
+
}
|
|
17672
|
+
]);
|
|
17673
|
+
}
|
|
17674
|
+
}
|
|
17675
|
+
this._initLabelMark();
|
|
17676
|
+
}
|
|
17677
|
+
_initLabelMark() {
|
|
17678
|
+
if (this._spec.label.visible !== true) {
|
|
17679
|
+
return;
|
|
17680
|
+
}
|
|
17681
|
+
const labelMark = this._createMark(PictogramSeries.mark.label, {
|
|
17682
|
+
isSeriesMark: false,
|
|
17683
|
+
parent: this._pictogramMark,
|
|
17684
|
+
groupKey: '_uniqueId',
|
|
17685
|
+
skipBeforeLayouted: true
|
|
17686
|
+
});
|
|
17687
|
+
if (labelMark) {
|
|
17688
|
+
this._labelMark = labelMark;
|
|
17689
|
+
this._labelMark.setData(this._mapViewData);
|
|
17690
|
+
}
|
|
17691
|
+
}
|
|
17692
|
+
initLabelMarkStyle() {
|
|
17693
|
+
if (!this._labelMark) {
|
|
17694
|
+
return;
|
|
17695
|
+
}
|
|
17696
|
+
this.setMarkStyle(this._labelMark, {
|
|
17697
|
+
visible: (d) => !!this._validElement(d),
|
|
17698
|
+
x: (d) => { var _a; return (_a = this.dataToPosition(d, true)) === null || _a === void 0 ? void 0 : _a.x; },
|
|
17699
|
+
y: (d) => { var _a; return (_a = this.dataToPosition(d, true)) === null || _a === void 0 ? void 0 : _a.y; },
|
|
17700
|
+
text: (d) => d[this.nameField],
|
|
17701
|
+
textAlign: 'center',
|
|
17702
|
+
textBaseline: 'middle'
|
|
17703
|
+
}, vchart.STATE_VALUE_ENUM.STATE_NORMAL, vchart.AttributeLevel.Series);
|
|
17704
|
+
}
|
|
17705
|
+
initMarkStyle() {
|
|
17706
|
+
const { root, viewBoxRect } = this._parsedSvgResult;
|
|
17707
|
+
const elements = this._mapViewData.getDataView().latestData;
|
|
17708
|
+
if (root) {
|
|
17709
|
+
this.setMarkStyle(this._pictogramMark, graphicAttributeTransform.group(root.attributes), 'normal', vchart.AttributeLevel.Built_In);
|
|
17710
|
+
if (root.transform) {
|
|
17711
|
+
this.setMarkStyle(this._pictogramMark, {
|
|
17712
|
+
postMatrix: () => root.transform
|
|
17713
|
+
}, 'normal', vchart.AttributeLevel.Built_In);
|
|
17714
|
+
}
|
|
17715
|
+
if (viewBoxRect) {
|
|
17716
|
+
this._pictogramMark.setMarkConfig({
|
|
17717
|
+
clip: true,
|
|
17718
|
+
clipPath: [createRect(Object.assign(Object.assign({}, viewBoxRect), { fill: true }))]
|
|
17719
|
+
});
|
|
17720
|
+
}
|
|
17721
|
+
}
|
|
17722
|
+
for (const element of elements) {
|
|
17723
|
+
const { _uniqueId, _finalAttributes: attributes } = element;
|
|
17724
|
+
const mark = this._idToMark.get(_uniqueId);
|
|
17725
|
+
const valid = this._validElement(element);
|
|
17726
|
+
if (mark) {
|
|
17727
|
+
this.setMarkStyle(mark, { keepStrokeScale: true }, 'normal', vchart.AttributeLevel.Built_In);
|
|
17728
|
+
if (valid) {
|
|
17729
|
+
this.initMarkStyleWithSpec(mark, vutils.merge({}, this._spec.pictogram, this._spec[mark.name]));
|
|
17730
|
+
this.setMarkStyle(mark, attributes, 'normal', vchart.AttributeLevel.Series);
|
|
17731
|
+
mark.setPostProcess('fill', (result, datum) => {
|
|
17732
|
+
return vutils.isValid(result) ? result : this._spec.defaultFillColor;
|
|
17733
|
+
});
|
|
17734
|
+
}
|
|
17735
|
+
else {
|
|
17736
|
+
mark.setMarkConfig({ interactive: false });
|
|
17737
|
+
this.setMarkStyle(mark, attributes, 'normal', vchart.AttributeLevel.Built_In);
|
|
17738
|
+
}
|
|
17739
|
+
}
|
|
17740
|
+
}
|
|
17741
|
+
this.initLabelMarkStyle();
|
|
17742
|
+
}
|
|
17743
|
+
_validElement(element) {
|
|
17744
|
+
return element.name || element._nameFromParent;
|
|
17745
|
+
}
|
|
17746
|
+
initTooltip() {
|
|
17747
|
+
this._tooltipHelper = new PictogramSeriesTooltipHelper(this);
|
|
17748
|
+
this.getMarksWithoutRoot().forEach(mark => {
|
|
17749
|
+
if (mark && mark.name) {
|
|
17750
|
+
this._tooltipHelper.activeTriggerSet.mark.add(mark);
|
|
17751
|
+
}
|
|
17752
|
+
});
|
|
17753
|
+
}
|
|
17754
|
+
dataToPosition(datum, global = false) {
|
|
17755
|
+
if (!datum) {
|
|
17756
|
+
return null;
|
|
17757
|
+
}
|
|
17758
|
+
const name = datum[this.nameField];
|
|
17759
|
+
if (!name) {
|
|
17760
|
+
return null;
|
|
17761
|
+
}
|
|
17762
|
+
const mark = this.getMarksWithoutRoot().filter(mark => mark.name === name);
|
|
17763
|
+
if (!mark || mark.length === 0) {
|
|
17764
|
+
return null;
|
|
17765
|
+
}
|
|
17766
|
+
let bounds = new vutils.Bounds();
|
|
17767
|
+
if (global) {
|
|
17768
|
+
mark.forEach(m => {
|
|
17769
|
+
bounds = bounds.union(m.getGraphics()[0].globalAABBBounds);
|
|
17770
|
+
});
|
|
17771
|
+
}
|
|
17772
|
+
else {
|
|
17773
|
+
mark.forEach(m => {
|
|
17774
|
+
bounds = bounds.union(m.getProduct().AABBBounds);
|
|
17775
|
+
});
|
|
17776
|
+
}
|
|
17777
|
+
const point = { x: (bounds.x1 + bounds.x2) / 2, y: (bounds.y1 + bounds.y2) / 2 };
|
|
17778
|
+
if (global) {
|
|
17779
|
+
const { x, y } = this.getLayoutStartPoint();
|
|
17780
|
+
point.x -= x;
|
|
17781
|
+
point.y -= y;
|
|
17782
|
+
}
|
|
17783
|
+
return point;
|
|
17784
|
+
}
|
|
17785
|
+
coordToPosition(point) {
|
|
17786
|
+
if (!point) {
|
|
17787
|
+
return null;
|
|
17788
|
+
}
|
|
17789
|
+
const { x, y } = point;
|
|
17790
|
+
const matrix = this.getRootMatrix();
|
|
17791
|
+
if (!matrix) {
|
|
17792
|
+
return null;
|
|
17793
|
+
}
|
|
17794
|
+
const position = {};
|
|
17795
|
+
matrix.getInverse().transformPoint({ x, y }, position);
|
|
17796
|
+
return position;
|
|
17797
|
+
}
|
|
17798
|
+
getRootMatrix() {
|
|
17799
|
+
var _a;
|
|
17800
|
+
return (_a = this.getPictogramRootGraphic()) === null || _a === void 0 ? void 0 : _a.transMatrix;
|
|
17801
|
+
}
|
|
17802
|
+
getPictogramRootGraphic() {
|
|
17803
|
+
return this._pictogramMark.getProduct();
|
|
17804
|
+
}
|
|
17805
|
+
initData() {
|
|
17806
|
+
var _a, _b;
|
|
17807
|
+
super.initData();
|
|
17808
|
+
const parsedSvg = svgSourceMap.get(this.svg);
|
|
17809
|
+
if (!parsedSvg) {
|
|
17810
|
+
(_a = this._option) === null || _a === void 0 ? void 0 : _a.onError('no valid svg found!');
|
|
17811
|
+
}
|
|
17812
|
+
const svgData = new DataView(this._dataSet, { name: `pictogram_${this.id}_data` });
|
|
17813
|
+
vchart.registerDataSetInstanceTransform(this._dataSet, 'pictogram', pictogram);
|
|
17814
|
+
vchart.registerDataSetInstanceTransform(this._dataSet, 'lookup', vchart.lookup);
|
|
17815
|
+
svgData
|
|
17816
|
+
.parse([parsedSvg], {
|
|
17817
|
+
type: 'dataview'
|
|
17818
|
+
})
|
|
17819
|
+
.transform({ type: 'pictogram' })
|
|
17820
|
+
.transform({
|
|
17821
|
+
type: 'lookup',
|
|
17822
|
+
options: {
|
|
17823
|
+
from: () => this.getViewData().latestData,
|
|
17824
|
+
key: 'name',
|
|
17825
|
+
fields: this._nameField,
|
|
17826
|
+
set: (a, b) => {
|
|
17827
|
+
if (b) {
|
|
17828
|
+
a.data = b;
|
|
17829
|
+
}
|
|
17830
|
+
}
|
|
17831
|
+
}
|
|
17832
|
+
})
|
|
17833
|
+
.transform({
|
|
17834
|
+
type: 'lookup',
|
|
17835
|
+
options: {
|
|
17836
|
+
from: () => this.getViewData().latestData,
|
|
17837
|
+
key: '_nameFromParent',
|
|
17838
|
+
fields: this._nameField,
|
|
17839
|
+
set: (a, b) => {
|
|
17840
|
+
if (b) {
|
|
17841
|
+
a.data = b;
|
|
17842
|
+
}
|
|
17843
|
+
}
|
|
17844
|
+
}
|
|
17845
|
+
});
|
|
17846
|
+
(_b = this._data) === null || _b === void 0 ? void 0 : _b.getDataView().target.addListener('change', svgData.reRunAllTransform);
|
|
17847
|
+
this._mapViewData = new vchart.CompilableData(this._option, svgData);
|
|
17848
|
+
}
|
|
17849
|
+
mapViewDataUpdate() {
|
|
17850
|
+
this._mapViewData.updateData();
|
|
17851
|
+
}
|
|
17852
|
+
onLayoutEnd() {
|
|
17853
|
+
var _a;
|
|
17854
|
+
super.onLayoutEnd();
|
|
17855
|
+
(_a = this._mapViewData) === null || _a === void 0 ? void 0 : _a.getDataView().reRunAllTransform();
|
|
17856
|
+
}
|
|
17857
|
+
updateSVGSize() {
|
|
17858
|
+
const { width: regionWidth, height: regionHeight } = this.getLayoutRect();
|
|
17859
|
+
const regionCenterX = regionWidth / 2;
|
|
17860
|
+
const regionCenterY = regionHeight / 2;
|
|
17861
|
+
const root = this.getPictogramRootGraphic();
|
|
17862
|
+
if (root) {
|
|
17863
|
+
const bounds = root.AABBBounds;
|
|
17864
|
+
const { x1, x2, y1, y2 } = root.AABBBounds;
|
|
17865
|
+
const width = bounds.width();
|
|
17866
|
+
const height = bounds.height();
|
|
17867
|
+
const rootCenterX = (x1 + x2) / 2;
|
|
17868
|
+
const rootCenterY = (y1 + y2) / 2;
|
|
17869
|
+
const scaleX = regionWidth / width;
|
|
17870
|
+
const scaleY = regionHeight / height;
|
|
17871
|
+
const scale = Math.min(scaleX, scaleY);
|
|
17872
|
+
root.scale(scale, scale, { x: rootCenterX, y: rootCenterY });
|
|
17873
|
+
root.translate(regionCenterX - rootCenterX, regionCenterY - rootCenterY);
|
|
17874
|
+
}
|
|
17875
|
+
}
|
|
17876
|
+
initEvent() {
|
|
17877
|
+
var _a;
|
|
17878
|
+
super.initEvent();
|
|
17879
|
+
(_a = this._mapViewData.getDataView()) === null || _a === void 0 ? void 0 : _a.target.addListener('change', this.mapViewDataUpdate.bind(this));
|
|
17880
|
+
this.event.on(vchart.ChartEvent.afterMarkLayoutEnd, this.updateSVGSize.bind(this));
|
|
17881
|
+
}
|
|
17882
|
+
handleZoom(e) {
|
|
17883
|
+
const { scale, scaleCenter } = e;
|
|
17884
|
+
if (scale === 1) {
|
|
17885
|
+
return;
|
|
17886
|
+
}
|
|
17887
|
+
const root = this.getPictogramRootGraphic();
|
|
17888
|
+
if (root) {
|
|
17889
|
+
if (!root.attribute.postMatrix) {
|
|
17890
|
+
root.setAttributes({
|
|
17891
|
+
postMatrix: new vutils.Matrix()
|
|
17892
|
+
});
|
|
17893
|
+
}
|
|
17894
|
+
root.scale(scale, scale, scaleCenter);
|
|
17895
|
+
}
|
|
17896
|
+
}
|
|
17897
|
+
handlePan(e) {
|
|
17898
|
+
const { delta } = e;
|
|
17899
|
+
if (delta[0] === 0 && delta[1] === 0) {
|
|
17900
|
+
return;
|
|
17901
|
+
}
|
|
17902
|
+
const root = this.getPictogramRootGraphic();
|
|
17903
|
+
if (root) {
|
|
17904
|
+
if (!root.attribute.postMatrix) {
|
|
17905
|
+
root.setAttributes({
|
|
17906
|
+
postMatrix: new vutils.Matrix()
|
|
17907
|
+
});
|
|
17908
|
+
}
|
|
17909
|
+
root.translate(delta[0], delta[1]);
|
|
17910
|
+
}
|
|
17911
|
+
}
|
|
17912
|
+
getMarkData(datum) {
|
|
17913
|
+
var _a;
|
|
17914
|
+
return (_a = datum.data) !== null && _a !== void 0 ? _a : {};
|
|
17915
|
+
}
|
|
17916
|
+
getMeasureField() {
|
|
17917
|
+
return [this.valueField];
|
|
17918
|
+
}
|
|
17919
|
+
getDimensionField() {
|
|
17920
|
+
return [this.nameField];
|
|
17921
|
+
}
|
|
17922
|
+
_getSeriesInfo(field, keys) {
|
|
17923
|
+
const defaultShapeType = this.getDefaultShapeType();
|
|
17924
|
+
return keys.map(key => {
|
|
17925
|
+
return {
|
|
17926
|
+
key,
|
|
17927
|
+
originalKey: key,
|
|
17928
|
+
style: this.getSeriesStyle({
|
|
17929
|
+
data: {
|
|
17930
|
+
[field]: key
|
|
17931
|
+
}
|
|
17932
|
+
}),
|
|
17933
|
+
shapeType: defaultShapeType
|
|
17934
|
+
};
|
|
17935
|
+
});
|
|
17936
|
+
}
|
|
17937
|
+
release() {
|
|
17938
|
+
this._parsedSvgResult = null;
|
|
17939
|
+
this._idToMark.clear();
|
|
17940
|
+
this._idToMark = null;
|
|
17941
|
+
}
|
|
17942
|
+
}
|
|
17943
|
+
PictogramSeries.type = PICTOGRAM_SERIES_TYPE;
|
|
17944
|
+
PictogramSeries.mark = PictogramSeriesMark;
|
|
17945
|
+
PictogramSeries.transformerConstructor = PictogramSeriesSpecTransformer;
|
|
17946
|
+
const registerPictogramSeries = () => {
|
|
17947
|
+
vchart.Factory.registerSeries(PictogramSeries.type, PictogramSeries);
|
|
17948
|
+
vchart.Factory.registerImplement('registerSVG', registerSVGSource);
|
|
17949
|
+
vchart.Factory.registerImplement('unregisterSVG', unregisterSVGSource);
|
|
17950
|
+
registerElementHighlightByGraphicName();
|
|
17951
|
+
registerElementSelectByGraphicName();
|
|
17952
|
+
};
|
|
17953
|
+
|
|
17954
|
+
class PictogramChart extends vchart.BaseChart {
|
|
17955
|
+
constructor() {
|
|
17956
|
+
super(...arguments);
|
|
17957
|
+
this.transformerConstructor = PictogramChartSpecTransformer;
|
|
17958
|
+
this.type = PICTOGRAM_CHART_TYPE;
|
|
17959
|
+
this.seriesType = PICTOGRAM_SERIES_TYPE;
|
|
17960
|
+
}
|
|
17961
|
+
}
|
|
17962
|
+
PictogramChart.type = PICTOGRAM_SERIES_TYPE;
|
|
17963
|
+
PictogramChart.seriesType = PICTOGRAM_CHART_TYPE;
|
|
17964
|
+
PictogramChart.transformerConstructor = PictogramChartSpecTransformer;
|
|
17965
|
+
const registerPictogramChart = () => {
|
|
17966
|
+
vchart.registerMarkTooltipProcessor();
|
|
17967
|
+
registerPictogramSeries();
|
|
17968
|
+
vchart.Factory.registerChart(PictogramChart.type, PictogramChart);
|
|
17969
|
+
};
|
|
17970
|
+
|
|
17971
|
+
class ImageCloudChartSpecTransformer extends vchart.BaseChartSpecTransformer {
|
|
17972
|
+
transformSpec(spec) {
|
|
17973
|
+
super.transformSpec(spec);
|
|
17974
|
+
this.transformSeriesSpec(spec);
|
|
17975
|
+
}
|
|
17976
|
+
_getDefaultSeriesSpec(spec) {
|
|
17977
|
+
const series = super._getDefaultSeriesSpec(spec, [
|
|
17978
|
+
'urlField',
|
|
17979
|
+
'nameField',
|
|
17980
|
+
'valueField',
|
|
17981
|
+
'imageSize',
|
|
17982
|
+
'imageSizeRange',
|
|
17983
|
+
'ratio',
|
|
17984
|
+
'maskShape',
|
|
17985
|
+
'imageMask',
|
|
17986
|
+
'layoutConfig',
|
|
17987
|
+
'image'
|
|
17988
|
+
]);
|
|
17989
|
+
return series;
|
|
17990
|
+
}
|
|
17991
|
+
}
|
|
17992
|
+
|
|
17993
|
+
const IMAGE_CLOUD_CHART_TYPE = 'imageCloud';
|
|
17994
|
+
const IMAGE_CLOUD_SERIES_TYPE = 'imageCloud';
|
|
17995
|
+
var ImageCloudMarkNameEnum;
|
|
17996
|
+
(function (ImageCloudMarkNameEnum) {
|
|
17997
|
+
ImageCloudMarkNameEnum["image"] = "image";
|
|
17998
|
+
ImageCloudMarkNameEnum["imageMask"] = "imageMask";
|
|
17999
|
+
})(ImageCloudMarkNameEnum || (ImageCloudMarkNameEnum = {}));
|
|
18000
|
+
const imageCloudSeriesMark = Object.assign(Object.assign({}, vchart.baseSeriesMark), { ["image"]: { name: "image", type: "image" }, ["imageMask"]: { name: "imageMask", type: "rect" } });
|
|
18001
|
+
|
|
18002
|
+
const shapes = {
|
|
18003
|
+
triangleForward: triangleForward,
|
|
18004
|
+
triangleUpright: triangle,
|
|
18005
|
+
triangle: triangle,
|
|
18006
|
+
diamond: diamond,
|
|
18007
|
+
square: square$1,
|
|
18008
|
+
star: star,
|
|
18009
|
+
cardioid: cardioid,
|
|
18010
|
+
circle: circle,
|
|
18011
|
+
pentagon: pentagon
|
|
18012
|
+
};
|
|
18013
|
+
function diamond() {
|
|
18014
|
+
return function (theta) {
|
|
18015
|
+
const thetaPrime = theta % (2 * Math.PI / 4);
|
|
18016
|
+
return 1 / (Math.cos(thetaPrime) + Math.sin(thetaPrime));
|
|
18017
|
+
};
|
|
18018
|
+
}
|
|
18019
|
+
function star() {
|
|
18020
|
+
return function (theta) {
|
|
18021
|
+
const thetaPrime = (theta + .955) % (2 * Math.PI / 10);
|
|
18022
|
+
return (theta + .955) % (2 * Math.PI / 5) - 2 * Math.PI / 10 >= 0 ? 1 / (Math.cos(2 * Math.PI / 10 - thetaPrime) + 3.07768 * Math.sin(2 * Math.PI / 10 - thetaPrime)) : 1 / (Math.cos(thetaPrime) + 3.07768 * Math.sin(thetaPrime));
|
|
18023
|
+
};
|
|
18024
|
+
}
|
|
18025
|
+
function square$1() {
|
|
18026
|
+
return function (theta) {
|
|
18027
|
+
return Math.min(1 / Math.abs(Math.cos(theta)), 1 / Math.abs(Math.sin(theta)));
|
|
18028
|
+
};
|
|
18029
|
+
}
|
|
18030
|
+
function triangle() {
|
|
18031
|
+
return function (theta) {
|
|
18032
|
+
const thetaPrime = (theta + 3 * Math.PI / 2) % (2 * Math.PI / 3);
|
|
18033
|
+
return 1 / (Math.cos(thetaPrime) + Math.sqrt(3) * Math.sin(thetaPrime));
|
|
18034
|
+
};
|
|
18035
|
+
}
|
|
18036
|
+
function triangleForward() {
|
|
18037
|
+
return function (theta) {
|
|
18038
|
+
const thetaPrime = theta % (2 * Math.PI / 3);
|
|
18039
|
+
return 1 / (Math.cos(thetaPrime) + Math.sqrt(3) * Math.sin(thetaPrime));
|
|
18040
|
+
};
|
|
18041
|
+
}
|
|
18042
|
+
function cardioid() {
|
|
18043
|
+
return function (theta) {
|
|
18044
|
+
return 1 + Math.sin(theta);
|
|
18045
|
+
};
|
|
18046
|
+
}
|
|
18047
|
+
function circle() {
|
|
18048
|
+
return function () {
|
|
18049
|
+
return 1;
|
|
18050
|
+
};
|
|
18051
|
+
}
|
|
18052
|
+
function pentagon() {
|
|
18053
|
+
return function (theta) {
|
|
18054
|
+
const thetaPrime = (theta + .955) % (2 * Math.PI / 5);
|
|
18055
|
+
return 1 / (Math.cos(thetaPrime) + .726543 * Math.sin(thetaPrime));
|
|
18056
|
+
};
|
|
18057
|
+
}
|
|
18058
|
+
function getMaxRadiusAndCenter(shape, size) {
|
|
18059
|
+
const w = size[0],
|
|
18060
|
+
h = size[1];
|
|
18061
|
+
let maxRadius = 1;
|
|
18062
|
+
const center = [size[0] >> 1, size[1] >> 1];
|
|
18063
|
+
switch (shape) {
|
|
18064
|
+
case "cardioid":
|
|
18065
|
+
center[1] = ~~(h / 2.7 * .4), maxRadius = Math.floor(Math.min(w / 2.3, h / 2.6));
|
|
18066
|
+
break;
|
|
18067
|
+
case "triangleForward":
|
|
18068
|
+
maxRadius = h / Math.sqrt(.75) > w ? Math.floor(w / 2) : Math.floor(h / (2 * Math.sqrt(.75)));
|
|
18069
|
+
break;
|
|
18070
|
+
case "triangle":
|
|
18071
|
+
case "triangleUpright":
|
|
18072
|
+
center[1] = ~~(h / 1.5), maxRadius = Math.floor(Math.min(h / 1.5, w / 2));
|
|
18073
|
+
break;
|
|
18074
|
+
case "circle":
|
|
18075
|
+
case "diamond":
|
|
18076
|
+
case "square":
|
|
18077
|
+
case "star":
|
|
18078
|
+
case "pentagon":
|
|
18079
|
+
maxRadius = Math.floor(Math.min(w / 2, h / 2));
|
|
18080
|
+
break;
|
|
18081
|
+
default:
|
|
18082
|
+
maxRadius = Math.floor(Math.max(w / 2, h / 2));
|
|
18083
|
+
}
|
|
18084
|
+
return {
|
|
18085
|
+
maxRadius: maxRadius,
|
|
18086
|
+
center: center
|
|
18087
|
+
};
|
|
18088
|
+
}
|
|
18089
|
+
const getShapeFunction = type => shapes[type] ? shapes[type]() : shapes.circle();
|
|
18090
|
+
|
|
18091
|
+
const spirals = {
|
|
18092
|
+
archimedean: archimedeanSpiral,
|
|
18093
|
+
rectangular: rectangularSpiral
|
|
18094
|
+
};
|
|
18095
|
+
function archimedeanSpiral(size) {
|
|
18096
|
+
const e = size[0] / size[1];
|
|
18097
|
+
return t => [e * (t *= .1) * Math.cos(t), t * Math.sin(t)];
|
|
18098
|
+
}
|
|
18099
|
+
function rectangularSpiral(size) {
|
|
18100
|
+
const dx = 4 * size[0] / size[1];
|
|
18101
|
+
let x = 0,
|
|
18102
|
+
y = 0;
|
|
18103
|
+
return t => {
|
|
18104
|
+
const sign = t < 0 ? -1 : 1;
|
|
18105
|
+
switch (Math.sqrt(1 + 4 * sign * t) - sign & 3) {
|
|
18106
|
+
case 0:
|
|
18107
|
+
x += dx;
|
|
18108
|
+
break;
|
|
18109
|
+
case 1:
|
|
18110
|
+
y += 4;
|
|
18111
|
+
break;
|
|
18112
|
+
case 2:
|
|
18113
|
+
x -= dx;
|
|
18114
|
+
break;
|
|
18115
|
+
default:
|
|
18116
|
+
y -= 4;
|
|
18117
|
+
}
|
|
18118
|
+
return [x, y];
|
|
18119
|
+
};
|
|
18120
|
+
}
|
|
18121
|
+
|
|
18122
|
+
const generateIsEmptyPixel = (backgroundColor, options, createCanvas) => {
|
|
18123
|
+
const {
|
|
18124
|
+
threshold: threshold,
|
|
18125
|
+
invert = !1
|
|
18126
|
+
} = null != options ? options : {};
|
|
18127
|
+
if (!backgroundColor || "#fff" === backgroundColor) return (imageData, y, x) => {
|
|
18128
|
+
const width = imageData.width;
|
|
18129
|
+
if (0 === imageData.data[y * width * 4 + 4 * x + 3]) return !invert;
|
|
18130
|
+
const r = imageData.data[y * width * 4 + 4 * x + 0],
|
|
18131
|
+
g = imageData.data[y * width * 4 + 4 * x + 1],
|
|
18132
|
+
b = imageData.data[y * width * 4 + 4 * x + 2];
|
|
18133
|
+
if (255 === r && 255 === g && 255 === b) return !invert;
|
|
18134
|
+
if (vutils.isValidNumber(threshold)) {
|
|
18135
|
+
const grayValue = .3 * r + .59 * g + .11 * b;
|
|
18136
|
+
return invert ? grayValue <= threshold : grayValue >= threshold;
|
|
18137
|
+
}
|
|
18138
|
+
return !1;
|
|
18139
|
+
};
|
|
18140
|
+
const bctx = createCanvas({
|
|
18141
|
+
width: 1,
|
|
18142
|
+
height: 1
|
|
18143
|
+
}).getContext("2d", {
|
|
18144
|
+
willReadFrequently: !0
|
|
18145
|
+
});
|
|
18146
|
+
bctx.fillStyle = backgroundColor, bctx.fillRect(0, 0, 1, 1);
|
|
18147
|
+
const bgPixel = bctx.getImageData(0, 0, 1, 1).data;
|
|
18148
|
+
return (imageData, y, x) => {
|
|
18149
|
+
const width = imageData.width;
|
|
18150
|
+
return [0, 1, 2, 3].every(i => invert ? imageData.data[4 * (y * width + x) + i] !== bgPixel[i] : imageData.data[4 * (y * width + x) + i] === bgPixel[i]);
|
|
18151
|
+
};
|
|
18152
|
+
};
|
|
18153
|
+
const generateMaskCanvas = function (shape, width, height, cacheCanvas) {
|
|
18154
|
+
let invert = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : !1;
|
|
18155
|
+
let createCanvas = arguments.length > 5 ? arguments[5] : undefined;
|
|
18156
|
+
let {
|
|
18157
|
+
backgroundColor = "#fff"
|
|
18158
|
+
} = shape,
|
|
18159
|
+
{
|
|
18160
|
+
fill: foregroundColor = "#000"
|
|
18161
|
+
} = shape;
|
|
18162
|
+
invert && ([backgroundColor, foregroundColor] = [foregroundColor, backgroundColor]);
|
|
18163
|
+
const maskCanvas = cacheCanvas || createCanvas({
|
|
18164
|
+
width: width,
|
|
18165
|
+
height: height,
|
|
18166
|
+
dpr: 1
|
|
18167
|
+
}),
|
|
18168
|
+
tempContext = maskCanvas.getContext("2d", {
|
|
18169
|
+
willReadFrequently: !0
|
|
18170
|
+
});
|
|
18171
|
+
if (cacheCanvas) {
|
|
18172
|
+
const prevWidth = cacheCanvas.width,
|
|
18173
|
+
prevHeight = cacheCanvas.height;
|
|
18174
|
+
tempContext.clearRect(0, 0, prevWidth, prevHeight), cacheCanvas.style.width = `${width}px`, cacheCanvas.style.height = `${height}px`, cacheCanvas.width = width, cacheCanvas.height = height;
|
|
18175
|
+
}
|
|
18176
|
+
return tempContext.fillStyle = backgroundColor, tempContext.fillRect(0, 0, maskCanvas.width, maskCanvas.height), "text" === shape.type ? drawTextMask(shape, foregroundColor, maskCanvas.width, maskCanvas.height, tempContext) : "geometric" === shape.type && drawGeometricMask(shape, foregroundColor, maskCanvas.width, maskCanvas.height, tempContext), maskCanvas;
|
|
18177
|
+
};
|
|
18178
|
+
const drawTextMask = (shape, fillColor, width, height, ctx) => {
|
|
18179
|
+
const {
|
|
18180
|
+
fontFamily = "sans-serif",
|
|
18181
|
+
fontWeight = "normal",
|
|
18182
|
+
fontStyle = "normal",
|
|
18183
|
+
fontVariant = "normal",
|
|
18184
|
+
text: text,
|
|
18185
|
+
hollow: hollow
|
|
18186
|
+
} = shape;
|
|
18187
|
+
let baseFontSize = 12;
|
|
18188
|
+
ctx.font = `${fontStyle} ${fontVariant} ${fontWeight} ${baseFontSize}px ${fontFamily}`, ctx.textAlign = "center", ctx.textBaseline = "middle", ctx.fillStyle = fillColor;
|
|
18189
|
+
const textMetrics = ctx.measureText(text),
|
|
18190
|
+
scale = "normal" !== fontStyle ? 1.1 : 1,
|
|
18191
|
+
actualWidth = vutils.isValid(textMetrics.actualBoundingBoxRight) && vutils.isValid(textMetrics.actualBoundingBoxLeft) ? Math.ceil(scale * (Math.abs(textMetrics.actualBoundingBoxRight) + Math.abs(textMetrics.actualBoundingBoxLeft))) : 0,
|
|
18192
|
+
textWidth = Math.max(Math.ceil(textMetrics.width), actualWidth, baseFontSize);
|
|
18193
|
+
if (hollow && (ctx.globalCompositeOperation = "xor"), textWidth > width) {
|
|
18194
|
+
const scale = Math.min(width / textWidth, height / baseFontSize);
|
|
18195
|
+
ctx.fillText(text, width / 2, height / 2), ctx.scale(scale, scale);
|
|
18196
|
+
} else baseFontSize = Math.floor(baseFontSize * width / textWidth), baseFontSize = Math.min(baseFontSize, height), ctx.font = `${fontStyle} ${fontVariant} ${fontWeight} ${baseFontSize}px ${fontFamily}`, ctx.fillText(text, Math.floor(width / 2), Math.floor(height / 2));
|
|
18197
|
+
};
|
|
18198
|
+
const generatePoints = function (center, radius) {
|
|
18199
|
+
let startAngle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
18200
|
+
let count = arguments.length > 3 ? arguments[3] : undefined;
|
|
18201
|
+
const angle = 2 * Math.PI / count;
|
|
18202
|
+
return new Array(count).fill(0).map((entry, index) => vutils.polarToCartesian(center, radius, startAngle + index * angle));
|
|
18203
|
+
};
|
|
18204
|
+
const generateCardioidPoints = function (center, radius) {
|
|
18205
|
+
let startAngle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
18206
|
+
let count = arguments.length > 3 ? arguments[3] : undefined;
|
|
18207
|
+
const angle = 2 * Math.PI / count,
|
|
18208
|
+
func = getShapeFunction("cardioid");
|
|
18209
|
+
return new Array(count).fill(0).map((entry, index) => {
|
|
18210
|
+
const theta = startAngle + index * angle,
|
|
18211
|
+
r = radius * func(theta);
|
|
18212
|
+
return vutils.polarToCartesian(center, r, theta);
|
|
18213
|
+
});
|
|
18214
|
+
};
|
|
18215
|
+
const drawRegularPolygon = (ctx, points) => {
|
|
18216
|
+
ctx.beginPath(), points.forEach((p, index) => {
|
|
18217
|
+
0 === index ? ctx.moveTo(p.x, p.y) : ctx.lineTo(p.x, p.y);
|
|
18218
|
+
}), ctx.closePath(), ctx.fill();
|
|
18219
|
+
};
|
|
18220
|
+
const drawCardioid = (ctx, points) => {
|
|
18221
|
+
let prev;
|
|
18222
|
+
ctx.beginPath(), points.forEach((p, index) => {
|
|
18223
|
+
0 === index ? ctx.moveTo(p.x, p.y) : ctx.bezierCurveTo(p.x, p.y, prev.x, prev.y, p.x, p.y), prev = p;
|
|
18224
|
+
}), ctx.closePath(), ctx.fill();
|
|
18225
|
+
};
|
|
18226
|
+
const drawGeometricMask = (shape, fillColor, width, height, ctx) => {
|
|
18227
|
+
const {
|
|
18228
|
+
hollow: hollow
|
|
18229
|
+
} = shape,
|
|
18230
|
+
{
|
|
18231
|
+
center: center,
|
|
18232
|
+
maxRadius: maxRadius
|
|
18233
|
+
} = getMaxRadiusAndCenter(shape.shape, [width, height]);
|
|
18234
|
+
ctx.fillStyle = fillColor, hollow && (ctx.globalCompositeOperation = "xor");
|
|
18235
|
+
const cx = center[0],
|
|
18236
|
+
cy = center[1];
|
|
18237
|
+
if ("cardioid" === shape.shape) drawCardioid(ctx, generateCardioidPoints({
|
|
18238
|
+
x: cx,
|
|
18239
|
+
y: cy
|
|
18240
|
+
}, maxRadius, 0, 100));else if ("circle" === shape.shape) ctx.beginPath(), ctx.arc(cx, cy, maxRadius, 0, 2 * Math.PI, !0), ctx.fill();else if ("diamond" === shape.shape) drawRegularPolygon(ctx, generatePoints({
|
|
18241
|
+
x: cx,
|
|
18242
|
+
y: cy
|
|
18243
|
+
}, maxRadius, -Math.PI / 2, 4));else if ("square" === shape.shape) drawRegularPolygon(ctx, generatePoints({
|
|
18244
|
+
x: cx,
|
|
18245
|
+
y: cy
|
|
18246
|
+
}, maxRadius, -Math.PI / 4, 4));else if ("pentagon" === shape.shape) drawRegularPolygon(ctx, generatePoints({
|
|
18247
|
+
x: cx,
|
|
18248
|
+
y: cy
|
|
18249
|
+
}, maxRadius, Math.PI / 2, 5));else if ("triangle" === shape.shape || "triangleUpright" === shape.shape) drawRegularPolygon(ctx, generatePoints({
|
|
18250
|
+
x: cx,
|
|
18251
|
+
y: cy
|
|
18252
|
+
}, maxRadius, -Math.PI / 2, 3));else if ("triangleForward" === shape.shape) drawRegularPolygon(ctx, generatePoints({
|
|
18253
|
+
x: cx,
|
|
18254
|
+
y: cy
|
|
18255
|
+
}, maxRadius, 0, 3));else if ("star" === shape.shape) {
|
|
18256
|
+
const outterPoints = generatePoints({
|
|
18257
|
+
x: cx,
|
|
18258
|
+
y: cy
|
|
18259
|
+
}, maxRadius, -Math.PI / 2, 5),
|
|
18260
|
+
innerPoints = generatePoints({
|
|
18261
|
+
x: cx,
|
|
18262
|
+
y: cy
|
|
18263
|
+
}, maxRadius / (2 * Math.cos(Math.PI / 5)), -Math.PI / 2 + Math.PI / 5, 5),
|
|
18264
|
+
points = [];
|
|
18265
|
+
for (let i = 0; i < 5; i++) points.push(outterPoints[i]), points.push(innerPoints[i]);
|
|
18266
|
+
drawRegularPolygon(ctx, points);
|
|
18267
|
+
} else ctx.fillRect(0, 0, width, height);
|
|
18268
|
+
};
|
|
18269
|
+
function segmentation(segmentationInput) {
|
|
18270
|
+
const {
|
|
18271
|
+
size: size,
|
|
18272
|
+
maskCanvas: maskCanvas
|
|
18273
|
+
} = segmentationInput,
|
|
18274
|
+
imageData = maskCanvas.getContext("2d", {
|
|
18275
|
+
willReadFrequently: !0
|
|
18276
|
+
}).getImageData(0, 0, maskCanvas.width, maskCanvas.height),
|
|
18277
|
+
labels = new Array(size[0] * size[1]).fill(0);
|
|
18278
|
+
let curLabel = 1;
|
|
18279
|
+
const offset = [[0, 1], [1, 0], [-1, 0], [0, -1]];
|
|
18280
|
+
let queue = [];
|
|
18281
|
+
for (let i = 0; i < size[1]; i++) for (let j = 0; j < size[0]; j++) if (0 === labels[i * size[0] + j] && !segmentationInput.isEmptyPixel(imageData, i, j)) {
|
|
18282
|
+
labels[i * size[0] + j] = curLabel, queue.push([i, j]);
|
|
18283
|
+
for (let k = 0; k < queue.length; k++) for (let m = 0; m < 4; m++) {
|
|
18284
|
+
let row = queue[k][0] + offset[m][0],
|
|
18285
|
+
col = queue[k][1] + offset[m][1];
|
|
18286
|
+
row = row < 0 ? 0 : row >= size[1] ? size[1] - 1 : row, col = col < 0 ? 0 : col >= size[0] ? size[0] - 1 : col, 0 !== labels[row * size[0] + col] || segmentationInput.isEmptyPixel(imageData, row, col) || (labels[row * size[0] + col] = curLabel, queue.push([row, col]));
|
|
18287
|
+
}
|
|
18288
|
+
curLabel++, queue = [];
|
|
18289
|
+
}
|
|
18290
|
+
const boundaries = {},
|
|
18291
|
+
areas = {},
|
|
18292
|
+
centers = {},
|
|
18293
|
+
maxPoints = {},
|
|
18294
|
+
maxR = {},
|
|
18295
|
+
ratios = {},
|
|
18296
|
+
shapeBounds = {
|
|
18297
|
+
x1: 1 / 0,
|
|
18298
|
+
x2: -1 / 0,
|
|
18299
|
+
y1: 1 / 0,
|
|
18300
|
+
y2: -1 / 0,
|
|
18301
|
+
width: 0,
|
|
18302
|
+
height: 0
|
|
18303
|
+
},
|
|
18304
|
+
boundaryPixels = [];
|
|
18305
|
+
for (let i = 0; i < size[1]; i++) for (let j = 0; j < size[0]; j++) {
|
|
18306
|
+
const label = labels[i * size[0] + j];
|
|
18307
|
+
0 !== label && (isBoundaryPixel(i, j) && (boundaryPixels.push([i, j]), boundaries[label] = boundaries[label] || [], boundaries[label].push([j, i]), maxPoints[label] || (maxPoints[label] = [1 / 0, -1 / 0, 1 / 0, -1 / 0]), i < maxPoints[label][0] && (maxPoints[label][0] = i), i > maxPoints[label][1] && (maxPoints[label][1] = i), j < maxPoints[label][2] && (maxPoints[label][2] = j), j > maxPoints[label][3] && (maxPoints[label][3] = j), j < shapeBounds.x1 && (shapeBounds.x1 = j), j > shapeBounds.x2 && (shapeBounds.x2 = j), i < shapeBounds.y1 && (shapeBounds.y1 = i), i > shapeBounds.y2 && (shapeBounds.y2 = i)), areas[label] = (areas[label] || 0) + 1);
|
|
18308
|
+
}
|
|
18309
|
+
const allBoundaries = [];
|
|
18310
|
+
for (const label in boundaries) {
|
|
18311
|
+
const boundary = boundaries[label],
|
|
18312
|
+
x = ~~(boundary.reduce((acc, cur) => acc + cur[0], 0) / boundary.length),
|
|
18313
|
+
y = ~~(boundary.reduce((acc, cur) => acc + cur[1], 0) / boundary.length);
|
|
18314
|
+
centers[label] = [x, y], allBoundaries.push(...boundary);
|
|
18315
|
+
const [yMin, yMax, xMin, xMax] = maxPoints[label];
|
|
18316
|
+
maxR[label] = ~~Math.max(Math.sqrt((x - xMin) ** 2 + (y - yMin) ** 2), Math.sqrt((x - xMax) ** 2 + (y - yMax) ** 2), Math.sqrt((x - xMin) ** 2 + (y - yMax) ** 2), Math.sqrt((x - xMax) ** 2 + (y - yMin) ** 2)), ratios[label] = (xMax - xMin) / (yMax - yMin);
|
|
18317
|
+
}
|
|
18318
|
+
const regions = Object.keys(centers).map(key => ({
|
|
18319
|
+
label: key - 1,
|
|
18320
|
+
boundary: boundaries[key],
|
|
18321
|
+
area: areas[key],
|
|
18322
|
+
center: centers[key],
|
|
18323
|
+
maxPoint: maxPoints[key],
|
|
18324
|
+
maxR: maxR[key],
|
|
18325
|
+
ratio: ratios[key]
|
|
18326
|
+
}));
|
|
18327
|
+
shapeBounds.width = shapeBounds.x2 - shapeBounds.x1 + 1, shapeBounds.height = shapeBounds.y2 - shapeBounds.y1 + 1;
|
|
18328
|
+
const x = ~~(allBoundaries.reduce((acc, cur) => acc + cur[0], 0) / allBoundaries.length),
|
|
18329
|
+
y = ~~(allBoundaries.reduce((acc, cur) => acc + cur[1], 0) / allBoundaries.length),
|
|
18330
|
+
shapeMaxR = ~~Math.max(Math.sqrt((x - shapeBounds.x1) ** 2 + (y - shapeBounds.y1) ** 2), Math.sqrt((x - shapeBounds.x2) ** 2 + (y - shapeBounds.y2) ** 2), Math.sqrt((x - shapeBounds.x1) ** 2 + (y - shapeBounds.y2) ** 2), Math.sqrt((x - shapeBounds.x2) ** 2 + (y - shapeBounds.y1) ** 2)),
|
|
18331
|
+
shapeRatio = shapeBounds.width / shapeBounds.height,
|
|
18332
|
+
shapeArea = Object.keys(areas).reduce((acc, key) => acc + areas[key], 0),
|
|
18333
|
+
segmentation = {
|
|
18334
|
+
regions: regions,
|
|
18335
|
+
labels: labels,
|
|
18336
|
+
labelNumber: curLabel - 1
|
|
18337
|
+
};
|
|
18338
|
+
if (segmentationInput.blur) {
|
|
18339
|
+
const blur = segmentationInput.blur,
|
|
18340
|
+
blurredLabels = gaussianBlur(labels, size[0], size[1], blur);
|
|
18341
|
+
drawContour(labels, boundaryPixels, size[0], size[1], Math.ceil(blur / 2)).forEach((value, index) => {
|
|
18342
|
+
1 === value && (labels[index] = blurredLabels[index]);
|
|
18343
|
+
});
|
|
18344
|
+
}
|
|
18345
|
+
return Object.assign(segmentationInput, {
|
|
18346
|
+
segmentation: segmentation,
|
|
18347
|
+
shapeBounds: shapeBounds,
|
|
18348
|
+
shapeMaxR: shapeMaxR,
|
|
18349
|
+
shapeRatio: shapeRatio,
|
|
18350
|
+
shapeCenter: [x, y],
|
|
18351
|
+
shapeArea: shapeArea
|
|
18352
|
+
});
|
|
18353
|
+
function isBoundaryPixel(i, j) {
|
|
18354
|
+
const offset = [[0, 1], [1, 0], [-1, 0], [0, -1]];
|
|
18355
|
+
if (0 === i || 0 === j || i === size[1] - 1 || j === size[0] - 1) return !0;
|
|
18356
|
+
for (let k = 0; k < 4; k++) {
|
|
18357
|
+
let row = i + offset[k][0],
|
|
18358
|
+
col = j + offset[k][1];
|
|
18359
|
+
if (row = row < 0 ? 0 : row >= size[1] ? size[1] - 1 : row, col = col < 0 ? 0 : col >= size[0] ? size[0] - 1 : col, 0 === labels[row * size[0] + col]) return !0;
|
|
18360
|
+
}
|
|
18361
|
+
return !1;
|
|
18362
|
+
}
|
|
18363
|
+
}
|
|
18364
|
+
function generateGaussianKernel1D(size, sigma) {
|
|
18365
|
+
const kernel = new Array(2 * size + 1).fill(0),
|
|
18366
|
+
center = size;
|
|
18367
|
+
let sum = 0;
|
|
18368
|
+
for (let x = -size; x <= size; x++) {
|
|
18369
|
+
const g = Math.exp(-x * x / (2 * sigma * sigma));
|
|
18370
|
+
kernel[x + center] = g, sum += g;
|
|
18371
|
+
}
|
|
18372
|
+
for (let i = 0; i < kernel.length; i++) kernel[i] /= sum;
|
|
18373
|
+
return kernel;
|
|
18374
|
+
}
|
|
18375
|
+
function gaussianBlur(labels, width, height, blur) {
|
|
18376
|
+
const sigma = blur / 3,
|
|
18377
|
+
size = Math.ceil(blur / 2),
|
|
18378
|
+
kernel = generateGaussianKernel1D(size, sigma),
|
|
18379
|
+
temp = new Array(labels.length).fill(0),
|
|
18380
|
+
result = new Array(labels.length).fill(0);
|
|
18381
|
+
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
18382
|
+
let sum = 0;
|
|
18383
|
+
for (let i = -size; i <= size; i++) {
|
|
18384
|
+
sum += labels[y * width + Math.min(Math.max(x + i, 0), width - 1)] * kernel[i + size];
|
|
18385
|
+
}
|
|
18386
|
+
temp[y * width + x] = sum;
|
|
18387
|
+
}
|
|
18388
|
+
for (let x = 0; x < width; x++) for (let y = 0; y < height; y++) {
|
|
18389
|
+
let sum = 0;
|
|
18390
|
+
for (let i = -size; i <= size; i++) {
|
|
18391
|
+
sum += temp[Math.min(Math.max(y + i, 0), height - 1) * width + x] * kernel[i + size];
|
|
18392
|
+
}
|
|
18393
|
+
result[y * width + x] = Math.max(0, Math.min(1, sum));
|
|
18394
|
+
}
|
|
18395
|
+
return result;
|
|
18396
|
+
}
|
|
18397
|
+
function drawContour(labels, boundaryPixels, width, height) {
|
|
18398
|
+
let thickness = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
|
|
18399
|
+
const result = new Array(labels.length).fill(0);
|
|
18400
|
+
for (const [i, j] of boundaryPixels) if (result[i * width + j] = 1, thickness > 1) for (let di = 1 - thickness; di <= thickness - 1; di++) for (let dj = 1 - thickness; dj <= thickness - 1; dj++) {
|
|
18401
|
+
if (Math.sqrt(di * di + dj * dj) < thickness) {
|
|
18402
|
+
const ni = i + di,
|
|
18403
|
+
nj = j + dj;
|
|
18404
|
+
ni >= 0 && ni < height && nj >= 0 && nj < width && (result[ni * width + nj] = 1);
|
|
18405
|
+
}
|
|
18406
|
+
}
|
|
18407
|
+
return result;
|
|
18408
|
+
}
|
|
18409
|
+
function removeBorder(image, canvas, isEmptyPixel) {
|
|
18410
|
+
canvas.width = image.width, canvas.height = image.height;
|
|
18411
|
+
const ctx = canvas.getContext("2d", {
|
|
18412
|
+
willReadFrequently: !0
|
|
18413
|
+
});
|
|
18414
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height), ctx.drawImage(image, 0, 0);
|
|
18415
|
+
const width = canvas.width,
|
|
18416
|
+
imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
18417
|
+
let top = 0,
|
|
18418
|
+
bottom = imageData.height,
|
|
18419
|
+
left = 0,
|
|
18420
|
+
right = imageData.width;
|
|
18421
|
+
const rowBlank = (width, y) => {
|
|
18422
|
+
for (let x = 0; x < width; ++x) if (!isEmptyPixel(imageData, y, x)) return !1;
|
|
18423
|
+
return !0;
|
|
18424
|
+
},
|
|
18425
|
+
columnBlank = (x, y0, y1) => {
|
|
18426
|
+
for (let y = y0; y < y1; ++y) if (!isEmptyPixel(imageData, y, x)) return !1;
|
|
18427
|
+
return !0;
|
|
18428
|
+
};
|
|
18429
|
+
for (; top < bottom && rowBlank(width, top);) ++top;
|
|
18430
|
+
for (; bottom - 1 > top && rowBlank(width, bottom - 1);) --bottom;
|
|
18431
|
+
for (; left < right && columnBlank(left, top, bottom);) ++left;
|
|
18432
|
+
for (; right - 1 > left && columnBlank(right - 1, top, bottom);) --right;
|
|
18433
|
+
const trimmed = ctx.getImageData(left, top, right - left, bottom - top);
|
|
18434
|
+
return canvas.width = trimmed.width, canvas.height = trimmed.height, ctx.clearRect(0, 0, canvas.width, canvas.height), ctx.putImageData(trimmed, 0, 0), canvas;
|
|
18435
|
+
}
|
|
18436
|
+
function scaleAndMiddleShape(image, size) {
|
|
18437
|
+
const width = image.width,
|
|
18438
|
+
height = image.height;
|
|
18439
|
+
let scale = size[0] / width;
|
|
18440
|
+
height * scale > size[1] && (scale = size[1] / height);
|
|
18441
|
+
const newWidth = Math.floor(scale * width),
|
|
18442
|
+
newHeight = Math.floor(scale * height);
|
|
18443
|
+
return {
|
|
18444
|
+
x: (size[0] - newWidth) / 2,
|
|
18445
|
+
y: (size[1] - newHeight) / 2,
|
|
18446
|
+
width: newWidth,
|
|
18447
|
+
height: newHeight,
|
|
18448
|
+
scale: scale
|
|
18449
|
+
};
|
|
18450
|
+
}
|
|
18451
|
+
|
|
18452
|
+
function loadImage(url, createImage) {
|
|
18453
|
+
return url && (vutils.isValidUrl(url) || vutils.isBase64(url) || url.startsWith("<svg")) ? new Promise((resolve, reject) => {
|
|
18454
|
+
var _a;
|
|
18455
|
+
const imageMark = createImage({
|
|
18456
|
+
image: url
|
|
18457
|
+
}),
|
|
18458
|
+
imgData = null === (_a = imageMark.resources) || void 0 === _a ? void 0 : _a.get(url);
|
|
18459
|
+
imgData && "success" === imgData.state && imgData.data ? resolve(imgData.data) : (imageMark.successCallback = () => {
|
|
18460
|
+
var _a;
|
|
18461
|
+
if (imageMark) {
|
|
18462
|
+
const imgData = null === (_a = imageMark.resources) || void 0 === _a ? void 0 : _a.get(url);
|
|
18463
|
+
imgData && "success" === imgData.state && imgData.data ? resolve(imgData.data) : reject(new Error("image load failed: " + url));
|
|
18464
|
+
} else reject(new Error("image load failed: " + url));
|
|
18465
|
+
}, imageMark.failCallback = () => {
|
|
18466
|
+
reject(new Error("image load failed: " + url));
|
|
18467
|
+
});
|
|
18468
|
+
}) : null;
|
|
18469
|
+
}
|
|
18470
|
+
function loadImages(urls, createImage) {
|
|
18471
|
+
return Promise.allSettled(urls.map(url => loadImage(url, createImage)));
|
|
18472
|
+
}
|
|
18473
|
+
|
|
18474
|
+
var ScaleEnum;
|
|
18475
|
+
!function (ScaleEnum) {
|
|
18476
|
+
ScaleEnum.Identity = "identity", ScaleEnum.Linear = "linear", ScaleEnum.Log = "log", ScaleEnum.Pow = "pow", ScaleEnum.Sqrt = "sqrt", ScaleEnum.Symlog = "symlog", ScaleEnum.Time = "time", ScaleEnum.Quantile = "quantile", ScaleEnum.Quantize = "quantize", ScaleEnum.Threshold = "threshold", ScaleEnum.Ordinal = "ordinal", ScaleEnum.Point = "point", ScaleEnum.Band = "band";
|
|
18477
|
+
}(ScaleEnum || (ScaleEnum = {}));
|
|
18478
|
+
Object.values(ScaleEnum).forEach(v => {
|
|
18479
|
+
});
|
|
18480
|
+
|
|
18481
|
+
function identity(x) {
|
|
18482
|
+
return x;
|
|
18483
|
+
}
|
|
18484
|
+
const sqrt = x => x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
|
|
18485
|
+
const square = x => x < 0 ? -x * x : x * x;
|
|
18486
|
+
function normalize(a, b) {
|
|
18487
|
+
if (a = Number(a), b = Number(b), b -= a) return x => (x - a) / b;
|
|
18488
|
+
const result = Number.isNaN(b) ? NaN : .5;
|
|
18489
|
+
return () => result;
|
|
18490
|
+
}
|
|
18491
|
+
function bimap(domain, range, interpolate) {
|
|
18492
|
+
const d0 = domain[0],
|
|
18493
|
+
d1 = domain[1],
|
|
18494
|
+
r0 = range[0],
|
|
18495
|
+
r1 = range[1];
|
|
18496
|
+
let d0Fuc, r0Fuc;
|
|
18497
|
+
return d1 < d0 ? (d0Fuc = normalize(d1, d0), r0Fuc = interpolate(r1, r0)) : (d0Fuc = normalize(d0, d1), r0Fuc = interpolate(r0, r1)), x => r0Fuc(d0Fuc(x));
|
|
18498
|
+
}
|
|
18499
|
+
function calculateWholeRangeFromRangeFactor(range, rangeFactor) {
|
|
18500
|
+
const k = (range[1] - range[0]) / (rangeFactor[1] - rangeFactor[0]),
|
|
18501
|
+
b = range[0] - k * rangeFactor[0];
|
|
18502
|
+
return [b, k + b];
|
|
18503
|
+
}
|
|
18504
|
+
function polymap(domain, range, interpolate) {
|
|
18505
|
+
const j = Math.min(domain.length, range.length) - 1,
|
|
18506
|
+
d = new Array(j),
|
|
18507
|
+
r = new Array(j);
|
|
18508
|
+
let i = -1;
|
|
18509
|
+
for (domain[j] < domain[0] && (domain = domain.slice().reverse(), range = range.slice().reverse()); ++i < j;) d[i] = normalize(domain[i], domain[i + 1]), r[i] = interpolate(range[i], range[i + 1]);
|
|
18510
|
+
return function (x) {
|
|
18511
|
+
const i = vutils.bisect(domain, x, 1, j) - 1;
|
|
18512
|
+
return r[i](d[i](x));
|
|
18513
|
+
};
|
|
18514
|
+
}
|
|
18515
|
+
const niceNumber = function (value) {
|
|
18516
|
+
let round = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1;
|
|
18517
|
+
const exponent = Math.floor(Math.log10(value)),
|
|
18518
|
+
fraction = value / Math.pow(10, exponent);
|
|
18519
|
+
let niceFraction;
|
|
18520
|
+
return niceFraction = round ? fraction < 1.5 ? 1 : fraction < 3 ? 2 : fraction < 7 ? 5 : 10 : fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 5 ? 5 : 10, niceFraction * Math.pow(10, exponent);
|
|
18521
|
+
};
|
|
18522
|
+
const restrictNumber = (value, domain) => {
|
|
18523
|
+
let min, max;
|
|
18524
|
+
return domain[0] < domain[1] ? (min = domain[0], max = domain[1]) : (min = domain[1], max = domain[0]), Math.min(Math.max(value, min), max);
|
|
18525
|
+
};
|
|
18526
|
+
|
|
18527
|
+
class BaseScale {
|
|
18528
|
+
constructor() {
|
|
18529
|
+
this._rangeFactorStart = null, this._rangeFactorEnd = null;
|
|
18530
|
+
}
|
|
18531
|
+
_calculateWholeRange(range) {
|
|
18532
|
+
return this._wholeRange ? this._wholeRange : vutils.isValid(this._rangeFactorStart) && vutils.isValid(this._rangeFactorEnd) && 2 === range.length ? (this._wholeRange = calculateWholeRangeFromRangeFactor(range, [this._rangeFactorStart, this._rangeFactorEnd]), this._wholeRange) : range;
|
|
18533
|
+
}
|
|
18534
|
+
rangeFactor(_, slience, clear) {
|
|
18535
|
+
return _ ? (2 === _.length && _.every(r => r >= 0 && r <= 1) && (this._wholeRange = null, 0 === _[0] && 1 === _[1] ? (this._rangeFactorStart = null, this._rangeFactorEnd = null) : (this._rangeFactorStart = _[0], this._rangeFactorEnd = _[1])), this) : clear ? (this._wholeRange = null, this._rangeFactorStart = null, this._rangeFactorEnd = null, this) : vutils.isValid(this._rangeFactorStart) && vutils.isValid(this._rangeFactorEnd) ? [this._rangeFactorStart, this._rangeFactorEnd] : null;
|
|
18536
|
+
}
|
|
18537
|
+
rangeFactorStart(_, slience) {
|
|
18538
|
+
var _a;
|
|
18539
|
+
return vutils.isNil(_) ? this._rangeFactorStart : (_ >= 0 && _ <= 1 && (this._wholeRange = null, 0 !== _ || !vutils.isNil(this._rangeFactorEnd) && 1 !== this._rangeFactorEnd ? (this._rangeFactorStart = _, this._rangeFactorEnd = null !== (_a = this._rangeFactorEnd) && void 0 !== _a ? _a : 1) : (this._rangeFactorStart = null, this._rangeFactorEnd = null)), this);
|
|
18540
|
+
}
|
|
18541
|
+
rangeFactorEnd(_, slience) {
|
|
18542
|
+
var _a;
|
|
18543
|
+
return vutils.isNil(_) ? this._rangeFactorEnd : (_ >= 0 && _ <= 1 && (this._wholeRange = null, 0 !== _ || !vutils.isNil(this._rangeFactorStart) && 0 !== this._rangeFactorStart ? (this._rangeFactorEnd = _, this._rangeFactorStart = null !== (_a = this._rangeFactorStart) && void 0 !== _a ? _a : 0) : (this._rangeFactorStart = null, this._rangeFactorEnd = null)), this);
|
|
18544
|
+
}
|
|
18545
|
+
generateFishEyeTransform() {
|
|
18546
|
+
var _a;
|
|
18547
|
+
if (!this._fishEyeOptions) return void (this._fishEyeTransform = null);
|
|
18548
|
+
const {
|
|
18549
|
+
distortion = 2,
|
|
18550
|
+
radiusRatio = .1,
|
|
18551
|
+
radius: radius
|
|
18552
|
+
} = this._fishEyeOptions,
|
|
18553
|
+
range = this.range(),
|
|
18554
|
+
first = range[0],
|
|
18555
|
+
last = range[range.length - 1],
|
|
18556
|
+
min = Math.min(first, last),
|
|
18557
|
+
max = Math.max(first, last),
|
|
18558
|
+
focus = vutils.clamp(null !== (_a = this._fishEyeOptions.focus) && void 0 !== _a ? _a : 0, min, max),
|
|
18559
|
+
rangeRadius = vutils.isNil(radius) ? (max - min) * radiusRatio : radius;
|
|
18560
|
+
let k0 = Math.exp(distortion);
|
|
18561
|
+
k0 = k0 / (k0 - 1) * rangeRadius;
|
|
18562
|
+
const k1 = distortion / rangeRadius;
|
|
18563
|
+
this._fishEyeTransform = output => {
|
|
18564
|
+
const delta = Math.abs(output - focus);
|
|
18565
|
+
if (delta >= rangeRadius) return output;
|
|
18566
|
+
if (delta <= 1e-6) return focus;
|
|
18567
|
+
const k = k0 * (1 - Math.exp(-delta * k1)) / delta * .75 + .25;
|
|
18568
|
+
return focus + (output - focus) * k;
|
|
18569
|
+
};
|
|
18570
|
+
}
|
|
18571
|
+
unknown(_) {
|
|
18572
|
+
return arguments.length ? (this._unknown = _, this) : this._unknown;
|
|
18573
|
+
}
|
|
18574
|
+
get(key, defaultValue) {
|
|
18575
|
+
var _a;
|
|
18576
|
+
return null !== (_a = null == this ? void 0 : this[key]) && void 0 !== _a ? _a : defaultValue;
|
|
18577
|
+
}
|
|
18578
|
+
}
|
|
18579
|
+
|
|
18580
|
+
const {
|
|
18581
|
+
interpolateRgb: interpolateRgb
|
|
18582
|
+
} = vutils.ColorUtil;
|
|
18583
|
+
function interpolate(a, b) {
|
|
18584
|
+
const t = typeof b;
|
|
18585
|
+
let c;
|
|
18586
|
+
if (vutils.isNil(b) || "boolean" === t) return () => b;
|
|
18587
|
+
if ("number" === t) return vutils.interpolateNumber(a, b);
|
|
18588
|
+
if ("string" === t) {
|
|
18589
|
+
if (c = vutils.ColorUtil.Color.parseColorString(b)) {
|
|
18590
|
+
const rgb = interpolateRgb(vutils.ColorUtil.Color.parseColorString(a), c);
|
|
18591
|
+
return t => rgb(t).formatRgb();
|
|
18592
|
+
}
|
|
18593
|
+
return vutils.interpolateNumber(Number(a), Number(b));
|
|
18594
|
+
}
|
|
18595
|
+
return b instanceof vutils.ColorUtil.RGB ? interpolateRgb(a, b) : b instanceof vutils.ColorUtil.Color ? interpolateRgb(a.color, b.color) : b instanceof Date ? vutils.interpolateDate(a, b) : vutils.interpolateNumber(Number(a), Number(b));
|
|
18596
|
+
}
|
|
18597
|
+
|
|
18598
|
+
class ContinuousScale extends BaseScale {
|
|
18599
|
+
constructor() {
|
|
18600
|
+
let transformer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : identity;
|
|
18601
|
+
let untransformer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : identity;
|
|
18602
|
+
super(), this._unknown = void 0, this.transformer = transformer, this.untransformer = untransformer, this._forceAlign = !0, this._domain = [0, 1], this._range = [0, 1], this._clamp = identity, this._piecewise = bimap, this._interpolate = interpolate;
|
|
18603
|
+
}
|
|
18604
|
+
calculateVisibleDomain(range) {
|
|
18605
|
+
var _a;
|
|
18606
|
+
if (vutils.isValid(this._rangeFactorStart) && vutils.isValid(this._rangeFactorEnd) && 2 === range.length) {
|
|
18607
|
+
return [this.invert(range[0]), this.invert(range[1])];
|
|
18608
|
+
}
|
|
18609
|
+
return null !== (_a = this._niceDomain) && void 0 !== _a ? _a : this._domain;
|
|
18610
|
+
}
|
|
18611
|
+
fishEye(options, slience, clear) {
|
|
18612
|
+
return options || clear ? (this._fishEyeOptions = options, this._fishEyeTransform = null, this.rescale(slience)) : this._fishEyeOptions;
|
|
18613
|
+
}
|
|
18614
|
+
scale(x) {
|
|
18615
|
+
var _a;
|
|
18616
|
+
if (x = Number(x), Number.isNaN(x) || this._domainValidator && !this._domainValidator(x)) return this._unknown;
|
|
18617
|
+
this._output || (this._output = this._piecewise((null !== (_a = this._niceDomain) && void 0 !== _a ? _a : this._domain).map(this.transformer), this._calculateWholeRange(this._range), this._interpolate));
|
|
18618
|
+
const output = this._output(this.transformer(this._clamp(x)));
|
|
18619
|
+
return this._fishEyeTransform ? this._fishEyeTransform(output) : output;
|
|
18620
|
+
}
|
|
18621
|
+
invert(y) {
|
|
18622
|
+
var _a;
|
|
18623
|
+
return this._input || (this._input = this._piecewise(this._calculateWholeRange(this._range), (null !== (_a = this._niceDomain) && void 0 !== _a ? _a : this._domain).map(this.transformer), vutils.interpolateNumber)), this._clamp(this.untransformer(this._input(y)));
|
|
18624
|
+
}
|
|
18625
|
+
domain(_, slience) {
|
|
18626
|
+
var _a;
|
|
18627
|
+
if (!_) return (null !== (_a = this._niceDomain) && void 0 !== _a ? _a : this._domain).slice();
|
|
18628
|
+
this._domainValidator = null, this._niceType = null, this._niceDomain = null;
|
|
18629
|
+
const nextDomain = Array.from(_, vutils.toNumber);
|
|
18630
|
+
return this._domain = nextDomain, this.rescale(slience);
|
|
18631
|
+
}
|
|
18632
|
+
range(_, slience) {
|
|
18633
|
+
if (!_) return this._range.slice();
|
|
18634
|
+
const nextRange = Array.from(_);
|
|
18635
|
+
return this._range = nextRange, this.rescale(slience);
|
|
18636
|
+
}
|
|
18637
|
+
rangeRound(_, slience) {
|
|
18638
|
+
const nextRange = Array.from(_);
|
|
18639
|
+
return this._range = nextRange, this._interpolate = vutils.interpolateNumberRound, this.rescale(slience);
|
|
18640
|
+
}
|
|
18641
|
+
rescale(slience) {
|
|
18642
|
+
var _a;
|
|
18643
|
+
if (slience) return this;
|
|
18644
|
+
const domain = null !== (_a = this._niceDomain) && void 0 !== _a ? _a : this._domain,
|
|
18645
|
+
domainLength = domain.length,
|
|
18646
|
+
rangeLength = this._range.length;
|
|
18647
|
+
let n = Math.min(domainLength, rangeLength);
|
|
18648
|
+
if (domainLength && domainLength < rangeLength && this._forceAlign) {
|
|
18649
|
+
const deltaStep = rangeLength - domainLength + 1,
|
|
18650
|
+
last = domain[domainLength - 1],
|
|
18651
|
+
delta = domainLength >= 2 ? (last - domain[domainLength - 2]) / deltaStep : 0;
|
|
18652
|
+
for (let i = 1; i <= deltaStep; i++) domain[domainLength - 2 + i] = last - delta * (deltaStep - i);
|
|
18653
|
+
n = rangeLength;
|
|
18654
|
+
}
|
|
18655
|
+
return this._autoClamp && (this._clamp = vutils.clamper(domain[0], domain[n - 1])), this._piecewise = n > 2 ? polymap : bimap, this._output = this._input = null, this._wholeRange = null, this.generateFishEyeTransform(), this;
|
|
18656
|
+
}
|
|
18657
|
+
clamp(_, f, slience) {
|
|
18658
|
+
return arguments.length ? (f ? (this._autoClamp = !1, this._clamp = f) : (this._autoClamp = !!_, this._clamp = _ ? void 0 : identity), this.rescale(slience)) : this._clamp !== identity;
|
|
18659
|
+
}
|
|
18660
|
+
interpolate(_, slience) {
|
|
18661
|
+
return arguments.length ? (this._interpolate = _, this.rescale(slience)) : this._interpolate;
|
|
18662
|
+
}
|
|
18663
|
+
ticks() {
|
|
18664
|
+
return [];
|
|
18665
|
+
}
|
|
18666
|
+
tickData() {
|
|
18667
|
+
let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
18668
|
+
const ticks = this.ticks(count);
|
|
18669
|
+
return (null != ticks ? ticks : []).map((tick, index) => ({
|
|
18670
|
+
index: index,
|
|
18671
|
+
tick: tick,
|
|
18672
|
+
value: (this.scale(tick) - this._range[0]) / (this._range[1] - this._range[0])
|
|
18673
|
+
}));
|
|
18674
|
+
}
|
|
18675
|
+
rangeFactor(_, slience) {
|
|
18676
|
+
return _ ? (super.rangeFactor(_), this._output = this._input = null, this) : super.rangeFactor();
|
|
18677
|
+
}
|
|
18678
|
+
rangeFactorStart(_, slience) {
|
|
18679
|
+
return vutils.isNil(_) ? super.rangeFactorStart() : (super.rangeFactorStart(_), this._output = this._input = null, this);
|
|
18680
|
+
}
|
|
18681
|
+
rangeFactorEnd(_, slience) {
|
|
18682
|
+
return vutils.isNil(_) ? super.rangeFactorEnd() : (super.rangeFactorEnd(_), this._output = this._input = null, this);
|
|
18683
|
+
}
|
|
18684
|
+
forceAlignDomainRange(forceAlign) {
|
|
18685
|
+
return arguments.length ? (this._forceAlign = forceAlign, this) : this._forceAlign;
|
|
18686
|
+
}
|
|
18687
|
+
}
|
|
18688
|
+
|
|
18689
|
+
const e10 = Math.sqrt(50),
|
|
18690
|
+
e5 = Math.sqrt(10),
|
|
18691
|
+
e2 = Math.sqrt(2),
|
|
18692
|
+
niceNumbers = [1, 2, 5, 10];
|
|
18693
|
+
const calculateTicksOfSingleValue = (value, tickCount, noDecimals) => {
|
|
18694
|
+
let step = 1,
|
|
18695
|
+
start = value;
|
|
18696
|
+
const middleIndex = Math.floor((tickCount - 1) / 2),
|
|
18697
|
+
absVal = Math.abs(value);
|
|
18698
|
+
return value >= 0 && value <= Number.MIN_VALUE ? start = 0 : value < 0 && value >= -Number.MIN_VALUE ? start = -(tickCount - 1) : !noDecimals && absVal < 1 ? step = getNickStep(absVal).step : (noDecimals || absVal > 1) && (start = Math.floor(value) - middleIndex * step), step > 0 ? (value > 0 ? start = Math.max(start, 0) : value < 0 && (start = Math.min(start, -(tickCount - 1) * step)), vutils.range(0, tickCount).map(index => start + index * step)) : value > 0 ? calculateTicksByStep(0, -(tickCount - 1) / step, step) : calculateTicksByStep((tickCount - 1) / step, 0, step);
|
|
18699
|
+
};
|
|
18700
|
+
const d3Ticks = vutils.memoize((start, stop, count, options) => {
|
|
18701
|
+
let reverse,
|
|
18702
|
+
n,
|
|
18703
|
+
ticks,
|
|
18704
|
+
step,
|
|
18705
|
+
i = -1;
|
|
18706
|
+
if (count = +count, (start = +start) === (stop = +stop)) return [start];
|
|
18707
|
+
if (Math.abs(start - stop) <= Number.MIN_VALUE && count > 0) return [start];
|
|
18708
|
+
if ((reverse = stop < start) && (n = start, start = stop, stop = n), step = tickIncrement(start, stop, count).step, !isFinite(step)) return [];
|
|
18709
|
+
if (step > 0) {
|
|
18710
|
+
let r0 = Math.round(start / step),
|
|
18711
|
+
r1 = Math.round(stop / step);
|
|
18712
|
+
for (r0 * step < start && ++r0, r1 * step > stop && --r1, ticks = new Array(n = r1 - r0 + 1); ++i < n;) ticks[i] = (r0 + i) * step;
|
|
18713
|
+
} else if (step < 0 && (null == options ? void 0 : options.noDecimals)) {
|
|
18714
|
+
step = 1;
|
|
18715
|
+
const r0 = Math.ceil(start),
|
|
18716
|
+
r1 = Math.floor(stop);
|
|
18717
|
+
if (!(r0 <= r1)) return [];
|
|
18718
|
+
for (ticks = new Array(n = r1 - r0 + 1); ++i < n;) ticks[i] = r0 + i;
|
|
18719
|
+
} else {
|
|
18720
|
+
step = -step;
|
|
18721
|
+
let r0 = Math.round(start * step),
|
|
18722
|
+
r1 = Math.round(stop * step);
|
|
18723
|
+
for (r0 / step < start && ++r0, r1 / step > stop && --r1, ticks = new Array(n = r1 - r0 + 1); ++i < n;) ticks[i] = (r0 + i) / step;
|
|
18724
|
+
}
|
|
18725
|
+
return reverse && ticks.reverse(), ticks;
|
|
18726
|
+
});
|
|
18727
|
+
const calculateTicksByStep = (start, stop, step) => {
|
|
18728
|
+
let n,
|
|
18729
|
+
ticks,
|
|
18730
|
+
i = -1;
|
|
18731
|
+
if (step > 0) {
|
|
18732
|
+
let r0 = Math.floor(start / step),
|
|
18733
|
+
r1 = Math.ceil(stop / step);
|
|
18734
|
+
for ((r0 + 1) * step < start && ++r0, (r1 - 1) * step > stop && --r1, ticks = new Array(n = r1 - r0 + 1); ++i < n;) ticks[i] = (r0 + i) * step;
|
|
18735
|
+
} else {
|
|
18736
|
+
step = -step;
|
|
18737
|
+
let r0 = Math.floor(start * step),
|
|
18738
|
+
r1 = Math.ceil(stop * step);
|
|
18739
|
+
for ((r0 + 1) / step < start && ++r0, (r1 - 1) / step > stop && --r1, ticks = new Array(n = r1 - r0 + 1); ++i < n;) ticks[i] = (r0 + i) / step;
|
|
18740
|
+
}
|
|
18741
|
+
return ticks;
|
|
18742
|
+
};
|
|
18743
|
+
const appendTicksToCount = (ticks, count, step) => {
|
|
18744
|
+
let n;
|
|
18745
|
+
const firstTick = ticks[0],
|
|
18746
|
+
lastTick = ticks[ticks.length - 1],
|
|
18747
|
+
appendCount = count - ticks.length;
|
|
18748
|
+
if (lastTick <= 0) {
|
|
18749
|
+
const headTicks = [];
|
|
18750
|
+
for (n = appendCount; n >= 1; n--) headTicks.push(firstTick - n * step);
|
|
18751
|
+
return headTicks.concat(ticks);
|
|
18752
|
+
}
|
|
18753
|
+
if (firstTick >= 0) {
|
|
18754
|
+
for (n = 1; n <= appendCount; n++) ticks.push(lastTick + n * step);
|
|
18755
|
+
return ticks;
|
|
18756
|
+
}
|
|
18757
|
+
let headTicks = [];
|
|
18758
|
+
const tailTicks = [];
|
|
18759
|
+
for (n = 1; n <= appendCount; n++) n % 2 == 0 ? headTicks = [firstTick - Math.floor(n / 2) * step].concat(headTicks) : tailTicks.push(lastTick + Math.ceil(n / 2) * step);
|
|
18760
|
+
return headTicks.concat(ticks).concat(tailTicks);
|
|
18761
|
+
};
|
|
18762
|
+
const ticks = vutils.memoize((start, stop, count, options) => {
|
|
18763
|
+
let reverse, ticks, n;
|
|
18764
|
+
if (count = +count, (start = +start) === (stop = +stop)) return calculateTicksOfSingleValue(start, count, null == options ? void 0 : options.noDecimals);
|
|
18765
|
+
if (Math.abs(start - stop) <= Number.MIN_VALUE && count > 0) return calculateTicksOfSingleValue(start, count, null == options ? void 0 : options.noDecimals);
|
|
18766
|
+
(reverse = stop < start) && (n = start, start = stop, stop = n);
|
|
18767
|
+
const stepRes = tickIncrement(start, stop, count);
|
|
18768
|
+
let step = stepRes.step;
|
|
18769
|
+
if (!isFinite(step)) return [];
|
|
18770
|
+
if (step > 0) {
|
|
18771
|
+
let cur = 1;
|
|
18772
|
+
const {
|
|
18773
|
+
power: power,
|
|
18774
|
+
gap: gap
|
|
18775
|
+
} = stepRes,
|
|
18776
|
+
delatStep = 10 === gap ? 2 * 10 ** power : 1 * 10 ** power;
|
|
18777
|
+
for (; cur <= 5 && (ticks = calculateTicksByStep(start, stop, step), ticks.length > count + 1) && count > 2;) step += delatStep, cur += 1;
|
|
18778
|
+
count > 2 && ticks.length < count - 1 && (ticks = appendTicksToCount(ticks, count, step));
|
|
18779
|
+
} else (null == options ? void 0 : options.noDecimals) && step < 0 && (step = 1), ticks = calculateTicksByStep(start, stop, step);
|
|
18780
|
+
return reverse && ticks.reverse(), ticks;
|
|
18781
|
+
});
|
|
18782
|
+
const getNickStep = step => {
|
|
18783
|
+
const power = Math.floor(Math.log(step) / Math.LN10),
|
|
18784
|
+
error = step / 10 ** power;
|
|
18785
|
+
let gap = niceNumbers[0];
|
|
18786
|
+
return error >= e10 ? gap = niceNumbers[3] : error >= e5 ? gap = niceNumbers[2] : error >= e2 && (gap = niceNumbers[1]), power >= 0 ? {
|
|
18787
|
+
step: gap * 10 ** power,
|
|
18788
|
+
gap: gap,
|
|
18789
|
+
power: power
|
|
18790
|
+
} : {
|
|
18791
|
+
step: -(10 ** -power) / gap,
|
|
18792
|
+
gap: gap,
|
|
18793
|
+
power: power
|
|
18794
|
+
};
|
|
18795
|
+
};
|
|
18796
|
+
function tickIncrement(start, stop, count) {
|
|
18797
|
+
const step = (stop - start) / Math.max(0, count);
|
|
18798
|
+
return getNickStep(step);
|
|
18799
|
+
}
|
|
18800
|
+
function forceTicks(start, stop, count) {
|
|
18801
|
+
let step;
|
|
18802
|
+
if (count = +count, (start = +start) === (stop = +stop) && count > 0) return [start];
|
|
18803
|
+
if (count <= 0 || 0 === (step = forceTickIncrement(start, stop, count)) || !isFinite(step)) return [];
|
|
18804
|
+
const ticks = new Array(count);
|
|
18805
|
+
for (let i = 0; i < count; i++) ticks[i] = start + i * step;
|
|
18806
|
+
return ticks;
|
|
18807
|
+
}
|
|
18808
|
+
function forceTickIncrement(start, stop, count) {
|
|
18809
|
+
return (stop - start) / Math.max(1, count - 1);
|
|
18810
|
+
}
|
|
18811
|
+
function stepTicks(start, stop, step) {
|
|
18812
|
+
let n,
|
|
18813
|
+
reverse,
|
|
18814
|
+
i = -1;
|
|
18815
|
+
if (step = +step, (reverse = (stop = +stop) < (start = +start)) && (n = start, start = stop, stop = n), !isFinite(step) || stop - start <= step) return [start];
|
|
18816
|
+
const count = Math.floor((stop - start) / step + 1),
|
|
18817
|
+
ticks = new Array(count);
|
|
18818
|
+
for (; ++i < count;) ticks[i] = start + i * step;
|
|
18819
|
+
return reverse && ticks.reverse(), ticks;
|
|
18820
|
+
}
|
|
18821
|
+
function niceLinear(d) {
|
|
18822
|
+
let count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
18823
|
+
let prestep,
|
|
18824
|
+
step,
|
|
18825
|
+
i0 = 0,
|
|
18826
|
+
i1 = d.length - 1,
|
|
18827
|
+
start = d[i0],
|
|
18828
|
+
stop = d[i1],
|
|
18829
|
+
maxIter = 10;
|
|
18830
|
+
for (stop < start && (step = start, start = stop, stop = step, step = i0, i0 = i1, i1 = step); maxIter-- > 0;) {
|
|
18831
|
+
if (step = tickIncrement(start, stop, count).step, step === prestep) return d[i0] = start, d[i1] = stop, d;
|
|
18832
|
+
if (step > 0) start = Math.floor(start / step) * step, stop = Math.ceil(stop / step) * step;else {
|
|
18833
|
+
if (!(step < 0)) break;
|
|
18834
|
+
start = Math.ceil(start * step) / step, stop = Math.floor(stop * step) / step;
|
|
18835
|
+
}
|
|
18836
|
+
prestep = step;
|
|
18837
|
+
}
|
|
18838
|
+
}
|
|
18839
|
+
function parseNiceOptions(originalDomain, option) {
|
|
18840
|
+
const hasForceMin = vutils.isNumber(option.forceMin),
|
|
18841
|
+
hasForceMax = vutils.isNumber(option.forceMax);
|
|
18842
|
+
let niceType = null;
|
|
18843
|
+
const niceMinMax = [];
|
|
18844
|
+
let niceDomain = null;
|
|
18845
|
+
const domainValidator = hasForceMin && hasForceMax ? x => x >= option.forceMin && x <= option.forceMax : hasForceMin ? x => x >= option.forceMin : hasForceMax ? x => x <= option.forceMax : null;
|
|
18846
|
+
return hasForceMin ? niceMinMax[0] = option.forceMin : vutils.isNumber(option.min) && option.min <= Math.min(originalDomain[0], originalDomain[originalDomain.length - 1]) && (niceMinMax[0] = option.min), hasForceMax ? niceMinMax[1] = option.forceMax : vutils.isNumber(option.max) && option.max >= Math.max(originalDomain[0], originalDomain[originalDomain.length - 1]) && (niceMinMax[1] = option.max), vutils.isNumber(niceMinMax[0]) && vutils.isNumber(niceMinMax[1]) ? (niceDomain = originalDomain.slice(), niceDomain[0] = niceMinMax[0], niceDomain[niceDomain.length - 1] = niceMinMax[1]) : niceType = vutils.isNumber(niceMinMax[0]) || vutils.isNumber(niceMinMax[1]) ? vutils.isNumber(niceMinMax[0]) ? "max" : "min" : "all", {
|
|
18847
|
+
niceType: niceType,
|
|
18848
|
+
niceDomain: niceDomain,
|
|
18849
|
+
niceMinMax: niceMinMax,
|
|
18850
|
+
domainValidator: domainValidator
|
|
18851
|
+
};
|
|
18852
|
+
}
|
|
18853
|
+
const fixPrecision = (start, stop, value) => Math.abs(stop - start) < 1 ? +value.toFixed(1) : Math.round(+value);
|
|
18854
|
+
vutils.memoize((start, stop, count, base, transformer, untransformer, options) => {
|
|
18855
|
+
let u = start,
|
|
18856
|
+
v = stop;
|
|
18857
|
+
const r = v < u;
|
|
18858
|
+
r && ([u, v] = [v, u]);
|
|
18859
|
+
let k,
|
|
18860
|
+
t,
|
|
18861
|
+
i = transformer(u),
|
|
18862
|
+
j = transformer(v),
|
|
18863
|
+
z = [];
|
|
18864
|
+
if (!(base % 1) && j - i < count) {
|
|
18865
|
+
if (i = Math.floor(i), j = Math.ceil(j), u > 0) {
|
|
18866
|
+
for (; i <= j; ++i) for (k = 1; k < base; ++k) if (t = i < 0 ? k / untransformer(-i) : k * untransformer(i), !(t < u)) {
|
|
18867
|
+
if (t > v) break;
|
|
18868
|
+
z.push(t);
|
|
18869
|
+
}
|
|
18870
|
+
} else for (; i <= j; ++i) for (k = base - 1; k >= 1; --k) if (t = i > 0 ? k / untransformer(-i) : k * untransformer(i), !(t < u)) {
|
|
18871
|
+
if (t > v) break;
|
|
18872
|
+
z.push(t);
|
|
18873
|
+
}
|
|
18874
|
+
2 * z.length < count && (z = ticks(u, v, count));
|
|
18875
|
+
} else z = ticks(i, j, Math.min(j - i, count)).map(untransformer);
|
|
18876
|
+
return z = z.filter(t => 0 !== t), (null == options ? void 0 : options.noDecimals) && (z = Array.from(new Set(z.map(t => Math.floor(t))))), r ? z.reverse() : z;
|
|
18877
|
+
});
|
|
18878
|
+
vutils.memoize((start, stop, count, base, transformer, untransformer) => {
|
|
18879
|
+
const ticksResult = [],
|
|
18880
|
+
ticksMap = {},
|
|
18881
|
+
startExp = transformer(start),
|
|
18882
|
+
stopExp = transformer(stop);
|
|
18883
|
+
let ticksExp = [];
|
|
18884
|
+
if (Number.isInteger(base)) ticksExp = ticks(startExp, stopExp, count);else {
|
|
18885
|
+
const stepExp = (stopExp - startExp) / (count - 1);
|
|
18886
|
+
for (let i = 0; i < count; i++) ticksExp.push(startExp + i * stepExp);
|
|
18887
|
+
}
|
|
18888
|
+
return ticksExp.forEach(tl => {
|
|
18889
|
+
const power = untransformer(tl),
|
|
18890
|
+
nicePower = Number.isInteger(base) ? fixPrecision(start, stop, power) : fixPrecision(start, stop, niceNumber(power)),
|
|
18891
|
+
scopePower = fixPrecision(start, stop, restrictNumber(nicePower, [start, stop]));
|
|
18892
|
+
!ticksMap[scopePower] && !isNaN(scopePower) && ticksExp.length > 1 && (ticksMap[scopePower] = 1, ticksResult.push(scopePower));
|
|
18893
|
+
}), ticksResult;
|
|
18894
|
+
});
|
|
18895
|
+
vutils.memoize((start, stop, count, transformer, untransformer) => forceTicks(transformer(start), transformer(stop), count).map(te => niceNumber(untransformer(te))));
|
|
18896
|
+
vutils.memoize((start, stop, step, transformer, untransformer) => stepTicks(transformer(start), transformer(stop), step).map(te => niceNumber(untransformer(te))));
|
|
18897
|
+
|
|
18898
|
+
class LinearScale extends ContinuousScale {
|
|
18899
|
+
constructor() {
|
|
18900
|
+
super(...arguments), this.type = ScaleEnum.Linear;
|
|
18901
|
+
}
|
|
18902
|
+
clone() {
|
|
18903
|
+
var _a;
|
|
18904
|
+
const scale = new LinearScale();
|
|
18905
|
+
return scale.domain(this._domain, !0).range(this._range, !0).unknown(this._unknown).clamp(this.clamp(), null, !0).interpolate(this._interpolate), this._niceType && (scale._niceType = this._niceType, scale._domainValidator = this._domainValidator, scale._niceDomain = null === (_a = this._niceDomain) || void 0 === _a ? void 0 : _a.slice()), scale;
|
|
18906
|
+
}
|
|
18907
|
+
tickFormat() {
|
|
18908
|
+
return () => {};
|
|
18909
|
+
}
|
|
18910
|
+
d3Ticks() {
|
|
18911
|
+
let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
18912
|
+
let options = arguments.length > 1 ? arguments[1] : undefined;
|
|
18913
|
+
const d = this.calculateVisibleDomain(this._range);
|
|
18914
|
+
return d3Ticks(d[0], d[d.length - 1], count, options);
|
|
18915
|
+
}
|
|
18916
|
+
ticks() {
|
|
18917
|
+
let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
18918
|
+
let options = arguments.length > 1 ? arguments[1] : undefined;
|
|
18919
|
+
var _a;
|
|
18920
|
+
if (vutils.isFunction(null == options ? void 0 : options.customTicks)) return options.customTicks(this, count);
|
|
18921
|
+
if (vutils.isValid(this._rangeFactorStart) && vutils.isValid(this._rangeFactorEnd) && (this._rangeFactorStart > 0 || this._rangeFactorEnd < 1) && 2 === this._range.length || !this._niceType) return this.d3Ticks(count, options);
|
|
18922
|
+
const curNiceDomain = null !== (_a = this._niceDomain) && void 0 !== _a ? _a : this._domain,
|
|
18923
|
+
originalDomain = this._domain,
|
|
18924
|
+
start = curNiceDomain[0],
|
|
18925
|
+
stop = curNiceDomain[curNiceDomain.length - 1];
|
|
18926
|
+
let ticksResult = ticks(originalDomain[0], originalDomain[originalDomain.length - 1], count, options);
|
|
18927
|
+
if (!ticksResult.length) return ticksResult;
|
|
18928
|
+
if (this._domainValidator) ticksResult = ticksResult.filter(this._domainValidator);else if ((ticksResult[0] !== start || ticksResult[ticksResult.length - 1] !== stop) && this._niceType) {
|
|
18929
|
+
const newNiceDomain = curNiceDomain.slice();
|
|
18930
|
+
if ("all" === this._niceType ? (newNiceDomain[0] = ticksResult[0], newNiceDomain[newNiceDomain.length - 1] = ticksResult[ticksResult.length - 1], this._niceDomain = newNiceDomain, this.rescale()) : "min" === this._niceType && ticksResult[0] !== start ? (newNiceDomain[0] = ticksResult[0], this._niceDomain = newNiceDomain, this.rescale()) : "max" === this._niceType && ticksResult[ticksResult.length - 1] !== stop && (newNiceDomain[newNiceDomain.length - 1] = ticksResult[ticksResult.length - 1], this._niceDomain = newNiceDomain, this.rescale()), "all" !== this._niceType) {
|
|
18931
|
+
const min = Math.min(newNiceDomain[0], newNiceDomain[newNiceDomain.length - 1]),
|
|
18932
|
+
max = Math.max(newNiceDomain[0], newNiceDomain[newNiceDomain.length - 1]);
|
|
18933
|
+
ticksResult = ticksResult.filter(entry => entry >= min && entry <= max);
|
|
18934
|
+
}
|
|
18935
|
+
}
|
|
18936
|
+
return ticksResult;
|
|
18937
|
+
}
|
|
18938
|
+
forceTicks() {
|
|
18939
|
+
let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
18940
|
+
const d = this.calculateVisibleDomain(this._range);
|
|
18941
|
+
return forceTicks(d[0], d[d.length - 1], count);
|
|
18942
|
+
}
|
|
18943
|
+
stepTicks(step) {
|
|
18944
|
+
const d = this.calculateVisibleDomain(this._range);
|
|
18945
|
+
return stepTicks(d[0], d[d.length - 1], step);
|
|
18946
|
+
}
|
|
18947
|
+
nice() {
|
|
18948
|
+
let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
18949
|
+
let option = arguments.length > 1 ? arguments[1] : undefined;
|
|
18950
|
+
var _a, _b;
|
|
18951
|
+
const originalDomain = this._domain;
|
|
18952
|
+
let niceMinMax = [];
|
|
18953
|
+
if (option) {
|
|
18954
|
+
const res = parseNiceOptions(originalDomain, option);
|
|
18955
|
+
if (niceMinMax = res.niceMinMax, this._domainValidator = res.domainValidator, this._niceType = res.niceType, res.niceDomain) return this._niceDomain = res.niceDomain, this.rescale(), this;
|
|
18956
|
+
} else this._niceType = "all";
|
|
18957
|
+
if (this._niceType) {
|
|
18958
|
+
const niceDomain = niceLinear(originalDomain.slice(), count);
|
|
18959
|
+
"min" === this._niceType ? niceDomain[niceDomain.length - 1] = null !== (_a = niceMinMax[1]) && void 0 !== _a ? _a : niceDomain[niceDomain.length - 1] : "max" === this._niceType && (niceDomain[0] = null !== (_b = niceMinMax[0]) && void 0 !== _b ? _b : niceDomain[0]), this._niceDomain = niceDomain, this.rescale();
|
|
18960
|
+
}
|
|
18961
|
+
return this;
|
|
18962
|
+
}
|
|
18963
|
+
niceMin() {
|
|
18964
|
+
let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
18965
|
+
this._niceType = "min";
|
|
18966
|
+
const maxD = this._domain[this._domain.length - 1],
|
|
18967
|
+
niceDomain = niceLinear(this.domain(), count);
|
|
18968
|
+
return niceDomain && (niceDomain[niceDomain.length - 1] = maxD, this._niceDomain = niceDomain, this.rescale()), this;
|
|
18969
|
+
}
|
|
18970
|
+
niceMax() {
|
|
18971
|
+
let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
18972
|
+
this._niceType = "max";
|
|
18973
|
+
const minD = this._domain[0],
|
|
18974
|
+
niceDomain = niceLinear(this._domain.slice(), count);
|
|
18975
|
+
return niceDomain && (niceDomain[0] = minD, this._niceDomain = niceDomain, this.rescale()), this;
|
|
18976
|
+
}
|
|
18977
|
+
}
|
|
18978
|
+
|
|
18979
|
+
class SqrtScale extends LinearScale {
|
|
18980
|
+
constructor() {
|
|
18981
|
+
super(sqrt, square), this.type = ScaleEnum.Sqrt;
|
|
18982
|
+
}
|
|
18983
|
+
clone() {
|
|
18984
|
+
return new SqrtScale().domain(this._domain, !0).range(this._range, !0).unknown(this._unknown).clamp(this.clamp(), null, !0).interpolate(this._interpolate);
|
|
18985
|
+
}
|
|
18986
|
+
}
|
|
18987
|
+
|
|
18988
|
+
var IMAGECLOUD_HOOK_EVENT;
|
|
18989
|
+
!function (IMAGECLOUD_HOOK_EVENT) {
|
|
18990
|
+
IMAGECLOUD_HOOK_EVENT.BEFORE_IMAGECLOUD_LAYOUT = "beforeImagecloudLayout", IMAGECLOUD_HOOK_EVENT.AFTER_IMAGECLOUD_LAYOUT = "afterImagecloudLayout", IMAGECLOUD_HOOK_EVENT.AFTER_IMAGECLOUD_DRAW = "afterImagecloudDraw";
|
|
18991
|
+
}(IMAGECLOUD_HOOK_EVENT || (IMAGECLOUD_HOOK_EVENT = {}));
|
|
18992
|
+
function setSize(image, longSideLength) {
|
|
18993
|
+
image.aspectRatio > 1 ? (image.width = longSideLength, image.height = ~~(longSideLength / image.aspectRatio)) : (image.height = longSideLength, image.width = ~~(longSideLength * image.aspectRatio));
|
|
18994
|
+
}
|
|
18995
|
+
function setSizeByShortSide(image, shortSideLength) {
|
|
18996
|
+
image.aspectRatio > 1 ? (image.height = shortSideLength, image.width = ~~(shortSideLength * image.aspectRatio)) : (image.width = shortSideLength, image.height = ~~(shortSideLength / image.aspectRatio));
|
|
18997
|
+
}
|
|
18998
|
+
|
|
18999
|
+
class Layout {
|
|
19000
|
+
constructor(options) {
|
|
19001
|
+
this.progressiveResult = [], this.imageCollageList = [], this.options = options;
|
|
19002
|
+
}
|
|
19003
|
+
preProcess() {
|
|
19004
|
+
const {
|
|
19005
|
+
imageConfig = {},
|
|
19006
|
+
weight: weight
|
|
19007
|
+
} = this.options,
|
|
19008
|
+
{
|
|
19009
|
+
padding = 0
|
|
19010
|
+
} = imageConfig;
|
|
19011
|
+
let images = this.imageCollageList;
|
|
19012
|
+
return images.forEach((img, index) => {
|
|
19013
|
+
!1 === img.valid ? (img.x = -10, img.y = -10, img.width = 0, img.height = 0, img.opacity = 0) : (img.padding = padding, img.weight = vutils.simpleField(weight)(this.data[index]), img.datum = this.data[index]);
|
|
19014
|
+
}), images = images.filter(img => !1 !== img.valid).sort((a, b) => b.weight - a.weight), images;
|
|
19015
|
+
}
|
|
19016
|
+
onImageCollageInputReady(images) {
|
|
19017
|
+
images.forEach((img, i) => {
|
|
19018
|
+
if ("fulfilled" === img.status) {
|
|
19019
|
+
const imageElement = img.value,
|
|
19020
|
+
{
|
|
19021
|
+
width: width,
|
|
19022
|
+
height: height
|
|
19023
|
+
} = imageElement;
|
|
19024
|
+
this.imageCollageList.push(Object.assign({}, this.data[i], {
|
|
19025
|
+
aspectRatio: width / height
|
|
19026
|
+
}));
|
|
19027
|
+
} else this.imageCollageList.push(Object.assign({}, this.data[i], {
|
|
19028
|
+
valid: !1
|
|
19029
|
+
}));
|
|
19030
|
+
});
|
|
19031
|
+
}
|
|
19032
|
+
layout(data) {
|
|
19033
|
+
this.data = data, this.loadSegmentationInput(), this.loadImageCollageInput();
|
|
19034
|
+
}
|
|
19035
|
+
loadSegmentationInput() {
|
|
19036
|
+
var _a, _b, _c, _d, _e, _f;
|
|
19037
|
+
const options = this.options,
|
|
19038
|
+
size = options.size,
|
|
19039
|
+
segmentationInput = {
|
|
19040
|
+
shapeUrl: null !== (_a = options.mask) && void 0 !== _a ? _a : {
|
|
19041
|
+
type: "geometric",
|
|
19042
|
+
shape: "rect"
|
|
19043
|
+
},
|
|
19044
|
+
size: size,
|
|
19045
|
+
ratio: options.ratio || .8,
|
|
19046
|
+
tempCanvas: void 0,
|
|
19047
|
+
boardSize: [0, 0],
|
|
19048
|
+
random: !1,
|
|
19049
|
+
randomGenerator: void 0,
|
|
19050
|
+
blur: null === (_b = options.maskConfig) || void 0 === _b ? void 0 : _b.edgeBlur
|
|
19051
|
+
},
|
|
19052
|
+
tempCanvas = this.options.createCanvas({
|
|
19053
|
+
width: size[0],
|
|
19054
|
+
height: size[1]
|
|
19055
|
+
}),
|
|
19056
|
+
tempCtx = tempCanvas.getContext("2d", {
|
|
19057
|
+
willReadFrequently: !0
|
|
19058
|
+
});
|
|
19059
|
+
tempCtx.textAlign = "center", tempCtx.textBaseline = "middle", segmentationInput.tempCanvas = tempCanvas;
|
|
19060
|
+
const boardW = size[0] + 31 >> 5 << 5;
|
|
19061
|
+
if (segmentationInput.boardSize = [boardW, size[1]], segmentationInput.random ? segmentationInput.randomGenerator = Math.random : segmentationInput.randomGenerator = vutils.fakeRandom(), this.segmentationInput = segmentationInput, vutils.isString(segmentationInput.shapeUrl)) {
|
|
19062
|
+
segmentationInput.isEmptyPixel = generateIsEmptyPixel(void 0, {
|
|
19063
|
+
threshold: null !== (_d = null === (_c = options.maskConfig) || void 0 === _c ? void 0 : _c.threshold) && void 0 !== _d ? _d : 200,
|
|
19064
|
+
invert: null === (_e = options.maskConfig) || void 0 === _e ? void 0 : _e.invert
|
|
19065
|
+
}, this.options.createCanvas);
|
|
19066
|
+
const imagePromise = loadImage(segmentationInput.shapeUrl, this.options.createImage);
|
|
19067
|
+
imagePromise ? (this.isMaskImageFinished = !1, this.isLayoutFinished = !1, imagePromise.then(shapeImage => {
|
|
19068
|
+
var _a, _b;
|
|
19069
|
+
this.isMaskImageFinished = !0;
|
|
19070
|
+
const size = options.size,
|
|
19071
|
+
maskCanvas = this.options.createCanvas({
|
|
19072
|
+
width: size[0],
|
|
19073
|
+
height: size[1],
|
|
19074
|
+
dpr: 1
|
|
19075
|
+
});
|
|
19076
|
+
segmentationInput.maskCanvas = maskCanvas;
|
|
19077
|
+
const ctx = maskCanvas.getContext("2d");
|
|
19078
|
+
(null === (_a = options.maskConfig) || void 0 === _a ? void 0 : _a.removeWhiteBorder) && removeBorder(shapeImage, maskCanvas, segmentationInput.isEmptyPixel);
|
|
19079
|
+
const shapeConfig = scaleAndMiddleShape(shapeImage, size);
|
|
19080
|
+
let transparentMaskCanvas;
|
|
19081
|
+
ctx.clearRect(0, 0, size[0], size[1]), ctx.drawImage(shapeImage, shapeConfig.x, shapeConfig.y, shapeConfig.width, shapeConfig.height), this.segmentationOutput = segmentation(this.segmentationInput), "masked" === (null === (_b = this.options.layoutConfig) || void 0 === _b ? void 0 : _b.placement) && (transparentMaskCanvas = this.generateTransparentMaskCanvas(shapeImage, size)), this.segmentationOutput.transparentMaskCanvas = transparentMaskCanvas, this.options.onUpdateMaskCanvas && this.options.onUpdateMaskCanvas(maskCanvas, transparentMaskCanvas);
|
|
19082
|
+
}).catch(error => {
|
|
19083
|
+
this.isMaskImageFinished = !0;
|
|
19084
|
+
})) : (this.isMaskImageFinished = !0, this.isLayoutFinished = !0);
|
|
19085
|
+
} else if (segmentationInput.shapeUrl && ("text" === segmentationInput.shapeUrl.type || "geometric" === segmentationInput.shapeUrl.type)) {
|
|
19086
|
+
segmentationInput.isEmptyPixel = generateIsEmptyPixel(segmentationInput.shapeUrl.backgroundColor, void 0, this.options.createCanvas), "text" !== segmentationInput.shapeUrl.type && "geometric" !== segmentationInput.shapeUrl.type || segmentationInput.shapeUrl.backgroundColor || (segmentationInput.shapeUrl.backgroundColor = "rgba(255,255,255,255)");
|
|
19087
|
+
const maskCanvas = generateMaskCanvas(segmentationInput.shapeUrl, size[0], size[1], void 0, null === (_f = options.maskConfig) || void 0 === _f ? void 0 : _f.invert, this.options.createCanvas);
|
|
19088
|
+
segmentationInput.maskCanvas = maskCanvas, this.segmentationOutput = segmentation(this.segmentationInput), this.options.onUpdateMaskCanvas && this.options.onUpdateMaskCanvas(maskCanvas, maskCanvas), this.isMaskImageFinished = !0;
|
|
19089
|
+
}
|
|
19090
|
+
}
|
|
19091
|
+
loadImageCollageInput() {
|
|
19092
|
+
const data = this.data,
|
|
19093
|
+
imagesPromise = loadImages(data.map(d => vutils.simpleField(this.options.image)(d)), this.options.createImage);
|
|
19094
|
+
imagesPromise ? imagesPromise.then(images => {
|
|
19095
|
+
this.onImageCollageInputReady(images), this.isImagesFinished = !0;
|
|
19096
|
+
}).catch(error => {
|
|
19097
|
+
this.isImagesFinished = !0, this.isLayoutFinished = !0, vutils.Logger.getInstance().error("image load failed", error);
|
|
19098
|
+
}) : (this.isImagesFinished = !0, this.isLayoutFinished = !0);
|
|
19099
|
+
}
|
|
19100
|
+
canAnimate() {
|
|
19101
|
+
return !0;
|
|
19102
|
+
}
|
|
19103
|
+
unfinished() {
|
|
19104
|
+
return !this.isLayoutFinished;
|
|
19105
|
+
}
|
|
19106
|
+
output() {
|
|
19107
|
+
return this.progressiveResult;
|
|
19108
|
+
}
|
|
19109
|
+
progressiveRun() {
|
|
19110
|
+
if (this.isImagesFinished && this.isMaskImageFinished && !this.isLayoutFinished) {
|
|
19111
|
+
const images = this.preProcess(),
|
|
19112
|
+
layoutResult = this.doLayout(images);
|
|
19113
|
+
this.options && this.options.onLayoutEnd && this.options.onLayoutEnd(layoutResult), this.progressiveResult = this.processOutput(layoutResult), this.isLayoutFinished = !0;
|
|
19114
|
+
}
|
|
19115
|
+
}
|
|
19116
|
+
progressiveOutput() {
|
|
19117
|
+
return this.progressiveResult;
|
|
19118
|
+
}
|
|
19119
|
+
release() {
|
|
19120
|
+
this.segmentationInput = null, this.data = null, this.progressiveResult = null, this.options = null;
|
|
19121
|
+
}
|
|
19122
|
+
calculateImageSize(images) {
|
|
19123
|
+
let imageConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
19124
|
+
let ratio = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : .45;
|
|
19125
|
+
const {
|
|
19126
|
+
imageSizeRange: imageSizeRange,
|
|
19127
|
+
padding = 0
|
|
19128
|
+
} = imageConfig,
|
|
19129
|
+
imageSize = vutils.isNumber(imageConfig.imageSize) ? imageConfig.imageSize : vutils.field(imageConfig.imageSize),
|
|
19130
|
+
size = this.options.size;
|
|
19131
|
+
if (imageSize || imageSizeRange) {
|
|
19132
|
+
if (imageSize && !vutils.isFunction(imageSize)) images.forEach(img => setSize(img, imageSize));else if (imageSizeRange) {
|
|
19133
|
+
const sizeScale = new SqrtScale().domain(vutils.extent(images, d => d.weight)).range(imageSizeRange);
|
|
19134
|
+
images.forEach(img => setSize(img, ~~sizeScale.scale(img.weight)));
|
|
19135
|
+
} else if (imageSize && vutils.isFunction(imageSize) && !imageSizeRange) {
|
|
19136
|
+
const a = .5,
|
|
19137
|
+
[min, max] = vutils.extent(images, d => d.weight),
|
|
19138
|
+
picArea = images.reduce((prev, img) => {
|
|
19139
|
+
const r = img.aspectRatio,
|
|
19140
|
+
w = (img.weight - min) / (max - min);
|
|
19141
|
+
return prev + (r > 1 ? 1 / r : r) * (a + (1 - a) * w) ** 2;
|
|
19142
|
+
}, 0),
|
|
19143
|
+
x = ~~Math.sqrt(ratio * size[0] * size[1] / picArea),
|
|
19144
|
+
range = [~~(a * x) - 2 * padding < 0 ? 1 : ~~(a * x) - 2 * padding, ~~x - 2 * padding < 0 ? 1 : ~~x - 2 * padding],
|
|
19145
|
+
sizeScale = new SqrtScale().domain(vutils.extent(images, d => d.weight)).range(range);
|
|
19146
|
+
images.forEach(img => setSize(img, ~~sizeScale.scale(img.weight)));
|
|
19147
|
+
} else console.warn("image cloud imageSize error");
|
|
19148
|
+
} else {
|
|
19149
|
+
const imageArea = images.reduce((prev, pic) => {
|
|
19150
|
+
const r = pic.aspectRatio;
|
|
19151
|
+
return prev + (r > 1 ? 1 / r : r);
|
|
19152
|
+
}, 0);
|
|
19153
|
+
let longSideLength = ~~Math.sqrt(ratio * size[0] * size[1] / imageArea);
|
|
19154
|
+
longSideLength = longSideLength - 2 * padding < 0 ? 1 : longSideLength - 2 * padding, images.forEach(img => setSize(img, longSideLength));
|
|
19155
|
+
}
|
|
19156
|
+
return images;
|
|
19157
|
+
}
|
|
19158
|
+
generateTransparentMaskCanvas(shapeImage, size) {
|
|
19159
|
+
var _a;
|
|
19160
|
+
const transparentMaskCanvas = this.options.createCanvas({
|
|
19161
|
+
width: size[0],
|
|
19162
|
+
height: size[1],
|
|
19163
|
+
dpr: 1
|
|
19164
|
+
}),
|
|
19165
|
+
transparentMaskContext = transparentMaskCanvas.getContext("2d");
|
|
19166
|
+
this.segmentationOutput.transparentMaskCanvas = transparentMaskCanvas, (null === (_a = this.options.maskConfig) || void 0 === _a ? void 0 : _a.removeWhiteBorder) && removeBorder(shapeImage, transparentMaskCanvas, this.segmentationInput.isEmptyPixel);
|
|
19167
|
+
const imageData = transparentMaskContext.createImageData(size[0], size[1]),
|
|
19168
|
+
labels = this.segmentationOutput.segmentation.labels;
|
|
19169
|
+
for (let i = 0; i < labels.length; i++) {
|
|
19170
|
+
const color = 0 === labels[i] ? 255 : 0,
|
|
19171
|
+
alpha = 255 * labels[i],
|
|
19172
|
+
pixelIndex = 4 * i;
|
|
19173
|
+
imageData.data[pixelIndex] = color, imageData.data[pixelIndex + 1] = color, imageData.data[pixelIndex + 2] = color, imageData.data[pixelIndex + 3] = alpha;
|
|
19174
|
+
}
|
|
19175
|
+
return transparentMaskContext.clearRect(0, 0, size[0], size[1]), transparentMaskContext.fillStyle = "rgba(255,255,255,0)", transparentMaskContext.fillRect(0, 0, size[0], size[1]), transparentMaskContext.putImageData(imageData, 0, 0), transparentMaskCanvas;
|
|
19176
|
+
}
|
|
19177
|
+
processOutput(images) {
|
|
19178
|
+
var _a;
|
|
19179
|
+
const outputAs = null === (_a = this.options) || void 0 === _a ? void 0 : _a.as;
|
|
19180
|
+
return outputAs && Object.keys(outputAs).forEach(key => {
|
|
19181
|
+
images.forEach(img => {
|
|
19182
|
+
img[outputAs[key]] = img[key], delete img[key];
|
|
19183
|
+
});
|
|
19184
|
+
}), images;
|
|
19185
|
+
}
|
|
19186
|
+
}
|
|
19187
|
+
|
|
19188
|
+
class SpiralLayout extends Layout {
|
|
19189
|
+
preProcess() {
|
|
19190
|
+
const images = super.preProcess(),
|
|
19191
|
+
{
|
|
19192
|
+
imageConfig = {},
|
|
19193
|
+
ratio = .45
|
|
19194
|
+
} = this.options;
|
|
19195
|
+
return this.calculateImageSize(images, imageConfig, ratio);
|
|
19196
|
+
}
|
|
19197
|
+
tryPlaceImage(image, size, spiralType, segmentationOutput, fixedImages) {
|
|
19198
|
+
let dt = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1;
|
|
19199
|
+
const [width, height] = size,
|
|
19200
|
+
centerX = width / 2,
|
|
19201
|
+
centerY = height / 2,
|
|
19202
|
+
maxR = Math.sqrt(centerX ** 2 + centerY ** 2),
|
|
19203
|
+
spiral = spirals[spiralType](size);
|
|
19204
|
+
let dx,
|
|
19205
|
+
dy,
|
|
19206
|
+
t = -dt;
|
|
19207
|
+
const {
|
|
19208
|
+
segmentation: segmentation
|
|
19209
|
+
} = segmentationOutput,
|
|
19210
|
+
{
|
|
19211
|
+
labels: labels
|
|
19212
|
+
} = segmentation;
|
|
19213
|
+
for (; ([dx, dy] = spiral(t += dt)) && !(Math.min(Math.abs(dx), Math.abs(dy)) >= maxR);) if (dx -= image.width / 2, dy -= image.height / 2, image.visible = !0, image.x = ~~(centerX + dx), image.y = ~~(centerY + dy), image._left = image.x + image.padding, image._top = image.y + image.padding, image._leftWithoutPadding = image.x, image._topWithoutPadding = image.y, fit(image, fixedImages)) {
|
|
19214
|
+
const {
|
|
19215
|
+
x: x,
|
|
19216
|
+
y: y,
|
|
19217
|
+
width: imageWidth,
|
|
19218
|
+
height: imageHeight
|
|
19219
|
+
} = image;
|
|
19220
|
+
let intersect = !1;
|
|
19221
|
+
for (let r = 0; r < imageWidth; r++) {
|
|
19222
|
+
for (let c = 0; c < imageHeight && y + r <= height; c++) {
|
|
19223
|
+
if (x + c > width) continue;
|
|
19224
|
+
if (!!!labels[(y + r) * width + (x + c)]) {
|
|
19225
|
+
intersect = !0;
|
|
19226
|
+
break;
|
|
19227
|
+
}
|
|
19228
|
+
}
|
|
19229
|
+
if (intersect) break;
|
|
19230
|
+
}
|
|
19231
|
+
if (!intersect) {
|
|
19232
|
+
const corners = [{
|
|
19233
|
+
x: image.x,
|
|
19234
|
+
y: image.y
|
|
19235
|
+
}, {
|
|
19236
|
+
x: image.x + image.width,
|
|
19237
|
+
y: image.y
|
|
19238
|
+
}, {
|
|
19239
|
+
x: image.x,
|
|
19240
|
+
y: image.y + image.height
|
|
19241
|
+
}, {
|
|
19242
|
+
x: image.x + image.width,
|
|
19243
|
+
y: image.y + image.height
|
|
19244
|
+
}];
|
|
19245
|
+
let allCornersInShape = !0;
|
|
19246
|
+
for (const corner of corners) if (!labels[corner.y * width + corner.x]) {
|
|
19247
|
+
allCornersInShape = !1;
|
|
19248
|
+
break;
|
|
19249
|
+
}
|
|
19250
|
+
if (!allCornersInShape) continue;
|
|
19251
|
+
return !0;
|
|
19252
|
+
}
|
|
19253
|
+
}
|
|
19254
|
+
return !1;
|
|
19255
|
+
}
|
|
19256
|
+
doLayout(images) {
|
|
19257
|
+
var _a;
|
|
19258
|
+
const {
|
|
19259
|
+
segmentationOutput: segmentationOutput
|
|
19260
|
+
} = this,
|
|
19261
|
+
{
|
|
19262
|
+
layoutConfig = {}
|
|
19263
|
+
} = this.options,
|
|
19264
|
+
size = this.options.size,
|
|
19265
|
+
{
|
|
19266
|
+
spiralType = "archimedean",
|
|
19267
|
+
fillingTimes = 4,
|
|
19268
|
+
minFillingImageSize = 10
|
|
19269
|
+
} = layoutConfig,
|
|
19270
|
+
fixedImages = [],
|
|
19271
|
+
key = Object.keys(images[0]).find(k => k.includes("VGRAMMAR"));
|
|
19272
|
+
for (const image of images) image._widthWithPadding = image.width + 2 * image.padding, image._heightWithPadding = image.height + 2 * image.padding, image.frequency = 1, this.tryPlaceImage(image, size, spiralType, segmentationOutput, fixedImages) && fixedImages.push(image);
|
|
19273
|
+
const minImageWidth = vutils.minInArray(fixedImages, (a, b) => a.width - b.width).width,
|
|
19274
|
+
minImageHeight = vutils.minInArray(fixedImages, (a, b) => a.height - b.height).height,
|
|
19275
|
+
fixedFillingImages = [];
|
|
19276
|
+
for (let i = 0; i < fillingTimes; i++) {
|
|
19277
|
+
const minWidth = .5 * minImageWidth - 1 * i,
|
|
19278
|
+
minHeight = .5 * minImageHeight - 1 * i;
|
|
19279
|
+
for (const image of images) {
|
|
19280
|
+
const fillingImage = Object.assign({}, image, {
|
|
19281
|
+
visible: !0
|
|
19282
|
+
}),
|
|
19283
|
+
imageSize = Math.max(minFillingImageSize, fillingImage.aspectRatio > 1 ? minWidth : minHeight);
|
|
19284
|
+
setSize(fillingImage, imageSize), fillingImage._widthWithPadding = fillingImage.width + 2 * fillingImage.padding, fillingImage._heightWithPadding = fillingImage.height + 2 * fillingImage.padding, this.tryPlaceImage(fillingImage, size, spiralType, segmentationOutput, [...fixedFillingImages, ...fixedImages], .5) && (image._tempFrequency = (null !== (_a = image._tempFrequency) && void 0 !== _a ? _a : image.frequency) + 1, fillingImage.frequency = image._tempFrequency, fillingImage.distance = Math.sqrt(Math.pow(fillingImage.x - size[0] / 2, 2) + Math.pow(fillingImage.y - size[1] / 2, 2)), fillingImage[key] = `${fillingImage[key]}_${fillingImage.frequency}`, fixedFillingImages.push(fillingImage));
|
|
19285
|
+
}
|
|
19286
|
+
}
|
|
19287
|
+
return [...fixedImages, ...fixedFillingImages].filter(image => image.visible);
|
|
19288
|
+
}
|
|
19289
|
+
}
|
|
19290
|
+
function fit(image, fixedImages) {
|
|
19291
|
+
for (let i = 0; i < fixedImages.length; i++) if (isOverlap$1(image, fixedImages[i])) return !1;
|
|
19292
|
+
return !0;
|
|
19293
|
+
}
|
|
19294
|
+
function isOverlap$1(a, b) {
|
|
19295
|
+
return !(a._leftWithoutPadding + a._widthWithPadding < b._leftWithoutPadding || a._topWithoutPadding + a._heightWithPadding < b._topWithoutPadding || a._leftWithoutPadding > b._leftWithoutPadding + b._widthWithPadding || a._topWithoutPadding > b._topWithoutPadding + b._heightWithPadding);
|
|
19296
|
+
}
|
|
19297
|
+
|
|
19298
|
+
function rectGridLayout(options) {
|
|
19299
|
+
const {
|
|
19300
|
+
imageConfig = {},
|
|
19301
|
+
size: size,
|
|
19302
|
+
ratio = .1,
|
|
19303
|
+
layoutConfig = {}
|
|
19304
|
+
} = options,
|
|
19305
|
+
{
|
|
19306
|
+
padding = 0,
|
|
19307
|
+
imageSize: imageSize
|
|
19308
|
+
} = imageConfig,
|
|
19309
|
+
[width, height] = size;
|
|
19310
|
+
let shortSideLength;
|
|
19311
|
+
shortSideLength = imageSize || Math.min(width, height) * ratio - 2 * padding, shortSideLength < 0 && (shortSideLength = 1);
|
|
19312
|
+
const {
|
|
19313
|
+
rectAspectRatio = 1
|
|
19314
|
+
} = layoutConfig;
|
|
19315
|
+
let cellWidth, cellHeight;
|
|
19316
|
+
rectAspectRatio > 1 ? (cellWidth = shortSideLength, cellHeight = shortSideLength / rectAspectRatio) : (cellHeight = shortSideLength, cellWidth = shortSideLength * rectAspectRatio);
|
|
19317
|
+
const rows = Math.ceil(height / (cellHeight + padding)),
|
|
19318
|
+
cols = Math.ceil(width / (cellWidth + padding)),
|
|
19319
|
+
center_x = width / 2,
|
|
19320
|
+
center_y = height / 2,
|
|
19321
|
+
cellInfo = new Array(cols * rows);
|
|
19322
|
+
for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) {
|
|
19323
|
+
const cellCenterX = c * (cellWidth + padding) + cellWidth / 2,
|
|
19324
|
+
cellCenterY = r * (cellHeight + padding) + cellHeight / 2;
|
|
19325
|
+
cellInfo[r * cols + c] = {
|
|
19326
|
+
centerX: cellCenterX,
|
|
19327
|
+
centerY: cellCenterY,
|
|
19328
|
+
x: cellCenterX - cellWidth / 2,
|
|
19329
|
+
y: cellCenterY - cellHeight / 2,
|
|
19330
|
+
row: r,
|
|
19331
|
+
col: c,
|
|
19332
|
+
distance: Math.sqrt(Math.pow(cellCenterX - center_x, 2) + Math.pow(cellCenterY - center_y, 2))
|
|
19333
|
+
};
|
|
19334
|
+
}
|
|
19335
|
+
return {
|
|
19336
|
+
context: Object.assign({}, layoutConfig, {
|
|
19337
|
+
cellWidth: cellWidth,
|
|
19338
|
+
cellHeight: cellHeight,
|
|
19339
|
+
cellInfo: cellInfo,
|
|
19340
|
+
cellCount: cellInfo.length,
|
|
19341
|
+
cellType: "rect",
|
|
19342
|
+
cellPixelCount: cellWidth * cellHeight,
|
|
19343
|
+
eachPixel: (cell, callback) => {
|
|
19344
|
+
const {
|
|
19345
|
+
x: x,
|
|
19346
|
+
y: y
|
|
19347
|
+
} = cell;
|
|
19348
|
+
for (let r = 0; r < cellWidth; r++) for (let c = 0; c < cellHeight && y + r <= height; c++) x + c > width || callback((~~y + r) * width + (~~x + c));
|
|
19349
|
+
},
|
|
19350
|
+
clipPath: `M${-cellWidth / 2} ${-cellHeight / 2} L${cellWidth / 2} ${-cellHeight / 2} L${cellWidth / 2} ${cellHeight / 2} L${-cellWidth / 2} ${cellHeight / 2} Z`
|
|
19351
|
+
}),
|
|
19352
|
+
imageLength: shortSideLength
|
|
19353
|
+
};
|
|
19354
|
+
}
|
|
19355
|
+
|
|
19356
|
+
function circleGridLayout(options) {
|
|
19357
|
+
const {
|
|
19358
|
+
imageConfig = {},
|
|
19359
|
+
size: size,
|
|
19360
|
+
ratio = .1,
|
|
19361
|
+
layoutConfig = {}
|
|
19362
|
+
} = options,
|
|
19363
|
+
{
|
|
19364
|
+
padding = 0,
|
|
19365
|
+
imageSize = 0
|
|
19366
|
+
} = imageConfig,
|
|
19367
|
+
[width, height] = size,
|
|
19368
|
+
center_x = width / 2,
|
|
19369
|
+
center_y = height / 2;
|
|
19370
|
+
let circleRadius = 0;
|
|
19371
|
+
circleRadius = imageSize ? imageSize / 2 : Math.min(width, height) * ratio / 2, circleRadius - padding <= 0 && (circleRadius = padding + 1);
|
|
19372
|
+
const circleDiameter = 2 * circleRadius,
|
|
19373
|
+
rowHeight = Math.sqrt(3) / 2 * circleDiameter + padding,
|
|
19374
|
+
cellInfo = [];
|
|
19375
|
+
let index = 0;
|
|
19376
|
+
for (let r = 0; r * rowHeight - circleRadius < height; r++) {
|
|
19377
|
+
const y = r * rowHeight,
|
|
19378
|
+
offsetX = r % 2 == 0 ? 0 : circleRadius;
|
|
19379
|
+
for (let c = -1; c * (circleDiameter + padding) + offsetX - circleRadius < width; c++) {
|
|
19380
|
+
const x = c * (circleDiameter + padding) + offsetX + circleRadius;
|
|
19381
|
+
cellInfo[index++] = {
|
|
19382
|
+
centerX: x,
|
|
19383
|
+
centerY: y,
|
|
19384
|
+
x: x - circleRadius,
|
|
19385
|
+
y: y - circleRadius,
|
|
19386
|
+
row: r,
|
|
19387
|
+
col: c,
|
|
19388
|
+
distance: Math.sqrt(Math.pow(x - center_x, 2) + Math.pow(y - center_y, 2))
|
|
19389
|
+
};
|
|
19390
|
+
}
|
|
19391
|
+
}
|
|
19392
|
+
let cellPixelCount = 0;
|
|
19393
|
+
const rSquared = circleRadius * circleRadius;
|
|
19394
|
+
for (let r = 0; r < circleDiameter; r++) for (let c = 0; c < circleDiameter; c++) {
|
|
19395
|
+
const dx = r - circleRadius,
|
|
19396
|
+
dy = c - circleRadius;
|
|
19397
|
+
dx * dx + dy * dy <= rSquared && cellPixelCount++;
|
|
19398
|
+
}
|
|
19399
|
+
return {
|
|
19400
|
+
context: Object.assign({}, layoutConfig, {
|
|
19401
|
+
cellWidth: circleDiameter,
|
|
19402
|
+
cellHeight: circleDiameter,
|
|
19403
|
+
cellInfo: cellInfo,
|
|
19404
|
+
cellCount: cellInfo.length,
|
|
19405
|
+
cellType: "circle",
|
|
19406
|
+
cellPixelCount: cellPixelCount,
|
|
19407
|
+
eachPixel: (cell, callback) => {
|
|
19408
|
+
const {
|
|
19409
|
+
x: x,
|
|
19410
|
+
y: y
|
|
19411
|
+
} = cell;
|
|
19412
|
+
for (let r = 0; r < circleDiameter; r++) for (let c = 0; c < circleDiameter; c++) {
|
|
19413
|
+
if (r + x < 0 || r + x > width || c + y > height || c + y < 0) continue;
|
|
19414
|
+
const dx = r - circleRadius,
|
|
19415
|
+
dy = c - circleRadius;
|
|
19416
|
+
dx * dx + dy * dy <= rSquared && callback((~~y + r) * width + (~~x + c));
|
|
19417
|
+
}
|
|
19418
|
+
},
|
|
19419
|
+
clipPath: "M 1 0 A 1 1 0 1 0 -1 0 A 1 1 0 1 0 1 0 Z"
|
|
19420
|
+
}),
|
|
19421
|
+
imageLength: circleDiameter
|
|
19422
|
+
};
|
|
19423
|
+
}
|
|
19424
|
+
|
|
19425
|
+
function hexagonalGridLayout(options) {
|
|
19426
|
+
const {
|
|
19427
|
+
imageConfig = {},
|
|
19428
|
+
size: size,
|
|
19429
|
+
ratio = .1,
|
|
19430
|
+
layoutConfig = {}
|
|
19431
|
+
} = options,
|
|
19432
|
+
{
|
|
19433
|
+
padding = 0,
|
|
19434
|
+
imageSize: imageSize
|
|
19435
|
+
} = imageConfig,
|
|
19436
|
+
[width, height] = size,
|
|
19437
|
+
center_x = width / 2,
|
|
19438
|
+
center_y = height / 2;
|
|
19439
|
+
let radius;
|
|
19440
|
+
radius = imageSize ? imageSize / 2 : Math.min(width, height) * ratio / 2, radius - padding <= 0 && (radius = padding + 1);
|
|
19441
|
+
const points = [],
|
|
19442
|
+
step = 2 * Math.PI / 6;
|
|
19443
|
+
for (let i = 0; i < 6; i++) {
|
|
19444
|
+
const angle = step * i;
|
|
19445
|
+
points.push({
|
|
19446
|
+
x: (radius - padding / 2) * Math.cos(angle),
|
|
19447
|
+
y: (radius - padding / 2) * Math.sin(angle)
|
|
19448
|
+
});
|
|
19449
|
+
}
|
|
19450
|
+
const diameter = 2 * radius,
|
|
19451
|
+
edgeLength = Math.sin(Math.PI / 6) * diameter,
|
|
19452
|
+
cellHeight = Math.sqrt(3) * edgeLength,
|
|
19453
|
+
gridSpaceX = diameter - edgeLength / 2,
|
|
19454
|
+
gridSpaceY = Math.cos(Math.PI / 6) * diameter,
|
|
19455
|
+
gridOffsetY = gridSpaceY / 2,
|
|
19456
|
+
rows = Math.floor(height / cellHeight),
|
|
19457
|
+
cols = Math.floor(width / edgeLength),
|
|
19458
|
+
cellInfo = [];
|
|
19459
|
+
for (let r = -1; r <= rows + 1; r++) for (let c = -1; c <= cols; c++) {
|
|
19460
|
+
const centerX = c * gridSpaceX,
|
|
19461
|
+
centerY = r * gridSpaceY + (c % 2 ? gridOffsetY : 0);
|
|
19462
|
+
cellInfo.push({
|
|
19463
|
+
centerX: centerX,
|
|
19464
|
+
centerY: centerY,
|
|
19465
|
+
x: centerX - edgeLength,
|
|
19466
|
+
y: centerY - edgeLength,
|
|
19467
|
+
row: r,
|
|
19468
|
+
col: c,
|
|
19469
|
+
distance: Math.sqrt(Math.pow(centerX - center_x, 2) + Math.pow(centerY - center_y, 2))
|
|
19470
|
+
});
|
|
19471
|
+
}
|
|
19472
|
+
let cellPixelCount = 0;
|
|
19473
|
+
const pixelMap = [];
|
|
19474
|
+
for (let r = 0; r <= cellHeight; r++) for (let c = 0; c <= 2 * edgeLength; c++) {
|
|
19475
|
+
const px = c - edgeLength,
|
|
19476
|
+
py = r - cellHeight / 2,
|
|
19477
|
+
q2x = Math.abs(px),
|
|
19478
|
+
q2y = Math.abs(py);
|
|
19479
|
+
q2x <= edgeLength && q2y <= cellHeight / 2 && 2 * q2y + q2x * Math.sqrt(3) <= cellHeight ? (cellPixelCount++, pixelMap.push(!0)) : pixelMap.push(!1);
|
|
19480
|
+
}
|
|
19481
|
+
return {
|
|
19482
|
+
context: Object.assign({}, layoutConfig, {
|
|
19483
|
+
cellHexSideLength: edgeLength,
|
|
19484
|
+
cellHexPoints: points,
|
|
19485
|
+
cellHeight: cellHeight,
|
|
19486
|
+
cellWidth: 2 * edgeLength,
|
|
19487
|
+
cellInfo: cellInfo,
|
|
19488
|
+
cellCount: cellInfo.length,
|
|
19489
|
+
cellType: "hexagonal",
|
|
19490
|
+
cellPixelCount: cellPixelCount,
|
|
19491
|
+
eachPixel: (cell, callback) => {
|
|
19492
|
+
const {
|
|
19493
|
+
x: x,
|
|
19494
|
+
y: y
|
|
19495
|
+
} = cell;
|
|
19496
|
+
let index = 0;
|
|
19497
|
+
for (let r = 0; r <= cellHeight; r++) for (let c = 0; c <= 2 * edgeLength; c++) pixelMap[index++] && callback((~~y + r) * width + (~~x + c));
|
|
19498
|
+
},
|
|
19499
|
+
clipPath: "M 1 0 L 0.5 0.866 L -0.5 0.866 L -1 0 L -0.5 -0.866 L 0.5 -0.866 Z"
|
|
19500
|
+
}),
|
|
19501
|
+
imageLength: diameter - padding
|
|
19502
|
+
};
|
|
19503
|
+
}
|
|
19504
|
+
|
|
19505
|
+
const cellLayout = {
|
|
19506
|
+
rect: rectGridLayout,
|
|
19507
|
+
circle: circleGridLayout,
|
|
19508
|
+
hexagonal: hexagonalGridLayout
|
|
19509
|
+
};
|
|
19510
|
+
class GridLayout extends Layout {
|
|
19511
|
+
preProcess() {
|
|
19512
|
+
var _a;
|
|
19513
|
+
const images = super.preProcess(),
|
|
19514
|
+
{
|
|
19515
|
+
layoutConfig = {}
|
|
19516
|
+
} = this.options,
|
|
19517
|
+
{
|
|
19518
|
+
cellType = "rect"
|
|
19519
|
+
} = layoutConfig,
|
|
19520
|
+
layoutResult = (null !== (_a = cellLayout[cellType]) && void 0 !== _a ? _a : cellLayout.rect)(this.options),
|
|
19521
|
+
{
|
|
19522
|
+
context: context,
|
|
19523
|
+
imageLength: shortSideLength
|
|
19524
|
+
} = layoutResult;
|
|
19525
|
+
return images.forEach(img => setSizeByShortSide(img, shortSideLength)), context.cellInfo.sort((cellA, cellB) => cellA.distance - cellB.distance), this.layoutContext = context, images;
|
|
19526
|
+
}
|
|
19527
|
+
doLayout(images) {
|
|
19528
|
+
const {
|
|
19529
|
+
cellWidth: cellWidth,
|
|
19530
|
+
cellHeight: cellHeight,
|
|
19531
|
+
cellInfo: cellInfo,
|
|
19532
|
+
cellCount: cellCount,
|
|
19533
|
+
clipPath: clipPath,
|
|
19534
|
+
eachPixel: eachPixel,
|
|
19535
|
+
cellPixelCount: cellPixelCount
|
|
19536
|
+
} = this.layoutContext;
|
|
19537
|
+
if (0 === images.length || 0 === cellCount || 0 === cellWidth || 0 === cellHeight || 0 === cellInfo.length) return void (this.isLayoutFinished = !0);
|
|
19538
|
+
const {
|
|
19539
|
+
segmentationOutput: segmentationOutput
|
|
19540
|
+
} = this,
|
|
19541
|
+
{
|
|
19542
|
+
layoutConfig = {}
|
|
19543
|
+
} = this.options,
|
|
19544
|
+
{
|
|
19545
|
+
placement = "default"
|
|
19546
|
+
} = layoutConfig;
|
|
19547
|
+
if ("edge" === placement || "default" === placement) {
|
|
19548
|
+
const {
|
|
19549
|
+
segmentation: segmentation
|
|
19550
|
+
} = segmentationOutput,
|
|
19551
|
+
{
|
|
19552
|
+
labels: labels
|
|
19553
|
+
} = segmentation;
|
|
19554
|
+
cellInfo.forEach(cell => {
|
|
19555
|
+
let intersectPixelCount = 0;
|
|
19556
|
+
eachPixel(cell, index => {
|
|
19557
|
+
labels[index] && intersectPixelCount++;
|
|
19558
|
+
}), cell.intersectPixels = intersectPixelCount;
|
|
19559
|
+
});
|
|
19560
|
+
}
|
|
19561
|
+
const imageCount = images.length,
|
|
19562
|
+
imageVisible = cell => {
|
|
19563
|
+
const {
|
|
19564
|
+
intersectPixels: intersectPixels
|
|
19565
|
+
} = cell;
|
|
19566
|
+
return "default" === placement ? intersectPixels >= .45 * cellPixelCount : "edge" !== placement || intersectPixels > .1 * cellPixelCount && intersectPixels < cellPixelCount;
|
|
19567
|
+
};
|
|
19568
|
+
for (let i = 0; i < imageCount; i++) {
|
|
19569
|
+
const image = images[i],
|
|
19570
|
+
cell = cellInfo[i];
|
|
19571
|
+
cell && (image.x = cell.centerX - image.width / 2, image.y = cell.centerY - image.height / 2, image.clipConfig = {
|
|
19572
|
+
shape: clipPath
|
|
19573
|
+
}, image.frequency = 1, image.visible = imageVisible(cell), image.cell = vutils.pickWithout(cell, ["image"]), image.distance = cell.distance, cell.image = image);
|
|
19574
|
+
}
|
|
19575
|
+
const key = Object.keys(images[0]).find(k => k.includes("VGRAMMAR"));
|
|
19576
|
+
if (imageCount < cellCount) for (let i = imageCount; i < cellCount; i++) {
|
|
19577
|
+
const image = images[i - imageCount],
|
|
19578
|
+
cell = cellInfo[i];
|
|
19579
|
+
if (cell) {
|
|
19580
|
+
const repeatImage = Object.assign({}, image);
|
|
19581
|
+
repeatImage.x = cell.centerX - repeatImage.width / 2, repeatImage.y = cell.centerY - repeatImage.height / 2, repeatImage.frequency += 1, repeatImage[key] = `${repeatImage[key]}_${repeatImage.frequency}`, repeatImage.visible = imageVisible(cell), repeatImage.distance = cell.distance, repeatImage.cell = vutils.pickWithout(cell, ["image"]), cell.image = repeatImage, images.push(repeatImage);
|
|
19582
|
+
}
|
|
19583
|
+
}
|
|
19584
|
+
return images.filter(img => img.visible);
|
|
19585
|
+
}
|
|
19586
|
+
}
|
|
19587
|
+
|
|
19588
|
+
class StackLayout extends Layout {
|
|
19589
|
+
preProcess() {
|
|
19590
|
+
const images = super.preProcess(),
|
|
19591
|
+
{
|
|
19592
|
+
imageConfig = {},
|
|
19593
|
+
ratio = .1
|
|
19594
|
+
} = this.options,
|
|
19595
|
+
cellLayoutMethod = rectGridLayout;
|
|
19596
|
+
return this.layoutContext = cellLayoutMethod(Object.assign({}, this.options, {
|
|
19597
|
+
imageConfig: {
|
|
19598
|
+
imageSize: null
|
|
19599
|
+
}
|
|
19600
|
+
})).context, this.layoutContext.cellInfo.sort((cellA, cellB) => cellA.distance - cellB.distance), this.calculateImageSize(images, imageConfig, ratio);
|
|
19601
|
+
}
|
|
19602
|
+
doLayout(images) {
|
|
19603
|
+
const {
|
|
19604
|
+
segmentationOutput: segmentationOutput
|
|
19605
|
+
} = this,
|
|
19606
|
+
{
|
|
19607
|
+
cellWidth: cellWidth,
|
|
19608
|
+
cellHeight: cellHeight,
|
|
19609
|
+
cellInfo: cellInfo,
|
|
19610
|
+
cellCount: cellCount,
|
|
19611
|
+
eachPixel: eachPixel,
|
|
19612
|
+
cellPixelCount: cellPixelCount
|
|
19613
|
+
} = this.layoutContext;
|
|
19614
|
+
if (0 === images.length || 0 === cellCount || 0 === cellWidth || 0 === cellHeight || 0 === cellInfo.length) return void (this.isLayoutFinished = !0);
|
|
19615
|
+
const {
|
|
19616
|
+
layoutConfig = {}
|
|
19617
|
+
} = this.options,
|
|
19618
|
+
size = this.options.size,
|
|
19619
|
+
{
|
|
19620
|
+
placement = "default",
|
|
19621
|
+
maxAngle = Math.PI / 180 * 45
|
|
19622
|
+
} = layoutConfig;
|
|
19623
|
+
if ("edge" === placement || "default" === placement) {
|
|
19624
|
+
const {
|
|
19625
|
+
segmentation: segmentation
|
|
19626
|
+
} = segmentationOutput,
|
|
19627
|
+
{
|
|
19628
|
+
labels: labels
|
|
19629
|
+
} = segmentation;
|
|
19630
|
+
cellInfo.forEach(cell => {
|
|
19631
|
+
let intersectPixelCount = 0;
|
|
19632
|
+
eachPixel(cell, index => {
|
|
19633
|
+
labels[index] && intersectPixelCount++;
|
|
19634
|
+
}), cell.intersectPixels = intersectPixelCount;
|
|
19635
|
+
});
|
|
19636
|
+
}
|
|
19637
|
+
const imageCount = images.length,
|
|
19638
|
+
maxDistance = Math.sqrt(Math.pow(size[0], 2) + Math.pow(size[1], 2)),
|
|
19639
|
+
imageVisible = cell => {
|
|
19640
|
+
const {
|
|
19641
|
+
intersectPixels: intersectPixels
|
|
19642
|
+
} = cell;
|
|
19643
|
+
return "default" === placement ? intersectPixels > .5 * cellPixelCount : "edge" !== placement || intersectPixels > .1 * cellPixelCount && intersectPixels < cellPixelCount;
|
|
19644
|
+
};
|
|
19645
|
+
for (let i = 0; i < imageCount; i++) {
|
|
19646
|
+
const image = images[i],
|
|
19647
|
+
cell = cellInfo[i];
|
|
19648
|
+
cell && (image.x = cell.centerX - image.width / 2, image.y = cell.centerY - image.height / 2, image.visible = imageVisible(cell), image.cell = `${cell.row}_${cell.col}`, image.angle = Math.random() * (2 * maxAngle) - maxAngle, image.anchor = [image.x + image.width / 2, image.y + image.height / 2], image.zIndex = maxDistance - cell.distance, image.distance = cell.distance, image.frequency = 1, cell.image = image);
|
|
19649
|
+
}
|
|
19650
|
+
const key = Object.keys(images[0]).find(k => k.includes("VGRAMMAR"));
|
|
19651
|
+
if (imageCount < cellCount) for (let i = imageCount; i < cellCount; i++) {
|
|
19652
|
+
const image = images[i - imageCount],
|
|
19653
|
+
cell = cellInfo[i];
|
|
19654
|
+
if (cell) {
|
|
19655
|
+
const repeatImage = Object.assign({}, image);
|
|
19656
|
+
repeatImage.x = cell.centerX - repeatImage.width / 2, repeatImage.y = cell.centerY - repeatImage.height / 2, repeatImage.anchor = [repeatImage.x + repeatImage.width / 2, repeatImage.y + repeatImage.height / 2], repeatImage.angle = Math.random() * (2 * maxAngle) - maxAngle, repeatImage.frequency += 1, repeatImage[key] = `${repeatImage[key]}_${repeatImage.frequency}`, repeatImage.visible = imageVisible(cell), repeatImage.cell = `${cell.row}_${cell.col}`, repeatImage.distance = cell.distance, repeatImage.zIndex = maxDistance - cell.distance, cell.image = repeatImage, images.push(repeatImage);
|
|
19657
|
+
}
|
|
19658
|
+
}
|
|
19659
|
+
return images.filter(img => img.visible);
|
|
19660
|
+
}
|
|
19661
|
+
}
|
|
19662
|
+
|
|
19663
|
+
const transform = (options, upstreamData, parameters) => {
|
|
19664
|
+
var _a, _b;
|
|
19665
|
+
const size = vutils.isFunction(options.size) ? options.size() : options.size;
|
|
19666
|
+
if (options.size = size, !size || vutils.isNil(size[0]) || vutils.isNil(size[1]) || size[0] <= 0 || size[1] <= 0) {
|
|
19667
|
+
return vutils.Logger.getInstance().info("Wordcloud size dimensions must be greater than 0"), [];
|
|
19668
|
+
}
|
|
19669
|
+
if (options.size = [Math.ceil(size[0]), Math.ceil(size[1])], options.image || vutils.Logger.getInstance().error("Imagecloud: image source must be specified."), options.onBeforeLayout && options.onBeforeLayout(), !upstreamData || 0 === upstreamData.length) return [];
|
|
19670
|
+
let layoutConstructor;
|
|
19671
|
+
switch (null !== (_b = null === (_a = options.layoutConfig) || void 0 === _a ? void 0 : _a.layoutMode) && void 0 !== _b ? _b : "spiral") {
|
|
19672
|
+
case "grid":
|
|
19673
|
+
layoutConstructor = GridLayout;
|
|
19674
|
+
break;
|
|
19675
|
+
case "stack":
|
|
19676
|
+
layoutConstructor = StackLayout;
|
|
19677
|
+
break;
|
|
19678
|
+
default:
|
|
19679
|
+
layoutConstructor = SpiralLayout;
|
|
19680
|
+
}
|
|
19681
|
+
const layout = new layoutConstructor(options);
|
|
19682
|
+
return layout.layout(upstreamData), layout.unfinished() ? {
|
|
19683
|
+
progressive: layout
|
|
19684
|
+
} : layout.output();
|
|
19685
|
+
};
|
|
19686
|
+
|
|
19687
|
+
class AxialRotateAnimation extends ACustomAnimate {
|
|
19688
|
+
constructor(from, to, duration, easing, params) {
|
|
19689
|
+
var _a;
|
|
19690
|
+
super(from, to, duration, easing, params);
|
|
19691
|
+
this._rotations = (_a = params === null || params === void 0 ? void 0 : params.rotation) !== null && _a !== void 0 ? _a : 1;
|
|
19692
|
+
}
|
|
19693
|
+
onBind() {
|
|
19694
|
+
this._scaleX = this.target.attribute.scaleX;
|
|
19695
|
+
if (!vutils.isValidNumber(this._rotations)) {
|
|
19696
|
+
this.valid = false;
|
|
19697
|
+
}
|
|
19698
|
+
}
|
|
19699
|
+
onUpdate(end, ratio, out) {
|
|
19700
|
+
var _a;
|
|
19701
|
+
if (this.valid === false) {
|
|
19702
|
+
return;
|
|
19703
|
+
}
|
|
19704
|
+
if (end) {
|
|
19705
|
+
out.scaleX = this._scaleX;
|
|
19706
|
+
return;
|
|
19707
|
+
}
|
|
19708
|
+
const currentAngle = this._rotations * 360 * ratio;
|
|
19709
|
+
const currentAngleInRadians = (currentAngle * Math.PI) / 180;
|
|
19710
|
+
const scaleX = Math.abs(Math.cos(currentAngleInRadians)) * ((_a = this._scaleX) !== null && _a !== void 0 ? _a : 1);
|
|
19711
|
+
this.target.attribute.scaleX = scaleX;
|
|
19712
|
+
this.target.addUpdatePositionTag();
|
|
19713
|
+
this.target.addUpdateShapeAndBoundsTag();
|
|
19714
|
+
}
|
|
19715
|
+
}
|
|
19716
|
+
function imageCloudPresetAnimation(params, preset) {
|
|
19717
|
+
switch (preset) {
|
|
19718
|
+
case 'axialRotate':
|
|
19719
|
+
return [
|
|
19720
|
+
{
|
|
19721
|
+
custom: AxialRotateAnimation,
|
|
19722
|
+
customParameters: {
|
|
19723
|
+
rotation: 1
|
|
19724
|
+
},
|
|
19725
|
+
duration: vchart.DEFAULT_ANIMATION_CONFIG.appear.duration
|
|
19726
|
+
},
|
|
19727
|
+
{
|
|
19728
|
+
channel: {
|
|
19729
|
+
y: {
|
|
19730
|
+
from: (datum, element) => {
|
|
19731
|
+
return params.height() + element.getFinalAttribute().y;
|
|
19732
|
+
}
|
|
19733
|
+
},
|
|
19734
|
+
fillOpacity: {
|
|
19735
|
+
from: 0,
|
|
19736
|
+
to: 1
|
|
19737
|
+
}
|
|
19738
|
+
},
|
|
19739
|
+
easing: 'sineInOut'
|
|
19740
|
+
}
|
|
19741
|
+
];
|
|
19742
|
+
case 'growIn':
|
|
19743
|
+
return {
|
|
19744
|
+
channel: {
|
|
19745
|
+
scaleX: {
|
|
19746
|
+
from: 0,
|
|
19747
|
+
to: 1
|
|
19748
|
+
},
|
|
19749
|
+
scaleY: {
|
|
19750
|
+
from: 0,
|
|
19751
|
+
to: 1
|
|
19752
|
+
},
|
|
19753
|
+
x: { from: () => params.center().x },
|
|
19754
|
+
y: { from: () => params.center().y }
|
|
19755
|
+
},
|
|
19756
|
+
duration: vchart.DEFAULT_ANIMATION_CONFIG.appear.duration
|
|
19757
|
+
};
|
|
19758
|
+
case 'scaleIn':
|
|
19759
|
+
return { type: 'scaleIn', duration: vchart.DEFAULT_ANIMATION_CONFIG.appear.duration };
|
|
19760
|
+
case 'fadeIn':
|
|
19761
|
+
default:
|
|
19762
|
+
return { type: 'fadeIn', easing: 'linear', duration: vchart.DEFAULT_ANIMATION_CONFIG.appear.duration };
|
|
19763
|
+
}
|
|
19764
|
+
}
|
|
19765
|
+
const registerImageCloudAnimation = () => {
|
|
19766
|
+
vchart.Factory.registerAnimation('imageCloud', (params, preset) => ({
|
|
19767
|
+
appear: imageCloudPresetAnimation(params, preset),
|
|
19768
|
+
enter: imageCloudPresetAnimation(params, preset),
|
|
19769
|
+
exit: { type: 'fadeOut' },
|
|
19770
|
+
disappear: { type: 'fadeOut' }
|
|
19771
|
+
}));
|
|
19772
|
+
};
|
|
19773
|
+
|
|
19774
|
+
class ImageCloudTooltipHelper extends vchart.BaseSeriesTooltipHelper {
|
|
19775
|
+
constructor() {
|
|
19776
|
+
super(...arguments);
|
|
19777
|
+
this.markTooltipKeyCallback = (datum) => {
|
|
19778
|
+
var _a, _b;
|
|
19779
|
+
return (_b = (_a = this.series) === null || _a === void 0 ? void 0 : _a.getMarkData(datum)) === null || _b === void 0 ? void 0 : _b[this.series.getDimensionField()[0]];
|
|
19780
|
+
};
|
|
19781
|
+
this.markTooltipValueCallback = (datum) => {
|
|
19782
|
+
var _a, _b;
|
|
19783
|
+
const { measureFields } = this._seriesCacheInfo;
|
|
19784
|
+
const data = (_a = this.series) === null || _a === void 0 ? void 0 : _a.getMarkData(datum);
|
|
19785
|
+
if (measureFields[0] && data) {
|
|
19786
|
+
return (_b = data[measureFields[0]]) !== null && _b !== void 0 ? _b : datum.value;
|
|
19787
|
+
}
|
|
19788
|
+
return undefined;
|
|
19789
|
+
};
|
|
19790
|
+
this.dimensionTooltipTitleCallback = (datum) => {
|
|
19791
|
+
var _a;
|
|
19792
|
+
const { dimensionFields } = this._seriesCacheInfo;
|
|
19793
|
+
const data = (_a = this.series) === null || _a === void 0 ? void 0 : _a.getMarkData(datum);
|
|
19794
|
+
if (dimensionFields[0] && data) {
|
|
19795
|
+
return data[dimensionFields[0]];
|
|
19796
|
+
}
|
|
19797
|
+
return undefined;
|
|
19798
|
+
};
|
|
19799
|
+
}
|
|
19800
|
+
get defaultShapeType() {
|
|
19801
|
+
return 'square';
|
|
19802
|
+
}
|
|
19803
|
+
}
|
|
19804
|
+
|
|
19805
|
+
class ImageCloudSeries extends vchart.BaseSeries {
|
|
19806
|
+
constructor() {
|
|
19807
|
+
super(...arguments);
|
|
19808
|
+
this.type = IMAGE_CLOUD_SERIES_TYPE;
|
|
19809
|
+
}
|
|
19810
|
+
setValueField(field) {
|
|
19811
|
+
if (vutils.isValid(field)) {
|
|
19812
|
+
this._valueField = field;
|
|
19813
|
+
}
|
|
19814
|
+
}
|
|
19815
|
+
setAttrFromSpec() {
|
|
19816
|
+
super.setAttrFromSpec();
|
|
19817
|
+
this._nameField = this._spec.nameField;
|
|
19818
|
+
this._valueField = this._spec.valueField;
|
|
19819
|
+
this._urlField = this._spec.urlField;
|
|
19820
|
+
}
|
|
19821
|
+
initMark() {
|
|
19822
|
+
var _a;
|
|
19823
|
+
if ((_a = this._spec.imageMask) === null || _a === void 0 ? void 0 : _a.visible) {
|
|
19824
|
+
this._maskMark = this._createMark(imageCloudSeriesMark.imageMask, {
|
|
19825
|
+
dataView: false,
|
|
19826
|
+
skipBeforeLayouted: true
|
|
19827
|
+
});
|
|
19828
|
+
}
|
|
19829
|
+
this._imageMark = this._createMark(imageCloudSeriesMark.image, {
|
|
19830
|
+
key: datum => `${datum[vchart.DEFAULT_DATA_KEY]}-${datum.frequency}`,
|
|
19831
|
+
isSeriesMark: true,
|
|
19832
|
+
skipBeforeLayouted: true
|
|
19833
|
+
});
|
|
19834
|
+
}
|
|
19835
|
+
initMarkStyle() {
|
|
19836
|
+
this._initImageMarkStyle();
|
|
19837
|
+
this._initMaskMarkStyle();
|
|
19838
|
+
}
|
|
19839
|
+
_initImageMarkStyle() {
|
|
19840
|
+
var _a, _b;
|
|
19841
|
+
if (!this._imageMark) {
|
|
19842
|
+
return;
|
|
19843
|
+
}
|
|
19844
|
+
this._imageMark.setTransform([
|
|
19845
|
+
Object.assign({ type: 'imagecloud' }, this._imageCloudTransformOption())
|
|
19846
|
+
]);
|
|
19847
|
+
this.setMarkStyle(this._imageMark, {
|
|
19848
|
+
x: (datum) => datum.x,
|
|
19849
|
+
y: (datum) => datum.y,
|
|
19850
|
+
width: (datum) => datum.width,
|
|
19851
|
+
height: (datum) => datum.height,
|
|
19852
|
+
visible: (datum) => datum.visible,
|
|
19853
|
+
angle: (datum) => datum.angle,
|
|
19854
|
+
clipConfig: (datum) => datum.clipConfig,
|
|
19855
|
+
image: (datum) => datum[this._urlField],
|
|
19856
|
+
scaleCenter: ['50%', '50%']
|
|
19857
|
+
}, 'normal', vchart.AttributeLevel.Series);
|
|
19858
|
+
const isMasked = ((_a = this._spec.layoutConfig) === null || _a === void 0 ? void 0 : _a.placement) === 'masked';
|
|
19859
|
+
if (isMasked) {
|
|
19860
|
+
this.setMarkStyle(this._imageMark, {
|
|
19861
|
+
globalCompositeOperation: 'source-atop'
|
|
19862
|
+
}, 'normal', vchart.AttributeLevel.Series);
|
|
19863
|
+
this.setMarkStyle(this._rootMark, {
|
|
19864
|
+
width: () => this._region.getLayoutRect().width,
|
|
19865
|
+
height: () => this._region.getLayoutRect().height,
|
|
19866
|
+
globalCompositeOperation: 'destination-in',
|
|
19867
|
+
clip: true,
|
|
19868
|
+
drawMode: 1
|
|
19869
|
+
}, 'normal', vchart.AttributeLevel.Series);
|
|
19870
|
+
}
|
|
19871
|
+
if (((_b = this._spec.layoutConfig) === null || _b === void 0 ? void 0 : _b.layoutMode) === 'stack') {
|
|
19872
|
+
this.setMarkStyle(this._imageMark, {
|
|
19873
|
+
stroke: 'white',
|
|
19874
|
+
lineWidth: 2,
|
|
19875
|
+
shadowBlur: 6,
|
|
19876
|
+
shadowColor: 'grey'
|
|
19877
|
+
}, 'normal', vchart.AttributeLevel.Series);
|
|
19878
|
+
}
|
|
19879
|
+
}
|
|
19880
|
+
isFillingImage(datum) {
|
|
19881
|
+
return datum._frequency > 1;
|
|
19882
|
+
}
|
|
19883
|
+
_initMaskMarkStyle() {
|
|
19884
|
+
if (!this._maskMark) {
|
|
19885
|
+
return;
|
|
19886
|
+
}
|
|
19887
|
+
this._maskMark.setMarkConfig({ interactive: false });
|
|
19888
|
+
this.setMarkStyle(this._maskMark, {
|
|
19889
|
+
width: () => {
|
|
19890
|
+
return this._region.getLayoutRect().width;
|
|
19891
|
+
},
|
|
19892
|
+
height: () => {
|
|
19893
|
+
return this._region.getLayoutRect().height;
|
|
19894
|
+
}
|
|
19895
|
+
}, 'normal', vchart.AttributeLevel.Series);
|
|
19896
|
+
}
|
|
19897
|
+
initTooltip() {
|
|
19898
|
+
this._tooltipHelper = new ImageCloudTooltipHelper(this);
|
|
19899
|
+
this._imageMark && this._tooltipHelper.activeTriggerSet.mark.add(this._imageMark);
|
|
19900
|
+
}
|
|
19901
|
+
_imageCloudTransformOption() {
|
|
19902
|
+
var _a;
|
|
19903
|
+
return {
|
|
19904
|
+
size: () => {
|
|
19905
|
+
const { width, height } = this._region.getLayoutRect();
|
|
19906
|
+
return [width, height];
|
|
19907
|
+
},
|
|
19908
|
+
image: { field: this._urlField },
|
|
19909
|
+
weight: { field: this._valueField },
|
|
19910
|
+
imageConfig: {
|
|
19911
|
+
imageSize: this._spec.imageSize,
|
|
19912
|
+
imageSizeRange: this._spec.imageSizeRange,
|
|
19913
|
+
padding: (_a = this._spec.image) === null || _a === void 0 ? void 0 : _a.padding
|
|
19914
|
+
},
|
|
19915
|
+
ratio: this._spec.ratio,
|
|
19916
|
+
mask: this._spec.maskShape,
|
|
19917
|
+
maskConfig: this._spec.imageMask,
|
|
19918
|
+
layoutConfig: this._spec.layoutConfig,
|
|
19919
|
+
createCanvas: vchart.vglobal.createCanvas.bind(vchart.vglobal),
|
|
19920
|
+
createImage,
|
|
19921
|
+
onUpdateMaskCanvas: ((inputImage, maskImage) => {
|
|
19922
|
+
var _a;
|
|
19923
|
+
if (inputImage && this._maskMark) {
|
|
19924
|
+
this._maskMark
|
|
19925
|
+
.getProduct()
|
|
19926
|
+
.getChildren()
|
|
19927
|
+
.forEach((element) => {
|
|
19928
|
+
element.setAttribute('background', inputImage);
|
|
19929
|
+
});
|
|
19930
|
+
}
|
|
19931
|
+
if (maskImage && ((_a = this._spec.layoutConfig) === null || _a === void 0 ? void 0 : _a.placement) === 'masked') {
|
|
19932
|
+
this._rootMark.getProduct().setAttribute('background', maskImage);
|
|
19933
|
+
}
|
|
19934
|
+
}).bind(this)
|
|
19935
|
+
};
|
|
19936
|
+
}
|
|
19937
|
+
_buildMarkAttributeContext() {
|
|
19938
|
+
super._buildMarkAttributeContext();
|
|
19939
|
+
this._markAttributeContext.isFillingImage = this.isFillingImage.bind(this);
|
|
19940
|
+
}
|
|
19941
|
+
initAnimation() {
|
|
19942
|
+
[this._imageMark].forEach(mark => {
|
|
19943
|
+
var _a, _b;
|
|
19944
|
+
if (mark) {
|
|
19945
|
+
const appearPreset = (_b = (_a = this._spec) === null || _a === void 0 ? void 0 : _a.animationAppear) === null || _b === void 0 ? void 0 : _b.preset;
|
|
19946
|
+
const params = {
|
|
19947
|
+
center: () => {
|
|
19948
|
+
const { width, height } = this._region.getLayoutRect();
|
|
19949
|
+
return { x: width / 2, y: height / 2 };
|
|
19950
|
+
},
|
|
19951
|
+
height: () => {
|
|
19952
|
+
const { height } = this._region.getLayoutRect();
|
|
19953
|
+
return height;
|
|
19954
|
+
}
|
|
19955
|
+
};
|
|
19956
|
+
mark.setAnimationConfig(vchart.animationConfig(vchart.Factory.getAnimationInKey('imageCloud')(params, appearPreset), vchart.userAnimationConfig("image", this._spec, this._markAttributeContext)));
|
|
19957
|
+
}
|
|
19958
|
+
});
|
|
19959
|
+
}
|
|
19960
|
+
getDimensionField() {
|
|
19961
|
+
var _a;
|
|
19962
|
+
return [(_a = this._nameField) !== null && _a !== void 0 ? _a : this._spec.urlField];
|
|
19963
|
+
}
|
|
19964
|
+
getMeasureField() {
|
|
19965
|
+
return [this._valueField];
|
|
19966
|
+
}
|
|
19967
|
+
getStatisticFields() {
|
|
19968
|
+
const fields = [];
|
|
19969
|
+
fields.push({ key: this._nameField, operations: ['values'] });
|
|
19970
|
+
fields.push({ key: this._valueField, operations: ['max', 'min'] });
|
|
19971
|
+
return fields;
|
|
19972
|
+
}
|
|
19973
|
+
getActiveMarks() {
|
|
19974
|
+
return [this._imageMark];
|
|
19975
|
+
}
|
|
19976
|
+
getMarkData(datum) {
|
|
19977
|
+
var _a;
|
|
19978
|
+
return (_a = datum === null || datum === void 0 ? void 0 : datum.datum) !== null && _a !== void 0 ? _a : datum;
|
|
19979
|
+
}
|
|
19980
|
+
getGroupFields() {
|
|
19981
|
+
return [];
|
|
19982
|
+
}
|
|
19983
|
+
dataToPosition(data) {
|
|
19984
|
+
return null;
|
|
19985
|
+
}
|
|
19986
|
+
dataToPositionX(data) {
|
|
19987
|
+
var _a;
|
|
19988
|
+
return (_a = this.dataToPosition(data)) === null || _a === void 0 ? void 0 : _a.x;
|
|
19989
|
+
}
|
|
19990
|
+
dataToPositionY(data) {
|
|
19991
|
+
var _a;
|
|
19992
|
+
return (_a = this.dataToPosition(data)) === null || _a === void 0 ? void 0 : _a.y;
|
|
19993
|
+
}
|
|
19994
|
+
valueToPosition(value1, value2) {
|
|
19995
|
+
return null;
|
|
19996
|
+
}
|
|
19997
|
+
getStackGroupFields() {
|
|
19998
|
+
return [];
|
|
19999
|
+
}
|
|
20000
|
+
getStackValueField() {
|
|
20001
|
+
return '';
|
|
20002
|
+
}
|
|
20003
|
+
}
|
|
20004
|
+
ImageCloudSeries.type = IMAGE_CLOUD_SERIES_TYPE;
|
|
20005
|
+
ImageCloudSeries.mark = imageCloudSeriesMark;
|
|
20006
|
+
const registerImageCloudSeries = () => {
|
|
20007
|
+
vchart.registerImageMark();
|
|
20008
|
+
registerImageCloudAnimation();
|
|
20009
|
+
vchart.Factory.registerSeries(ImageCloudSeries.type, ImageCloudSeries);
|
|
20010
|
+
vchart.Factory.registerGrammarTransform('imagecloud', {
|
|
20011
|
+
transform: transform
|
|
20012
|
+
});
|
|
20013
|
+
};
|
|
20014
|
+
|
|
20015
|
+
class ImageCloudChart extends vchart.BaseChart {
|
|
20016
|
+
constructor() {
|
|
20017
|
+
super(...arguments);
|
|
20018
|
+
this.transformerConstructor = ImageCloudChart.transformerConstructor;
|
|
20019
|
+
this.type = IMAGE_CLOUD_CHART_TYPE;
|
|
20020
|
+
this.seriesType = IMAGE_CLOUD_SERIES_TYPE;
|
|
20021
|
+
}
|
|
20022
|
+
}
|
|
20023
|
+
ImageCloudChart.type = IMAGE_CLOUD_CHART_TYPE;
|
|
20024
|
+
ImageCloudChart.seriesType = IMAGE_CLOUD_SERIES_TYPE;
|
|
20025
|
+
ImageCloudChart.transformerConstructor = ImageCloudChartSpecTransformer;
|
|
20026
|
+
const registerImageCloudChart = () => {
|
|
20027
|
+
registerImageCloudSeries();
|
|
20028
|
+
vchart.Factory.registerChart(ImageCloudChart.type, ImageCloudChart);
|
|
20029
|
+
};
|
|
20030
|
+
|
|
16988
20031
|
const GROUP_ATTRIBUTES = ["x", "y", "dx", "dy", "scaleX", "scaleY", "angle", "anchor", "postMatrix", "visible", "clip", "pickable", "childrenPickable", "zIndex", "cursor"];
|
|
16989
20032
|
class AbstractComponent extends Group {
|
|
16990
20033
|
constructor(attributes, options) {
|
|
@@ -20053,7 +23096,11 @@
|
|
|
20053
23096
|
exports.Funnel3dSeries = Funnel3dSeries;
|
|
20054
23097
|
exports.Funnel3dSeriesSpecTransformer = Funnel3dSeriesSpecTransformer;
|
|
20055
23098
|
exports.Histogram3dChart = Histogram3dChart;
|
|
23099
|
+
exports.ImageCloudChart = ImageCloudChart;
|
|
20056
23100
|
exports.MapLabelComponent = MapLabelComponent;
|
|
23101
|
+
exports.PictogramChart = PictogramChart;
|
|
23102
|
+
exports.PictogramChartSpecTransformer = PictogramChartSpecTransformer;
|
|
23103
|
+
exports.PictogramSeries = PictogramSeries;
|
|
20057
23104
|
exports.Pie3dChart = Pie3dChart;
|
|
20058
23105
|
exports.Pie3dChartSpecTransformer = Pie3dChartSpecTransformer;
|
|
20059
23106
|
exports.Pie3dSeries = Pie3dSeries;
|
|
@@ -20076,7 +23123,9 @@
|
|
|
20076
23123
|
exports.appendBarLinkConfig = appendBarLinkConfig;
|
|
20077
23124
|
exports.appendSeriesBreakConfig = appendSeriesBreakConfig;
|
|
20078
23125
|
exports.appendSeriesLabelConfig = appendSeriesLabelConfig;
|
|
23126
|
+
exports.clearSVGSource = clearSVGSource;
|
|
20079
23127
|
exports.getBarLinkConfig = getBarLinkConfig;
|
|
23128
|
+
exports.getSVGSource = getSVGSource;
|
|
20080
23129
|
exports.getSeriesBreakConfig = getSeriesBreakConfig;
|
|
20081
23130
|
exports.getSeriesLabelConfig = getSeriesLabelConfig;
|
|
20082
23131
|
exports.register3DPlugin = register3DPlugin;
|
|
@@ -20088,13 +23137,17 @@
|
|
|
20088
23137
|
exports.registerFunnel3dChart = registerFunnel3dChart;
|
|
20089
23138
|
exports.registerFunnel3dSeries = registerFunnel3dSeries;
|
|
20090
23139
|
exports.registerHistogram3dChart = registerHistogram3dChart;
|
|
23140
|
+
exports.registerImageCloudChart = registerImageCloudChart;
|
|
20091
23141
|
exports.registerMapLabel = registerMapLabel;
|
|
23142
|
+
exports.registerPictogramChart = registerPictogramChart;
|
|
23143
|
+
exports.registerPictogramSeries = registerPictogramSeries;
|
|
20092
23144
|
exports.registerPie3dChart = registerPie3dChart;
|
|
20093
23145
|
exports.registerPie3dSeries = registerPie3dSeries;
|
|
20094
23146
|
exports.registerRangeColumn3dChart = registerRangeColumn3dChart;
|
|
20095
23147
|
exports.registerRangeColumn3dSeries = registerRangeColumn3dSeries;
|
|
20096
23148
|
exports.registerRankingBarChart = registerRankingBarChart;
|
|
20097
23149
|
exports.registerRankingList = registerRankingList;
|
|
23150
|
+
exports.registerSVGSource = registerSVGSource;
|
|
20098
23151
|
exports.registerSequenceScatterKDE = registerSequenceScatterKDE;
|
|
20099
23152
|
exports.registerSequenceScatterLink = registerSequenceScatterLink;
|
|
20100
23153
|
exports.registerSequenceScatterPixel = registerSequenceScatterPixel;
|
|
@@ -20104,5 +23157,7 @@
|
|
|
20104
23157
|
exports.registerWordCloud3dSeries = registerWordCloud3dSeries;
|
|
20105
23158
|
exports.registerWordCloudShape3dChart = registerWordCloudShape3dChart;
|
|
20106
23159
|
exports.registerWordCloudShape3dSeries = registerWordCloudShape3dSeries;
|
|
23160
|
+
exports.svgSourceMap = svgSourceMap;
|
|
23161
|
+
exports.unregisterSVGSource = unregisterSVGSource;
|
|
20107
23162
|
|
|
20108
23163
|
}));
|