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

92 lines (91 loc) 3.45 kB
import { LinearScale } from "./linear-scale"; import { Scale } from "./scale"; import { IBandScale, IHasInnerScale, IScale } from "./types"; /** * Nova wrapper around [D3's scaleBand](https://d3indepth.com/scales/#scaleband) * A typical use case for a band scale is a bar chart */ export declare class BandScale<T = string> extends Scale<T> implements IBandScale<T>, IHasInnerScale<T> { innerScale: IScale<any>; constructor(id?: string); protected createD3Scale(): any; /** * This returns center of a band. To return the beginning of a band, manually subtract this.bandwidth()/2 * This differs from the "bandScale.convert" method in d3 * * @param {T} value The value to convert * @param {number} [position=0.5] Number in the range of [0, 1] that will define the point inside of the band. Where 0 stands for start. * @returns {number} Center of a band */ convert(value: T, position?: number): number; /** * Converts the specified coordinate into the value of the closest band data point * * @param {number} coordinate The coordinate to convert * @returns {T} The value of the closest band data point */ invert(coordinate: number): T; /** See {@link IScale#range} */ range(): [number, number]; range(range: [number, number]): this; /** * Gets the rounded setting for the scale * * @returns {boolean} The value indicating whether the scale is rounded */ round(): boolean; /** * Sets whether the scale should be rounded * Rounding helps to have crisp edges https://github.com/d3/d3-scale#band_round * * @param {boolean} round The specified round setting */ round(round: boolean): this; /** * A convenience method for setting the inner and outer padding. * This differs from D3 implementation. We're setting the outer padding to half of the inner padding. * * @param padding Value in [0, 1] interval. */ padding(padding: number): this; /** * Returns the current alignment which defaults to 0.5. * * @returns {number} The current alignment */ align(): number; /** * Sets the alignment to the specified value which must be in the range [0, 1]. * * The default is 0.5. * * The alignment determines how any leftover unused space in the range is distributed. * A value of 0.5 indicates that the leftover space should be equally distributed before the first band and * after the last band, i.e. the bands should be centered within the range. A value of 0 or 1 may be used to * shift the bands to one side, say to position them adjacent to an axis. * * @param {number} align Value for alignment setting in [0, 1] interval. */ align(align: number): this; /** * Returns the width of each band (bar). */ bandwidth(): number; /** * Returns the width of each step with paddings. * Please note the fact that bandScale._d3Scale.step() returns step size without outer paddings! */ step(): number; /** * Creates linear scale with domain and range that are equal to current scale's range */ copyToLinear(): LinearScale; /** * Gets the locations for the band ticks * * @returns {number[]} The band tick locations */ bandTicks(): number[]; isContinuous(): boolean; private getRangeMidPoints; }