MCPcopy
hub / github.com/markmap/markmap / constructor

Method constructor

packages/markmap-view/src/view.ts:72–107  ·  view source on GitHub ↗
(
    svg: string | SVGElement | ID3SVGElement,
    opts?: Partial<IMarkmapOptions>,
  )

Source from the content-addressed store, hash-verified

70 private _disposeList: (() => void)[] = [];
71
72 constructor(
73 svg: string | SVGElement | ID3SVGElement,
74 opts?: Partial<IMarkmapOptions>,
75 ) {
76 this.svg = (svg as ID3SVGElement).datum
77 ? (svg as ID3SVGElement)
78 : select(svg as string);
79 this.styleNode = this.svg.append('style');
80 this.zoom = zoom<SVGElement, INode>()
81 .filter((event) => {
82 if (this.options.scrollForPan) {
83 // Pan with wheels, zoom with ctrl+wheels
84 if (event.type === 'wheel') return event.ctrlKey && !event.button;
85 }
86 return (!event.ctrlKey || event.type === 'wheel') && !event.button;
87 })
88 .on('zoom', this.handleZoom);
89 this.setOptions(opts);
90 this.state = {
91 id: this.options.id || this.svg.attr('id') || getId(),
92 rect: { x1: 0, y1: 0, x2: 0, y2: 0 },
93 };
94 this.g = this.svg.append('g');
95 this.g.append('g').attr('class', 'markmap-highlight');
96 this._observer = new ResizeObserver(
97 debounce(() => {
98 this.renderData();
99 }, 100),
100 );
101 this._disposeList.push(
102 refreshHook.tap(() => {
103 this.setData();
104 }),
105 () => this._observer.disconnect(),
106 );
107 }
108
109 getStyleContent(): string {
110 const { style } = this.options;

Callers

nothing calls this directly

Calls 6

setOptionsMethod · 0.95
renderDataMethod · 0.95
setDataMethod · 0.95
getIdFunction · 0.90
debounceFunction · 0.90
tapMethod · 0.80

Tested by

no test coverage detected