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