cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
237 lines (236 loc) • 7.2 kB
JavaScript
import { __extends } from "../../../../tslib/tslib.es6.mjs";
import { containStroke } from "../../../../zrender/lib/contain/line.mjs";
import { containStroke as containStroke$1 } from "../../../../zrender/lib/contain/quadratic.mjs";
import { getECData } from "../../util/innerStore.mjs";
import BoundingRect from "../../../../zrender/lib/core/BoundingRect.mjs";
import Path from "../../../../zrender/lib/graphic/Path.mjs";
import Group from "../../../../zrender/lib/graphic/Group.mjs";
var LargeLinesPathShape = function() {
function LargeLinesPathShape2() {
this.polyline = false;
this.curveness = 0;
this.segs = [];
}
return LargeLinesPathShape2;
}();
var LargeLinesPath = function(_super) {
__extends(LargeLinesPath2, _super);
function LargeLinesPath2(opts) {
var _this = _super.call(this, opts) || this;
_this._off = 0;
_this.hoverDataIdx = -1;
return _this;
}
LargeLinesPath2.prototype.reset = function() {
this.notClear = false;
this._off = 0;
};
LargeLinesPath2.prototype.getDefaultStyle = function() {
return {
stroke: "#000",
fill: null
};
};
LargeLinesPath2.prototype.getDefaultShape = function() {
return new LargeLinesPathShape();
};
LargeLinesPath2.prototype.buildPath = function(ctx, shape) {
var segs = shape.segs;
var curveness = shape.curveness;
var i;
if (shape.polyline) {
for (i = this._off; i < segs.length; ) {
var count = segs[i++];
if (count > 0) {
ctx.moveTo(segs[i++], segs[i++]);
for (var k = 1; k < count; k++) {
ctx.lineTo(segs[i++], segs[i++]);
}
}
}
} else {
for (i = this._off; i < segs.length; ) {
var x0 = segs[i++];
var y0 = segs[i++];
var x1 = segs[i++];
var y1 = segs[i++];
ctx.moveTo(x0, y0);
if (curveness > 0) {
var x2 = (x0 + x1) / 2 - (y0 - y1) * curveness;
var y2 = (y0 + y1) / 2 - (x1 - x0) * curveness;
ctx.quadraticCurveTo(x2, y2, x1, y1);
} else {
ctx.lineTo(x1, y1);
}
}
}
if (this.incremental) {
this._off = i;
this.notClear = true;
}
};
LargeLinesPath2.prototype.findDataIndex = function(x, y) {
var shape = this.shape;
var segs = shape.segs;
var curveness = shape.curveness;
var lineWidth = this.style.lineWidth;
if (shape.polyline) {
var dataIndex = 0;
for (var i = 0; i < segs.length; ) {
var count = segs[i++];
if (count > 0) {
var x0 = segs[i++];
var y0 = segs[i++];
for (var k = 1; k < count; k++) {
var x1 = segs[i++];
var y1 = segs[i++];
if (containStroke(x0, y0, x1, y1, lineWidth, x, y)) {
return dataIndex;
}
}
}
dataIndex++;
}
} else {
var dataIndex = 0;
for (var i = 0; i < segs.length; ) {
var x0 = segs[i++];
var y0 = segs[i++];
var x1 = segs[i++];
var y1 = segs[i++];
if (curveness > 0) {
var x2 = (x0 + x1) / 2 - (y0 - y1) * curveness;
var y2 = (y0 + y1) / 2 - (x1 - x0) * curveness;
if (containStroke$1(x0, y0, x2, y2, x1, y1, lineWidth, x, y)) {
return dataIndex;
}
} else {
if (containStroke(x0, y0, x1, y1, lineWidth, x, y)) {
return dataIndex;
}
}
dataIndex++;
}
}
return -1;
};
LargeLinesPath2.prototype.contain = function(x, y) {
var localPos = this.transformCoordToLocal(x, y);
var rect = this.getBoundingRect();
x = localPos[0];
y = localPos[1];
if (rect.contain(x, y)) {
var dataIdx = this.hoverDataIdx = this.findDataIndex(x, y);
return dataIdx >= 0;
}
this.hoverDataIdx = -1;
return false;
};
LargeLinesPath2.prototype.getBoundingRect = function() {
var rect = this._rect;
if (!rect) {
var shape = this.shape;
var points = shape.segs;
var minX = Infinity;
var minY = Infinity;
var maxX = -Infinity;
var maxY = -Infinity;
for (var i = 0; i < points.length; ) {
var x = points[i++];
var y = points[i++];
minX = Math.min(x, minX);
maxX = Math.max(x, maxX);
minY = Math.min(y, minY);
maxY = Math.max(y, maxY);
}
rect = this._rect = new BoundingRect(minX, minY, maxX, maxY);
}
return rect;
};
return LargeLinesPath2;
}(Path);
var LargeLineDraw = function() {
function LargeLineDraw2() {
this.group = new Group();
}
LargeLineDraw2.prototype.updateData = function(data) {
this._clear();
var lineEl = this._create();
lineEl.setShape({
segs: data.getLayout("linesPoints")
});
this._setCommon(lineEl, data);
};
LargeLineDraw2.prototype.incrementalPrepareUpdate = function(data) {
this.group.removeAll();
this._clear();
};
LargeLineDraw2.prototype.incrementalUpdate = function(taskParams, data) {
var lastAdded = this._newAdded[0];
var linePoints = data.getLayout("linesPoints");
var oldSegs = lastAdded && lastAdded.shape.segs;
if (oldSegs && oldSegs.length < 2e4) {
var oldLen = oldSegs.length;
var newSegs = new Float32Array(oldLen + linePoints.length);
newSegs.set(oldSegs);
newSegs.set(linePoints, oldLen);
lastAdded.setShape({
segs: newSegs
});
} else {
this._newAdded = [];
var lineEl = this._create();
lineEl.incremental = true;
lineEl.setShape({
segs: linePoints
});
this._setCommon(lineEl, data);
lineEl.__startIndex = taskParams.start;
}
};
LargeLineDraw2.prototype.remove = function() {
this._clear();
};
LargeLineDraw2.prototype.eachRendered = function(cb) {
this._newAdded[0] && cb(this._newAdded[0]);
};
LargeLineDraw2.prototype._create = function() {
var lineEl = new LargeLinesPath({
cursor: "default",
ignoreCoarsePointer: true
});
this._newAdded.push(lineEl);
this.group.add(lineEl);
return lineEl;
};
LargeLineDraw2.prototype._setCommon = function(lineEl, data, isIncremental) {
var hostModel = data.hostModel;
lineEl.setShape({
polyline: hostModel.get("polyline"),
curveness: hostModel.get(["lineStyle", "curveness"])
});
lineEl.useStyle(hostModel.getModel("lineStyle").getLineStyle());
lineEl.style.strokeNoScale = true;
var style = data.getVisual("style");
if (style && style.stroke) {
lineEl.setStyle("stroke", style.stroke);
}
lineEl.setStyle("fill", null);
var ecData = getECData(lineEl);
ecData.seriesIndex = hostModel.seriesIndex;
lineEl.on("mousemove", function(e) {
ecData.dataIndex = null;
var dataIndex = lineEl.hoverDataIdx;
if (dataIndex > 0) {
ecData.dataIndex = dataIndex + lineEl.__startIndex;
}
});
};
LargeLineDraw2.prototype._clear = function() {
this._newAdded = [];
this.group.removeAll();
};
return LargeLineDraw2;
}();
var LargeLineDraw$1 = LargeLineDraw;
export { LargeLineDraw$1 as default };