* Init a tree data structure from data in option series
(option: TreeSeriesOption)
| 151 | * Init a tree data structure from data in option series |
| 152 | */ |
| 153 | getInitialData(option: TreeSeriesOption): SeriesData { |
| 154 | |
| 155 | // create a virtual root |
| 156 | const root: TreeSeriesNodeItemOption = { |
| 157 | name: option.name, |
| 158 | children: option.data |
| 159 | }; |
| 160 | |
| 161 | const leaves = option.leaves || {}; |
| 162 | const leavesModel = new Model(leaves, this, this.ecModel); |
| 163 | |
| 164 | const tree = Tree.createTree(root, this, beforeLink); |
| 165 | |
| 166 | function beforeLink(nodeData: SeriesData) { |
| 167 | nodeData.wrapMethod('getItemModel', function (model, idx) { |
| 168 | const node = tree.getNodeByDataIndex(idx); |
| 169 | if (!(node && node.children.length && node.isExpand)) { |
| 170 | model.parentModel = leavesModel; |
| 171 | } |
| 172 | return model; |
| 173 | }); |
| 174 | } |
| 175 | |
| 176 | let treeDepth = 0; |
| 177 | |
| 178 | tree.eachNode('preorder', function (node) { |
| 179 | if (node.depth > treeDepth) { |
| 180 | treeDepth = node.depth; |
| 181 | } |
| 182 | }); |
| 183 | |
| 184 | const expandAndCollapse = option.expandAndCollapse; |
| 185 | const expandTreeDepth = (expandAndCollapse && option.initialTreeDepth >= 0) |
| 186 | ? option.initialTreeDepth : treeDepth; |
| 187 | |
| 188 | tree.root.eachNode('preorder', function (node) { |
| 189 | const item = node.hostTree.data.getRawDataItem(node.dataIndex) as TreeSeriesNodeItemOption; |
| 190 | // Add item.collapsed != null, because users can collapse node original in the series.data. |
| 191 | node.isExpand = (item && item.collapsed != null) |
| 192 | ? !item.collapsed |
| 193 | : node.depth <= expandTreeDepth; |
| 194 | }); |
| 195 | |
| 196 | return tree.data; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Make the configuration 'orient' backward compatibly, with 'horizontal = LR', 'vertical = TB'. |
nothing calls this directly
no test coverage detected