UNPKG

psychart

Version:

View air conditions on a psychrometric chart

78 lines (77 loc) 2.77 kB
import { Color } from 'viridis'; import { ChartOptions, Point, TextAnchor } from './types'; /** * Represents a generic SVG chart to be inherited by another class. */ export declare abstract class Chart<T extends ChartOptions> { /** * Initialization counter for any chart */ private static id_count; /** * Unique numeric identifier for this chart */ protected readonly id: number; /** * SVG Namespace URI */ protected readonly NS = "http://www.w3.org/2000/svg"; /** * Options for this chart */ protected readonly options: T; /** * Base `<div>` element */ protected readonly base: HTMLDivElement; /** * The `<svg>` element used for rendering */ protected readonly svg: SVGSVGElement; /** * Create a new instance of this chart. * @param options Supply some options to customize this chart. * @param defaults Supply all default options for this chart. */ constructor(options: Partial<T>, defaults: T); /** * Produce a deep copy of an object. * @param obj Any object * @returns A deep copy of an object. */ protected static deepCopy<Z>(obj: Z): Z; /** * Take an object with all optional values, and set all unset values to their defaults. * @param options An object with all parameters optional. * @param defaults An object with all parameters default. * @returns An object with all parameters that are unset as their default values. */ protected static setDefaults<Z>(options: Partial<Z>, defaults: Z): Z; /** * Remove all the children from a parent element. * @param parent Any element to clear the children of */ protected static clearChildren(parent: Node): void; /** * Generate a text element to append onto a parent element. * @param content The contents of the text element * @param location The location of the text element, in pixels * @param color The fill color of the text * @param anchor How the text is anchored relative to its location * @returns A `<text>` element */ protected createLabel(content: string, location: Point, color: Color, anchor: TextAnchor): SVGTextElement; /** * Draw a tooltip onto the chart. * @param content The text content of the tooltip * @param location The position of the tooltip * @param color The background color * @param parent The element to append onto */ protected drawTooltip(content: string, location: Point, color: Color, parent: SVGElement): void; /** * Return the base `<div>` element for this chart to append on the parent. * @returns The base element. */ getElement(): HTMLDivElement; }