Skip to content

Commit

Permalink
Remove I prefix from TS types (#8017)
Browse files Browse the repository at this point in the history
* Remove I prefix from TS types
* Update missing `ILayoutItem` typedefs
* IEvent should become ChartEvent
* Prevent FillTarget collision
* Import FontSpec instead of IFontSpec
* Prevent recursive DateAdapter problem
  • Loading branch information
etimberg authored Nov 7, 2020
1 parent 34312fd commit 17f6edb
Show file tree
Hide file tree
Showing 22 changed files with 499 additions and 499 deletions.
8 changes: 4 additions & 4 deletions docs/docs/developers/charts.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,16 @@ new Chart(ctx, {

If you want your new chart type to be statically typed, you must provide a `.d.ts` TypeScript declaration file. Chart.js provides a way to augment built-in types with user-defined ones, by using the concept of "declaration merging".

When adding a new chart type, `IChartTypeRegistry` must contains the declarations for the new type, either by extending an existing entry in `IChartTypeRegistry` or by creating a new one.
When adding a new chart type, `ChartTypeRegistry` must contains the declarations for the new type, either by extending an existing entry in `ChartTypeRegistry` or by creating a new one.

For example, to provide typings for a new chart type that extends from a bubble chart, you would add a `.d.ts` containing:

```ts
import { IChartTypeRegistry } from 'chart.js'
import { ChartTypeRegistry } from 'chart.js'

declare module 'chart.js' {
interface IChartTypeRegistry {
derivedBubble: IChartTypeRegistry['bubble']
interface ChartTypeRegistry {
derivedBubble: ChartTypeRegistry['bubble']
}
}
```
6 changes: 3 additions & 3 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {clear as canvasClear, clipArea, unclipArea, _isPointInArea} from '../hel
import {version} from '../../package.json';

/**
* @typedef { import("../platform/platform.base").IEvent } IEvent
* @typedef { import("../platform/platform.base").ChartEvent } ChartEvent
*/

const KNOWN_POSITIONS = ['top', 'bottom', 'left', 'right', 'chartArea'];
Expand Down Expand Up @@ -319,7 +319,7 @@ class Chart {
me.scales = scales;

each(scales, (scale) => {
// Set ILayoutItem parameters for backwards compatibility
// Set LayoutItem parameters for backwards compatibility
scale.fullWidth = scale.options.fullWidth;
scale.position = scale.options.position;
scale.weight = scale.options.weight;
Expand Down Expand Up @@ -1006,7 +1006,7 @@ class Chart {

/**
* Handle an event
* @param {IEvent} e the event to handle
* @param {ChartEvent} e the event to handle
* @param {boolean} [replay] - true if the event was replayed by `update`
* @return {boolean} true if the chart needs to re-render
* @private
Expand Down
4 changes: 2 additions & 2 deletions src/core/core.interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import {getRelativePosition as helpersGetRelativePosition} from '../helpers/help

/**
* @typedef { import("./core.controller").default } Chart
* @typedef { import("../platform/platform.base").IEvent } IEvent
* @typedef { import("../platform/platform.base").ChartEvent } ChartEvent
* @typedef {{axis?: string, intersect?: boolean}} InteractionOptions
* @typedef {{datasetIndex: number, index: number, element: import("./core.element").default}} InteractionItem
*/

/**
* Helper function to get relative position for an event
* @param {Event|IEvent} e - The event to get the position for
* @param {Event|ChartEvent} e - The event to get the position for
* @param {Chart} chart - The chart
* @returns {object} the event position
*/
Expand Down
10 changes: 5 additions & 5 deletions src/core/core.layouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ defaults.set('layout', {
});

/**
* @interface ILayoutItem
* @typedef {object} ILayoutItem
* @interface LayoutItem
* @typedef {object} LayoutItem
* @prop {string} position - The position of the item in the chart layout. Possible values are
* 'left', 'top', 'right', 'bottom', and 'chartArea'
* @prop {number} weight - The weight used to sort the item. Higher weights are further away from the chart area
Expand All @@ -241,7 +241,7 @@ export default {
* Register a box to a chart.
* A box is simply a reference to an object that requires layout. eg. Scales, Legend, Title.
* @param {Chart} chart - the chart to use
* @param {ILayoutItem} item - the item to add to be laid out
* @param {LayoutItem} item - the item to add to be laid out
*/
addBox(chart, item) {
if (!chart.boxes) {
Expand All @@ -268,7 +268,7 @@ export default {
/**
* Remove a layoutItem from a chart
* @param {Chart} chart - the chart to remove the box from
* @param {ILayoutItem} layoutItem - the item to remove from the layout
* @param {LayoutItem} layoutItem - the item to remove from the layout
*/
removeBox(chart, layoutItem) {
const index = chart.boxes ? chart.boxes.indexOf(layoutItem) : -1;
Expand All @@ -280,7 +280,7 @@ export default {
/**
* Sets (or updates) options on the given `item`.
* @param {Chart} chart - the chart in which the item lives (or will be added to)
* @param {ILayoutItem} item - the item to configure with the given options
* @param {LayoutItem} item - the item to configure with the given options
* @param {object} options - the new item options.
*/
configure(chart, item, options) {
Expand Down
8 changes: 4 additions & 4 deletions src/core/core.plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {mergeIf} from '../helpers/helpers.core';

/**
* @typedef { import("./core.controller").default } Chart
* @typedef { import("../platform/platform.base").IEvent } IEvent
* @typedef { import("../platform/platform.base").ChartEvent } ChartEvent
* @typedef { import("../plugins/plugin.tooltip").default } Tooltip
*/

Expand Down Expand Up @@ -108,7 +108,7 @@ function createDescriptors(plugins, options) {

/**
* Plugin extension hooks.
* @interface IPlugin
* @interface Plugin
* @typedef {object} IPlugin
* @since 2.1.0
*/
Expand Down Expand Up @@ -301,7 +301,7 @@ function createDescriptors(plugins, options) {
* @desc Called before processing the specified `event`. If any plugin returns `false`,
* the event will be discarded.
* @param {Chart} chart - The chart instance.
* @param {IEvent} event - The event object.
* @param {ChartEvent} event - The event object.
* @param {boolean} replay - True if this event is replayed from `Chart.update`
* @param {object} options - The plugin options.
*/
Expand All @@ -310,7 +310,7 @@ function createDescriptors(plugins, options) {
* @desc Called after the `event` has been consumed. Note that this hook
* will not be called if the `event` has been previously discarded.
* @param {Chart} chart - The chart instance.
* @param {IEvent} event - The event object.
* @param {ChartEvent} event - The event object.
* @param {boolean} replay - True if this event is replayed from `Chart.update`
* @param {object} options - The plugin options.
*/
Expand Down
10 changes: 5 additions & 5 deletions src/platform/platform.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ export default class BasePlatform {
/**
* Registers the specified listener on the given chart.
* @param {Chart} chart - Chart from which to listen for event
* @param {string} type - The ({@link IEvent}) type to listen for
* @param {string} type - The ({@link ChartEvent}) type to listen for
* @param {function} listener - Receives a notification (an object that implements
* the {@link IEvent} interface) when an event of the specified type occurs.
* the {@link ChartEvent} interface) when an event of the specified type occurs.
*/
addEventListener(chart, type, listener) {} // eslint-disable-line no-unused-vars

/**
* Removes the specified listener previously registered with addEventListener.
* @param {Chart} chart - Chart from which to remove the listener
* @param {string} type - The ({@link IEvent}) type to remove
* @param {string} type - The ({@link ChartEvent}) type to remove
* @param {function} listener - The listener function to remove from the event target.
*/
removeEventListener(chart, type, listener) {} // eslint-disable-line no-unused-vars
Expand Down Expand Up @@ -75,8 +75,8 @@ export default class BasePlatform {
}

/**
* @interface IEvent
* @typedef {object} IEvent
* @interface ChartEvent
* @typedef {object} ChartEvent
* @prop {string} type - The event type name, possible values are:
* 'contextmenu', 'mouseenter', 'mousedown', 'mousemove', 'mouseup', 'mouseout',
* 'click', 'dblclick', 'keydown', 'keypress', 'keyup' and 'resize'
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/plugin.legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '../helpers/index';

/**
* @typedef { import("../platform/platform.base").IEvent } IEvent
* @typedef { import("../platform/platform.base").ChartEvent } ChartEvent
*/

/**
Expand Down Expand Up @@ -587,7 +587,7 @@ export class Legend extends Element {

/**
* Handle an event
* @param {IEvent} e - The event to handle
* @param {ChartEvent} e - The event to handle
*/
handleEvent(e) {
const me = this;
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/plugin.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {toFont} from '../helpers/helpers.options';
import {drawPoint} from '../helpers';

/**
* @typedef { import("../platform/platform.base").IEvent } IEvent
* @typedef { import("../platform/platform.base").ChartEvent } ChartEvent
*/

const positioners = {
Expand Down Expand Up @@ -979,7 +979,7 @@ export class Tooltip extends Element {

/**
* Handle an event
* @param {IEvent} e - The event to handle
* @param {ChartEvent} e - The event to handle
* @param {boolean} [replay] - This is a replayed event (from update)
* @returns {boolean} true if the tooltip changed
*/
Expand Down Expand Up @@ -1027,7 +1027,7 @@ export class Tooltip extends Element {
* Determine if the active elements + event combination changes the
* tooltip position
* @param {array} active - Active elements
* @param {IEvent} e - Event that triggered the position change
* @param {ChartEvent} e - Event that triggered the position change
* @returns {boolean} True if the position has changed
*/
_positionChanged(active, e) {
Expand Down
Loading

0 comments on commit 17f6edb

Please sign in to comment.