MCPcopy Index your code
hub / github.com/markmap/markmap / deriveOptions

Function deriveOptions

packages/markmap-view/src/util.ts:6–61  ·  view source on GitHub ↗
(jsonOptions?: Partial<IMarkmapJSONOptions>)

Source from the content-addressed store, hash-verified

4import { IMarkmapJSONOptions, IMarkmapOptions } from './types';
5
6export function deriveOptions(jsonOptions?: Partial<IMarkmapJSONOptions>) {
7 const derivedOptions: Partial<IMarkmapOptions> = {};
8 const options = { ...jsonOptions };
9
10 const { color, colorFreezeLevel, lineWidth } = options;
11 if (color?.length === 1) {
12 const solidColor = color[0];
13 derivedOptions.color = () => solidColor;
14 } else if (color?.length) {
15 const colorFn = scaleOrdinal(color);
16 derivedOptions.color = (node: INode) => colorFn(`${node.state.path}`);
17 }
18 if (colorFreezeLevel) {
19 const color = derivedOptions.color || defaultOptions.color;
20 derivedOptions.color = (node: INode) => {
21 node = {
22 ...node,
23 state: {
24 ...node.state,
25 path: node.state.path.split('.').slice(0, colorFreezeLevel).join('.'),
26 },
27 };
28 return color(node);
29 };
30 }
31 if (lineWidth) {
32 const args = Array.isArray(lineWidth) ? lineWidth : [lineWidth, 0, 1];
33 derivedOptions.lineWidth = lineWidthFactory(
34 ...(args as Parameters<typeof lineWidthFactory>),
35 );
36 }
37
38 const numberKeys = [
39 'duration',
40 'fitRatio',
41 'initialExpandLevel',
42 'maxInitialScale',
43 'maxWidth',
44 'nodeMinHeight',
45 'paddingX',
46 'spacingHorizontal',
47 'spacingVertical',
48 ] as const;
49 numberKeys.forEach((key) => {
50 const value = options[key];
51 if (typeof value === 'number') derivedOptions[key] = value;
52 });
53
54 const booleanKeys = ['zoom', 'pan'] as const;
55 booleanKeys.forEach((key) => {
56 const value = options[key];
57 if (value != null) derivedOptions[key] = !!value;
58 });
59
60 return derivedOptions;
61}
62
63/**

Callers 1

doRenderFunction · 0.85

Calls 1

lineWidthFactoryFunction · 0.90

Tested by

no test coverage detected