Skip to content

Commit

Permalink
Merge pull request #1757 from tradingview/CLL-310_smaller-price-scale…
Browse files Browse the repository at this point in the history
…-when-crosshair-label-hidden

improve check for crosshair label visibility on the price scale
  • Loading branch information
SlicedSilver committed Dec 17, 2024
1 parent 0432678 commit 2520d6f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/gui/price-axis-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { makeFont } from '../helpers/make-font';

import { ChartOptionsInternalBase } from '../model/chart-model';
import { Coordinate } from '../model/coordinate';
import { CrosshairMode } from '../model/crosshair';
import { CrosshairMode, CrosshairOptions } from '../model/crosshair';
import { IDataSource, IDataSourcePaneViews } from '../model/idata-source';
import { InvalidationLevel } from '../model/invalidate-mask';
import { PrimitivePaneViewZOrder } from '../model/ipane-primitive';
Expand Down Expand Up @@ -120,6 +120,10 @@ function recalculateOverlapping(views: IPriceAxisView[], direction: 1 | -1, scal
}
}

function priceScaleCrosshairLabelVisible(crosshair: CrosshairOptions): boolean {
return crosshair.mode !== CrosshairMode.Hidden && crosshair.horzLine.visible && crosshair.horzLine.labelVisible;
}

export class PriceAxisWidget implements IDestroyable {
private readonly _pane: PaneWidget;
private readonly _options: Readonly<ChartOptionsInternalBase>;
Expand Down Expand Up @@ -278,7 +282,11 @@ export class PriceAxisWidget implements IDestroyable {
}

const firstValue = this._priceScale.firstValue();
if (firstValue !== null && this._size !== null && this._options.crosshair.mode !== CrosshairMode.Hidden) {
if (
firstValue !== null &&
this._size !== null &&
priceScaleCrosshairLabelVisible(this._options.crosshair)
) {
const topValue = this._priceScale.coordinateToPrice(1 as Coordinate, firstValue);
const bottomValue = this._priceScale.coordinateToPrice(this._size.height - 2 as Coordinate, firstValue);

Expand Down

0 comments on commit 2520d6f

Please sign in to comment.