* Renders the Component to a given HTML Element. * * @param {String|d3.Selection} element The element, a selector string for the element, or a d3.Selection for the element. * @returns {Component} The calling Component.
(element: string | HTMLElement | d3.Selection<HTMLElement, any, any, any>)
| 360 | * @returns {Component} The calling Component. |
| 361 | */ |
| 362 | public renderTo(element: string | HTMLElement | d3.Selection<HTMLElement, any, any, any>): this { |
| 363 | this.detach(); |
| 364 | if (element != null) { |
| 365 | let selection: d3.Selection<HTMLElement, any, any, any>; |
| 366 | if (typeof(element) === "string") { |
| 367 | selection = d3.select<HTMLElement, any>(element); |
| 368 | } else if (isElement(element)) { |
| 369 | selection = d3.select<HTMLElement, any>(element as HTMLElement); |
| 370 | } else { |
| 371 | selection = coerceExternalD3(element as d3.Selection<HTMLElement, any, any, any>); |
| 372 | } |
| 373 | if (!selection.node() || selection.node().nodeName == null) { |
| 374 | throw new Error("Plottable requires a valid Element to renderTo"); |
| 375 | } |
| 376 | if (selection.node().nodeName === "svg") { |
| 377 | throw new Error("Plottable 3.x and later can only renderTo an HTML component; pass a div instead!"); |
| 378 | } |
| 379 | this.anchor(selection); |
| 380 | } |
| 381 | if (this._element == null) { |
| 382 | throw new Error("If a Component has never been rendered before, then renderTo must be given a node to render to, " + |
| 383 | "or a d3.Selection, or a selector string"); |
| 384 | } |
| 385 | RenderController.registerToComputeLayoutAndRender(this); |
| 386 | // flush so that consumers can immediately attach to stuff we create in the DOM |
| 387 | RenderController.flush(); |
| 388 | return this; |
| 389 | } |
| 390 | |
| 391 | /** |
| 392 | * Gets the x alignment of the Component. |
no test coverage detected