From 2520d6f734f13d7db8f3bab3c372cf203ef9ec20 Mon Sep 17 00:00:00 2001 From: Mark Silverwood Date: Tue, 17 Dec 2024 17:56:44 +0000 Subject: [PATCH] Merge pull request #1757 from tradingview/CLL-310_smaller-price-scale-when-crosshair-label-hidden improve check for crosshair label visibility on the price scale --- src/gui/price-axis-widget.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gui/price-axis-widget.ts b/src/gui/price-axis-widget.ts index 5891b271a9..c96f8abec1 100644 --- a/src/gui/price-axis-widget.ts +++ b/src/gui/price-axis-widget.ts @@ -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'; @@ -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; @@ -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);