Skip to content

Commit

Permalink
fix(types): Specify context for callbacks
Browse files Browse the repository at this point in the history
- Specify explicitly this context for all callbacks
- Remove ctx params from examples docs

Fix #1551
  • Loading branch information
netil committed Jul 27, 2020
1 parent fe315dc commit f3b9f26
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 102 deletions.
32 changes: 16 additions & 16 deletions src/config/Options/common/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ export default {
* @type {Function}
* @default undefined
* @example
* // @param {Chart} ctx - Instance itself
* onover: function(ctx) {
* onover: function() {
* this; // chart instance itself
* ...
* }
*/
Expand All @@ -162,8 +162,8 @@ export default {
* @type {Function}
* @default undefined
* @example
* // @param {Chart} ctx - Instance itself
* onout: function(ctx) {
* onout: function() {
* this; // chart instance itself
* ...
* }
*/
Expand All @@ -176,8 +176,8 @@ export default {
* @type {Function}
* @default undefined
* @example
* // @param {Chart} ctx - Instance itself
* onresize: function(ctx) {
* onresize: function() {
* this; // chart instance itself
* ...
* }
*/
Expand All @@ -190,8 +190,8 @@ export default {
* @type {Function}
* @default undefined
* @example
* // @param {Chart} ctx - Instance itself
* onresized: function(ctx) {
* onresized: function() {
* this; // chart instance itself
* ...
* }
*/
Expand All @@ -204,8 +204,8 @@ export default {
* @type {Function}
* @default undefined
* @example
* // @param {Chart} ctx - Instance itself
* onbeforeinit: function(ctx) {
* onbeforeinit: function() {
* this; // chart instance itself
* ...
* }
*/
Expand All @@ -218,8 +218,8 @@ export default {
* @type {Function}
* @default undefined
* @example
* // @param {Chart} ctx - Instance itself
* oninit: function(ctx) {
* oninit: function() {
* this; // chart instance itself
* ...
* }
*/
Expand All @@ -232,8 +232,8 @@ export default {
* @type {Function}
* @default undefined
* @example
* // @param {Chart} ctx - Instance itself
* onafterinit: function(ctx) {
* onafterinit: function() {
* this; // chart instance itself
* ...
* }
*/
Expand All @@ -246,8 +246,8 @@ export default {
* @type {Function}
* @default undefined
* @example
* // @param {Chart} ctx - Instance itself
* onrendered: function(ctx) {
* onrendered: function() {
* this; // chart instance itself
* ...
* }
*/
Expand Down
16 changes: 4 additions & 12 deletions src/config/Options/common/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,36 +136,28 @@ export default {
* },
*
* // fires prior tooltip is shown
* onshow: function(ctx, selectedData) {
* ctx; // current chart instance
*
* onshow: function(selectedData) {
* // current dataset selected
* // ==> [{x: 4, value: 150, id: "data2", index: 4, name: "data2"}, ...]
* selectedData;
* },
*
* // fires prior tooltip is hidden
* onhide: function(ctx, selectedData) {
* ctx; // current chart instance
*
* onhide: function(selectedData) {
* // current dataset selected
* // ==> [{x: 4, value: 150, id: "data2", index: 4, name: "data2"}, ...]
* selectedData;
* },
*
* // fires after tooltip is shown
* onshown: function(ctx, selectedData) {
* ctx; // current chart instance
*
* onshown: function(selectedData) {
* // current dataset selected
* // ==> [{x: 4, value: 150, id: "data2", index: 4, name: "data2"}, ...]
* selectedData;
* },
*
* // fires after tooltip is hidden
* onhidden: function(ctx, selectedData) {
* ctx; // current chart instance
*
* onhidden: function(selectedData) {
* // current dataset selected
* // ==> [{x: 4, value: 150, id: "data2", index: 4, name: "data2"}, ...]
* selectedData;
Expand Down
15 changes: 9 additions & 6 deletions types/axis.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Chart} from "./chart";

/**
* Copyright (c) 2017 ~ present NAVER Corp.
* billboard.js project is licensed under the MIT license
Expand Down Expand Up @@ -94,6 +96,7 @@ export interface xAxisConfiguration extends AxisConfigurationBase {
*/
extent?: number[] | string[] | (
(
this: Chart,
domain: Date|string|number[],
scale: (value: any) => number
) => number[]
Expand Down Expand Up @@ -202,8 +205,8 @@ export interface XTickConfiguration {
* A function to format tick value. Format string is also available for timeseries data.
*/
format?: string
| ((x: number | Date) => string | number)
| ((index: number, categoryName: string) => string);
| ((this: Chart, x: number | Date) => string | number)
| ((this: Chart, index: number, categoryName: string) => string);

/**
* Setting for culling ticks.
Expand Down Expand Up @@ -236,7 +239,7 @@ export interface XTickConfiguration {
* If this option is provided, the position of the ticks will be determined based on those values.
* This option works with timeseries data and the x values will be parsed accoding to the type of the value and data.xFormat option.
*/
values?: number[] | string[];
values?: number[] | string[] | ((this: Chart) => number[]);

/**
* Rotate x axis tick text.
Expand Down Expand Up @@ -308,7 +311,7 @@ export interface YTickConfiguration {
/**
* Set the y values of ticks manually.
*/
values?: number[];
values?: number[] | ((this: Chart) => number[]);

/**
* Rotate y(or y2) axis tick text.
Expand All @@ -328,7 +331,7 @@ export interface YTickConfiguration {
* Set formatter for y axis tick text.
* This option accepts d3.format object as well as a function you define.
*/
format?(x: number): string;
format?(this: Chart, x: number): string;

/**
* Setting for culling ticks.
Expand Down Expand Up @@ -383,7 +386,7 @@ export interface AxesConfiguration {
/**
* Set formatter for tick text
*/
format?: (x: string) => string;
format?: (this: Chart, x: string) => string;

/**
* Set the number of y axis ticks
Expand Down
8 changes: 4 additions & 4 deletions types/chart.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export interface Chart {
* - done will be called after data loaded, but it's not after rendering.
* It's because rendering will finish after some transition and there is some time lag between loading and rendering
*/
load(args: {
load(this: Chart, args: {
url?: string;
json?: [{ [key: string]: string }];
rows?: PrimitiveArray[];
Expand Down Expand Up @@ -352,7 +352,7 @@ export interface Chart {
* - If you call load API soon after/before unload, unload param of load should be used. Otherwise chart will not be rendered properly because of cancel of animation.
* - done will be called after data loaded, but it's not after rendering. It's because rendering will finish after some transition and there is some time lag between loading and rendering.
*/
unload(targetIds?: TargetIds, done?: () => any): any;
unload(this: Chart, targetIds?: TargetIds, done?: () => any): any;

/**
* Flow data to the chart. By this API, you can append new data points to the chart.
Expand Down Expand Up @@ -383,7 +383,7 @@ export interface Chart {
to?: any;
length?: number;
duration?: number;
done?(): any;
done?(this: Chart): any;
}): void;

/**
Expand Down Expand Up @@ -482,7 +482,7 @@ export interface Chart {
* @param mimeType The desired output image format. (ex. 'image/png' for png, 'image/jpeg' for jpeg format)
* @param callback The callback to be invoked when export is ready.
*/
export(mimeType?: string, callback?: (dataUrl: string) => string): string;
export(this: Chart, mimeType?: string, callback?: (dataUrl: string) => string): string;

/**
* Get or set single config option value.
Expand Down
Loading

0 comments on commit f3b9f26

Please sign in to comment.