@visactor/vchart
Version:
charts lib based @visactor/VGrammar
35 lines (31 loc) • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.HorizontalBarSplitStrategy = void 0;
class HorizontalBarSplitStrategy {
constructor() {
this.name = "horizontalBarSplit";
}
shouldApply(mark, graphic) {
var _a, _b;
const isRectMark = "rect" === mark.type, isHorizontal = "horizontal" === (null === (_a = mark.model) || void 0 === _a ? void 0 : _a.direction), diffAttrs = (null === (_b = graphic.context) || void 0 === _b ? void 0 : _b.diffAttrs) || {};
return isRectMark && isHorizontal && ("y" in diffAttrs || "height" in diffAttrs || "y1" in diffAttrs) && ("x" in diffAttrs || "width" in diffAttrs || "x1" in diffAttrs);
}
split(mark, graphic) {
var _a;
const diffAttrs = (null === (_a = graphic.context) || void 0 === _a ? void 0 : _a.diffAttrs) || {}, dimensionAttrs = {}, valueAttrs = {};
Object.entries(diffAttrs).forEach((([key, value]) => {
"y" === key || "height" === key || "y1" === key ? dimensionAttrs[key] = value : "x" === key || "width" === key || "x1" === key ? valueAttrs[key] = value : dimensionAttrs[key] = value;
}));
const context = graphic.context, fieldY = context.fieldY, originalFieldY = context.originalFieldY, isGrouped = Array.isArray(fieldY) && fieldY.length > 1, group2stack = !(originalFieldY ? !(Array.isArray(originalFieldY) && originalFieldY.length > 1) : !isGrouped) && !isGrouped;
return [ {
attrs: dimensionAttrs,
order: group2stack ? 2 : 1
}, {
attrs: valueAttrs,
order: group2stack ? 1 : 2
} ];
}
}
exports.HorizontalBarSplitStrategy = HorizontalBarSplitStrategy;
//# sourceMappingURL=horizontal-bar-split.js.map