import * as Core from "./index.cjs"; import { AnimationEvent, AreaDrawEvent as AreaDrawEvent$1, AxesDrawEvent as AxesDrawEvent$1, BarChartCreatedEvent as BarChartCreatedEvent$1, BarDrawEvent as BarDrawEvent$1, ChartPlugin, DataEvent as DataEvent$1, LineChartCreatedEvent as LineChartCreatedEvent$1, LineDrawEvent as LineDrawEvent$1, Options, OptionsChangedEvent as OptionsChangedEvent$1, PieChartCreatedEvent as PieChartCreatedEvent$1, PointDrawEvent as PointDrawEvent$1, SliceDrawEvent as SliceDrawEvent$1, SliceLabelDrawEvent as SliceLabelDrawEvent$1 } from "./index.cjs"; //#region src/compat/types.d.ts /** * The 1.x `draw` event of an area (with `showArea`), one per series and * segment. `index` is the series' index and `meta` the series' meta. */ type AreaDrawEvent = Core.AreaDrawEvent; /** The 1.x `draw` events of the axes: grid lines, the grid background and labels. */ type AxesDrawEvent = Core.AxesDrawEvent; /** The payload of a bar chart's 1.x `created` event. */ type BarChartCreatedEvent = Core.BarChartCreatedEvent; /** * The 1.x `draw` event of a bar, one per value. The bar is a `line` element * from its base (`x1`, `y1`) to its value (`x2`, `y2`). */ type BarDrawEvent = Core.BarDrawEvent; /** * The payload of the 1.x `created` event, emitted once a chart is drawn: * its SVG, drawing area, axes and options. */ type CreatedEvent = Core.CreatedEvent; /** * The payload of the 1.x `data` event, emitted before a chart draws new * data. Listeners may change `data` in place to transform it. */ type DataEvent = Core.DataEvent; /** * The fields every 1.x `draw` event shares. A `draw` listener gets one per * element drawn; check `type` to tell them apart. */ type DrawEvent = Core.DrawEvent; /** * The 1.x `draw` event of the grid background, the `rect` behind the * drawing area (with `showGridBackground`). */ type GridBackgroundDrawEvent = Core.GridBackgroundDrawEvent; /** * The 1.x `draw` event of a grid line, one per tick of each axis. `x1`, * `y1`, `x2`, `y2` are the line's ends in px. */ type GridDrawEvent = Core.GridDrawEvent; /** * The 1.x `draw` event of an axis label, one per tick. The label is a * `foreignObject` with a `span`, placed at `x`, `y` with the given size. */ type LabelDrawEvent = Core.LabelDrawEvent; /** The payload of a line chart's 1.x `created` event. */ type LineChartCreatedEvent = Core.LineChartCreatedEvent; /** * The 1.x `draw` event of a line, one per series. `index` is the series' * index and `meta` the series' meta. */ type LineDrawEvent = Core.LineDrawEvent; /** * The payload of the 1.x `optionsChanged` event, emitted when a responsive * option starts or stops applying. */ type OptionsChangedEvent = Core.OptionsChangedEvent; /** The payload of a pie chart's 1.x `created` event: as for other charts, without axes. */ type PieChartCreatedEvent = Core.PieChartCreatedEvent; /** * A 1.x plugin: a function that gets the chart object (and its options) * and registers listeners with `chart.on('draw', …)`. It runs with the * `compat` plugin from `chartist/compat`, whose `fromLegacyPlugin()` also * turns it into a v2 plugin. */ type Plugin = Core.Plugin; /** * The 1.x `draw` event of a line chart's point, one per value. The point is a * very short `line` element at `x`, `y` (CSS gives it a round cap). */ type PointDrawEvent = Core.PointDrawEvent; /** * The 1.x `draw` event of a pie or donut slice, one per value. `index` is * the slice's index and `series` its value as given in the data. */ type SliceDrawEvent = Core.SliceDrawEvent; /** * The 1.x `draw` event of a pie slice's label. `index` is the slice's * index; the label is a `text` element anchored at `x`, `y`. */ type SliceLabelDrawEvent = Core.SliceLabelDrawEvent; //#endregion //#region src/compat/index.d.ts declare module './index.cjs' { interface ChartEvents { /** * 1.x: the chart's data, before the first render (`type: 'initial'`) * and after an update with new data (`type: 'update'`). Listeners can * change it in place. Needs the {@link compat} plugin. */ data: DataEvent$1; /** * 1.x: the responsive options changed, with the options before and * after. Needs the {@link compat} plugin. */ optionsChanged: OptionsChangedEvent$1; /** * 1.x: an element was drawn: a grid line, label, point, line, area, * bar or slice, with its live `element`. Check `type` to narrow it. * Needs the {@link compat} plugin. */ draw: PointDrawEvent$1 | LineDrawEvent$1 | AreaDrawEvent$1 | BarDrawEvent$1 | SliceDrawEvent$1 | SliceLabelDrawEvent$1 | AxesDrawEvent$1; /** * 1.x: the chart is drawn and in the DOM, after its `draw` events, * with the `svg`, the chart area and the axes. Needs the {@link compat} * plugin. */ created: LineChartCreatedEvent$1 | BarChartCreatedEvent$1 | PieChartCreatedEvent$1; /** * 1.x: an SMIL animation began, started with `animate()` on an element * of the chart, such as the `element` of a `draw` event. Needs the * {@link compat} plugin. */ animationBegin: AnimationEvent; /** * 1.x: an SMIL animation ended, started with `animate()` on an element * of the chart. Needs the {@link compat} plugin. */ animationEnd: AnimationEvent; } } type LegacyPlugin = (chart: any, options?: any) => void; /** * Runs a 1.x plugin function as a v2 plugin, with the given chart object. * Used by the 1.x chart classes, which pass themselves. */ declare function legacyPlugin(plugin: LegacyPlugin, options?: unknown, chart?: unknown): ChartPlugin; /** * The compat plugin. Restores the 1.x events (`data`, `optionsChanged`, * `draw`, `created`, `animationBegin`, `animationEnd`) with 1.x payloads. * With it, the 1.x chart classes also run 1.x plugin functions. * * Add it to `plugins`, of a 1.x class, a preset or `chart()`. The `draw` * events come in the 1.x order, right after the chart is in the DOM, so * `element` is a live element; then `created`. Animations started with * `animate()` on the chart's elements emit `animationBegin` and * `animationEnd`. Importing * `chartist/compat` also types the 1.x events on every chart handle. It * needs the DOM renderer, and the `draw` and `created` events need a * chart made by a preset or a 1.x class. * * @example * ```ts * import { lineChart } from 'chartist'; * import { compat } from 'chartist/compat'; * * const chart = lineChart( * '#chart', * { * labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'], * series: [[12, 9, 7, 8, 5]] * }, * { plugins: [compat] } * ); * * // Registered after the first render, so it runs from the next one on. * chart.on('draw', data => { * if (data.type === 'point' && data.index === 4) { * data.element.addClass('is-friday'); * } * }); * ``` */ export declare const compat: ChartPlugin & { legacyPlugin: typeof legacyPlugin; }; /** * Converts a 1.x plugin function into a v2 plugin for `chart()` and the * preset functions. It turns the 1.x events on for the chart and calls the * plugin with a 1.x-style chart object (`container`, `data`, `options`, * `svg`, `eventEmitter`, `on`, `off`, `update`, `detach`). You don't need * {@link compat} in the list as well. * * @param plugin The 1.x plugin: a function that gets the chart (and its * options) * @param options The plugin's options; without them, the plugin is called * with the chart only, as in 1.x * @example * ```ts * import { lineChart, type Plugin } from 'chartist'; * import { fromLegacyPlugin } from 'chartist/compat'; * * // A 1.x plugin: a function that gets the chart and its options. * const caption: Plugin = (chart, options) => { * chart.on('created', () => { * chart.container.setAttribute('aria-label', options.text); * }); * }; * * lineChart( * '#chart', * { series: [[1, 3, 2, 4]] }, * { plugins: [fromLegacyPlugin(caption, { text: 'Visitors per week' })] } * ); * ``` */ export declare function fromLegacyPlugin(plugin: LegacyPlugin, options?: unknown): ChartPlugin; //#endregion export type { AreaDrawEvent, AxesDrawEvent, BarChartCreatedEvent, BarDrawEvent, CreatedEvent, DataEvent, DrawEvent, GridBackgroundDrawEvent, GridDrawEvent, LabelDrawEvent, LineChartCreatedEvent, LineDrawEvent, OptionsChangedEvent, PieChartCreatedEvent, Plugin, PointDrawEvent, SliceDrawEvent, SliceLabelDrawEvent }; //# sourceMappingURL=compat.d.cts.map