UNPKG

@nova-ui/charts

Version:

Nova Charts is a library created to provide potential consumers with solutions for various data visualizations that conform with the Nova Design Language. It's designed to solve common patterns identified by UX designers, but also be very flexible so that

126 lines (125 loc) 5.52 kB
import { Selection } from "d3-selection"; import { Subject } from "rxjs"; import { EventBus } from "../common/event-bus"; import { Lasagna } from "../common/lasagna"; import { ScalesIndex } from "../common/scales/types"; import { IChart, IChartEvent, IChartPlugin } from "../common/types"; import { D3Selection } from "../common/types"; import { IBorders, IDimensions, IGrid, IGridConfig } from "./types"; export declare const borderMidpoint = 0.5; /** * @implements {IGrid} * Implementation for the dimensions, scaling, interactive area, and borders of a basic grid */ export declare abstract class Grid implements IGrid { /** Class name for the grid */ static GRID_CLASS_NAME: string; /** Class name applied to each of the grid's borders by default */ static DEFAULT_BORDER_CLASS_NAME: string; /** Prefix applied to the rendering area clip path id */ static RENDERING_AREA_CLIP_PATH_PREFIX: string; /** Name for the lasagna layer containing the grid's rendered elements */ static GRID_ELEMENTS_LAYER_NAME: string; /** Name for the rendering area lasagna layer */ static RENDERING_AREA_LAYER_NAME: string; /** @ignore Height correction needed to prevent interaction gap between vertically stacked charts */ static RENDER_AREA_HEIGHT_CORRECTION: number; /** @ignore Width correction needed to prevent interaction gap between right side of grid and the edge of the rendering area */ static RENDER_AREA_WIDTH_CORRECTION: number; /** @ignore Width correction needed to sync bottom border length and grid width to tick placement */ static TICK_DIMENSION_CORRECTION: number; /** Subject for indicating that the chart's dimensions should be updated */ updateChartDimensionsSubject: Subject<void>; /** Event bus provided by the chart */ eventBus: EventBus<IChartEvent>; /** d3 container for the grid */ protected container: D3Selection<SVGGElement>; /** d3 selection for the grid's rendering area clip path */ protected renderingAreaClipPath: D3Selection<SVGRectElement>; /** d3 selection for the grid's rendering area */ protected renderingArea: D3Selection<SVGRectElement>; /** d3 selection for the grid's interactive area */ protected interactiveArea: D3Selection<SVGRectElement>; /** The grid's layer manager */ protected lasagna: Lasagna; /** Lasagna layer for the grid's rendered elements */ protected gridElementsLayer: Selection<SVGElement, any, SVGElement, any>; /** Definition of the grid's borders as rendered */ protected borders: Partial<IBorders>; /** Property value of the grid's scales */ protected _scales: ScalesIndex; /** Property value of the grid's configuration */ protected _config: IGridConfig; /** Property value of the grid's target d3 selection */ protected _target: D3Selection<SVGSVGElement>; /** See {@link IGrid#getInteractiveArea} */ getInteractiveArea(): D3Selection<SVGRectElement>; /** See {@link IGrid#getLasagna} */ getLasagna(): Lasagna; /** @ignore */ set scales(scales: ScalesIndex); /** @ignore */ get scales(): ScalesIndex; /** See {@link IGrid#config} */ config(): IGridConfig; /** See {@link IGrid#config} */ config(config: IGridConfig): this; /** See {@link IGrid#target} */ target(): D3Selection<SVGSVGElement>; /** See {@link IGrid#target} */ target(target: D3Selection<SVGSVGElement>): IGrid; /** See {@link IGrid#build} */ build(): IGrid; /** * Derived classes override this method to build the grid's plugins * * @param {IChart} chart The chart instance to pass to each plugin * * @returns {IChartPlugin[]} Default implementation returns an empty array */ buildPlugins(chart: IChart): IChartPlugin[]; /** See {@link IGrid#update} */ update(): IGrid; /** See {@link IGrid#updateDimensions} */ updateDimensions(dimensions: Partial<IDimensions>): IGrid; /** See {@link IGrid#updateRanges} */ updateRanges(): IGrid; /** * Calculate the width correction needed for accommodating grid elements that may extend beyond the chart's configured width */ protected getOuterWidthDimensionCorrection(): number; /** * Builds the grid borders as SVGElements based on the specified configuration * * @param {D3Selection} container d3 container for the borders * * @returns {Partial<IBorders>} The grid's borders */ protected buildBorders(container: D3Selection): Partial<IBorders> | undefined; /** * Adjusts the grid's rendering area and clip path based on the grid's configured width and height */ protected adjustRenderingArea: () => void; /** * Builds the grid's rendering area as a layer on the lasagna * * @param {string} clipPathId The clip path identifier * * @returns {D3Selection} The grid's rendering area */ private buildRenderingArea; /** * Creates a border with the specified configuration in the provided container * * @param {D3Selection} container The container to append the border to * @param {IBorderConfig} config The configuration to apply to the border * * @returns {SVGElement} The created border */ private createBorder; protected updateBottomBorder(): void; /** * Updates the d3 line positioning and visibility attributes of each of the configured borders */ protected updateBorders(): void; }