add Chart.js packages

This commit is contained in:
Ben Goldsworthy 2025-02-20 23:42:38 +01:00
parent dae35f0e05
commit c77c48133b
No known key found for this signature in database
23 changed files with 13374 additions and 0 deletions

View file

@ -0,0 +1,9 @@
The MIT License (MIT)
Copyright (c) 2016-2021 chartjs-plugin-annotation Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1,41 @@
# chartjs-plugin-annotation.js
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/chartjs/chartjs-plugin-annotation/ci.yml?branch=master)](https://github.com/chartjs/chartjs-plugin-annotation/actions/workflows/ci.yml)
[![Coverage Status](https://coveralls.io/repos/github/chartjs/chartjs-plugin-annotation/badge.svg?branch=master)](https://coveralls.io/github/chartjs/chartjs-plugin-annotation?branch=master)
[![release](https://img.shields.io/github/v/release/chartjs/chartjs-plugin-annotation?include_prereleases)](https://github.com/chartjs/chartjs-plugin-annotation/releases)
[![npm (latest)](https://img.shields.io/npm/v/chartjs-plugin-annotation/latest)](https://www.npmjs.com/package/chartjs-plugin-annotation/v/latest)
[![documentation](https://img.shields.io/static/v1?message=Documentation&color=informational)](https://www.chartjs.org/chartjs-plugin-annotation/index)
<a href="https://github.com/chartjs/awesome"><img src="https://awesome.re/badge-flat2.svg" alt="Awesome"></a>
An annotation plugin for Chart.js >= 4.0.0
---
> This plugin needs to be registered. It does not function as inline plugin.
---
For Chart.js 3.7.0 to 3.9.1 support, use [version 2.2.1 of this plugin](https://github.com/chartjs/chartjs-plugin-annotation/releases/tag/v2.2.1)
For Chart.js 3.0.0 to 3.6.2 support, use [version 1.4.0 of this plugin](https://github.com/chartjs/chartjs-plugin-annotation/releases/tag/v1.4.0)
For Chart.js 2.4.0 to 2.9.x support, use [version 0.5.7 of this plugin](https://github.com/chartjs/chartjs-plugin-annotation/releases/tag/v0.5.7)
This plugin draws lines, boxes, points, labels, polygons and ellipses on the chart area.
Annotations work with line, bar, scatter and bubble charts that use linear, logarithmic, time, or category scales.
Furthermore you can use a doughnut label annotation which can be used to add contents (text, image, canvas) in the middle area of the doughnut charts.
![Example Screenshot](docs/guide/banner.png)
[View this example](https://www.chartjs.org/chartjs-plugin-annotation/latest/samples/intro.html)
## Documentation
You can find documentation for chartjs-plugin-annotation at [www.chartjs.org/chartjs-plugin-annotation](https://www.chartjs.org/chartjs-plugin-annotation/index).
## Contributing
Before submitting an issue or a pull request to the project, please take a moment to look over the [contributing guidelines](CONTRIBUTING.md) first.
## License
Chart.Annotation.js is available under the [MIT license](LICENSE.md).

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,90 @@
{
"name": "chartjs-plugin-annotation",
"homepage": "https://www.chartjs.org/chartjs-plugin-annotation/index",
"description": "Annotations for Chart.js",
"version": "3.1.0",
"author": "Evert Timberg <evert.timberg@gmail.com>",
"license": "MIT",
"type": "module",
"main": "dist/chartjs-plugin-annotation.cjs",
"module": "dist/chartjs-plugin-annotation.esm.js",
"types": "types/index.d.ts",
"jsdelivr": "dist/chartjs-plugin-annotation.min.js",
"unpkg": "dist/chartjs-plugin-annotation.min.js",
"exports": {
"types": "./types/index.d.ts",
"import": "./dist/chartjs-plugin-annotation.esm.js",
"require": "./dist/chartjs-plugin-annotation.cjs",
"script": "./dist/chartjs-plugin-annotation.min.js"
},
"sideEffects": [
"dist/chartjs-plugin-annotation.cjs",
"dist/chartjs-plugin-annotation.min.js"
],
"repository": {
"type": "git",
"url": "https://github.com/chartjs/chartjs-plugin-annotation.git"
},
"files": [
"dist/*",
"!dist/docs/**",
"types/*.d.ts"
],
"scripts": {
"build": "rollup -c",
"dev": "karma start ./karma.conf.cjs --auto-watch --no-single-run --browsers chrome",
"dev:ff": "karma start ./karma.conf.cjs --auto-watch --no-single-run --browsers firefox",
"docs": "npm run build && vuepress build docs --no-cache",
"docs:dev": "npm run build && vuepress dev docs --no-cache",
"lint": "concurrently --group \"npm:lint-*\"",
"lint-js": "eslint \"test/**/*.js\" \"src/**/*.js\"",
"lint-md": "eslint \"**/*.md\"",
"lint-types": "eslint \"types/**/*.ts\" && tsc -p types/tests/",
"test": "cross-env NODE_ENV=test concurrently --group \"npm:test-*\"",
"test-karma": "karma start ./karma.conf.cjs --auto-watch --single-run",
"test-lint": "npm run lint",
"test-types": "tsc -p types/tests/",
"test-integration": "mocha --full-trace test/integration/*-test.js"
},
"devDependencies": {
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.4.0",
"@simonbrunel/vuepress-plugin-versions": "^0.2.0",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"chart.js": "^4.3.0",
"chartjs-test-utils": "^0.5.0",
"concurrently": "^7.6.0",
"cross-env": "^7.0.3",
"eslint": "^8.33.0",
"eslint-config-chartjs": "^0.3.0",
"eslint-plugin-es": "^4.1.0",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-markdown": "^3.0.0",
"fs-extra": "^11.1.0",
"karma": "^6.4.1",
"karma-chrome-launcher": "^3.1.1",
"karma-coverage": "^2.2.0",
"karma-firefox-launcher": "^2.1.2",
"karma-jasmine": "^5.1.0",
"karma-jasmine-html-reporter": "^2.0.0",
"karma-rollup-preprocessor": "7.0.7",
"markdown-it-include": "^2.0.0",
"mocha": "^10.2.0",
"pixelmatch": "^5.3.0",
"rollup": "^3.14.0",
"rollup-plugin-istanbul": "^4.0.0",
"typedoc": "^0.23.24",
"typedoc-plugin-markdown": "^3.14.0",
"typescript": "^4.2.4",
"vuepress": "^1.9.7",
"vuepress-plugin-flexsearch": "^0.3.0",
"vuepress-plugin-redirect": "^1.2.5",
"vuepress-plugin-typedoc": "^0.10.0",
"vuepress-theme-chartjs": "^0.2.0"
},
"peerDependencies": {
"chart.js": ">=4.0.0"
}
}

View file

@ -0,0 +1,18 @@
import { AnnotationOptions } from './options';
export interface AnnotationBoxModel {
x: number,
y: number,
x2: number,
y2: number,
centerX: number,
centerY: number,
height: number,
width: number,
radius?: number
}
export interface AnnotationElement extends AnnotationBoxModel {
label?: AnnotationElement,
options: AnnotationOptions
}

View file

@ -0,0 +1,28 @@
import { Chart, ChartEvent } from 'chart.js';
import { AnnotationElement } from './element';
export interface EventContext {
chart: Chart,
element: AnnotationElement,
elements: AnnotationElement[],
id: string,
type: string
}
/**
* Some scriptable options may be called with during the chart's initial
* display, when the element isn't fully initialized.
*/
export interface PartialEventContext {
chart: Chart,
element?: Partial<AnnotationElement>,
elements?: AnnotationElement[],
id?: string,
type?: string
}
export interface AnnotationEvents {
enter?(context: EventContext, event: ChartEvent): boolean | void,
leave?(context: EventContext, event: ChartEvent): boolean | void,
click?(context: EventContext, event: ChartEvent): boolean | void,
}

View file

@ -0,0 +1,31 @@
import { Chart, ChartType, Plugin } from 'chart.js';
import { AnnotationPluginOptions, BoxAnnotationOptions, EllipseAnnotationOptions, LabelAnnotationOptions, LineAnnotationOptions, PointAnnotationOptions, PolygonAnnotationOptions, DoughnutLabelAnnotationOptions } from './options';
import { AnnotationElement } from './element';
declare module 'chart.js' {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface PluginOptionsByType<TType extends ChartType> {
annotation: AnnotationPluginOptions;
}
interface ElementOptionsByType<TType extends ChartType> {
boxAnnotation: BoxAnnotationOptions;
doughnutLabelAnnotation: DoughnutLabelAnnotationOptions;
ellipseAnnotation: EllipseAnnotationOptions;
labelAnnotation: LabelAnnotationOptions;
lineAnnotation: LineAnnotationOptions;
pointAnnotation: PointAnnotationOptions;
polygonAnnotation: PolygonAnnotationOptions;
}
}
declare const Annotation: Plugin & {
getAnnotations(chart: Chart): AnnotationElement[];
};
export default Annotation;
export * from './element';
export * from './events';
export * from './label';
export * from './options';

View file

@ -0,0 +1,165 @@
import { Color, FontSpec, BorderRadius } from 'chart.js';
import { PartialEventContext } from './events';
import { DrawTime, Scriptable, ShadowOptions } from './options';
type percentString = `${number}%`;
export type LabelPosition = 'start' | 'center' | 'end' | percentString;
export type LabelTextAlign = 'left' | 'start' | 'center' | 'right' | 'end';
export type CalloutPosition = 'left' | 'top' | 'bottom' | 'right' | 'auto';
export interface LabelPositionObject {
x?: LabelPosition,
y?: LabelPosition
}
export interface LabelPadding {
top?: number,
left?: number,
right?: number,
bottom?: number,
x?: number,
y?: number
}
export interface CalloutOptions {
borderCapStyle?: Scriptable<CanvasLineCap, PartialEventContext>,
borderColor?: Scriptable<Color, PartialEventContext>,
borderDash?: Scriptable<number[], PartialEventContext>,
borderDashOffset?: Scriptable<number, PartialEventContext>,
borderJoinStyle?: Scriptable<CanvasLineJoin, PartialEventContext>,
borderWidth?: Scriptable<number, PartialEventContext>,
display?: Scriptable<boolean, PartialEventContext>,
margin?: Scriptable<number, PartialEventContext>,
position?: Scriptable<CalloutPosition, PartialEventContext>,
side?: Scriptable<number, PartialEventContext>,
start?: Scriptable<number | string, PartialEventContext>,
}
export interface CoreLabelOptions {
drawTime?: Scriptable<DrawTime, PartialEventContext>,
font?: Scriptable<Partial<FontSpec> | Partial<FontSpec>[], PartialEventContext>,
color?: Scriptable<Color | Color[], PartialEventContext>,
/**
* Padding of label
* @default 6
*/
padding?: Scriptable<number | LabelPadding, PartialEventContext>,
/**
* Text alignment when the content of the label is multi-line.
* @default 'center'
*/
textAlign?: Scriptable<LabelTextAlign, PartialEventContext>,
textStrokeColor?: Scriptable<Color, PartialEventContext>,
textStrokeWidth?: Scriptable<number, PartialEventContext>,
/**
* Adjustment along x-axis (left-right) of label relative to above number (can be negative)
* For horizontal lines positioned left or right, negative values move
* the label toward the edge, and positive values toward the center.
* @default 0
*/
xAdjust?: Scriptable<number, PartialEventContext>,
/**
* Adjustment along y-axis (top-bottom) of label relative to above number (can be negative)
* For vertical lines positioned top or bottom, negative values move
* the label toward the edge, and positive values toward the center.
* @default 0
*/
yAdjust?: Scriptable<number, PartialEventContext>,
/**
* Text to display in label. Provide an array to display multiple lines
*/
content: Scriptable<string | string[] | HTMLImageElement | HTMLCanvasElement | null, PartialEventContext>,
/**
* Overrides the width of the image. Could be set in pixel by a number,
* or in percentage of current width of image by a string
*/
width?: Scriptable<number | percentString, PartialEventContext>,
/**
* Overrides the height of the image. Could be set in pixel by a number,
* or in percentage of current height of image by a string
*/
height?: Scriptable<number | percentString, PartialEventContext>,
/**
* Overrides the opacity of the image.
*/
opacity?: Scriptable<number, PartialEventContext>,
z?: Scriptable<number, PartialEventContext>
}
export interface ContainedLabelOptions extends CoreLabelOptions {
backgroundColor?: Scriptable<Color, PartialEventContext>,
borderWidth?: Scriptable<number, PartialEventContext>,
borderColor?: Scriptable<Color, PartialEventContext>,
/**
* Border line cap style. See MDN.
* @default 'butt'
*/
borderCapStyle?: Scriptable<CanvasLineCap, PartialEventContext>,
/**
* Border line dash. See MDN.
* @default []
*/
borderDash?: Scriptable<number[], PartialEventContext>,
/**
* Border line dash offset. See MDN.
* @default 0.0
*/
borderDashOffset?: Scriptable<number, PartialEventContext>,
/**
* Border line join style. See MDN.
* @default 'miter'
*/
borderJoinStyle?: Scriptable<CanvasLineJoin, PartialEventContext>,
/**
* Border radius of the label rectangle
* @default 6
*/
borderRadius?: Scriptable<number | BorderRadius, PartialEventContext>
}
export interface LabelOptions extends ContainedLabelOptions, ShadowOptions {
position?: Scriptable<LabelPosition, PartialEventContext>,
/**
* Whether the label should be displayed
* @default true
*/
display?: Scriptable<boolean, PartialEventContext>,
hitTolerance?: Scriptable<number, PartialEventContext>,
/**
* Rotation of label, in degrees, or 'auto' to use the degrees of the line, default is 0
* @default 90
*/
rotation?: Scriptable<number | 'auto', PartialEventContext>,
z?: Scriptable<number, PartialEventContext>,
callout?: CalloutOptions,
}
export interface BoxLabelOptions extends CoreLabelOptions {
position?: Scriptable<LabelPosition | LabelPositionObject, PartialEventContext>,
/**
* Whether the label should be displayed
* @default true
*/
display?: Scriptable<boolean, PartialEventContext>,
hitTolerance?: Scriptable<number, PartialEventContext>,
rotation?: Scriptable<number, PartialEventContext>,
z?: Scriptable<number, PartialEventContext>
}
export interface LabelTypeOptions extends ContainedLabelOptions {
position?: Scriptable<LabelPosition | LabelPositionObject, PartialEventContext>,
z?: Scriptable<number, PartialEventContext>,
callout?: CalloutOptions,
}
export interface DoughnutLabelOptions extends Omit<ContainedLabelOptions, 'borderCapStyle' | 'borderRadius' | 'padding'> {
position?: Scriptable<LabelPosition | LabelPositionObject, PartialEventContext>,
/**
* Whether the label should be displayed
* @default true
*/
display?: Scriptable<boolean, PartialEventContext>,
rotation?: Scriptable<number, PartialEventContext>
}

View file

@ -0,0 +1,166 @@
import { Chart, Color, PointStyle, BorderRadius, CoreInteractionOptions } from 'chart.js';
import { AnnotationEvents, PartialEventContext, EventContext } from './events';
import { LabelOptions, BoxLabelOptions, LabelTypeOptions, DoughnutLabelOptions } from './label';
import { AnnotationBoxModel, AnnotationElement } from './element';
export type DrawTime = 'afterDraw' | 'afterDatasetsDraw' | 'beforeDraw' | 'beforeDatasetsDraw' | number;
export interface AnnotationTypeRegistry {
box: BoxAnnotationOptions
ellipse: EllipseAnnotationOptions
label: LabelAnnotationOptions
line: LineAnnotationOptions
point: PointAnnotationOptions
polygon: PolygonAnnotationOptions
}
export type AnnotationType = keyof AnnotationTypeRegistry;
export type AnnotationOptions<TYPE extends AnnotationType = AnnotationType> =
{ [key in TYPE]: { type: key } & AnnotationTypeRegistry[key] }[TYPE]
interface AnnotationHooks {
beforeDraw?(context: EventContext): void,
afterDraw?(context: EventContext): void
}
export type Scriptable<T, TContext> = T | ((ctx: TContext, options: AnnotationOptions) => T);
export type ScaleValue = number | string;
interface ShadowOptions {
backgroundShadowColor?: Scriptable<Color, PartialEventContext>,
borderShadowColor?: Scriptable<Color, PartialEventContext>,
shadowBlur?: Scriptable<number, PartialEventContext>,
shadowOffsetX?: Scriptable<number, PartialEventContext>,
shadowOffsetY?: Scriptable<number, PartialEventContext>
}
export interface CoreAnnotationOptions extends AnnotationEvents, ShadowOptions, AnnotationHooks {
adjustScaleRange?: Scriptable<boolean, PartialEventContext>,
borderColor?: Scriptable<Color, PartialEventContext>,
borderDash?: Scriptable<number[], PartialEventContext>,
borderDashOffset?: Scriptable<number, PartialEventContext>,
borderWidth?: Scriptable<number, PartialEventContext>,
display?: Scriptable<boolean, PartialEventContext>,
drawTime?: Scriptable<DrawTime, PartialEventContext>,
hitTolerance?: Scriptable<number, PartialEventContext>,
init?: boolean | (({ chart: Chart, properties: AnnotationBoxModel, options: AnnotationOptions }) => void | boolean | Partial<AnnotationElement>),
id?: string,
xMax?: Scriptable<ScaleValue, PartialEventContext>,
xMin?: Scriptable<ScaleValue, PartialEventContext>,
xScaleID?: Scriptable<string, PartialEventContext>,
yMax?: Scriptable<ScaleValue, PartialEventContext>,
yMin?: Scriptable<ScaleValue, PartialEventContext>,
yScaleID?: Scriptable<string, PartialEventContext>,
z?: Scriptable<number, PartialEventContext>
}
interface AnnotationPointCoordinates {
xValue?: Scriptable<ScaleValue, PartialEventContext>,
yValue?: Scriptable<ScaleValue, PartialEventContext>,
}
export interface ArrowHeadOptions extends ShadowOptions {
backgroundColor?: Scriptable<Color, PartialEventContext>,
borderColor?: Scriptable<Color, PartialEventContext>,
borderDash?: Scriptable<number[], PartialEventContext>,
borderDashOffset?: Scriptable<number, PartialEventContext>,
borderWidth?: Scriptable<number, PartialEventContext>,
display?: Scriptable<boolean, PartialEventContext>,
fill?: Scriptable<boolean, PartialEventContext>,
length?: Scriptable<number, PartialEventContext>,
width?: Scriptable<number, PartialEventContext>,
}
export interface ArrowHeadsOptions extends ArrowHeadOptions{
end?: ArrowHeadOptions,
start?: ArrowHeadOptions,
}
export interface ControlPointOptions {
x?: Scriptable<number | string, PartialEventContext>,
y?: Scriptable<number | string, PartialEventContext>,
}
export interface LineAnnotationOptions extends CoreAnnotationOptions {
arrowHeads?: ArrowHeadsOptions,
curve?: Scriptable<boolean, PartialEventContext>,
controlPoint?: Scriptable<number | string | ControlPointOptions, PartialEventContext>,
endValue?: Scriptable<number|string, PartialEventContext>,
label?: LabelOptions,
scaleID?: Scriptable<string, PartialEventContext>,
value?: Scriptable<number|string, PartialEventContext>
}
export interface BoxAnnotationOptions extends CoreAnnotationOptions {
backgroundColor?: Scriptable<Color, PartialEventContext>,
/**
* Border line cap style. See MDN.
* @default 'butt'
*/
borderCapStyle?: Scriptable<CanvasLineCap, PartialEventContext>,
/**
* Border line dash. See MDN.
* @default []
*/
borderDash?: Scriptable<number[], PartialEventContext>,
/**
* Border line dash offset. See MDN.
* @default 0.0
*/
borderDashOffset?: Scriptable<number, PartialEventContext>,
/**
* Border line join style. See MDN.
* @default 'miter'
*/
borderJoinStyle?: Scriptable<CanvasLineJoin, PartialEventContext>,
borderRadius?: Scriptable<number | BorderRadius, PartialEventContext>,
label?: BoxLabelOptions,
rotation?: Scriptable<number, PartialEventContext>
}
export interface EllipseAnnotationOptions extends CoreAnnotationOptions {
backgroundColor?: Scriptable<Color, PartialEventContext>,
label?: BoxLabelOptions,
rotation?: Scriptable<number, PartialEventContext>
}
export interface PointAnnotationOptions extends CoreAnnotationOptions, AnnotationPointCoordinates {
backgroundColor: Scriptable<Color, PartialEventContext>,
pointStyle?: Scriptable<PointStyle, PartialEventContext>,
radius?: Scriptable<number, PartialEventContext>,
rotation?: Scriptable<number, PartialEventContext>,
xAdjust?: Scriptable<number, PartialEventContext>,
yAdjust?: Scriptable<number, PartialEventContext>,
}
export interface LabelAnnotationOptions extends CoreAnnotationOptions, LabelTypeOptions, AnnotationPointCoordinates {
rotation?: Scriptable<number, PartialEventContext>
}
export interface DoughnutLabelAnnotationOptions extends AnnotationEvents, DoughnutLabelOptions, ShadowOptions {
autoFit?: Scriptable<boolean, PartialEventContext>,
autoHide?: Scriptable<boolean, PartialEventContext>,
id?: string,
init: boolean | ((chart: Chart, properties: AnnotationBoxModel, options: AnnotationOptions) => void | boolean | AnnotationBoxModel),
spacing?: Scriptable<number, PartialEventContext>
}
interface PolygonAnnotationOptions extends CoreAnnotationOptions, AnnotationPointCoordinates {
backgroundColor: Scriptable<Color, PartialEventContext>,
borderCapStyle?: Scriptable<CanvasLineCap, PartialEventContext>,
borderJoinStyle?: Scriptable<CanvasLineJoin, PartialEventContext>,
point?: PointAnnotationOptions,
radius?: Scriptable<number, PartialEventContext>,
rotation?: Scriptable<number, PartialEventContext>,
sides?: Scriptable<number, PartialEventContext>,
xAdjust?: Scriptable<number, PartialEventContext>,
yAdjust?: Scriptable<number, PartialEventContext>,
}
export interface AnnotationPluginOptions extends AnnotationEvents, AnnotationHooks {
animations?: Record<string, unknown>,
annotations: AnnotationOptions[] | Record<string, AnnotationOptions>,
clip?: boolean,
common?: BoxAnnotationOptions | EllipseAnnotationOptions | LabelAnnotationOptions | LineAnnotationOptions | PointAnnotationOptions | PolygonAnnotationOptions | DoughnutLabelAnnotationOptions,
interaction?: CoreInteractionOptions
}