@visactor/vchart
Version:
charts lib based @visactor/VGrammar
39 lines (35 loc) • 1.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.executeMediaQueryAction = void 0;
const vutils_extension_1 = require("@visactor/vutils-extension"), util_1 = require("../../../../util"), filter_1 = require("./filter"), executeMediaQueryAction = (action, query, chartSpec, chartSpecInfo) => {
const {spec: spec, filter: filter, filterType: filterType, forceAppend: forceAppend} = action, {isChart: isChart, modelType: modelType, specKey: specKey, type: type, modelInfo: modelInfo} = (0,
filter_1.executeMediaQueryActionFilter)(filterType, filter, action, query, chartSpec, chartSpecInfo);
if (0 === modelInfo.length && !forceAppend) return {
chartSpec: chartSpec,
hasChanged: !1
};
const targetSpec = (0, vutils_extension_1.mergeSpec)({}, chartSpec), newSpec = (0,
util_1.isFunction)(spec) ? spec(modelInfo, action, query) : spec;
for (const {spec: spec, specPath: specPath} of modelInfo) {
if (isChart) return {
chartSpec: (0, vutils_extension_1.mergeSpec)(targetSpec, newSpec),
hasChanged: !0
};
const modelSpec = (0, vutils_extension_1.mergeSpec)({}, spec, newSpec);
(0, vutils_extension_1.setProperty)(targetSpec, specPath, modelSpec);
}
if (0 === modelInfo.length && forceAppend) {
const newSpecToAppend = Object.assign({
type: type
}, newSpec);
(0, util_1.isArray)(targetSpec[specKey]) ? targetSpec[specKey].push(newSpecToAppend) : (0,
util_1.isNil)(targetSpec[specKey]) ? targetSpec[specKey] = "component" === modelType ? newSpecToAppend : [ newSpecToAppend ] : targetSpec[specKey] = [ targetSpec[specKey], newSpecToAppend ];
}
return {
chartSpec: targetSpec,
hasChanged: !0
};
};
exports.executeMediaQueryAction = executeMediaQueryAction;
//# sourceMappingURL=action.js.map