Skip to content

Commit

Permalink
fix(shape): Fix circleY() undefined error
Browse files Browse the repository at this point in the history
- Make .circleY() visible and included as part of common
- Move .circleY() to shape.ts file

Fix #3388
  • Loading branch information
netil authored Sep 4, 2023
1 parent 216da62 commit f4ac3f1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/ChartInternal/data/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ export default {
return !!(config.data_stack_normalize && config.data_groups.length);
},

isGrouped(id) {
/**
* Check if given id is grouped data or has grouped data
* @param {string} id Data id value
* @returns {boolean} is grouped data or has grouped data
* @private
*/
isGrouped(id?: string): boolean {
const groups = this.config.data_groups;

return id ?
Expand Down
5 changes: 0 additions & 5 deletions src/ChartInternal/internals/redraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ export default {
$$.updateDimension(true);
}

// update circleY based on updated parameters
if (!treemap && (!$$.hasArcType() || state.hasRadar)) {
$$.updateCircleY && ($$.circleY = $$.updateCircleY());
}

// Data empty label positioning and text.
config.data_empty_label_text && main.select(`text.${$TEXT.text}.${$COMMON.empty}`)
.attr("x", state.width / 2)
Expand Down
41 changes: 41 additions & 0 deletions src/ChartInternal/shape/shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ import CLASS from "../../config/classes";
import {capitalize, getPointer, getRectSegList, getUnique, isObjectType, isNumber, isValue, isUndefined, notEmpty} from "../../module/util";
import type {IDataRow, IDataIndice, TIndices} from "../data/IData";

/**
* Get grouped data point function for y coordinate
* - Note: Grouped(stacking) works only for line and bar types
* @param {object} d data vlaue
* @returns {Function|undefined}
* @private
*/
function getGroupedDataPointsFn(d) {
const $$ = this;
let fn;

if ($$.isLineType(d)) {
fn = $$.generateGetLinePoints($$.getShapeIndices($$.isLineType));
} else if ($$.isBarType(d)) {
fn = $$.generateGetBarPoints($$.getShapeIndices($$.isBarType));
}

return fn;
}

export interface IOffset {
_$width: number;
_$total: number[]
Expand Down Expand Up @@ -376,6 +396,27 @@ export default {
};
},

/**
* Get data's y coordinate
* @param {object} d Target data
* @param {number} i Index number
* @returns {number} y coordinate
* @private
*/
circleY(d: IDataRow, i: number): number {
const $$ = this;
const id = d.id;
let points;

if ($$.isGrouped(id)) {
points = getGroupedDataPointsFn.bind($$)(d);
}

return points ?
points(d, i)[0][1] :
$$.getYScaleById(id)($$.getBaseValue(d));
},

getBarW(type, axis, targetsNum: number): number | IOffset {
const $$ = this;
const {config, org, scale} = $$;
Expand Down
2 changes: 1 addition & 1 deletion test/internals/tooltip-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,7 @@ describe("TOOLTIP", function() {
x: {
type: "timeseries",
tick: {
format: "%Y-%m-%d",
format: "%Y-%m-%d",
}
}
}
Expand Down

0 comments on commit f4ac3f1

Please sign in to comment.