parseIfDate |
(data: any): Date \| undefined |
takes any piece of data and tries to convert it into instance of Date. Returns undefined if the conversion fails |
parseObject |
<T>(obj: Object, arg: string, applicator: (obj) => any): T[] |
takes and object, a typeof argument, and an applicator function. It will map through the object's values with the applicator, then filter the results according to the typeof argument |
getX |
(data: GenericData[], xKey?: string): any[] |
takes an array of data objects and optionally an xKey and returns the xKey points for each object in the data array, or tries to parse a date from each object. Example: getX([{messages: 123, users: 133}, {messages: 100, users: 33}, 'messages']) would return: [123, 100, ...] |
getY |
(data: GenericData[], yKey?: string): any[] |
same as getX except it tries to fall back to a number instead of trying to parse a Date. Example: getY([{messages: 123, date: '11-10-2018'},{messages: 100, date: '08-10-2018'}, ...]) would result in [123, 100,...] |
extractX |
(datum: Object, xKey?: string, type: string): any[] |
similar to getX , but instead of taking an array of data objects, it takes a single data object and extracts all x values from that object |
extractY |
(datum: Object, xKey?: string): any[] |
same as extractX , but with y values |
extractLabels |
(datum: Object): string[] |
takes a data object and extracts the y labels by parsing which values contain numbers |
createLinearScales |
(data: GenericData[], dataKeys: string[], height: number, margin: Margin ): ScalarObject |
creates a vertical linear scale for each of the data keys found in the array of data objects. Example: createLinearScales([{messages: 123, users: 333}, ...], ['messages', 'users'], 400, {top: 10, bottom: 10, left: 10, right: 10}) would result in: {messages: scaleFunctionForMessages, users: scaleFunctionForUsers} |
formatTime |
(d: string): string |
default time formatter for viiksetjs, returns dates in the following format: Mon Jan 19 (ddd mmm DD) |
tooltipTime |
(d: string): string |
default time format for tooltips, returns time in this format: Sun Jan 21st 20:29 (ddd mmm DD HH:MM) |
formatTicks |
(d: string \| number): string |
default tick formatter, if it the argument is a number, it will return ${arg}k if the argument is over 1000, else it just returns the argument |
formatXTicks |
(d: string \| Date \| number): string \| number |
returns the default date format if the argument passed is a valid date, otherwise, just returns what it was given |
determineXScale |
(type: 'ordinal'\|'linear', xPoints: number[]\|Date[]\|string[], orientation?: 'horizontal', margin: Margin, width: number): ScaleFunction |
returns a horizontal scale based on the type of chart, width, and margin |
determineYScale |
(type: 'ordinal'\|'linear', orientation?: 'horizontal', yPoints: number[]\|string[], height: number, margin: Margin ): ScaleFunction |
returns a vertical scale based on the type of chart, height, and margin |
findTooltipX |
(calculatedX: any, xScale: ScaleFunction): number |
takes a calculated x value and returns its position in the chart based on the given xScale |
prepChartData |
(size: Size, xKey?: string, yKey?: string, type: 'ordinal'\|'linear', margin: Margin, data: GenericData[], orientation?: 'horizontal'): Promise<State> |
prepares x and y scales, calculates chart height and width, xPoints, yPoints, and datakeys |
interpolateColors |
(a: string, b: string, amount: number): string |
interpolates between the given 2 numbers to get, for example, the color in between the two. Amount is a range from 0.0 - 1.1 |