Skip to content
On this page

module common.ts

type Value

ts
export type Value = number | string | Date;

type NearestPoint

ts
export type NearestPoint = {
  node: KDTreeNode | BTreeNode;
  screenDistanceSq: number;
};

The result of either a BTree or KDTree search

  • node BTreeNode | KDTreeNode
  • screenDistanceSq number

type Threshold

ts
export type Threshold = {
    label?: string;
    color?: string;
    value: number | Domain;
};

Thresholds are used to represent static values or ranges on a particular series. They could be used for safety limits, known good/bad values etc...

  • label string If defined, draws near threshold
  • color string color override, accepts html color names and hex values like '#FF9900'
  • value number | Domain value can be a single number which will produce a line, or a Domain value representing a range

type Margins

ts
export type Margins = {
  top: number;
  bottom: number;
  left: number;
  right: number;
};

DDV components provide a Margins object to all of their children. This object is computed continuously based on the domState and which children have reserved room in the chart's spaceReservations. all members represent screen-space pixels

  • top number
  • bottom number
  • left number
  • right number

type DataSet

ts
export type DataSet = {
  title?: string;
  color?: string;
  points: Point[];
  xAxisFormatter?: AxisTickFormatter;
  yAxisFormatter?: AxisTickFormatter;
  xValueFormatter?: ValueFormatter;
  yValueFormatter?: ValueFormatter;
  xAxisLabel?: string;
  yAxisLabel?: string;
  xDomain?: NumericDomain; 
  yDomain?: NumericDomain; 
  curveType?: CurveType;
  reverseXAxis?: boolean;
  reverseYAxis?: boolean;
  thresholds?: {
    x?: Threshold[];
    y?: Threshold[];
  };
};

Each DataSet represents a single series of 2D data as well as associated meta data. The only required attribute is points

  • title string
  • color string
  • points Point[]
  • xAxisFormatter AxisTickFormatter
  • yAxisFormatter AxisTickFormatter
  • xValueFormatter ValueFormatter
  • yValueFormatter ValueFormatter
  • xAxisLabel string
  • yAxisLabel string
  • xDomain NumericDomain
  • yDomain NumericDomain
  • curveType CurveType
  • reverseXAxis boolean
  • reverseYAxis boolean
  • thresholds { x?: Threshold[]; y?: Threshold[]; }

type DOMState

ts
export type DOMState = {
    plotWidth: number;
    plotHeight: number;
    elementWidth: number;
    elementHeight: number;
    computedHeight: number;
};

The DDV component provides a DOMState object to all of its children. This object represents the outside world to the internals of ddv.

  • plotWidth number width of plottable area in pixels
  • plotHeight number with of plottable area in pixels
  • elementWidth number container element width in pixels
  • elementHeight number container-element height in pixels
  • computedHeight number computed height based on elementWidth and aspectRatio

type MouseState

ts
export type MouseState = {
    mouse: NumericPoint;
  normalizedMouse: NumericPoint;
  globalMouse: NumericPoint; 
  isHovered: boolean; 
  isPlotHovered: boolean; 
};

DDV components provide a MouseState object to all of their children. This object represents the outside world's mouse to the internals of ddv.

  • mouse NumericPoint mouse coordinates relative to 0,0 as top left of plot area
  • normalizedMouse NumericPoint
  • globalMouse NumericPoint
  • isHovered boolean
  • isPlotHovered boolean

type SpaceReservations

ts
export type SpaceReservations = {
  [index: string]: Margins;
};

type LinearScaler

ts
export type LinearScaler = {
  scale: ScaleFuncDiff<Value, number>;
  normalize?: ScaleFuncDiff<Value, number>;
  interpolate?: ScaleFunc<number>;
  invert?: ScaleFunc<number>;
  dereference?: ScaleFuncDiff<number, string>;
};
  • scale ScaleFuncDiff<Value, number>
  • normalize ScaleFuncDiff<Value, number>
  • interpolate ScaleFunc<number>
  • invert ScaleFunc<number>
  • dereference ScaleFuncDiff<number, string>

type DiscreteScaler

ts
export type DiscreteScaler = {
  scale: ScaleFunc<number>;
  normalize?: ScaleFunc<number>;
  interpolate?: ScaleFunc<number>;
  
};
  • scale ScaleFunc<number>
  • normalize ScaleFunc<number>
  • interpolate ScaleFunc<number>

type CartesianScaler

ts
export type CartesianScaler = {
  scale: ScaleFuncDiff<Point, NumericPoint>;
};
  • scale ScaleFuncDiff<Point, NumericPoint>

type ToolTipSeries

ts
export type ToolTipSeries = {
  title?: string;
  xLabel?: string;
  yLabel?: string;
  isActive: boolean;
  nearestPoint: NearestPoint | null;
  xFormatter: ValueFormatter;
  yFormatter: ValueFormatter;
};
  • title string
  • xLabel string
  • yLabel string
  • isActive boolean
  • nearestPoint NearestPoint
  • xFormatter ValueFormatter
  • yFormatter ValueFormatter

type ToolTipInfo

ts
export type ToolTipInfo = {
  [key: number]: ToolTipSeries;
};

interface Point

ts
export interface Point {
  x: Value;
  y: Value;
}

Thanks, Euclid! Pretty much what you'd expect. Call it a 2D vector or a point, it's 2 numbers in an object.

interface NumericPoint

ts
export interface NumericPoint extends Point {
  x: number;
  y: number;
}

interface DatePoint

ts
export interface DatePoint extends Point {
  x: Date;
  y: number;
}

interface DiscretePoint

ts
export interface DiscretePoint extends Point {
  x: string;
  y: number;
}

interface ScaleFunc

ts
export interface ScaleFunc<T> {
  (val: T): T; 
}

ScaleFunc<T> is a generic interface representing scaling a value in 1 range onto it's scaled value in another range. For instance graphing x point 10 from the range 0..100 onto the range 0..200 would yield 20. ScaleFuncs are generally used for individual dimensions of a plot mapping data points into screen points, one dimension at a time.

  • undefined undefined

interface ScaleFuncDiff

ts
export interface ScaleFuncDiff<T_IN, T_OUT> {
  (val: T_IN): T_OUT; 
}
  • undefined undefined

function isNumeric

ts
(p: Point) => p is NumericPoint

Parameters

Returns boolean

function isDatePoint

ts
(p: Point) => p is DatePoint

Parameters

Returns boolean

function isDiscretePoint

ts
(p: Point) => p is DiscretePoint

Parameters

Returns boolean

function isNumericSeries

ts
(points: Point[]) => points is NumericPoint[]

Parameters

Returns boolean

function isDateSeries

ts
(points: Point[]) => points is DatePoint[]

Parameters

Returns boolean

function isDiscreteSeries

ts
(points: Point[]) => points is DiscretePoint[]

Parameters

Returns boolean

function valueToNumber

ts
(v: Value, domain: Domain) => number

Parameters

Returns number

function getUniqueXValues

ts
(points: DiscretePoint[]) => string[]

Parameters

Returns string[]

function uniqueFilter

ts
(value: unknown, index: number, self: unknown[]) => boolean

Parameters

  • value unknown
  • index number
  • self unknown[]

Returns boolean

Released under the MIT License.