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