cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
80 lines (79 loc) • 2.56 kB
JavaScript
import { createHashMap, isArray, defaults } from "../../../../zrender/lib/core/util.mjs";
import { makeInner } from "../../util/model.mjs";
import Rect from "../../../../zrender/lib/graphic/shape/Rect.mjs";
var inner = makeInner();
function rectCoordAxisBuildSplitArea(axisView, axisGroup, axisModel, gridModel) {
var axis = axisModel.axis;
if (axis.scale.isBlank()) {
return;
}
var splitAreaModel = axisModel.getModel("splitArea");
var areaStyleModel = splitAreaModel.getModel("areaStyle");
var areaColors = areaStyleModel.get("color");
var gridRect = gridModel.coordinateSystem.getRect();
var ticksCoords = axis.getTicksCoords({
tickModel: splitAreaModel,
clamp: true
});
if (!ticksCoords.length) {
return;
}
var areaColorsLen = areaColors.length;
var lastSplitAreaColors = inner(axisView).splitAreaColors;
var newSplitAreaColors = createHashMap();
var colorIndex = 0;
if (lastSplitAreaColors) {
for (var i = 0; i < ticksCoords.length; i++) {
var cIndex = lastSplitAreaColors.get(ticksCoords[i].tickValue);
if (cIndex != null) {
colorIndex = (cIndex + (areaColorsLen - 1) * i) % areaColorsLen;
break;
}
}
}
var prev = axis.toGlobalCoord(ticksCoords[0].coord);
var areaStyle = areaStyleModel.getAreaStyle();
areaColors = isArray(areaColors) ? areaColors : [areaColors];
for (var i = 1; i < ticksCoords.length; i++) {
var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
var x = void 0;
var y = void 0;
var width = void 0;
var height = void 0;
if (axis.isHorizontal()) {
x = prev;
y = gridRect.y;
width = tickCoord - x;
height = gridRect.height;
prev = x + width;
} else {
x = gridRect.x;
y = prev;
width = gridRect.width;
height = tickCoord - y;
prev = y + height;
}
var tickValue = ticksCoords[i - 1].tickValue;
tickValue != null && newSplitAreaColors.set(tickValue, colorIndex);
axisGroup.add(new Rect({
anid: tickValue != null ? "area_" + tickValue : null,
shape: {
x,
y,
width,
height
},
style: defaults({
fill: areaColors[colorIndex]
}, areaStyle),
autoBatch: true,
silent: true
}));
colorIndex = (colorIndex + 1) % areaColorsLen;
}
inner(axisView).splitAreaColors = newSplitAreaColors;
}
function rectCoordAxisHandleRemove(axisView) {
inner(axisView).splitAreaColors = null;
}
export { rectCoordAxisBuildSplitArea, rectCoordAxisHandleRemove };