From c70ef8123037a52c93712cd053737e536827081b Mon Sep 17 00:00:00 2001 From: kurkle Date: Thu, 9 Dec 2021 12:12:30 +0200 Subject: [PATCH] Fix remaining files --- docs/guide/types/box.md | 3 ++- docs/guide/types/label.md | 9 +++++---- docs/guide/types/line.md | 1 + src/annotation.js | 1 + src/helpers.js | 1 + src/types/box.js | 1 + src/types/label.js | 1 + src/types/point.js | 1 + test/events.js | 1 + test/specs/label.spec.js | 1 - 10 files changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/guide/types/box.md b/docs/guide/types/box.md index b09d4c9b2..01be8699f 100644 --- a/docs/guide/types/box.md +++ b/docs/guide/types/box.md @@ -2,6 +2,7 @@ Box annotations are used to draw rectangles on the chart area. This can be useful for highlighting different areas of a chart. + ```js chart-editor /* */ const options = { @@ -126,6 +127,6 @@ All of these options can be [Scriptable](../options#scriptable-options) #### Position -If this value is a string (possible options are `'start'`, `'center'`, `'end'`), it is applied to vertical and horizontal position in the box. +If this value is a string (possible options are `'start'`, `'center'`, `'end'`), it is applied to vertical and horizontal position in the box. If this value is an object, the `x` property defines the horizontal alignment in the box. Similarly, the `y` property defines the vertical alignment in the box. Possible options for both properties are `'start'`, `'center'`, `'end'`. Omitted property have value of the default, `'center'`. diff --git a/docs/guide/types/label.md b/docs/guide/types/label.md index 31c4f66e4..4dbed1809 100644 --- a/docs/guide/types/label.md +++ b/docs/guide/types/label.md @@ -2,6 +2,7 @@ Label annotations are used to add contents on the chart area. This can be useful for describing values that are of interest. + ```js chart-editor /* */ const options = { @@ -68,7 +69,7 @@ The following options are available for label annotations. | [`display`](#general) | `boolean` | Yes | `true` | [`drawTime`](#general) | `string` | Yes | `'afterDatasetsDraw'` | [`font`](#styling) | [`Font`](../options#font) | Yes | `{}` -| [`height`](#general) | `number`\|`string` | Yes | `undefined` +| [`height`](#general) | `number`\|`string` | Yes | `undefined` | [`padding`](#general) | [`Padding`](../options#padding) | Yes | `6` | [`point`](#point) | `object` | Yes | | [`position`](#position) | `string`\|`{x: string, y: string}` | Yes | `'center'` @@ -89,7 +90,7 @@ The following options are available for label annotations. If one of the axes does not match an axis in the chart, the content will be rendered in the center of the chart. The 2 coordinates, xValue, yValue are optional. If not specified, the content will be rendered in the center of the chart. -The 4 coordinates, xMin, xMax, yMin, yMax are optional. If not specified, the box is expanded out to the edges in the respective direction and the box size is used to calculated the center of the point. To enable to use the box positioning, the `radius` must be set to `0` or `NaN`. +The 4 coordinates, xMin, xMax, yMin, yMax are optional. If not specified, the box is expanded out to the edges in the respective direction and the box size is used to calculated the center of the point. To enable to use the box positioning, the `radius` must be set to `0` or `NaN`. | Name | Description | @@ -277,7 +278,7 @@ All of these options can be [Scriptable](../options#scriptable-options). | Name | Type | Default | Notes | ---- | ---- | :----: | ---- | ---- -| `borderCapStyle` | `string` | `'butt'` | Cap style of the border line of callout. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineCap). +| `borderCapStyle` | `string` | `'butt'` | Cap style of the border line of callout. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineCap). | `borderColor` | [`Color`](../options#color) | `undefined` | Stroke color of the pointer of the callout. | `borderDash` | `number[]` | `[]` | Length and spacing of dashes of callout. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash). | `borderDashOffset` | `number` | `0` | Offset for line dashes of callout. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset). @@ -287,4 +288,4 @@ All of these options can be [Scriptable](../options#scriptable-options). | `margin` | `number` | `5` | Amount of pixels between the label and the callout separator. | `position` | `string` | `'auto'` | The position of callout, with respect to the label. Could be `left`, `top`, `right`, `bottom` or `auto`. | `side` | `number` | `5` | Width of the starter line of callout pointer. -| `start` | `number`\|`string` | `'50%'` | The percentage of the separator dimension to use as starting point for callout pointer. Could be set in pixel by a number, or in percentage of the separator dimension by a string. +| `start` | `number`\|`string` | `'50%'` | The percentage of the separator dimension to use as starting point for callout pointer. Could be set in pixel by a number, or in percentage of the separator dimension by a string. diff --git a/docs/guide/types/line.md b/docs/guide/types/line.md index addcea7a7..78c41921d 100644 --- a/docs/guide/types/line.md +++ b/docs/guide/types/line.md @@ -2,6 +2,7 @@ Line annotations are used to draw lines on the chart area. This can be useful for highlighting information such as a threshold. + ```js chart-editor /* */ const options = { diff --git a/src/annotation.js b/src/annotation.js index c634b2cf5..8973640a5 100644 --- a/src/annotation.js +++ b/src/annotation.js @@ -4,6 +4,7 @@ import {handleEvent, hooks, updateListeners} from './events'; import {annotationTypes} from './types'; import {version} from '../package.json'; + const chartStates = new Map(); export default { diff --git a/src/helpers.js b/src/helpers.js index 32e6d1c2c..a521b16f3 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -1,6 +1,7 @@ import {isFinite, isArray, isObject, toFont, addRoundedRectPath, toTRBLCorners, valueOrDefault, drawPoint as drawPointOnChart} from 'chart.js/helpers'; const widthCache = new Map(); + const toPercent = (s) => typeof s === 'string' && s.endsWith('%') && parseFloat(s) / 100; export function getSize(size, value) { diff --git a/src/types/box.js b/src/types/box.js index 7ae8b7b51..59ef4e52f 100644 --- a/src/types/box.js +++ b/src/types/box.js @@ -2,6 +2,7 @@ import {Element} from 'chart.js'; import {toPadding} from 'chart.js/helpers'; import {drawBox, drawLabel, measureLabelSize, isLabelVisible, getRectCenterPoint, getChartRect, toPosition} from '../helpers'; + export default class BoxAnnotation extends Element { inRange(mouseX, mouseY, useFinalPosition) { const {x, y, width, height} = this.getProps(['x', 'y', 'width', 'height'], useFinalPosition); diff --git a/src/types/label.js b/src/types/label.js index a26416a81..efc24bc18 100644 --- a/src/types/label.js +++ b/src/types/label.js @@ -2,6 +2,7 @@ import {drawBox, drawLabel, drawPoint, measureLabelSize, isLabelVisible, getChar import {color as getColor, toPadding} from 'chart.js/helpers'; import {Element} from 'chart.js'; + export default class LabelAnnotation extends Element { inRange(mouseX, mouseY) { diff --git a/src/types/point.js b/src/types/point.js index eae968e8d..b23103ad8 100644 --- a/src/types/point.js +++ b/src/types/point.js @@ -1,6 +1,7 @@ import {Element} from 'chart.js'; import {drawPoint, inPointRange, getElementCenterPoint, resolvePointPosition} from '../helpers'; + export default class PointAnnotation extends Element { inRange(x, y) { diff --git a/test/events.js b/test/events.js index f67c74a9b..2b74bf472 100644 --- a/test/events.js +++ b/test/events.js @@ -1,3 +1,4 @@ + export function testEvents(options, innerElement) { const descr = innerElement ? options.type + '.' + innerElement : options.type; const chartConfig = { diff --git a/test/specs/label.spec.js b/test/specs/label.spec.js index ba06b7265..3cc366ed3 100644 --- a/test/specs/label.spec.js +++ b/test/specs/label.spec.js @@ -25,7 +25,6 @@ describe('Label annotation', function() { }; window.testEvents(options); - window.testEvents(options, 'point'); });