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