MCPcopy
hub / github.com/palantir/plottable / SVGDrawer

Class SVGDrawer

src/drawers/svgDrawer.ts:20–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18 * This class is immutable (but has internal state).
19 */
20export class SVGDrawer implements IDrawer {
21 protected _className: string;
22 protected _svgElementName: string;
23
24 /**
25 * The root element holding the visual elements. The SVGDrawer owns
26 * this variable and manipulates it accordingly.
27 */
28 protected _root: d3.Selection<SVGElement, any, any, any>;
29
30 /**
31 * All of the DOM elements from the last draw.
32 */
33 private _selection: d3.Selection<Element, any, any, any>;
34
35 /**
36 * Cache of the _selection.nodes().
37 */
38 private _cachedVisualPrimitivesNodes: Element[];
39 private _cachedVisualPrimitivesNodeMap: Utils.Map<number, Element>;
40
41 /**
42 * @param svgElementName an HTML/SVG tag name to be created, one per datum.
43 * @param className CSS classes to be applied to the drawn primitives.
44 * @param applyDefaultAttributes
45 */
46 constructor(svgElementName: string, className: string) {
47 this._root = d3.select(document.createElementNS("http://www.w3.org/2000/svg", "g"));
48 this._className = className;
49 this._svgElementName = svgElementName;
50 }
51
52 public draw(data: any[], appliedDrawSteps: AppliedDrawStep[]) {
53 /*
54 * Draw to the DOM by clearing old DOM elements, adding new DOM elements,
55 * and then passing those DOM elements to the animator, which will set the
56 * appropriate attributes on the DOM.
57 */
58 this._createAndDestroyDOMElements(data);
59
60 let delay = 0;
61 const drawLength = appliedDrawSteps.length;
62 for (let i = 0; i < drawLength; i++) {
63 const drawStep = appliedDrawSteps[i];
64 Utils.Window.setTimeout(() => this._drawStep(drawStep), delay);
65 delay += drawStep.animator.totalTime(data.length);
66 }
67 }
68
69 public getVisualPrimitives() {
70 if (this._cachedVisualPrimitivesNodes == null) {
71 this._cachedVisualPrimitivesNodes = this._selection.nodes();
72 }
73 return this._cachedVisualPrimitivesNodes;
74 }
75
76 public getVisualPrimitiveAtIndex(index: number) {
77 if (this._cachedVisualPrimitivesNodeMap == null) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected