12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- var zrUtil = require("zrender/lib/core/util");
- var DEFAULT_TOOLBOX_BTNS = ['rect', 'polygon', 'keep', 'clear'];
- function _default(option, isNew) {
- var brushComponents = option && option.brush;
- if (!zrUtil.isArray(brushComponents)) {
- brushComponents = brushComponents ? [brushComponents] : [];
- }
- if (!brushComponents.length) {
- return;
- }
- var brushComponentSpecifiedBtns = [];
- zrUtil.each(brushComponents, function (brushOpt) {
- var tbs = brushOpt.hasOwnProperty('toolbox') ? brushOpt.toolbox : [];
- if (tbs instanceof Array) {
- brushComponentSpecifiedBtns = brushComponentSpecifiedBtns.concat(tbs);
- }
- });
- var toolbox = option && option.toolbox;
- if (zrUtil.isArray(toolbox)) {
- toolbox = toolbox[0];
- }
- if (!toolbox) {
- toolbox = {
- feature: {}
- };
- option.toolbox = [toolbox];
- }
- var toolboxFeature = toolbox.feature || (toolbox.feature = {});
- var toolboxBrush = toolboxFeature.brush || (toolboxFeature.brush = {});
- var brushTypes = toolboxBrush.type || (toolboxBrush.type = []);
- brushTypes.push.apply(brushTypes, brushComponentSpecifiedBtns);
- removeDuplicate(brushTypes);
- if (isNew && !brushTypes.length) {
- brushTypes.push.apply(brushTypes, DEFAULT_TOOLBOX_BTNS);
- }
- }
- function removeDuplicate(arr) {
- var map = {};
- zrUtil.each(arr, function (val) {
- map[val] = 1;
- });
- arr.length = 0;
- zrUtil.each(map, function (flag, val) {
- arr.push(val);
- });
- }
- module.exports = _default;
|