import { AxisFactory, AxisSide, Layer, LineAttrs, NoSeries, NodeRoles, ScaleAxis, TextAttrs } from "chartist"; //#region src/axisTitle.d.ts declare module 'chartist' { interface NodeRoles { /** An axis title of {@link axisTitle}: a `text` (class `ct-axis-title`). */ axisTitle: { ctx: { /** The id of the axis the title names. */ readonly axis: string; /** The side of the chart the axis is on. */ readonly side: AxisSide; /** The title's text. */ readonly text: string; /** Where the text is anchored, in px in the SVG. */ readonly x: number; readonly y: number; }; attrs: { readonly x: number; readonly y: number; }; }; } } /** Options of {@link axisTitle}. */ interface AxisTitleOptions { /** * The id of the axis the title names: `x` or `y` on the presets, the ids * you gave in `cartesianAxes()` in composed charts. */ readonly axis: string; /** The title's text; an empty text draws nothing and takes no room. */ readonly text: string; /** * Where along the axis the title sits: at the start (left on X axes, the * bottom on Y axes), in the middle or at the end. */ readonly align?: 'start' | 'middle' | 'end'; /** * Turns titles of left and right axes to read from top to bottom instead * of from bottom to top. Titles of top and bottom axes don't change. */ readonly flip?: boolean; /** Space between the title and the axis labels, in px. */ readonly gap?: number; /** Extra class names for the title, e.g. `ct-series-b` for a color. */ readonly className?: string; /** Replaces the default class: `title` instead of `ct-axis-title`. */ readonly classNames?: { readonly title?: string; }; } /** * Names an axis with a title next to its labels, on any side of the chart. * The layer reserves the room the title needs, so the drawing area shrinks * and the title never overlaps the labels, whatever font size the * stylesheet gives it. One layer draws one title; give each axis its own. * Titles on the same side stack outward in the order of `layers`. * * The title is an SVG `text` with the classes `ct-axis-title`, * `ct-horizontal` or `ct-vertical` and `ct-start` or `ct-end`, styled with * `--ct-axis-title-color` and `--ct-axis-title-size` from * `@chartist-js/essentials/styles.css`. * * @example * ```ts * import { lineChart } from 'chartist'; * import { axisTitle } from '@chartist-js/essentials'; * import 'chartist/styles.css'; * import '@chartist-js/essentials/styles.css'; * * lineChart( * '#chart', * { labels: ['Mon', 'Tue', 'Wed'], series: [[12, 9, 7]] }, * { * layers: { * above: [ * axisTitle({ axis: 'x', text: 'Day' }), * axisTitle({ axis: 'y', text: 'Visits' }) * ] * } * } * ); * ``` */ export declare function axisTitle(options: AxisTitleOptions): Layer; //#endregion //#region src/logAxis.d.ts /** Options of {@link logAxis}. */ interface LogAxisOptions { /** * The base of the logarithm: the ticks are its powers. Any finite number * above 1, such as 2 for a scale that doubles; default 10. */ readonly base?: number; /** * Draws minor grid lines between the ticks, without labels: at 2 to 9 * times each power for base 10, or at the powers left out when the ticks * skip some. Style them with `--ct-grid-minor-*`. */ readonly minorTicks?: boolean; } /** * Creates a logarithmic axis, for values that span several orders of * magnitude: each power of the base (1, 10, 100, … for base 10) is the * same distance from the next, so growth by a factor looks the same * everywhere. It goes in the `type` of a preset's `axisX` or `axisY`, or * of an axis of `cartesianAxes()`. * * Without `low` and `high`, the range runs from the power at or below the * smallest value to the power at or above the largest; the axis's own * `low` and `high` set it exactly. The ticks are the powers, every second * or third when they'd be closer than `scaleMinSpace`; the axis's `ticks` * replace them. Zero and negative values have no place on a log scale: * they don't count towards the range and are drawn at the start of the * axis, so a bar for zero has no length. Use `null` for a gap. * * Trend lines on a log axis are fitted to the logarithms of the values, * so they're straight on the axis: an exponential trend on a log Y axis. * * @example * ```ts * import { lineChart } from 'chartist'; * import { logAxis } from '@chartist-js/essentials'; * * lineChart( * '#chart', * { * labels: ['2019', '2020', '2021', '2022', '2023', '2024'], * series: [[120, 980, 4100, 36000, 210000, 850000]] * }, * { * axisY: { * type: logAxis({ minorTicks: true }), * labelTransform: value => value.toLocaleString('en-US') * } * } * ); * ``` * @param options The base and whether to draw minor grid lines. */ export declare function logAxis(options?: LogAxisOptions): AxisFactory; //#endregion //#region src/roles.d.ts /** * The context of a `targetLine` node: the line of a `targetLine()` layer, * across the chart area at a value on an axis. Its ends are in px in the * SVG. */ interface TargetLineContext extends NoSeries { /** The axis the value is on; `axis.dimension` is `x` or `y`. */ readonly axis: ScaleAxis; /** The value the line is drawn at. */ readonly value: number; /** The line's label, if it has one. */ readonly label?: string; /** The X of the line's start, in px. */ readonly x1: number; /** The Y of the line's start, in px. */ readonly y1: number; /** The X of the line's end, in px. */ readonly x2: number; /** The Y of the line's end, in px. */ readonly y2: number; } /** * The context of a `targetLabel` node: the label of a target line, and * where it's anchored, in px in the SVG. */ interface TargetLabelContext extends NoSeries { /** The axis of the line's value. */ readonly axis: ScaleAxis; /** The value of the line. */ readonly value: number; /** The label as drawn. */ readonly text: string; /** Px from the left edge of the SVG. */ readonly x: number; /** Px from the top edge of the SVG. */ readonly y: number; } /** * The context of a `trendLine` node: the line a `trendLine()` layer fits * through a series' values, `y = slope * x + intercept` in the axes' * values (X is the value's index on a step axis). Its ends are in px in * the SVG. */ interface TrendLineContext { /** The series' index in the chart's data, across layers. */ readonly seriesIndex: number; /** Always absent: the line stands for the whole series. */ readonly valueIndex?: undefined; /** * How much the fitted value changes per unit of X. On axes with a * transform, such as a log axis, it's in their transformed values: on a * base 10 log Y axis, the powers of ten per unit of X. */ readonly slope: number; /** The fitted value at X 0, in transformed values like `slope`. */ readonly intercept: number; /** * How closely the values follow the line: Pearson's correlation * coefficient r, from -1 (every value on a falling line) through 0 (no * straight trend) to 1 (every value on a rising line). Its square is R², * the share of the values' variation the line explains, as spreadsheets * show it next to a trendline. It describes the fit, not how reliable it * is: with two values it's always 1 or -1. On axes with a transform, * it's computed in their transformed values, so it says how straight * the values look on the chart. Absent when all values are equal, where * it isn't defined. */ readonly correlation?: number; /** The X of the line's start (the series' smallest X), in px. */ readonly x1: number; /** The Y of the line's start, in px. */ readonly y1: number; /** The X of the line's end (the series' largest X), in px. */ readonly x2: number; /** The Y of the line's end, in px. */ readonly y2: number; } declare module 'chartist' { interface NodeRoles { /** * A line of a `targetLine()` layer: a `line` across the chart area * (class `ct-target-line`). */ targetLine: { ctx: TargetLineContext; attrs: LineAttrs; }; /** A target line's label: SVG `text` (class `ct-target-label`). */ targetLabel: { ctx: TargetLabelContext; attrs: TextAttrs; }; /** * The fitted line of a `trendLine()` layer through a series: a `line` * (class `ct-trend-line`). */ trendLine: { ctx: TrendLineContext; attrs: LineAttrs; }; } } //#endregion //#region src/targetLine.d.ts /** * The options of the {@link targetLine} layer: the line's value, its * label and class, and the axis it's on. For several lines, add a layer * per line. */ interface TargetLineOptions { /** * The value the line is drawn at, on the layer's axis. On a step axis, * the position by index, as for the axis's ticks. */ readonly value: number; /** The text drawn next to the line; no label without it. */ readonly label?: string; /** Extra classes for the line and its label, e.g. `ct-series-b`. */ readonly className?: string; /** * The id of the axis the value is on: a Y axis draws a horizontal line, * an X axis a vertical one. Default: the first Y axis. */ readonly axis?: string; /** * Where the label sits along the line: at the `end` (right, or top for * a vertical line) or the `start` (left, or bottom). */ readonly labelPosition?: 'start' | 'end'; /** * Replaces the classes of what the layer draws: `line` * (`ct-target-line`) and `label` (`ct-target-label`). */ readonly classNames?: { readonly line?: string; readonly label?: string; }; } /** * Creates a layer that draws a line across the chart area at a constant * value on one axis, such as a goal or a limit (`line.ct-target-line`). * On a Y axis the line is horizontal, on an X axis vertical. It can have * a label, drawn as SVG text (`text.ct-target-label`) next to it inside * the chart area, and a class, e.g. `ct-series-b` for a series' color. * The axis widens to include the value, unless its own `low` or `high` * leave it out; a line outside the axis isn't drawn. For several lines, * add a layer per line. * * @example * ```ts * import { lineChart } from 'chartist'; * import { targetLine } from '@chartist-js/essentials'; * import 'chartist/styles.css'; * import '@chartist-js/essentials/styles.css'; * * lineChart( * '#chart', * { labels: ['Jan', 'Feb', 'Mar', 'Apr'], series: [[620, 810, 740, 930]] }, * { * low: 0, * layers: { * above: [ * targetLine({ value: 700, label: 'Min' }), * targetLine({ value: 1000, label: 'Goal', className: 'ct-series-b' }) * ] * } * } * ); * ``` */ export declare function targetLine(options: TargetLineOptions): Layer; //#endregion //#region src/trendLine.d.ts /** * The options of the {@link trendLine} layer. Without them, it draws a * trend line for every series, on the first X and Y axis. */ interface TrendLineOptions { /** Series to draw a trend line for, by index or name; default: all series. */ readonly series?: readonly (number | string)[]; /** The id of the X axis to draw on; default: the first X axis. */ readonly x?: string; /** The id of the Y axis to draw on; default: the first Y axis. */ readonly y?: string; /** * Where the line's ends sit on a step axis: at the `start` of their * steps, as the points of `line()`, or at the `center`, where bars * are centered. */ readonly align?: 'start' | 'center'; /** * Replaces the classes of what the layer draws: `series` (`ct-series`) * and `line` (`ct-trend-line`). */ readonly classNames?: { readonly series?: string; readonly line?: string; }; } /** * Creates a layer that draws a trend line for each series: the straight * line that fits its values best (least squares), from its smallest to its * largest X, as a `line.ct-trend-line` in a series group * (`g.ct-series.ct-series-a`), so it takes the series' color. On a step * axis X is the value's index, on a scale axis the value's `x`. Holes are * skipped, and a series with fewer than two values gets no line. The Y * axis widens to include the line's ends. On an axis with a transform, * such as a log axis, the line is fitted to the transformed values, so * it's straight on that axis: an exponential trend on a log Y axis. Add * it next to the `line()` or `bar()` layer that draws the values. * * @example * ```ts * import { lineChart } from 'chartist'; * import { trendLine } from '@chartist-js/essentials'; * import 'chartist/styles.css'; * import '@chartist-js/essentials/styles.css'; * * lineChart( * '#chart', * { * labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'], * series: [{ name: 'sales', data: [620, 810, 740, 930, 880, 1020] }] * }, * { layers: { above: [trendLine()] } } * ); * ``` */ export declare function trendLine(options?: TrendLineOptions): Layer; //#endregion //#region src/valueLabels.d.ts /** The roles whose nodes get labels. */ type ValueLabelRole = 'point' | 'bar'; /** Where a point's label sits. */ type PointLabelPosition = 'above' | 'below' | 'left' | 'right' | 'center'; /** * Where a bar's label sits, from the bar's base to its value: past its * end, inside its end, in its middle or inside its base. */ type BarLabelPosition = 'end' | 'inside-end' | 'center' | 'inside-base'; /** * The value a label is about: what `format` gets. It has the fields of * the item `@chartist-js/tooltips` gives its `format`, under the same * names, so a function written for one mostly works for the other. * Checking `item.role` narrows `item.context` to that role's context. */ type ValueLabelItem = { [K in R]: { /** The role of the labeled node: `point` or `bar`. */ readonly role: K; /** The series' index in the chart's data. */ readonly seriesIndex: number; /** The value's index in its series. */ readonly valueIndex: number; /** The value: a number, or `{ x, y }` when it has both. */ readonly value: number | { readonly x: number; readonly y: number; }; /** The value's `meta`. */ readonly meta: unknown; /** The series as given in the data. */ readonly series: unknown; /** The series' `name`, when it has one. */ readonly seriesName?: string; /** The chart's label at the value's index. */ readonly label?: string; /** The labeled node's data context. */ readonly context: NodeRoles[K]['ctx']; }; }[R]; /** The context of a `valueLabel` node. */ interface ValueLabelContext { /** The role of the node the label is for. */ readonly role: ValueLabelRole; /** The series' index in the chart's data. */ readonly seriesIndex: number; /** The value's index in its series. */ readonly valueIndex: number; /** The labeled value, as the node has it. */ readonly value: unknown; /** The value's `meta`. */ readonly meta: unknown; /** The series as given in the data. */ readonly series: unknown; /** The label's text. */ readonly text: string; /** Where the label ended up, after fitting. */ readonly position: PointLabelPosition | BarLabelPosition; /** Px from the left edge of the SVG: where the text is anchored. */ readonly x: number; /** Px from the top edge of the SVG: the first line's baseline. */ readonly y: number; } declare module 'chartist' { interface NodeRoles { /** * A label of the `valueLabels()` layer: SVG `text`, or a * `foreignObject` with a `span` (class `ct-value-label`). */ valueLabel: { ctx: ValueLabelContext; attrs: object; }; } } /** Options of {@link valueLabels}. */ interface ValueLabelsOptions { /** The nodes that get labels: `point`, `bar` or both (the default). */ readonly roles?: readonly R[]; /** The series to label, by index or name; default: all of them. */ readonly series?: readonly (number | string)[]; /** Where point labels sit; default `above`. */ readonly pointPosition?: PointLabelPosition; /** * Where bar labels sit; default `end`, and `center` for segments of * stacked bars. */ readonly barPosition?: BarLabelPosition; /** * The gap in px between a point's center, or a bar's end or base, and * the label's nearest edge; default 8 for points and 4 for bars. */ readonly offset?: number; /** * The label's text for a value: a string or a number. `undefined` keeps * the default text, `null` or `''` draw no label, and `\n` starts a new * line. */ readonly format?: (item: ValueLabelItem) => string | number | null | undefined; /** `Intl.NumberFormat` options for the default text. */ readonly numberFormat?: Intl.NumberFormatOptions; /** * The locale of the default text; default: the runtime's. Set it when * charts render on a server, so the text doesn't depend on its locale. */ readonly locale?: string | readonly string[]; /** * `fit` (the default) moves labels that don't fit their bar or would * leave the chart; `show` draws every label where its position puts it. */ readonly overflow?: 'fit' | 'show'; /** SVG `text` (the default) or HTML in a `foreignObject`. */ readonly labels?: 'svg' | 'html'; /** * Replace the classes: `group` (`ct-value-labels`), `label` * (`ct-value-label`) and `inside` (`ct-value-label-inside`). */ readonly classNames?: { readonly group?: string; readonly label?: string; readonly inside?: string; }; } /** * Creates a layer that writes each value next to the point or bar that * shows it: above points, past the ends of bars, and in the middle of * stacked segments. It draws from where the chart's other layers drew, * after stacking, offsets and `compose` listeners, so add it as an extra * layer: `layers.above` on a preset, anywhere in a composed chart. * * The text is the value along the value axis, written with * `Intl.NumberFormat`; `format` gets the same item as the `format` of * `@chartist-js/tooltips`. Labels that don't fit their bar, or would * leave the chart, move to a place where they fit. They're SVG `text`, so * they render on servers and in the terminal, styled with * `--ct-value-label-color`, `--ct-value-label-inside-color` and * `--ct-value-label-size` from `@chartist-js/essentials/styles.css`. * * @example * ```ts * import { barChart } from 'chartist'; * import { valueLabels } from '@chartist-js/essentials'; * import 'chartist/styles.css'; * import '@chartist-js/essentials/styles.css'; * * barChart( * '#chart', * { labels: ['Q1', 'Q2', 'Q3'], series: [[1250, 1830, 1470]] }, * { * layers: { * above: [ * valueLabels({ format: item => `${item.value} units` }) * ] * } * } * ); * ``` */ export declare function valueLabels(options?: ValueLabelsOptions): Layer; //#endregion export type { AxisTitleOptions, BarLabelPosition, LogAxisOptions, PointLabelPosition, TargetLabelContext, TargetLineContext, TargetLineOptions, TrendLineContext, TrendLineOptions, ValueLabelContext, ValueLabelItem, ValueLabelRole, ValueLabelsOptions }; //# sourceMappingURL=index.d.cts.map