Skip to content

Commit

Permalink
Merge pull request #1743 from tradingview/CLL-310-price-axis-width-wi…
Browse files Browse the repository at this point in the history
…thout-crosshair

CLL-310: Do not allocate space for crosshair label is crosshair is di…
  • Loading branch information
SlicedSilver authored Dec 2, 2024
2 parents f8a017b + 4096374 commit ad7c919
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/gui/price-axis-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +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 { IDataSource } from '../model/idata-source';
import { InvalidationLevel } from '../model/invalidate-mask';
import { IPriceDataSource } from '../model/iprice-data-source';
Expand Down Expand Up @@ -272,7 +273,7 @@ export class PriceAxisWidget implements IDestroyable {
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function runTestCase(container) {
const chartOptions = {
height: 400,
width: 600,
rightPriceScale: {
scaleMargins: {
top: 0,
bottom: 0,
},
entireTextOnly: true,
alignLabels: true,
},
crosshair: {
mode: 2,
},
};

const chart = (window.chart = LightweightCharts.createChart(
container,
chartOptions
));

const data1 = Array.from({ length: 10 }).map((_, index) => ({ time: index * 10000, value: 1000000 * (100 - index), color: index % 2 ? '#ff0000' : '#0000ff' }));

const series1 = chart.addLineSeries({
priceFormat: {
type: 'volume',
precision: 3,
},
});
series1.setData(data1);

chart.timeScale().fitContent();
}

0 comments on commit ad7c919

Please sign in to comment.