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 authored Dec 17, 2024
2 parents 3753bd2 + ff396ff commit f2b5fb7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 4 additions & 4 deletions .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ module.exports = [
{
name: 'CJS',
path: 'dist/lightweight-charts.production.cjs',
limit: '49.29 KB',
limit: '49.32 KB',
},
{
name: 'ESM',
path: 'dist/lightweight-charts.production.mjs',
limit: '49.22 KB',
limit: '49.25 KB',
},
{
name: 'Standalone-ESM',
path: 'dist/lightweight-charts.standalone.production.mjs',
limit: '50.94 KB',
limit: '50.97 KB',
},
{
name: 'Standalone',
path: 'dist/lightweight-charts.standalone.production.js',
limit: '50.98 KB',
limit: '51.00 KB',
},
];
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 } from '../model/idata-source';
import { InvalidationLevel } from '../model/invalidate-mask';
import { IPriceDataSource } from '../model/iprice-data-source';
Expand Down Expand Up @@ -119,6 +119,10 @@ function recalculateOverlapping(
}
}

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 @@ -273,7 +277,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 f2b5fb7

Please sign in to comment.