(option: ECUnitOption, isNew: boolean)
| 28 | const DEFAULT_TOOLBOX_BTNS: BrushToolboxIconType[] = ['rect', 'polygon', 'keep', 'clear']; |
| 29 | |
| 30 | export default function brushPreprocessor(option: ECUnitOption, isNew: boolean): void { |
| 31 | const brushComponents = normalizeToArray(option ? option.brush : []); |
| 32 | |
| 33 | if (!brushComponents.length) { |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | let brushComponentSpecifiedBtns = [] as string[]; |
| 38 | |
| 39 | zrUtil.each(brushComponents, function (brushOpt: BrushOption) { |
| 40 | const tbs = brushOpt.hasOwnProperty('toolbox') |
| 41 | ? brushOpt.toolbox : []; |
| 42 | |
| 43 | if (tbs instanceof Array) { |
| 44 | brushComponentSpecifiedBtns = brushComponentSpecifiedBtns.concat(tbs); |
| 45 | } |
| 46 | }); |
| 47 | |
| 48 | let toolbox: ToolboxOption = option && option.toolbox; |
| 49 | |
| 50 | if (zrUtil.isArray(toolbox)) { |
| 51 | toolbox = toolbox[0]; |
| 52 | } |
| 53 | if (!toolbox) { |
| 54 | toolbox = {feature: {}}; |
| 55 | option.toolbox = [toolbox]; |
| 56 | } |
| 57 | |
| 58 | const toolboxFeature = (toolbox.feature || (toolbox.feature = {})); |
| 59 | const toolboxBrush = (toolboxFeature.brush || (toolboxFeature.brush = {})) as ToolboxBrushFeatureOption; |
| 60 | const brushTypes = toolboxBrush.type || (toolboxBrush.type = []); |
| 61 | |
| 62 | brushTypes.push.apply(brushTypes, brushComponentSpecifiedBtns); |
| 63 | |
| 64 | removeDuplicates(brushTypes, item => item + '', null); |
| 65 | |
| 66 | if (isNew && !brushTypes.length) { |
| 67 | brushTypes.push.apply(brushTypes, DEFAULT_TOOLBOX_BTNS); |
| 68 | } |
| 69 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…