Skip to content

Commit

Permalink
1620: Fixed tests and review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-korobko committed Jul 5, 2024
1 parent edd5100 commit eb791e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
20 changes: 7 additions & 13 deletions src/gui/price-axis-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ function recalculateOverlapping(
views: IPriceAxisView[],
direction: 1 | -1,
scaleHeight: number,
center: number,
rendererOptions: Readonly<PriceAxisViewRendererOptions>
): void {
if (!views.length) {
return;
}
let currentGroupStart = 0;
const center = scaleHeight / 2;

const initLabelHeight = views[0].height(rendererOptions, true);
let spaceBeforeCurrentGroup = direction === 1
Expand Down Expand Up @@ -566,8 +566,6 @@ export class PriceAxisWidget implements IDestroyable {
if (this._size === null || this._priceScale === null) {
return;
}
const center = this._size.height / 2;

const views: IPriceAxisView[] = [];
const orderedSources = this._priceScale.orderedSources().slice(); // Copy of array
const pane = this._pane;
Expand Down Expand Up @@ -610,28 +608,24 @@ export class PriceAxisWidget implements IDestroyable {
return;
}

this._fixLabelOverlap(views, rendererOptions, center);
this._fixLabelOverlap(views, rendererOptions);
}

private _fixLabelOverlap(views: IPriceAxisView[], rendererOptions: Readonly<PriceAxisViewRendererOptions>, center: number): void {
private _fixLabelOverlap(views: IPriceAxisView[], rendererOptions: Readonly<PriceAxisViewRendererOptions>): void {
if (this._size === null) {
return;
}

const center = this._size.height / 2;

// split into two parts
const top = views.filter((view: IPriceAxisView) => view.coordinate() <= center);
const bottom = views.filter((view: IPriceAxisView) => view.coordinate() > center);

// sort top from center to top
top.sort((l: IPriceAxisView, r: IPriceAxisView) => r.coordinate() - l.coordinate());

bottom.sort((l: IPriceAxisView, r: IPriceAxisView) => l.coordinate() - r.coordinate());

// share center label
if (top.length && bottom.length) {
bottom.unshift(top[0]);
}

for (const view of views) {
const halfHeight = Math.floor(view.height(rendererOptions) / 2);
const coordinate = view.coordinate();
Expand All @@ -644,8 +638,8 @@ export class PriceAxisWidget implements IDestroyable {
}
}

recalculateOverlapping(top, 1, this._size.height, center, rendererOptions);
recalculateOverlapping(bottom, -1, this._size.height, center, rendererOptions);
recalculateOverlapping(top, 1, this._size.height, rendererOptions);
recalculateOverlapping(bottom, -1, this._size.height, rendererOptions);
}

private _drawBackLabels(target: CanvasRenderingTarget2D): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function runTestCase(container) {
const chartOptions = {
height: 320,
height: 500,
width: 600,
rightPriceScale: {
scaleMargins: {
Expand Down

0 comments on commit eb791e0

Please sign in to comment.