d3chart.options
Version:
options for d3chart
78 lines (62 loc) • 2.13 kB
JavaScript
var core = require('d3chart._core/core.js');
var buildLabel = require('./label.js');
var base = {
style: null,
//只接受 function
color: null,
label: {
formatter: null
}
};
function buildBase (custom) {
var settings = core.cloneDeep(base);
if (!core.isPlainObject(custom)) { return settings; }
//
if (custom.hasOwnProperty('style')) {
if (!core.isPlainObject(custom.style)) {
//给个默认值
custom.style = {};
} else {
//检查 CSS 样式是否标准
//TODO
}
}
//
if (custom.hasOwnProperty('attr')) {
if (!core.isPlainObject(custom.attr)) {
custom.attr = {};
} else {
//TODO
}
}
//
if (!core.isFunction(custom.color)) {
custom.color = null;
}
custom.label = buildLabel(custom.label);
return core.merge(settings, custom);
}
var itemStyle = {
normal: {},
emphasis: {}
};
var buildItemStyle = function (custom) {
var settings = core.cloneDeep(itemStyle);
settings.normal = core.merge(settings.normal,
core.cloneDeep(base));
settings.emphasis = core.merge(settings.emphasis,
core.cloneDeep(base));
if (!core.isPlainObject(custom)) { return settings; }
custom.normal = buildBase(custom.normal);
custom.emphasis = buildBase(custom.emphasis);
// 将 emphasis 中有但是 normal 中没有的样式【的名称】也分配给 normal 并赋值成 null,这是为了在从 emphasis 切换到 normal 时去掉 emphasis 中多余 normal 的样式
// 这里赋值为 null,暂定
// TODO,目测好像不需要,因为都是来自 Base
var fakeStyle = core.mapValues(custom.emphasis.style, function (k, v) { return null; });
custom.normal.style = core.merge(fakeStyle, custom.normal.style);
var fakeAttr = core.mapValues(custom.emphasis.attr, function (k, v) { return null; });
custom.normal.attr = core.merge(fakeAttr, custom.normal.attr);
return core.merge(settings, custom);
};
module.exports = buildItemStyle;