markmap-view 0.18.5 → 0.18.8
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/browser/index.js +31 -25
- package/dist/constants.d.ts +2 -1
- package/dist/index.js +373 -368
- package/dist/types.d.ts +1 -0
- package/dist/view.d.ts +21 -1
- package/package.json +8 -8
package/dist/browser/index.js
CHANGED
|
@@ -327,31 +327,33 @@
|
|
|
327
327
|
}
|
|
328
328
|
const isMacintosh = typeof navigator !== "undefined" && navigator.userAgent.includes("Macintosh");
|
|
329
329
|
const defaultColorFn = d32.scaleOrdinal(d32.schemeCategory10);
|
|
330
|
+
const lineWidthFactory = (baseWidth = 1, deltaWidth = 3, k = 2) => (node) => baseWidth + deltaWidth / k ** node.state.depth;
|
|
330
331
|
const defaultOptions = {
|
|
331
332
|
autoFit: false,
|
|
332
|
-
color: (node) => {
|
|
333
|
-
var _a;
|
|
334
|
-
return defaultColorFn(`${((_a = node.state) == null ? void 0 : _a.path) || ""}`);
|
|
335
|
-
},
|
|
336
333
|
duration: 500,
|
|
337
334
|
embedGlobalCSS: true,
|
|
338
335
|
fitRatio: 0.95,
|
|
339
336
|
maxInitialScale: 2,
|
|
340
|
-
maxWidth: 0,
|
|
341
|
-
nodeMinHeight: 16,
|
|
342
|
-
paddingX: 8,
|
|
343
337
|
scrollForPan: isMacintosh,
|
|
344
|
-
spacingHorizontal: 80,
|
|
345
|
-
spacingVertical: 5,
|
|
346
338
|
initialExpandLevel: -1,
|
|
347
339
|
zoom: true,
|
|
348
340
|
pan: true,
|
|
349
|
-
toggleRecursively: false
|
|
341
|
+
toggleRecursively: false,
|
|
342
|
+
color: (node) => {
|
|
343
|
+
var _a;
|
|
344
|
+
return defaultColorFn(`${((_a = node.state) == null ? void 0 : _a.path) || ""}`);
|
|
345
|
+
},
|
|
346
|
+
lineWidth: lineWidthFactory(),
|
|
347
|
+
maxWidth: 0,
|
|
348
|
+
nodeMinHeight: 16,
|
|
349
|
+
paddingX: 8,
|
|
350
|
+
spacingHorizontal: 80,
|
|
351
|
+
spacingVertical: 5
|
|
350
352
|
};
|
|
351
353
|
function deriveOptions(jsonOptions) {
|
|
352
354
|
const derivedOptions = {};
|
|
353
355
|
const options = { ...jsonOptions };
|
|
354
|
-
const { color, colorFreezeLevel } = options;
|
|
356
|
+
const { color, colorFreezeLevel, lineWidth } = options;
|
|
355
357
|
if ((color == null ? void 0 : color.length) === 1) {
|
|
356
358
|
const solidColor = color[0];
|
|
357
359
|
derivedOptions.color = () => solidColor;
|
|
@@ -372,6 +374,12 @@
|
|
|
372
374
|
return color2(node);
|
|
373
375
|
};
|
|
374
376
|
}
|
|
377
|
+
if (lineWidth) {
|
|
378
|
+
const args = Array.isArray(lineWidth) ? lineWidth : [lineWidth, 0, 1];
|
|
379
|
+
derivedOptions.lineWidth = lineWidthFactory(
|
|
380
|
+
...args
|
|
381
|
+
);
|
|
382
|
+
}
|
|
375
383
|
const numberKeys = [
|
|
376
384
|
"duration",
|
|
377
385
|
"fitRatio",
|
|
@@ -948,9 +956,6 @@
|
|
|
948
956
|
const SELECTOR_LINK = "path.markmap-link";
|
|
949
957
|
const SELECTOR_HIGHLIGHT = "g.markmap-highlight";
|
|
950
958
|
const linkShape = d32.linkHorizontal();
|
|
951
|
-
function linkWidth(data) {
|
|
952
|
-
return Math.max(4 - 2 * data.state.depth, 1.5);
|
|
953
|
-
}
|
|
954
959
|
function minBy(numbers, by) {
|
|
955
960
|
const index = d32.minIndex(numbers, by);
|
|
956
961
|
return numbers[index];
|
|
@@ -961,7 +966,7 @@
|
|
|
961
966
|
const refreshHook = new Hook();
|
|
962
967
|
class Markmap {
|
|
963
968
|
constructor(svg, opts) {
|
|
964
|
-
this.options = defaultOptions;
|
|
969
|
+
this.options = { ...defaultOptions };
|
|
965
970
|
this._disposeList = [];
|
|
966
971
|
this.handleZoom = (e) => {
|
|
967
972
|
const { transform } = e;
|
|
@@ -1089,7 +1094,7 @@
|
|
|
1089
1094
|
const newSize = [el.scrollWidth, el.scrollHeight];
|
|
1090
1095
|
d.state.size = newSize;
|
|
1091
1096
|
});
|
|
1092
|
-
const {
|
|
1097
|
+
const { lineWidth, paddingX, spacingHorizontal, spacingVertical } = this.options;
|
|
1093
1098
|
const layout = flextree({}).children((d) => {
|
|
1094
1099
|
var _a;
|
|
1095
1100
|
if (!((_a = d.payload) == null ? void 0 : _a.fold)) return d.children;
|
|
@@ -1097,7 +1102,7 @@
|
|
|
1097
1102
|
const [width, height] = node.data.state.size;
|
|
1098
1103
|
return [height, width + (width ? paddingX * 2 : 0) + spacingHorizontal];
|
|
1099
1104
|
}).spacing((a, b) => {
|
|
1100
|
-
return a.parent === b.parent ? spacingVertical : spacingVertical * 2;
|
|
1105
|
+
return (a.parent === b.parent ? spacingVertical : spacingVertical * 2) + lineWidth(a.data);
|
|
1101
1106
|
});
|
|
1102
1107
|
const tree = layout.hierarchy(this.state.data);
|
|
1103
1108
|
layout(tree);
|
|
@@ -1165,7 +1170,7 @@
|
|
|
1165
1170
|
return rect;
|
|
1166
1171
|
}
|
|
1167
1172
|
async renderData(originData) {
|
|
1168
|
-
const { paddingX, autoFit, color, maxWidth } = this.options;
|
|
1173
|
+
const { paddingX, autoFit, color, maxWidth, lineWidth } = this.options;
|
|
1169
1174
|
const rootNode = this.state.data;
|
|
1170
1175
|
if (!rootNode) return;
|
|
1171
1176
|
const nodeMap = {};
|
|
@@ -1298,13 +1303,13 @@
|
|
|
1298
1303
|
);
|
|
1299
1304
|
this.transition(mmLineExit).attr("x1", (d) => d.state.rect.width).attr("stroke-width", 0);
|
|
1300
1305
|
mmLineEnter.attr("x1", (d) => d.state.rect.width).attr("x2", (d) => d.state.rect.width);
|
|
1301
|
-
mmLineMerge.attr("y1", (d) => d.state.rect.height).attr("y2", (d) => d.state.rect.height);
|
|
1302
|
-
this.transition(mmLineMerge).attr("x1", -1).attr("x2", (d) => d.state.rect.width + 2).attr("stroke", (d) => color(d)).attr("stroke-width",
|
|
1306
|
+
mmLineMerge.attr("y1", (d) => d.state.rect.height + lineWidth(d) / 2).attr("y2", (d) => d.state.rect.height + lineWidth(d) / 2);
|
|
1307
|
+
this.transition(mmLineMerge).attr("x1", -1).attr("x2", (d) => d.state.rect.width + 2).attr("stroke", (d) => color(d)).attr("stroke-width", lineWidth);
|
|
1303
1308
|
const mmCircleExit = mmGExit.selectAll(
|
|
1304
1309
|
childSelector("circle")
|
|
1305
1310
|
);
|
|
1306
1311
|
this.transition(mmCircleExit).attr("r", 0).attr("stroke-width", 0);
|
|
1307
|
-
mmCircleMerge.attr("cx", (d) => d.state.rect.width).attr("cy", (d) => d.state.rect.height);
|
|
1312
|
+
mmCircleMerge.attr("cx", (d) => d.state.rect.width).attr("cy", (d) => d.state.rect.height + lineWidth(d) / 2);
|
|
1308
1313
|
this.transition(mmCircleMerge).attr("r", 6).attr("stroke-width", "1.5");
|
|
1309
1314
|
this.transition(mmFoExit).style("opacity", 0);
|
|
1310
1315
|
mmFoMerge.attr("width", (d) => Math.max(0, d.state.rect.width - paddingX * 2)).attr("height", (d) => d.state.rect.height);
|
|
@@ -1313,20 +1318,20 @@
|
|
|
1313
1318
|
const targetRect = getOriginTargetRect(d.target);
|
|
1314
1319
|
const pathTarget = [
|
|
1315
1320
|
targetRect.x + targetRect.width,
|
|
1316
|
-
targetRect.y + targetRect.height
|
|
1321
|
+
targetRect.y + targetRect.height + lineWidth(d.target) / 2
|
|
1317
1322
|
];
|
|
1318
1323
|
return linkShape({ source: pathTarget, target: pathTarget });
|
|
1319
1324
|
}).attr("stroke-width", 0).remove();
|
|
1320
|
-
this.transition(mmPathMerge).attr("stroke", (d) => color(d.target)).attr("stroke-width", (d) =>
|
|
1325
|
+
this.transition(mmPathMerge).attr("stroke", (d) => color(d.target)).attr("stroke-width", (d) => lineWidth(d.target)).attr("d", (d) => {
|
|
1321
1326
|
const origSource = d.source;
|
|
1322
1327
|
const origTarget = d.target;
|
|
1323
1328
|
const source = [
|
|
1324
1329
|
origSource.state.rect.x + origSource.state.rect.width,
|
|
1325
|
-
origSource.state.rect.y + origSource.state.rect.height
|
|
1330
|
+
origSource.state.rect.y + origSource.state.rect.height + lineWidth(origSource) / 2
|
|
1326
1331
|
];
|
|
1327
1332
|
const target = [
|
|
1328
1333
|
origTarget.state.rect.x,
|
|
1329
|
-
origTarget.state.rect.y + origTarget.state.rect.height
|
|
1334
|
+
origTarget.state.rect.y + origTarget.state.rect.height + lineWidth(origTarget) / 2
|
|
1330
1335
|
];
|
|
1331
1336
|
return linkShape({ source, target });
|
|
1332
1337
|
});
|
|
@@ -1467,6 +1472,7 @@
|
|
|
1467
1472
|
exports.deriveOptions = deriveOptions;
|
|
1468
1473
|
exports.globalCSS = globalCSS;
|
|
1469
1474
|
exports.isMacintosh = isMacintosh;
|
|
1475
|
+
exports.lineWidthFactory = lineWidthFactory;
|
|
1470
1476
|
exports.loadCSS = loadCSS;
|
|
1471
1477
|
exports.loadJS = loadJS;
|
|
1472
1478
|
exports.refreshHook = refreshHook;
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { IMarkmapOptions } from 'markmap-common';
|
|
1
|
+
import { IMarkmapOptions, INode } from 'markmap-common';
|
|
2
2
|
export declare const isMacintosh: boolean;
|
|
3
3
|
export declare const defaultColorFn: import("d3").ScaleOrdinal<string, string, never>;
|
|
4
|
+
export declare const lineWidthFactory: (baseWidth?: number, deltaWidth?: number, k?: number) => (node: INode) => number;
|
|
4
5
|
export declare const defaultOptions: IMarkmapOptions;
|