Skip to content

Commit

Permalink
feat: Improve X-labels generation time // PR fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillBobkov committed Dec 7, 2023
1 parent 65fe25f commit 1a76d21
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/chart/components/x_axis/x-axis-labels.generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export class XAxisTimeLabelsGenerator implements XAxisLabelsGenerator {
private labelsGroupedByWeight: Record<number, XAxisLabelWeighted[]> = {};
private weightedCache?: { labels: XAxisLabelWeighted[]; coverUpLevel: number };
private levelsCache: Record<number, XAxisLabelWeighted[]> = {};
private prevAnimationId = '';

get labels(): XAxisLabelWeighted[] {
return this.filterLabelsInViewport(this.getLabelsFromChartType());
Expand Down Expand Up @@ -360,20 +359,14 @@ export class XAxisTimeLabelsGenerator implements XAxisLabelsGenerator {
private calculateCoverUpLevel = () => {
const animation = this.scale.currentAnimation;
const meanCandleWidthInUnits = this.chartModel.mainCandleSeries.meanCandleWidth;
let meanCandleWidthInPixels;
if (Object.getOwnPropertyNames(this.labelsGroupedByWeight).length === 0) {
return -1;
}

// calculate coverUpLevel for target zoomX to prevent extra labels calculations on every animation tick
if (animation?.animationInProgress) {
if (animation.id !== this.prevAnimationId) {
this.prevAnimationId = animation.id;
}
meanCandleWidthInPixels = unitToPixels(meanCandleWidthInUnits, animation.animationConfig.targetZoomX);
} else {
meanCandleWidthInPixels = unitToPixels(meanCandleWidthInUnits, this.scale.zoomX);
}
const meanCandleWidthInPixels = animation?.animationInProgress
? unitToPixels(meanCandleWidthInUnits, animation.animationConfig.targetZoomX)
: unitToPixels(meanCandleWidthInUnits, this.scale.zoomX);

if (!isFinite(meanCandleWidthInPixels)) {
return -1;
}
Expand Down

0 comments on commit 1a76d21

Please sign in to comment.