Skip to content

Commit

Permalink
fix(types): Fix types for the tooltip contents callback
Browse files Browse the repository at this point in the history
Fix tooltip.contents callback params types.

Close #2693
  • Loading branch information
stof authored and netil committed May 23, 2022
1 parent 40f4b66 commit a0c0355
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/ChartInternal/internals/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {document, window} from "../../module/browser";
import {$ARC, $COLOR, $SHAPE} from "../../config/classes";
import {KEY} from "../../module/Cache";
import {notEmpty, isFunction, isObject, isString} from "../../module/util";
import {IArcData, IDataRow} from "../data/IData";

/**
* Set pattern's background color
Expand Down Expand Up @@ -103,8 +104,8 @@ export default {
$$.patterns = colorizedPatterns;
}

return function(d) {
const id: string = d.id || d.data?.id || d;
return function(d: IDataRow | IArcData | string): string {
const id: string = (d as IDataRow).id || (d as IArcData).data?.id || d as string;
const isLine = $$.isTypeOf(id, ["line", "spline", "step"]) || !config.data_types[id];
let color;

Expand Down
2 changes: 1 addition & 1 deletion src/config/Options/common/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default {
* - **Note:**
* - defaultTitleFormat:
* - if `axis.x.tick.format` option will be used if set.
* - otherwise, will return funciton based on tick format type(category, timeseries).
* - otherwise, will return function based on tick format type(category, timeseries).
* - defaultValueFormat:
* - for Arc type (except gauge, radar), the function will return value from `(ratio * 100).toFixed(1)`.
* - for Axis based types, will be used `axis.[y|y2].tick.format` option value if is set.
Expand Down
10 changes: 5 additions & 5 deletions types/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Bubblecompare from "./plugin/bubblecompare/index";
import Stanford from "./plugin/stanford/index";
import TextOverlap from "./plugin/textoverlap/index";
import {Chart} from "./chart";
import {IData} from "../src/ChartInternal/data/IData";
import {IArcData, IData, IDataRow} from "../src/ChartInternal/data/IData";

export interface ChartOptions {
/**
Expand Down Expand Up @@ -1082,10 +1082,10 @@ export interface TooltipOptions {
*/
contents?: ((
this: Chart,
data: any,
defaultTitleFormat: string,
defaultValueFormat: string,
color: any
data: IDataRow[],

This comment has been minimized.

Copy link
@stof

stof Jul 6, 2022

Author Contributor

Isn't this IArcData for pie charts ?

And the value format expects a ratio, but IArcData does not have a ratio property so it might not even be the right.

Also, the type IDataRow looks wrong to me here, as it says that x is number, which looks wrong for timeseries chart where we have dates.

This comment has been minimized.

Copy link
@stof

stof Jul 6, 2022

Author Contributor

shouldn't this be DataItem instead ?

defaultTitleFormat: (x: Date|number|string) => number|string,
defaultValueFormat: (value: number, ratio: number|undefined, id: string) => number|string,
color: (d: IDataRow|IArcData|string) => string
) => string) | {
/**
* Set CSS selector or element reference to bind tooltip.
Expand Down

0 comments on commit a0c0355

Please sign in to comment.