MCPcopy Index your code
hub / github.com/markmap/markmap / _initializeData

Method _initializeData

packages/markmap-view/src/view.ts:168–213  ·  view source on GitHub ↗
(node: IPureNode | INode)

Source from the content-addressed store, hash-verified

166 };
167
168 private _initializeData(node: IPureNode | INode) {
169 let nodeId = 0;
170 const { color, initialExpandLevel } = this.options;
171
172 let foldRecursively = 0;
173 let depth = 0;
174 walkTree(node as INode, (item, next, parent) => {
175 depth += 1;
176 item.children = item.children?.map((child) => ({ ...child }));
177 nodeId += 1;
178 item.state = {
179 ...item.state,
180 depth,
181 id: nodeId,
182 rect: {
183 x: 0,
184 y: 0,
185 width: 0,
186 height: 0,
187 },
188 size: [0, 0],
189 };
190 item.state.key =
191 [parent?.state?.id, item.state.id].filter(Boolean).join('.') +
192 simpleHash(item.content);
193 item.state.path = [parent?.state?.path, item.state.id]
194 .filter(Boolean)
195 .join('.');
196 color(item); // preload colors
197
198 const isFoldRecursively = item.payload?.fold === 2;
199 if (isFoldRecursively) {
200 foldRecursively += 1;
201 } else if (
202 foldRecursively ||
203 (initialExpandLevel >= 0 && item.state.depth >= initialExpandLevel)
204 ) {
205 item.payload = { ...item.payload, fold: 1 };
206 }
207 next();
208 if (isFoldRecursively) foldRecursively -= 1;
209 depth -= 1;
210 });
211
212 return node as INode;
213 }
214
215 private _relayout() {
216 if (!this.state.data) return;

Callers 1

setDataMethod · 0.95

Calls 2

walkTreeFunction · 0.90
simpleHashFunction · 0.90

Tested by

no test coverage detected