MCPcopy
hub / github.com/antvis/Infographic / Renderer

Class Renderer

src/renderer/renderer.ts:46–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44};
45
46export class Renderer implements IRenderer {
47 private rendered = false;
48
49 constructor(
50 private options: ParsedInfographicOptions,
51 private template: SVGSVGElement,
52 ) {}
53
54 public getOptions(): ParsedInfographicOptions {
55 return this.options;
56 }
57
58 public getSVG(): SVGSVGElement {
59 return this.template;
60 }
61
62 render(): SVGSVGElement {
63 const svg = this.getSVG();
64 if (this.rendered) return svg;
65
66 renderTemplate(svg, this.options);
67 svg.style.visibility = 'hidden';
68 const postRender = () => {
69 setView(this.template, this.options);
70 loadFonts(this.template);
71 svg.style.removeProperty('visibility');
72 };
73
74 if (isNode) {
75 postRender();
76 } else {
77 const observer = new MutationObserver((mutations) => {
78 mutations.forEach((mutation) => {
79 mutation.addedNodes.forEach((node) => {
80 if (node === svg || node.contains(svg)) {
81 postRender();
82 observer.disconnect();
83 }
84 });
85 });
86 });
87
88 try {
89 observer.observe(this.options.container, {
90 childList: true,
91 subtree: true,
92 });
93 } catch (error) {
94 // Fallback for micro-app environments that proxy document.
95 postRender();
96 console.error(error);
97 }
98 }
99
100 this.rendered = true;
101 return svg;
102 }
103}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected