markmap-view 0.14.4 → 0.15.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index.cjs.js → browser/index.js} +311 -383
- package/dist/index.js +145 -588
- package/dist/{index.esm.js → index.mjs} +122 -359
- package/package.json +11 -13
- package/types/view.d.ts +3 -2
- package/dist/index.min.js +0 -5
|
@@ -1,49 +1,43 @@
|
|
|
1
|
-
/*! markmap-view v0.
|
|
2
|
-
import { Hook, getId, addClass, walkTree,
|
|
1
|
+
/*! markmap-view v0.15.0-alpha.0 | MIT License */
|
|
2
|
+
import { Hook, getId, addClass, walkTree, childSelector, noop } from 'markmap-common';
|
|
3
3
|
export { loadCSS, loadJS } from 'markmap-common';
|
|
4
4
|
import * as d3 from 'd3';
|
|
5
5
|
|
|
6
6
|
function _extends() {
|
|
7
|
-
_extends = Object.assign
|
|
7
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
8
8
|
for (var i = 1; i < arguments.length; i++) {
|
|
9
9
|
var source = arguments[i];
|
|
10
|
-
|
|
11
10
|
for (var key in source) {
|
|
12
11
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
13
12
|
target[key] = source[key];
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
return target;
|
|
19
17
|
};
|
|
20
|
-
|
|
21
18
|
return _extends.apply(this, arguments);
|
|
22
19
|
}
|
|
23
20
|
|
|
24
21
|
function count(node) {
|
|
25
22
|
var sum = 0,
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
children = node.children,
|
|
24
|
+
i = children && children.length;
|
|
28
25
|
if (!i) sum = 1;else while (--i >= 0) sum += children[i].value;
|
|
29
26
|
node.value = sum;
|
|
30
27
|
}
|
|
31
|
-
|
|
32
28
|
function node_count () {
|
|
33
29
|
return this.eachAfter(count);
|
|
34
30
|
}
|
|
35
31
|
|
|
36
32
|
function node_each (callback) {
|
|
37
33
|
var node = this,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
current,
|
|
35
|
+
next = [node],
|
|
36
|
+
children,
|
|
37
|
+
i,
|
|
38
|
+
n;
|
|
44
39
|
do {
|
|
45
40
|
current = next.reverse(), next = [];
|
|
46
|
-
|
|
47
41
|
while (node = current.pop()) {
|
|
48
42
|
callback(node), children = node.children;
|
|
49
43
|
if (children) for (i = 0, n = children.length; i < n; ++i) {
|
|
@@ -51,56 +45,48 @@ function node_each (callback) {
|
|
|
51
45
|
}
|
|
52
46
|
}
|
|
53
47
|
} while (next.length);
|
|
54
|
-
|
|
55
48
|
return this;
|
|
56
49
|
}
|
|
57
50
|
|
|
58
51
|
function node_eachBefore (callback) {
|
|
59
52
|
var node = this,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
nodes = [node],
|
|
54
|
+
children,
|
|
55
|
+
i;
|
|
64
56
|
while (node = nodes.pop()) {
|
|
65
57
|
callback(node), children = node.children;
|
|
66
58
|
if (children) for (i = children.length - 1; i >= 0; --i) {
|
|
67
59
|
nodes.push(children[i]);
|
|
68
60
|
}
|
|
69
61
|
}
|
|
70
|
-
|
|
71
62
|
return this;
|
|
72
63
|
}
|
|
73
64
|
|
|
74
65
|
function node_eachAfter (callback) {
|
|
75
66
|
var node = this,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
67
|
+
nodes = [node],
|
|
68
|
+
next = [],
|
|
69
|
+
children,
|
|
70
|
+
i,
|
|
71
|
+
n;
|
|
82
72
|
while (node = nodes.pop()) {
|
|
83
73
|
next.push(node), children = node.children;
|
|
84
74
|
if (children) for (i = 0, n = children.length; i < n; ++i) {
|
|
85
75
|
nodes.push(children[i]);
|
|
86
76
|
}
|
|
87
77
|
}
|
|
88
|
-
|
|
89
78
|
while (node = next.pop()) {
|
|
90
79
|
callback(node);
|
|
91
80
|
}
|
|
92
|
-
|
|
93
81
|
return this;
|
|
94
82
|
}
|
|
95
83
|
|
|
96
84
|
function node_sum (value) {
|
|
97
85
|
return this.eachAfter(function (node) {
|
|
98
86
|
var sum = +value(node.data) || 0,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
87
|
+
children = node.children,
|
|
88
|
+
i = children && children.length;
|
|
102
89
|
while (--i >= 0) sum += children[i].value;
|
|
103
|
-
|
|
104
90
|
node.value = sum;
|
|
105
91
|
});
|
|
106
92
|
}
|
|
@@ -115,49 +101,40 @@ function node_sort (compare) {
|
|
|
115
101
|
|
|
116
102
|
function node_path (end) {
|
|
117
103
|
var start = this,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
104
|
+
ancestor = leastCommonAncestor(start, end),
|
|
105
|
+
nodes = [start];
|
|
121
106
|
while (start !== ancestor) {
|
|
122
107
|
start = start.parent;
|
|
123
108
|
nodes.push(start);
|
|
124
109
|
}
|
|
125
|
-
|
|
126
110
|
var k = nodes.length;
|
|
127
|
-
|
|
128
111
|
while (end !== ancestor) {
|
|
129
112
|
nodes.splice(k, 0, end);
|
|
130
113
|
end = end.parent;
|
|
131
114
|
}
|
|
132
|
-
|
|
133
115
|
return nodes;
|
|
134
116
|
}
|
|
135
|
-
|
|
136
117
|
function leastCommonAncestor(a, b) {
|
|
137
118
|
if (a === b) return a;
|
|
138
119
|
var aNodes = a.ancestors(),
|
|
139
|
-
|
|
140
|
-
|
|
120
|
+
bNodes = b.ancestors(),
|
|
121
|
+
c = null;
|
|
141
122
|
a = aNodes.pop();
|
|
142
123
|
b = bNodes.pop();
|
|
143
|
-
|
|
144
124
|
while (a === b) {
|
|
145
125
|
c = a;
|
|
146
126
|
a = aNodes.pop();
|
|
147
127
|
b = bNodes.pop();
|
|
148
128
|
}
|
|
149
|
-
|
|
150
129
|
return c;
|
|
151
130
|
}
|
|
152
131
|
|
|
153
132
|
function node_ancestors () {
|
|
154
133
|
var node = this,
|
|
155
|
-
|
|
156
|
-
|
|
134
|
+
nodes = [node];
|
|
157
135
|
while (node = node.parent) {
|
|
158
136
|
nodes.push(node);
|
|
159
137
|
}
|
|
160
|
-
|
|
161
138
|
return nodes;
|
|
162
139
|
}
|
|
163
140
|
|
|
@@ -181,7 +158,7 @@ function node_leaves () {
|
|
|
181
158
|
|
|
182
159
|
function node_links () {
|
|
183
160
|
var root = this,
|
|
184
|
-
|
|
161
|
+
links = [];
|
|
185
162
|
root.each(function (node) {
|
|
186
163
|
if (node !== root) {
|
|
187
164
|
// Don’t include the root’s parent, if any.
|
|
@@ -196,21 +173,18 @@ function node_links () {
|
|
|
196
173
|
|
|
197
174
|
function hierarchy(data, children) {
|
|
198
175
|
var root = new Node$1(data),
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
176
|
+
valued = +data.value && (root.value = data.value),
|
|
177
|
+
node,
|
|
178
|
+
nodes = [root],
|
|
179
|
+
child,
|
|
180
|
+
childs,
|
|
181
|
+
i,
|
|
182
|
+
n;
|
|
206
183
|
if (children == null) children = defaultChildren;
|
|
207
|
-
|
|
208
184
|
while (node = nodes.pop()) {
|
|
209
185
|
if (valued) node.value = +node.data.value;
|
|
210
|
-
|
|
211
186
|
if ((childs = children(node.data)) && (n = childs.length)) {
|
|
212
187
|
node.children = new Array(n);
|
|
213
|
-
|
|
214
188
|
for (i = n - 1; i >= 0; --i) {
|
|
215
189
|
nodes.push(child = node.children[i] = new Node$1(childs[i]));
|
|
216
190
|
child.parent = node;
|
|
@@ -218,25 +192,19 @@ function hierarchy(data, children) {
|
|
|
218
192
|
}
|
|
219
193
|
}
|
|
220
194
|
}
|
|
221
|
-
|
|
222
195
|
return root.eachBefore(computeHeight);
|
|
223
196
|
}
|
|
224
|
-
|
|
225
197
|
function node_copy() {
|
|
226
198
|
return hierarchy(this).eachBefore(copyData);
|
|
227
199
|
}
|
|
228
|
-
|
|
229
200
|
function defaultChildren(d) {
|
|
230
201
|
return d.children;
|
|
231
202
|
}
|
|
232
|
-
|
|
233
203
|
function copyData(node) {
|
|
234
204
|
node.data = node.data.data;
|
|
235
205
|
}
|
|
236
|
-
|
|
237
206
|
function computeHeight(node) {
|
|
238
207
|
var height = 0;
|
|
239
|
-
|
|
240
208
|
do node.height = height; while ((node = node.parent) && node.height < ++height);
|
|
241
209
|
}
|
|
242
210
|
function Node$1(data) {
|
|
@@ -260,110 +228,29 @@ Node$1.prototype = hierarchy.prototype = {
|
|
|
260
228
|
copy: node_copy
|
|
261
229
|
};
|
|
262
230
|
|
|
263
|
-
var
|
|
264
|
-
var version$1 = "2.1.2";
|
|
265
|
-
var main = "build/d3-flextree.js";
|
|
266
|
-
var module = "index";
|
|
267
|
-
var author = {
|
|
268
|
-
name: "Chris Maloney",
|
|
269
|
-
url: "http://chrismaloney.org"
|
|
270
|
-
};
|
|
271
|
-
var description = "Flexible tree layout algorithm that allows for variable node sizes.";
|
|
272
|
-
var keywords = [
|
|
273
|
-
"d3",
|
|
274
|
-
"d3-module",
|
|
275
|
-
"layout",
|
|
276
|
-
"tree",
|
|
277
|
-
"hierarchy",
|
|
278
|
-
"d3-hierarchy",
|
|
279
|
-
"plugin",
|
|
280
|
-
"d3-plugin",
|
|
281
|
-
"infovis",
|
|
282
|
-
"visualization",
|
|
283
|
-
"2d"
|
|
284
|
-
];
|
|
285
|
-
var homepage = "https://github.com/klortho/d3-flextree";
|
|
286
|
-
var license = "WTFPL";
|
|
287
|
-
var repository = {
|
|
288
|
-
type: "git",
|
|
289
|
-
url: "https://github.com/klortho/d3-flextree.git"
|
|
290
|
-
};
|
|
291
|
-
var scripts = {
|
|
292
|
-
clean: "rm -rf build demo test",
|
|
293
|
-
"build:demo": "rollup -c --environment BUILD:demo",
|
|
294
|
-
"build:dev": "rollup -c --environment BUILD:dev",
|
|
295
|
-
"build:prod": "rollup -c --environment BUILD:prod",
|
|
296
|
-
"build:test": "rollup -c --environment BUILD:test",
|
|
297
|
-
build: "rollup -c",
|
|
298
|
-
lint: "eslint index.js src",
|
|
299
|
-
"test:main": "node test/bundle.js",
|
|
300
|
-
"test:browser": "node test/browser-tests.js",
|
|
301
|
-
test: "npm-run-all test:*",
|
|
302
|
-
prepare: "npm-run-all clean build lint test"
|
|
303
|
-
};
|
|
304
|
-
var dependencies = {
|
|
305
|
-
"d3-hierarchy": "^1.1.5"
|
|
306
|
-
};
|
|
307
|
-
var devDependencies = {
|
|
308
|
-
"babel-plugin-external-helpers": "^6.22.0",
|
|
309
|
-
"babel-preset-es2015-rollup": "^3.0.0",
|
|
310
|
-
d3: "^4.13.0",
|
|
311
|
-
"d3-selection-multi": "^1.0.1",
|
|
312
|
-
eslint: "^4.19.1",
|
|
313
|
-
jsdom: "^11.6.2",
|
|
314
|
-
"npm-run-all": "^4.1.2",
|
|
315
|
-
rollup: "^0.55.3",
|
|
316
|
-
"rollup-plugin-babel": "^2.7.1",
|
|
317
|
-
"rollup-plugin-commonjs": "^8.0.2",
|
|
318
|
-
"rollup-plugin-copy": "^0.2.3",
|
|
319
|
-
"rollup-plugin-json": "^2.3.0",
|
|
320
|
-
"rollup-plugin-node-resolve": "^3.0.2",
|
|
321
|
-
"rollup-plugin-uglify": "^3.0.0",
|
|
322
|
-
"uglify-es": "^3.3.9"
|
|
323
|
-
};
|
|
324
|
-
var packageInfo = {
|
|
325
|
-
name: name,
|
|
326
|
-
version: version$1,
|
|
327
|
-
main: main,
|
|
328
|
-
module: module,
|
|
329
|
-
"jsnext:main": "index",
|
|
330
|
-
author: author,
|
|
331
|
-
description: description,
|
|
332
|
-
keywords: keywords,
|
|
333
|
-
homepage: homepage,
|
|
334
|
-
license: license,
|
|
335
|
-
repository: repository,
|
|
336
|
-
scripts: scripts,
|
|
337
|
-
dependencies: dependencies,
|
|
338
|
-
devDependencies: devDependencies
|
|
339
|
-
};
|
|
231
|
+
var version = "2.1.1";
|
|
340
232
|
|
|
341
|
-
const {
|
|
342
|
-
version
|
|
343
|
-
} = packageInfo;
|
|
344
233
|
const defaults = Object.freeze({
|
|
345
234
|
children: data => data.children,
|
|
346
235
|
nodeSize: node => node.data.size,
|
|
347
236
|
spacing: 0
|
|
348
|
-
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// Create a layout function with customizable options. Per D3-style, the
|
|
349
240
|
// options can be set at any time using setter methods. The layout function
|
|
350
241
|
// will compute the tree node positions based on the options in effect at the
|
|
351
242
|
// time it is called.
|
|
352
|
-
|
|
353
243
|
function flextree(options) {
|
|
354
244
|
const opts = Object.assign({}, defaults, options);
|
|
355
|
-
|
|
356
245
|
function accessor(name) {
|
|
357
246
|
const opt = opts[name];
|
|
358
247
|
return typeof opt === 'function' ? opt : () => opt;
|
|
359
248
|
}
|
|
360
|
-
|
|
361
249
|
function layout(tree) {
|
|
362
250
|
const wtree = wrap(getWrapper(), tree, node => node.children);
|
|
363
251
|
wtree.update();
|
|
364
252
|
return wtree.data;
|
|
365
253
|
}
|
|
366
|
-
|
|
367
254
|
function getFlexNode() {
|
|
368
255
|
const nodeSize = accessor('nodeSize');
|
|
369
256
|
const spacing = accessor('spacing');
|
|
@@ -371,78 +258,60 @@ function flextree(options) {
|
|
|
371
258
|
constructor(data) {
|
|
372
259
|
super(data);
|
|
373
260
|
}
|
|
374
|
-
|
|
375
261
|
copy() {
|
|
376
262
|
const c = wrap(this.constructor, this, node => node.children);
|
|
377
263
|
c.each(node => node.data = node.data.data);
|
|
378
264
|
return c;
|
|
379
265
|
}
|
|
380
|
-
|
|
381
266
|
get size() {
|
|
382
267
|
return nodeSize(this);
|
|
383
268
|
}
|
|
384
|
-
|
|
385
269
|
spacing(oNode) {
|
|
386
270
|
return spacing(this, oNode);
|
|
387
271
|
}
|
|
388
|
-
|
|
389
272
|
get nodes() {
|
|
390
273
|
return this.descendants();
|
|
391
274
|
}
|
|
392
|
-
|
|
393
275
|
get xSize() {
|
|
394
276
|
return this.size[0];
|
|
395
277
|
}
|
|
396
|
-
|
|
397
278
|
get ySize() {
|
|
398
279
|
return this.size[1];
|
|
399
280
|
}
|
|
400
|
-
|
|
401
281
|
get top() {
|
|
402
282
|
return this.y;
|
|
403
283
|
}
|
|
404
|
-
|
|
405
284
|
get bottom() {
|
|
406
285
|
return this.y + this.ySize;
|
|
407
286
|
}
|
|
408
|
-
|
|
409
287
|
get left() {
|
|
410
288
|
return this.x - this.xSize / 2;
|
|
411
289
|
}
|
|
412
|
-
|
|
413
290
|
get right() {
|
|
414
291
|
return this.x + this.xSize / 2;
|
|
415
292
|
}
|
|
416
|
-
|
|
417
293
|
get root() {
|
|
418
294
|
const ancs = this.ancestors();
|
|
419
295
|
return ancs[ancs.length - 1];
|
|
420
296
|
}
|
|
421
|
-
|
|
422
297
|
get numChildren() {
|
|
423
298
|
return this.hasChildren ? this.children.length : 0;
|
|
424
299
|
}
|
|
425
|
-
|
|
426
300
|
get hasChildren() {
|
|
427
301
|
return !this.noChildren;
|
|
428
302
|
}
|
|
429
|
-
|
|
430
303
|
get noChildren() {
|
|
431
304
|
return this.children === null;
|
|
432
305
|
}
|
|
433
|
-
|
|
434
306
|
get firstChild() {
|
|
435
307
|
return this.hasChildren ? this.children[0] : null;
|
|
436
308
|
}
|
|
437
|
-
|
|
438
309
|
get lastChild() {
|
|
439
310
|
return this.hasChildren ? this.children[this.numChildren - 1] : null;
|
|
440
311
|
}
|
|
441
|
-
|
|
442
312
|
get extents() {
|
|
443
313
|
return (this.children || []).reduce((acc, kid) => FlexNode.maxExtents(acc, kid.extents), this.nodeExtents);
|
|
444
314
|
}
|
|
445
|
-
|
|
446
315
|
get nodeExtents() {
|
|
447
316
|
return {
|
|
448
317
|
top: this.top,
|
|
@@ -451,7 +320,6 @@ function flextree(options) {
|
|
|
451
320
|
right: this.right
|
|
452
321
|
};
|
|
453
322
|
}
|
|
454
|
-
|
|
455
323
|
static maxExtents(e0, e1) {
|
|
456
324
|
return {
|
|
457
325
|
top: Math.min(e0.top, e1.top),
|
|
@@ -460,10 +328,8 @@ function flextree(options) {
|
|
|
460
328
|
right: Math.max(e0.right, e1.right)
|
|
461
329
|
};
|
|
462
330
|
}
|
|
463
|
-
|
|
464
331
|
};
|
|
465
332
|
}
|
|
466
|
-
|
|
467
333
|
function getWrapper() {
|
|
468
334
|
const FlexNode = getFlexNode();
|
|
469
335
|
const nodeSize = accessor('nodeSize');
|
|
@@ -486,40 +352,31 @@ function flextree(options) {
|
|
|
486
352
|
rThr: null
|
|
487
353
|
});
|
|
488
354
|
}
|
|
489
|
-
|
|
490
355
|
get size() {
|
|
491
356
|
return nodeSize(this.data);
|
|
492
357
|
}
|
|
493
|
-
|
|
494
358
|
spacing(oNode) {
|
|
495
359
|
return spacing(this.data, oNode.data);
|
|
496
360
|
}
|
|
497
|
-
|
|
498
361
|
get x() {
|
|
499
362
|
return this.data.x;
|
|
500
363
|
}
|
|
501
|
-
|
|
502
364
|
set x(v) {
|
|
503
365
|
this.data.x = v;
|
|
504
366
|
}
|
|
505
|
-
|
|
506
367
|
get y() {
|
|
507
368
|
return this.data.y;
|
|
508
369
|
}
|
|
509
|
-
|
|
510
370
|
set y(v) {
|
|
511
371
|
this.data.y = v;
|
|
512
372
|
}
|
|
513
|
-
|
|
514
373
|
update() {
|
|
515
374
|
layoutChildren(this);
|
|
516
375
|
resolveX(this);
|
|
517
376
|
return this;
|
|
518
377
|
}
|
|
519
|
-
|
|
520
378
|
};
|
|
521
379
|
}
|
|
522
|
-
|
|
523
380
|
function wrap(FlexClass, treeData, children) {
|
|
524
381
|
const _wrap = (data, parent) => {
|
|
525
382
|
const node = new FlexClass(data);
|
|
@@ -531,41 +388,32 @@ function flextree(options) {
|
|
|
531
388
|
});
|
|
532
389
|
const kidsData = children(data) || [];
|
|
533
390
|
node.children = kidsData.length === 0 ? null : kidsData.map(kd => _wrap(kd, node));
|
|
534
|
-
|
|
535
391
|
if (node.children) {
|
|
536
392
|
Object.assign(node, node.children.reduce((hl, kid) => ({
|
|
537
393
|
height: Math.max(hl.height, kid.height + 1),
|
|
538
394
|
length: hl.length + kid.length
|
|
539
395
|
}), node));
|
|
540
396
|
}
|
|
541
|
-
|
|
542
397
|
return node;
|
|
543
398
|
};
|
|
544
|
-
|
|
545
399
|
return _wrap(treeData, null);
|
|
546
400
|
}
|
|
547
|
-
|
|
548
401
|
Object.assign(layout, {
|
|
549
402
|
nodeSize(arg) {
|
|
550
403
|
return arguments.length ? (opts.nodeSize = arg, layout) : opts.nodeSize;
|
|
551
404
|
},
|
|
552
|
-
|
|
553
405
|
spacing(arg) {
|
|
554
406
|
return arguments.length ? (opts.spacing = arg, layout) : opts.spacing;
|
|
555
407
|
},
|
|
556
|
-
|
|
557
408
|
children(arg) {
|
|
558
409
|
return arguments.length ? (opts.children = arg, layout) : opts.children;
|
|
559
410
|
},
|
|
560
|
-
|
|
561
411
|
hierarchy(treeData, children) {
|
|
562
412
|
const kids = typeof children === 'undefined' ? opts.children : children;
|
|
563
413
|
return wrap(getFlexNode(), treeData, kids);
|
|
564
414
|
},
|
|
565
|
-
|
|
566
415
|
dump(tree) {
|
|
567
416
|
const nodeSize = accessor('nodeSize');
|
|
568
|
-
|
|
569
417
|
const _dump = i0 => node => {
|
|
570
418
|
const i1 = i0 + ' ';
|
|
571
419
|
const i2 = i0 + ' ';
|
|
@@ -578,22 +426,19 @@ function flextree(options) {
|
|
|
578
426
|
const kdumps = kids.length === 0 ? ' ' : `,${i1}children: [${i2}${kids.map(_dump(i2)).join(i2)}${i1}],${i0}`;
|
|
579
427
|
return `{ size: [${size.join(', ')}],${i1}x: ${x}, y: ${y}${kdumps}},`;
|
|
580
428
|
};
|
|
581
|
-
|
|
582
429
|
return _dump('\n')(tree);
|
|
583
430
|
}
|
|
584
|
-
|
|
585
431
|
});
|
|
586
432
|
return layout;
|
|
587
433
|
}
|
|
588
434
|
flextree.version = version;
|
|
589
|
-
|
|
590
435
|
const layoutChildren = (w, y = 0) => {
|
|
591
436
|
w.y = y;
|
|
592
437
|
(w.children || []).reduce((acc, kid) => {
|
|
593
438
|
const [i, lastLows] = acc;
|
|
594
|
-
layoutChildren(kid, w.y + w.ySize);
|
|
439
|
+
layoutChildren(kid, w.y + w.ySize);
|
|
440
|
+
// The lowest vertical coordinate while extreme nodes still point
|
|
595
441
|
// in current subtree.
|
|
596
|
-
|
|
597
442
|
const lowY = (i === 0 ? kid.lExt : kid.rExt).bottom;
|
|
598
443
|
if (i !== 0) separate(w, i, lastLows);
|
|
599
444
|
const lows = updateLows(lowY, i, lastLows);
|
|
@@ -602,12 +447,12 @@ const layoutChildren = (w, y = 0) => {
|
|
|
602
447
|
shiftChange(w);
|
|
603
448
|
positionRoot(w);
|
|
604
449
|
return w;
|
|
605
|
-
};
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
// Resolves the relative coordinate properties - relX and prelim --
|
|
606
453
|
// to set the final, absolute x coordinate for each node. This also sets
|
|
607
454
|
// `prelim` to 0, so that `relX` for each node is its x-coordinate relative
|
|
608
455
|
// to its parent.
|
|
609
|
-
|
|
610
|
-
|
|
611
456
|
const resolveX = (w, prevSum, parentX) => {
|
|
612
457
|
// A call to resolveX without arguments is assumed to be for the root of
|
|
613
458
|
// the tree. This will set the root's x-coord to zero.
|
|
@@ -615,17 +460,16 @@ const resolveX = (w, prevSum, parentX) => {
|
|
|
615
460
|
prevSum = -w.relX - w.prelim;
|
|
616
461
|
parentX = 0;
|
|
617
462
|
}
|
|
618
|
-
|
|
619
463
|
const sum = prevSum + w.relX;
|
|
620
464
|
w.relX = sum + w.prelim - parentX;
|
|
621
465
|
w.prelim = 0;
|
|
622
466
|
w.x = parentX + w.relX;
|
|
623
467
|
(w.children || []).forEach(k => resolveX(k, sum, w.x));
|
|
624
468
|
return w;
|
|
625
|
-
};
|
|
626
|
-
// each child's modifier.
|
|
627
|
-
|
|
469
|
+
};
|
|
628
470
|
|
|
471
|
+
// Process shift and change for all children, to add intermediate spacing to
|
|
472
|
+
// each child's modifier.
|
|
629
473
|
const shiftChange = w => {
|
|
630
474
|
(w.children || []).reduce((acc, child) => {
|
|
631
475
|
const [lastShiftSum, lastChangeSum] = acc;
|
|
@@ -634,11 +478,10 @@ const shiftChange = w => {
|
|
|
634
478
|
child.relX += changeSum;
|
|
635
479
|
return [shiftSum, changeSum];
|
|
636
480
|
}, [0, 0]);
|
|
637
|
-
};
|
|
481
|
+
};
|
|
638
482
|
|
|
483
|
+
// Separates the latest child from its previous sibling
|
|
639
484
|
/* eslint-disable complexity */
|
|
640
|
-
|
|
641
|
-
|
|
642
485
|
const separate = (w, i, lows) => {
|
|
643
486
|
const lSib = w.children[i - 1];
|
|
644
487
|
const curSubtree = w.children[i];
|
|
@@ -647,56 +490,49 @@ const separate = (w, i, lows) => {
|
|
|
647
490
|
let lContour = curSubtree;
|
|
648
491
|
let lSumMods = curSubtree.relX;
|
|
649
492
|
let isFirst = true;
|
|
650
|
-
|
|
651
493
|
while (rContour && lContour) {
|
|
652
|
-
if (rContour.bottom > lows.lowY) lows = lows.next;
|
|
494
|
+
if (rContour.bottom > lows.lowY) lows = lows.next;
|
|
495
|
+
// How far to the left of the right side of rContour is the left side
|
|
653
496
|
// of lContour? First compute the center-to-center distance, then add
|
|
654
497
|
// the "spacing"
|
|
655
|
-
|
|
656
498
|
const dist = rSumMods + rContour.prelim - (lSumMods + lContour.prelim) + rContour.xSize / 2 + lContour.xSize / 2 + rContour.spacing(lContour);
|
|
657
|
-
|
|
658
499
|
if (dist > 0 || dist < 0 && isFirst) {
|
|
659
|
-
lSumMods += dist;
|
|
660
|
-
|
|
500
|
+
lSumMods += dist;
|
|
501
|
+
// Move subtree by changing relX.
|
|
661
502
|
moveSubtree(curSubtree, dist);
|
|
662
503
|
distributeExtra(w, i, lows.index, dist);
|
|
663
504
|
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
505
|
+
isFirst = false;
|
|
506
|
+
// Advance highest node(s) and sum(s) of modifiers
|
|
667
507
|
const rightBottom = rContour.bottom;
|
|
668
508
|
const leftBottom = lContour.bottom;
|
|
669
|
-
|
|
670
509
|
if (rightBottom <= leftBottom) {
|
|
671
510
|
rContour = nextRContour(rContour);
|
|
672
511
|
if (rContour) rSumMods += rContour.relX;
|
|
673
512
|
}
|
|
674
|
-
|
|
675
513
|
if (rightBottom >= leftBottom) {
|
|
676
514
|
lContour = nextLContour(lContour);
|
|
677
515
|
if (lContour) lSumMods += lContour.relX;
|
|
678
516
|
}
|
|
679
|
-
}
|
|
517
|
+
}
|
|
518
|
+
// Set threads and update extreme nodes. In the first case, the
|
|
680
519
|
// current subtree is taller than the left siblings.
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
if (!rContour && lContour) setLThr(w, i, lContour, lSumMods); // In the next case, the left siblings are taller than the current subtree
|
|
520
|
+
if (!rContour && lContour) setLThr(w, i, lContour, lSumMods);
|
|
521
|
+
// In the next case, the left siblings are taller than the current subtree
|
|
684
522
|
else if (rContour && !lContour) setRThr(w, i, rContour, rSumMods);
|
|
685
523
|
};
|
|
686
524
|
/* eslint-enable complexity */
|
|
687
|
-
// Move subtree by changing relX.
|
|
688
|
-
|
|
689
525
|
|
|
526
|
+
// Move subtree by changing relX.
|
|
690
527
|
const moveSubtree = (subtree, distance) => {
|
|
691
528
|
subtree.relX += distance;
|
|
692
529
|
subtree.lExtRelX += distance;
|
|
693
530
|
subtree.rExtRelX += distance;
|
|
694
531
|
};
|
|
695
|
-
|
|
696
532
|
const distributeExtra = (w, curSubtreeI, leftSibI, dist) => {
|
|
697
533
|
const curSubtree = w.children[curSubtreeI];
|
|
698
|
-
const n = curSubtreeI - leftSibI;
|
|
699
|
-
|
|
534
|
+
const n = curSubtreeI - leftSibI;
|
|
535
|
+
// Are there intermediate children?
|
|
700
536
|
if (n > 1) {
|
|
701
537
|
const delta = dist / n;
|
|
702
538
|
w.children[leftSibI + 1].shift += delta;
|
|
@@ -704,31 +540,28 @@ const distributeExtra = (w, curSubtreeI, leftSibI, dist) => {
|
|
|
704
540
|
curSubtree.change -= dist - delta;
|
|
705
541
|
}
|
|
706
542
|
};
|
|
707
|
-
|
|
708
543
|
const nextLContour = w => {
|
|
709
544
|
return w.hasChildren ? w.firstChild : w.lThr;
|
|
710
545
|
};
|
|
711
|
-
|
|
712
546
|
const nextRContour = w => {
|
|
713
547
|
return w.hasChildren ? w.lastChild : w.rThr;
|
|
714
548
|
};
|
|
715
|
-
|
|
716
549
|
const setLThr = (w, i, lContour, lSumMods) => {
|
|
717
550
|
const firstChild = w.firstChild;
|
|
718
551
|
const lExt = firstChild.lExt;
|
|
719
552
|
const curSubtree = w.children[i];
|
|
720
|
-
lExt.lThr = lContour;
|
|
721
|
-
|
|
553
|
+
lExt.lThr = lContour;
|
|
554
|
+
// Change relX so that the sum of modifier after following thread is correct.
|
|
722
555
|
const diff = lSumMods - lContour.relX - firstChild.lExtRelX;
|
|
723
|
-
lExt.relX += diff;
|
|
724
|
-
|
|
725
|
-
lExt.prelim -= diff;
|
|
726
|
-
|
|
556
|
+
lExt.relX += diff;
|
|
557
|
+
// Change preliminary x coordinate so that the node does not move.
|
|
558
|
+
lExt.prelim -= diff;
|
|
559
|
+
// Update extreme node and its sum of modifiers.
|
|
727
560
|
firstChild.lExt = curSubtree.lExt;
|
|
728
561
|
firstChild.lExtRelX = curSubtree.lExtRelX;
|
|
729
|
-
};
|
|
730
|
-
|
|
562
|
+
};
|
|
731
563
|
|
|
564
|
+
// Mirror image of setLThr.
|
|
732
565
|
const setRThr = (w, i, rContour, rSumMods) => {
|
|
733
566
|
const curSubtree = w.children[i];
|
|
734
567
|
const rExt = curSubtree.rExt;
|
|
@@ -739,9 +572,9 @@ const setRThr = (w, i, rContour, rSumMods) => {
|
|
|
739
572
|
rExt.prelim -= diff;
|
|
740
573
|
curSubtree.rExt = lSib.rExt;
|
|
741
574
|
curSubtree.rExtRelX = lSib.rExtRelX;
|
|
742
|
-
};
|
|
743
|
-
|
|
575
|
+
};
|
|
744
576
|
|
|
577
|
+
// Position root between children, taking into account their modifiers
|
|
745
578
|
const positionRoot = w => {
|
|
746
579
|
if (w.hasChildren) {
|
|
747
580
|
const k0 = w.firstChild;
|
|
@@ -755,15 +588,14 @@ const positionRoot = w => {
|
|
|
755
588
|
rExtRelX: kf.rExtRelX
|
|
756
589
|
});
|
|
757
590
|
}
|
|
758
|
-
};
|
|
759
|
-
// lowest vertical coordinate.
|
|
760
|
-
|
|
591
|
+
};
|
|
761
592
|
|
|
593
|
+
// Make/maintain a linked list of the indexes of left siblings and their
|
|
594
|
+
// lowest vertical coordinate.
|
|
762
595
|
const updateLows = (lowY, index, lastLows) => {
|
|
763
596
|
// Remove siblings that are hidden by the new subtree.
|
|
764
|
-
while (lastLows !== null && lowY >= lastLows.lowY) lastLows = lastLows.next;
|
|
765
|
-
|
|
766
|
-
|
|
597
|
+
while (lastLows !== null && lowY >= lastLows.lowY) lastLows = lastLows.next;
|
|
598
|
+
// Prepend the new subtree.
|
|
767
599
|
return {
|
|
768
600
|
lowY,
|
|
769
601
|
index,
|
|
@@ -783,19 +615,15 @@ var NS_ATTRS = {
|
|
|
783
615
|
actuate: XLINK_NS,
|
|
784
616
|
href: XLINK_NS
|
|
785
617
|
};
|
|
786
|
-
|
|
787
618
|
var isLeaf = function isLeaf(c) {
|
|
788
619
|
return typeof c === 'string' || typeof c === 'number';
|
|
789
620
|
};
|
|
790
|
-
|
|
791
621
|
var isElement = function isElement(c) {
|
|
792
622
|
return (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
|
|
793
623
|
};
|
|
794
|
-
|
|
795
624
|
var isRenderFunction = function isRenderFunction(c) {
|
|
796
625
|
return (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
|
|
797
626
|
};
|
|
798
|
-
|
|
799
627
|
function jsx(type, props) {
|
|
800
628
|
var vtype;
|
|
801
629
|
if (typeof type === 'string') vtype = VTYPE_ELEMENT;else if (typeof type === 'function') vtype = VTYPE_FUNCTION;else throw new Error('Invalid VNode type');
|
|
@@ -805,15 +633,12 @@ function jsx(type, props) {
|
|
|
805
633
|
props: props
|
|
806
634
|
};
|
|
807
635
|
}
|
|
808
|
-
|
|
809
636
|
function Fragment(props) {
|
|
810
637
|
return props.children;
|
|
811
638
|
}
|
|
812
|
-
|
|
813
639
|
var DEFAULT_ENV = {
|
|
814
640
|
isSvg: false
|
|
815
641
|
};
|
|
816
|
-
|
|
817
642
|
function insertDom(parent, ref) {
|
|
818
643
|
if (ref.type === MOUNT_SINGLE) {
|
|
819
644
|
if (ref.node != null) parent.append(ref.node);
|
|
@@ -825,11 +650,9 @@ function insertDom(parent, ref) {
|
|
|
825
650
|
throw new Error("Unkown ref type " + JSON.stringify(ref));
|
|
826
651
|
}
|
|
827
652
|
}
|
|
828
|
-
|
|
829
653
|
function mountAttributes(domElement, props, env) {
|
|
830
654
|
for (var key in props) {
|
|
831
655
|
if (key === 'key' || key === 'children' || key === 'ref') continue;
|
|
832
|
-
|
|
833
656
|
if (key === 'dangerouslySetInnerHTML') {
|
|
834
657
|
domElement.innerHTML = props[key].__html;
|
|
835
658
|
} else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText') {
|
|
@@ -841,22 +664,18 @@ function mountAttributes(domElement, props, env) {
|
|
|
841
664
|
}
|
|
842
665
|
}
|
|
843
666
|
}
|
|
844
|
-
|
|
845
667
|
var attrMap = {
|
|
846
668
|
className: 'class',
|
|
847
669
|
labelFor: 'for'
|
|
848
670
|
};
|
|
849
|
-
|
|
850
671
|
function setDOMAttribute(el, attr, value, isSVG) {
|
|
851
672
|
attr = attrMap[attr] || attr;
|
|
852
|
-
|
|
853
673
|
if (value === true) {
|
|
854
674
|
el.setAttribute(attr, '');
|
|
855
675
|
} else if (value === false) {
|
|
856
676
|
el.removeAttribute(attr);
|
|
857
677
|
} else {
|
|
858
678
|
var namespace = isSVG ? NS_ATTRS[attr] : undefined;
|
|
859
|
-
|
|
860
679
|
if (namespace !== undefined) {
|
|
861
680
|
el.setAttributeNS(namespace, attr, value);
|
|
862
681
|
} else {
|
|
@@ -864,91 +683,72 @@ function setDOMAttribute(el, attr, value, isSVG) {
|
|
|
864
683
|
}
|
|
865
684
|
}
|
|
866
685
|
}
|
|
867
|
-
|
|
868
686
|
function mount(vnode, env) {
|
|
869
687
|
if (env === void 0) {
|
|
870
688
|
env = DEFAULT_ENV;
|
|
871
689
|
}
|
|
872
|
-
|
|
873
690
|
if (vnode == null || typeof vnode === 'boolean') {
|
|
874
691
|
return {
|
|
875
692
|
type: MOUNT_SINGLE,
|
|
876
693
|
node: null
|
|
877
694
|
};
|
|
878
695
|
}
|
|
879
|
-
|
|
880
696
|
if (vnode instanceof Node) {
|
|
881
697
|
return {
|
|
882
698
|
type: MOUNT_SINGLE,
|
|
883
699
|
node: vnode
|
|
884
700
|
};
|
|
885
701
|
}
|
|
886
|
-
|
|
887
702
|
if (isRenderFunction(vnode)) {
|
|
888
703
|
var _ref = vnode,
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
704
|
+
type = _ref.type,
|
|
705
|
+
props = _ref.props;
|
|
892
706
|
if (type === Fragment) {
|
|
893
707
|
var node = document.createDocumentFragment();
|
|
894
|
-
|
|
895
708
|
if (props.children) {
|
|
896
709
|
var childrenRef = mount(props.children, env);
|
|
897
710
|
insertDom(node, childrenRef);
|
|
898
711
|
}
|
|
899
|
-
|
|
900
712
|
return {
|
|
901
713
|
type: MOUNT_SINGLE,
|
|
902
714
|
node: node
|
|
903
715
|
};
|
|
904
716
|
}
|
|
905
|
-
|
|
906
717
|
var childVNode = type(props);
|
|
907
718
|
return mount(childVNode, env);
|
|
908
719
|
}
|
|
909
|
-
|
|
910
720
|
if (isLeaf(vnode)) {
|
|
911
721
|
return {
|
|
912
722
|
type: MOUNT_SINGLE,
|
|
913
723
|
node: document.createTextNode("" + vnode)
|
|
914
724
|
};
|
|
915
725
|
}
|
|
916
|
-
|
|
917
726
|
if (isElement(vnode)) {
|
|
918
727
|
var _node;
|
|
919
|
-
|
|
920
728
|
var _ref2 = vnode,
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
729
|
+
_type = _ref2.type,
|
|
730
|
+
_props = _ref2.props;
|
|
924
731
|
if (!env.isSvg && _type === 'svg') {
|
|
925
732
|
env = Object.assign({}, env, {
|
|
926
733
|
isSvg: true
|
|
927
734
|
});
|
|
928
735
|
}
|
|
929
|
-
|
|
930
736
|
if (!env.isSvg) {
|
|
931
737
|
_node = document.createElement(_type);
|
|
932
738
|
} else {
|
|
933
739
|
_node = document.createElementNS(SVG_NS, _type);
|
|
934
740
|
}
|
|
935
|
-
|
|
936
741
|
mountAttributes(_node, _props, env);
|
|
937
|
-
|
|
938
742
|
var _childrenRef;
|
|
939
|
-
|
|
940
743
|
if (_props.children) {
|
|
941
744
|
var childEnv = env;
|
|
942
|
-
|
|
943
745
|
if (env.isSvg && _type === 'foreignObject') {
|
|
944
746
|
childEnv = Object.assign({}, childEnv, {
|
|
945
747
|
isSvg: false
|
|
946
748
|
});
|
|
947
749
|
}
|
|
948
|
-
|
|
949
750
|
_childrenRef = mount(_props.children, childEnv);
|
|
950
751
|
}
|
|
951
|
-
|
|
952
752
|
if (_childrenRef != null) insertDom(_node, _childrenRef);
|
|
953
753
|
var ref = _props.ref;
|
|
954
754
|
if (typeof ref === 'function') ref(_node);
|
|
@@ -957,7 +757,6 @@ function mount(vnode, env) {
|
|
|
957
757
|
node: _node
|
|
958
758
|
};
|
|
959
759
|
}
|
|
960
|
-
|
|
961
760
|
if (Array.isArray(vnode)) {
|
|
962
761
|
return {
|
|
963
762
|
type: MOUNT_ARRAY,
|
|
@@ -966,52 +765,42 @@ function mount(vnode, env) {
|
|
|
966
765
|
})
|
|
967
766
|
};
|
|
968
767
|
}
|
|
969
|
-
|
|
970
768
|
throw new Error('mount: Invalid Vnode!');
|
|
971
769
|
}
|
|
972
|
-
|
|
973
770
|
function flattenWithoutNull(array) {
|
|
974
771
|
var result = [];
|
|
975
|
-
|
|
976
772
|
for (var i = 0; i < array.length; i += 1) {
|
|
977
773
|
var item = array[i];
|
|
978
774
|
if (Array.isArray(item)) result = result.concat(flattenWithoutNull(item));else if (item != null) result.push(item);
|
|
979
775
|
}
|
|
980
|
-
|
|
981
776
|
return result;
|
|
982
777
|
}
|
|
983
|
-
|
|
984
778
|
function asDom(result) {
|
|
985
779
|
if (result.type === MOUNT_SINGLE) {
|
|
986
780
|
return result.node;
|
|
987
781
|
}
|
|
988
|
-
|
|
989
782
|
return result.children.map(asDom);
|
|
990
783
|
}
|
|
991
784
|
/**
|
|
992
785
|
* Mount vdom as real DOM nodes.
|
|
993
786
|
*/
|
|
994
787
|
|
|
995
|
-
|
|
996
788
|
function mountDom(vnode) {
|
|
997
789
|
if (Array.isArray(vnode)) {
|
|
998
790
|
return flattenWithoutNull(vnode.map(mountDom));
|
|
999
791
|
}
|
|
1000
|
-
|
|
1001
792
|
return asDom(mount(vnode));
|
|
1002
793
|
}
|
|
1003
794
|
|
|
1004
|
-
var css_248z$1 = ".markmap{font:300 16px/20px sans-serif}.markmap-link{fill:none}.markmap-node>circle{cursor:pointer}.markmap-foreign{display:inline-block}.markmap-foreign a{color:#0097e6}.markmap-foreign a:hover{color:#00a8ff}.markmap-foreign code{background-color:#f0f0f0;border-radius:2px;color:#555;font-size:calc(1em - 2px)}.markmap-foreign :not(pre)>code{padding:.2em .4em}.markmap-foreign del{text-decoration:line-through}.markmap-foreign em{font-style:italic}.markmap-foreign strong{font-weight:
|
|
795
|
+
var css_248z$1 = ".markmap{font:300 16px/20px sans-serif}.markmap-link{fill:none}.markmap-node>circle{cursor:pointer}.markmap-foreign{display:inline-block}.markmap-foreign a{color:#0097e6}.markmap-foreign a:hover{color:#00a8ff}.markmap-foreign code{background-color:#f0f0f0;border-radius:2px;color:#555;font-size:calc(1em - 2px)}.markmap-foreign :not(pre)>code{padding:.2em .4em}.markmap-foreign del{text-decoration:line-through}.markmap-foreign em{font-style:italic}.markmap-foreign strong{font-weight:700}.markmap-foreign mark{background:#ffeaa7}.markmap-foreign pre,.markmap-foreign pre[class*=language-]{margin:0;padding:.2em .4em}";
|
|
1005
796
|
|
|
1006
797
|
var css_248z = ".markmap-container{height:0;left:-100px;overflow:hidden;position:absolute;top:-100px;width:0}.markmap-container>.markmap-foreign{display:inline-block}.markmap-container>.markmap-foreign>div:last-child{white-space:nowrap}";
|
|
1007
798
|
|
|
1008
799
|
const globalCSS = css_248z$1;
|
|
1009
|
-
|
|
1010
800
|
function linkWidth(nodeData) {
|
|
1011
801
|
const data = nodeData.data;
|
|
1012
802
|
return Math.max(4 - 2 * data.depth, 1.5);
|
|
1013
803
|
}
|
|
1014
|
-
|
|
1015
804
|
function adjustSpacing(tree, spacing) {
|
|
1016
805
|
walkTree(tree, (d, next) => {
|
|
1017
806
|
d.ySizeInner = d.ySize - spacing;
|
|
@@ -1019,26 +808,22 @@ function adjustSpacing(tree, spacing) {
|
|
|
1019
808
|
next();
|
|
1020
809
|
}, 'children');
|
|
1021
810
|
}
|
|
1022
|
-
|
|
1023
811
|
function minBy(numbers, by) {
|
|
1024
812
|
const index = d3.minIndex(numbers, by);
|
|
1025
813
|
return numbers[index];
|
|
1026
814
|
}
|
|
1027
|
-
|
|
1028
815
|
function stopPropagation(e) {
|
|
1029
816
|
e.stopPropagation();
|
|
1030
817
|
}
|
|
1031
|
-
|
|
1032
818
|
function createViewHooks() {
|
|
1033
819
|
return {
|
|
1034
820
|
transformHtml: new Hook()
|
|
1035
821
|
};
|
|
1036
822
|
}
|
|
823
|
+
|
|
1037
824
|
/**
|
|
1038
825
|
* A global hook to refresh all markmaps when called.
|
|
1039
826
|
*/
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
827
|
const refreshHook = new Hook();
|
|
1043
828
|
const defaultColorFn = d3.scaleOrdinal(d3.schemeCategory10);
|
|
1044
829
|
const isMacintosh = typeof navigator !== 'undefined' && navigator.userAgent.includes('Macintosh');
|
|
@@ -1056,7 +841,6 @@ class Markmap {
|
|
|
1056
841
|
// Pan with wheels, zoom with ctrl+wheels
|
|
1057
842
|
if (event.type === 'wheel') return event.ctrlKey && !event.button;
|
|
1058
843
|
}
|
|
1059
|
-
|
|
1060
844
|
return (!event.ctrlKey || event.type === 'wheel') && !event.button;
|
|
1061
845
|
}).on('zoom', this.handleZoom);
|
|
1062
846
|
this.setOptions(opts);
|
|
@@ -1068,7 +852,6 @@ class Markmap {
|
|
|
1068
852
|
this.setData();
|
|
1069
853
|
}));
|
|
1070
854
|
}
|
|
1071
|
-
|
|
1072
855
|
getStyleContent() {
|
|
1073
856
|
const {
|
|
1074
857
|
style
|
|
@@ -1079,39 +862,45 @@ class Markmap {
|
|
|
1079
862
|
const styleText = typeof style === 'function' ? style(id) : '';
|
|
1080
863
|
return [this.options.embedGlobalCSS && css_248z$1, styleText].filter(Boolean).join('\n');
|
|
1081
864
|
}
|
|
1082
|
-
|
|
1083
865
|
updateStyle() {
|
|
1084
866
|
this.svg.attr('class', addClass(this.svg.attr('class'), 'markmap', this.state.id));
|
|
1085
867
|
const style = this.getStyleContent();
|
|
1086
868
|
this.styleNode.text(style);
|
|
1087
869
|
}
|
|
1088
|
-
|
|
1089
870
|
handleZoom(e) {
|
|
1090
871
|
const {
|
|
1091
872
|
transform
|
|
1092
873
|
} = e;
|
|
1093
874
|
this.g.attr('transform', transform);
|
|
1094
875
|
}
|
|
1095
|
-
|
|
1096
876
|
handlePan(e) {
|
|
1097
877
|
e.preventDefault();
|
|
1098
878
|
const transform = d3.zoomTransform(this.svg.node());
|
|
1099
879
|
const newTransform = transform.translate(-e.deltaX / transform.k, -e.deltaY / transform.k);
|
|
1100
880
|
this.svg.call(this.zoom.transform, newTransform);
|
|
1101
881
|
}
|
|
1102
|
-
|
|
1103
|
-
handleClick(_, d) {
|
|
882
|
+
toggleNode(data, recursive = false) {
|
|
1104
883
|
var _data$payload;
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
884
|
+
const fold = (_data$payload = data.payload) != null && _data$payload.fold ? 0 : 1;
|
|
885
|
+
if (recursive) {
|
|
886
|
+
// recursively
|
|
887
|
+
walkTree(data, (item, next) => {
|
|
888
|
+
item.payload = _extends({}, item.payload, {
|
|
889
|
+
fold
|
|
890
|
+
});
|
|
891
|
+
next();
|
|
892
|
+
});
|
|
893
|
+
} else {
|
|
894
|
+
var _data$payload2;
|
|
895
|
+
data.payload = _extends({}, data.payload, {
|
|
896
|
+
fold: (_data$payload2 = data.payload) != null && _data$payload2.fold ? 0 : 1
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
this.renderData(data);
|
|
900
|
+
}
|
|
901
|
+
handleClick(e, d) {
|
|
902
|
+
this.toggleNode(d.data, e.ctrlKey);
|
|
1113
903
|
}
|
|
1114
|
-
|
|
1115
904
|
initializeData(node) {
|
|
1116
905
|
let nodeId = 0;
|
|
1117
906
|
const {
|
|
@@ -1134,7 +923,6 @@ class Markmap {
|
|
|
1134
923
|
let foldRecursively = 0;
|
|
1135
924
|
walkTree(node, (item, next, parent) => {
|
|
1136
925
|
var _item$children, _parent$state, _item$payload;
|
|
1137
|
-
|
|
1138
926
|
item.children = (_item$children = item.children) == null ? void 0 : _item$children.map(child => _extends({}, child));
|
|
1139
927
|
nodeId += 1;
|
|
1140
928
|
const group = mountDom(jsx("div", {
|
|
@@ -1151,11 +939,10 @@ class Markmap {
|
|
|
1151
939
|
id: nodeId,
|
|
1152
940
|
el: group.firstChild
|
|
1153
941
|
});
|
|
1154
|
-
item.state.path = [parent == null
|
|
942
|
+
item.state.path = [parent == null || (_parent$state = parent.state) == null ? void 0 : _parent$state.path, item.state.id].filter(Boolean).join('.');
|
|
1155
943
|
color(item); // preload colors
|
|
1156
944
|
|
|
1157
945
|
const isFoldRecursively = ((_item$payload = item.payload) == null ? void 0 : _item$payload.fold) === 2;
|
|
1158
|
-
|
|
1159
946
|
if (isFoldRecursively) {
|
|
1160
947
|
foldRecursively += 1;
|
|
1161
948
|
} else if (foldRecursively || initialExpandLevel >= 0 && item.depth >= initialExpandLevel) {
|
|
@@ -1163,45 +950,40 @@ class Markmap {
|
|
|
1163
950
|
fold: 1
|
|
1164
951
|
});
|
|
1165
952
|
}
|
|
1166
|
-
|
|
1167
953
|
next();
|
|
1168
954
|
if (isFoldRecursively) foldRecursively -= 1;
|
|
1169
955
|
});
|
|
1170
|
-
const nodes =
|
|
1171
|
-
this.viewHooks.transformHtml.call(this, nodes);
|
|
956
|
+
const nodes = Array.from(container.childNodes).map(group => group.firstChild);
|
|
957
|
+
this.viewHooks.transformHtml.call(this, nodes);
|
|
958
|
+
// Clone the rendered HTML and set `white-space: nowrap` to it to detect its max-width.
|
|
1172
959
|
// The parent node will have a width of the max-width and the original content without
|
|
1173
960
|
// `white-space: nowrap` gets re-layouted, then we will get the expected layout, with
|
|
1174
961
|
// content in one line as much as possible, and subjecting to the given max-width.
|
|
1175
|
-
|
|
1176
962
|
nodes.forEach(node => {
|
|
1177
963
|
node.parentNode.append(node.cloneNode(true));
|
|
1178
964
|
});
|
|
1179
965
|
walkTree(node, (item, next, parent) => {
|
|
1180
966
|
var _parent$state2;
|
|
1181
|
-
|
|
1182
967
|
const rect = item.state.el.getBoundingClientRect();
|
|
1183
968
|
item.content = item.state.el.innerHTML;
|
|
1184
969
|
item.state.size = [Math.ceil(rect.width) + 1, Math.max(Math.ceil(rect.height), nodeMinHeight)];
|
|
1185
|
-
item.state.key = [parent == null
|
|
970
|
+
item.state.key = [parent == null || (_parent$state2 = parent.state) == null ? void 0 : _parent$state2.id, item.state.id].filter(Boolean).join('.') +
|
|
971
|
+
// FIXME: find a way to check content hash
|
|
1186
972
|
item.content;
|
|
1187
973
|
next();
|
|
1188
974
|
});
|
|
1189
975
|
container.remove();
|
|
1190
976
|
style.remove();
|
|
1191
977
|
}
|
|
1192
|
-
|
|
1193
978
|
setOptions(opts) {
|
|
1194
979
|
this.options = _extends({}, Markmap.defaultOptions, opts);
|
|
1195
|
-
|
|
1196
980
|
if (this.options.zoom) {
|
|
1197
981
|
this.svg.call(this.zoom);
|
|
1198
982
|
} else {
|
|
1199
983
|
this.svg.on('.zoom', null);
|
|
1200
984
|
}
|
|
1201
|
-
|
|
1202
985
|
this.svg.on('wheel', this.options.pan ? this.handlePan : null);
|
|
1203
986
|
}
|
|
1204
|
-
|
|
1205
987
|
setData(data, opts) {
|
|
1206
988
|
if (data) this.state.data = data;
|
|
1207
989
|
if (opts) this.setOptions(opts);
|
|
@@ -1209,10 +991,8 @@ class Markmap {
|
|
|
1209
991
|
this.updateStyle();
|
|
1210
992
|
this.renderData();
|
|
1211
993
|
}
|
|
1212
|
-
|
|
1213
994
|
renderData(originData) {
|
|
1214
995
|
var _origin$data$state$x, _origin$data$state$y;
|
|
1215
|
-
|
|
1216
996
|
if (!this.state.data) return;
|
|
1217
997
|
const {
|
|
1218
998
|
spacingHorizontal,
|
|
@@ -1223,7 +1003,6 @@ class Markmap {
|
|
|
1223
1003
|
} = this.options;
|
|
1224
1004
|
const layout = flextree().children(d => {
|
|
1225
1005
|
var _d$payload;
|
|
1226
|
-
|
|
1227
1006
|
return !((_d$payload = d.payload) != null && _d$payload.fold) && d.children;
|
|
1228
1007
|
}).nodeSize(d => {
|
|
1229
1008
|
const [width, height] = d.data.state.size;
|
|
@@ -1250,8 +1029,9 @@ class Markmap {
|
|
|
1250
1029
|
if (autoFit) this.fit();
|
|
1251
1030
|
const origin = originData && descendants.find(item => item.data === originData) || tree;
|
|
1252
1031
|
const x0 = (_origin$data$state$x = origin.data.state.x0) != null ? _origin$data$state$x : origin.x;
|
|
1253
|
-
const y0 = (_origin$data$state$y = origin.data.state.y0) != null ? _origin$data$state$y : origin.y;
|
|
1032
|
+
const y0 = (_origin$data$state$y = origin.data.state.y0) != null ? _origin$data$state$y : origin.y;
|
|
1254
1033
|
|
|
1034
|
+
// Update the nodes
|
|
1255
1035
|
const node = this.g.selectAll(childSelector('g')).data(descendants, d => d.data.state.key);
|
|
1256
1036
|
const nodeEnter = node.enter().append('g').attr('data-depth', d => d.data.depth).attr('data-path', d => d.data.state.path).attr('transform', d => `translate(${y0 + origin.ySizeInner - d.ySizeInner},${x0 + origin.xSize / 2 - d.xSize})`);
|
|
1257
1037
|
const nodeExit = this.transition(node.exit());
|
|
@@ -1260,22 +1040,22 @@ class Markmap {
|
|
|
1260
1040
|
nodeExit.attr('transform', d => `translate(${origin.y + origin.ySizeInner - d.ySizeInner},${origin.x + origin.xSize / 2 - d.xSize})`).remove();
|
|
1261
1041
|
const nodeMerge = node.merge(nodeEnter).attr('class', d => {
|
|
1262
1042
|
var _d$data$payload;
|
|
1263
|
-
|
|
1264
1043
|
return ['markmap-node', ((_d$data$payload = d.data.payload) == null ? void 0 : _d$data$payload.fold) && 'markmap-fold'].filter(Boolean).join(' ');
|
|
1265
1044
|
});
|
|
1266
|
-
this.transition(nodeMerge).attr('transform', d => `translate(${d.y},${d.x - d.xSize / 2})`);
|
|
1045
|
+
this.transition(nodeMerge).attr('transform', d => `translate(${d.y},${d.x - d.xSize / 2})`);
|
|
1267
1046
|
|
|
1047
|
+
// Update lines under the content
|
|
1268
1048
|
const line = nodeMerge.selectAll(childSelector('line')).data(d => [d], d => d.data.state.key).join(enter => {
|
|
1269
1049
|
return enter.append('line').attr('x1', d => d.ySizeInner).attr('x2', d => d.ySizeInner);
|
|
1270
1050
|
}, update => update, exit => exit.remove());
|
|
1271
|
-
this.transition(line).attr('x1', -1).attr('x2', d => d.ySizeInner + 2).attr('y1', d => d.xSize).attr('y2', d => d.xSize).attr('stroke', d => color(d.data)).attr('stroke-width', linkWidth);
|
|
1051
|
+
this.transition(line).attr('x1', -1).attr('x2', d => d.ySizeInner + 2).attr('y1', d => d.xSize).attr('y2', d => d.xSize).attr('stroke', d => color(d.data)).attr('stroke-width', linkWidth);
|
|
1272
1052
|
|
|
1053
|
+
// Circle to link to children of the node
|
|
1273
1054
|
const circle = nodeMerge.selectAll(childSelector('circle')).data(d => d.data.children ? [d] : [], d => d.data.state.key).join(enter => {
|
|
1274
|
-
return enter.append('circle').attr('stroke-width', '1.5').attr('cx', d => d.ySizeInner).attr('cy', d => d.xSize).attr('r', 0).on('click', (e, d) => this.handleClick(e, d));
|
|
1055
|
+
return enter.append('circle').attr('stroke-width', '1.5').attr('cx', d => d.ySizeInner).attr('cy', d => d.xSize).attr('r', 0).on('click', (e, d) => this.handleClick(e, d)).on('mousedown', stopPropagation);
|
|
1275
1056
|
}, update => update, exit => exit.remove());
|
|
1276
1057
|
this.transition(circle).attr('r', 6).attr('cx', d => d.ySizeInner).attr('cy', d => d.xSize).attr('stroke', d => color(d.data)).attr('fill', d => {
|
|
1277
1058
|
var _d$data$payload2;
|
|
1278
|
-
|
|
1279
1059
|
return (_d$data$payload2 = d.data.payload) != null && _d$data$payload2.fold && d.data.children ? color(d.data) : '#fff';
|
|
1280
1060
|
});
|
|
1281
1061
|
const foreignObject = nodeMerge.selectAll(childSelector('foreignObject')).data(d => [d], d => d.data.state.key).join(enter => {
|
|
@@ -1287,8 +1067,9 @@ class Markmap {
|
|
|
1287
1067
|
}).attr('xmlns', 'http://www.w3.org/1999/xhtml');
|
|
1288
1068
|
return fo;
|
|
1289
1069
|
}, update => update, exit => exit.remove()).attr('width', d => Math.max(0, d.ySizeInner - paddingX * 2)).attr('height', d => d.xSize);
|
|
1290
|
-
this.transition(foreignObject).style('opacity', 1);
|
|
1070
|
+
this.transition(foreignObject).style('opacity', 1);
|
|
1291
1071
|
|
|
1072
|
+
// Update the links
|
|
1292
1073
|
const path = this.g.selectAll(childSelector('path')).data(links, d => d.target.data.state.key).join(enter => {
|
|
1293
1074
|
const source = [y0 + origin.ySizeInner, x0 + origin.xSize / 2];
|
|
1294
1075
|
return enter.insert('path', 'g').attr('class', 'markmap-link').attr('data-depth', d => d.target.data.depth).attr('data-path', d => d.target.data.state.path).attr('d', linkShape({
|
|
@@ -1315,18 +1096,16 @@ class Markmap {
|
|
|
1315
1096
|
d.data.state.y0 = d.y;
|
|
1316
1097
|
});
|
|
1317
1098
|
}
|
|
1318
|
-
|
|
1319
1099
|
transition(sel) {
|
|
1320
1100
|
const {
|
|
1321
1101
|
duration
|
|
1322
1102
|
} = this.options;
|
|
1323
1103
|
return sel.transition().duration(duration);
|
|
1324
1104
|
}
|
|
1105
|
+
|
|
1325
1106
|
/**
|
|
1326
1107
|
* Fit the content to the viewport.
|
|
1327
1108
|
*/
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
1109
|
async fit() {
|
|
1331
1110
|
const svgNode = this.svg.node();
|
|
1332
1111
|
const {
|
|
@@ -1348,49 +1127,43 @@ class Markmap {
|
|
|
1348
1127
|
const initialZoom = d3.zoomIdentity.translate((offsetWidth - naturalWidth * scale) / 2 - minY * scale, (offsetHeight - naturalHeight * scale) / 2 - minX * scale).scale(scale);
|
|
1349
1128
|
return this.transition(this.svg).call(this.zoom.transform, initialZoom).end().catch(noop);
|
|
1350
1129
|
}
|
|
1130
|
+
|
|
1351
1131
|
/**
|
|
1352
1132
|
* Pan the content to make the provided node visible in the viewport.
|
|
1353
1133
|
*/
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
1134
|
async ensureView(node, padding) {
|
|
1357
|
-
let g;
|
|
1358
1135
|
let itemData;
|
|
1359
1136
|
this.g.selectAll(childSelector('g')).each(function walk(d) {
|
|
1360
1137
|
if (d.data === node) {
|
|
1361
|
-
g = this;
|
|
1362
1138
|
itemData = d;
|
|
1363
1139
|
}
|
|
1364
1140
|
});
|
|
1365
|
-
if (!
|
|
1141
|
+
if (!itemData) return;
|
|
1366
1142
|
const svgNode = this.svg.node();
|
|
1367
1143
|
const relRect = svgNode.getBoundingClientRect();
|
|
1368
1144
|
const transform = d3.zoomTransform(svgNode);
|
|
1369
1145
|
const [left, right] = [itemData.y, itemData.y + itemData.ySizeInner + 2].map(x => x * transform.k + transform.x);
|
|
1370
|
-
const [top, bottom] = [itemData.x - itemData.xSize / 2, itemData.x + itemData.xSize / 2].map(y => y * transform.k + transform.y);
|
|
1371
|
-
|
|
1146
|
+
const [top, bottom] = [itemData.x - itemData.xSize / 2, itemData.x + itemData.xSize / 2].map(y => y * transform.k + transform.y);
|
|
1147
|
+
// Skip if the node includes or is included in the container.
|
|
1372
1148
|
const pd = _extends({
|
|
1373
1149
|
left: 0,
|
|
1374
1150
|
right: 0,
|
|
1375
1151
|
top: 0,
|
|
1376
1152
|
bottom: 0
|
|
1377
1153
|
}, padding);
|
|
1378
|
-
|
|
1379
1154
|
const dxs = [pd.left - left, relRect.width - pd.right - right];
|
|
1380
1155
|
const dys = [pd.top - top, relRect.height - pd.bottom - bottom];
|
|
1381
1156
|
const dx = dxs[0] * dxs[1] > 0 ? minBy(dxs, Math.abs) / transform.k : 0;
|
|
1382
1157
|
const dy = dys[0] * dys[1] > 0 ? minBy(dys, Math.abs) / transform.k : 0;
|
|
1383
|
-
|
|
1384
1158
|
if (dx || dy) {
|
|
1385
1159
|
const newTransform = transform.translate(dx, dy);
|
|
1386
1160
|
return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(noop);
|
|
1387
1161
|
}
|
|
1388
1162
|
}
|
|
1163
|
+
|
|
1389
1164
|
/**
|
|
1390
1165
|
* Scale content with it pinned at the center of the viewport.
|
|
1391
1166
|
*/
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
1167
|
async rescale(scale) {
|
|
1395
1168
|
const svgNode = this.svg.node();
|
|
1396
1169
|
const {
|
|
@@ -1403,7 +1176,6 @@ class Markmap {
|
|
|
1403
1176
|
const newTransform = transform.translate((halfWidth - transform.x) * (1 - scale) / transform.k, (halfHeight - transform.y) * (1 - scale) / transform.k).scale(scale);
|
|
1404
1177
|
return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(noop);
|
|
1405
1178
|
}
|
|
1406
|
-
|
|
1407
1179
|
destroy() {
|
|
1408
1180
|
this.svg.on('.zoom', null);
|
|
1409
1181
|
this.svg.html(null);
|
|
@@ -1411,10 +1183,8 @@ class Markmap {
|
|
|
1411
1183
|
fn();
|
|
1412
1184
|
});
|
|
1413
1185
|
}
|
|
1414
|
-
|
|
1415
1186
|
static create(svg, opts, data) {
|
|
1416
1187
|
const mm = new Markmap(svg, opts);
|
|
1417
|
-
|
|
1418
1188
|
if (data) {
|
|
1419
1189
|
mm.setData(data);
|
|
1420
1190
|
mm.fit(); // always fit for the first render
|
|
@@ -1422,7 +1192,6 @@ class Markmap {
|
|
|
1422
1192
|
|
|
1423
1193
|
return mm;
|
|
1424
1194
|
}
|
|
1425
|
-
|
|
1426
1195
|
}
|
|
1427
1196
|
Markmap.defaultOptions = {
|
|
1428
1197
|
autoFit: false,
|
|
@@ -1447,20 +1216,15 @@ function deriveOptions(jsonOptions) {
|
|
|
1447
1216
|
color,
|
|
1448
1217
|
colorFreezeLevel
|
|
1449
1218
|
} = jsonOptions;
|
|
1450
|
-
|
|
1451
1219
|
if ((color == null ? void 0 : color.length) === 1) {
|
|
1452
1220
|
const solidColor = color[0];
|
|
1453
|
-
|
|
1454
1221
|
opts.color = () => solidColor;
|
|
1455
1222
|
} else if (color != null && color.length) {
|
|
1456
1223
|
const colorFn = d3.scaleOrdinal(color);
|
|
1457
|
-
|
|
1458
1224
|
opts.color = node => colorFn(`${node.state.path}`);
|
|
1459
1225
|
}
|
|
1460
|
-
|
|
1461
1226
|
if (colorFreezeLevel) {
|
|
1462
1227
|
const color = opts.color || Markmap.defaultOptions.color;
|
|
1463
|
-
|
|
1464
1228
|
opts.color = node => {
|
|
1465
1229
|
node = _extends({}, node, {
|
|
1466
1230
|
state: _extends({}, node.state, {
|
|
@@ -1470,7 +1234,6 @@ function deriveOptions(jsonOptions) {
|
|
|
1470
1234
|
return color(node);
|
|
1471
1235
|
};
|
|
1472
1236
|
}
|
|
1473
|
-
|
|
1474
1237
|
const numberKeys = ['duration', 'maxWidth', 'initialExpandLevel'];
|
|
1475
1238
|
numberKeys.forEach(key => {
|
|
1476
1239
|
const value = jsonOptions[key];
|