diff --git a/src/component/Overlay.ts b/src/component/Overlay.ts index e8e7d046e..20b85b806 100644 --- a/src/component/Overlay.ts +++ b/src/component/Overlay.ts @@ -67,12 +67,20 @@ export interface OverlayFigure { ignoreEvent?: boolean | OverlayFigureIgnoreEventType[] } +export interface OverlayPrecision extends Precision { + max: number + min: number + excludePriceVolumeMax: number + excludePriceVolumeMin: number + [key: string]: number +} + export interface OverlayCreateFiguresCallbackParams { overlay: Overlay coordinates: Coordinate[] bounding: Bounding barSpace: BarSpace - precision: Precision + precision: OverlayPrecision thousandsSeparator: string decimalFoldThreshold: number dateTimeFormat: Intl.DateTimeFormat diff --git a/src/component/YAxis.ts b/src/component/YAxis.ts index f10d907cd..af622945b 100644 --- a/src/component/YAxis.ts +++ b/src/component/YAxis.ts @@ -34,6 +34,7 @@ interface FiguresResult { export interface YAxis extends Axis { isFromZero: () => boolean + isInCandle: () => boolean } export type YAxisConstructor = new (parent: DrawPane) => YAxisImp diff --git a/src/extension/overlay/fibonacciLine.ts b/src/extension/overlay/fibonacciLine.ts index e6bbfd45f..4c17fe005 100644 --- a/src/extension/overlay/fibonacciLine.ts +++ b/src/extension/overlay/fibonacciLine.ts @@ -26,9 +26,10 @@ const fibonacciLine: OverlayTemplate = { needDefaultPointFigure: true, needDefaultXAxisFigure: true, needDefaultYAxisFigure: true, - createPointFigures: ({ coordinates, bounding, overlay, precision, thousandsSeparator, decimalFoldThreshold }) => { + createPointFigures: ({ coordinates, bounding, overlay, precision, thousandsSeparator, decimalFoldThreshold, yAxis }) => { const points = overlay.points if (coordinates.length > 0) { + const currentPrecision = (yAxis?.isInCandle() ?? true) ? precision.price : precision.excludePriceVolumeMax const lines: LineAttrs[] = [] const texts: TextAttrs[] = [] const startX = 0 @@ -39,7 +40,7 @@ const fibonacciLine: OverlayTemplate = { const valueDif = points[0].value - points[1].value percents.forEach(percent => { const y = coordinates[1].y + yDif * percent - const value = formatFoldDecimal(formatThousands(((points[1].value ?? 0) + valueDif * percent).toFixed(precision.price), thousandsSeparator), decimalFoldThreshold) + const value = formatFoldDecimal(formatThousands(((points[1].value ?? 0) + valueDif * percent).toFixed(currentPrecision), thousandsSeparator), decimalFoldThreshold) lines.push({ coordinates: [{ x: startX, y }, { x: endX, y }] }) texts.push({ x: startX, diff --git a/src/extension/overlay/priceLine.ts b/src/extension/overlay/priceLine.ts index 3e9e098d8..a7b2e3dc0 100644 --- a/src/extension/overlay/priceLine.ts +++ b/src/extension/overlay/priceLine.ts @@ -22,8 +22,9 @@ const priceLine: OverlayTemplate = { needDefaultPointFigure: true, needDefaultXAxisFigure: true, needDefaultYAxisFigure: true, - createPointFigures: ({ coordinates, bounding, precision, overlay, thousandsSeparator, decimalFoldThreshold }) => { + createPointFigures: ({ coordinates, bounding, precision, overlay, thousandsSeparator, decimalFoldThreshold, yAxis }) => { const { value = 0 } = (overlay.points)[0] + const currentPrecision = (yAxis?.isInCandle() ?? true) ? precision.price : precision.excludePriceVolumeMax return [ { type: 'line', @@ -35,7 +36,7 @@ const priceLine: OverlayTemplate = { attrs: { x: coordinates[0].x, y: coordinates[0].y, - text: formatFoldDecimal(formatThousands(value.toFixed(precision.price), thousandsSeparator), decimalFoldThreshold), + text: formatFoldDecimal(formatThousands(value.toFixed(currentPrecision), thousandsSeparator), decimalFoldThreshold), baseline: 'bottom' } } diff --git a/src/view/OverlayView.ts b/src/view/OverlayView.ts index bda7b82d3..60fdf771c 100644 --- a/src/view/OverlayView.ts +++ b/src/view/OverlayView.ts @@ -17,7 +17,6 @@ import type Coordinate from '../common/Coordinate' import type Point from '../common/Point' import type Bounding from '../common/Bounding' import type BarSpace from '../common/BarSpace' -import type Precision from '../common/Precision' import { type OverlayStyle } from '../common/Styles' import { type EventHandler, type EventName, type MouseTouchEvent, type MouseTouchEventCallback } from '../common/SyntheticEvent' import { isBoolean, isNumber, isValid } from '../common/utils/typeChecks' @@ -27,7 +26,7 @@ import { type CustomApi } from '../Options' import type Axis from '../component/Axis' import type XAxis from '../component/XAxis' import type YAxis from '../component/YAxis' -import { type OverlayFigure, type OverlayFigureIgnoreEventType } from '../component/Overlay' +import { type OverlayPrecision, type OverlayFigure, type OverlayFigureIgnoreEventType } from '../component/Overlay' import type Overlay from '../component/Overlay' import { OVERLAY_FIGURE_KEY_PREFIX, OverlayMode, getAllOverlayFigureIgnoreEventTypes } from '../component/Overlay' @@ -393,10 +392,26 @@ export default class OverlayView extends View { const hoverInstanceInfo = overlayStore.getHoverInstanceInfo() const clickInstanceInfo = overlayStore.getClickInstanceInfo() const overlays = this.getCompleteOverlays(overlayStore, paneId) + const paneIndicators = chartStore.getIndicatorStore().getInstances(paneId) + const overlayPrecision = paneIndicators.reduce((prev, indicator) => { + const precision = indicator.precision + prev[indicator.name] = precision + prev.max = Math.max(prev.max, precision) + prev.min = Math.min(prev.min, precision) + prev.excludePriceVolumeMax = Math.max(prev.excludePriceVolumeMax, precision) + prev.excludePriceVolumeMin = Math.min(prev.excludePriceVolumeMin, precision) + return prev + }, { + ...precision, + max: Math.max(precision.price, precision.volume), + min: Math.min(precision.price, precision.volume), + excludePriceVolumeMax: Number.MIN_SAFE_INTEGER, + excludePriceVolumeMin: Number.MAX_SAFE_INTEGER + }) overlays.forEach(overlay => { if (overlay.visible) { this._drawOverlay( - ctx, overlay, bounding, barSpace, precision, + ctx, overlay, bounding, barSpace, overlayPrecision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, defaultStyles, xAxis, yAxis, hoverInstanceInfo, clickInstanceInfo, timeScaleStore @@ -410,7 +425,7 @@ export default class OverlayView extends View { if (overlay !== null && overlay.visible) { this._drawOverlay( ctx, overlay, bounding, barSpace, - precision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, + overlayPrecision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, defaultStyles, xAxis, yAxis, hoverInstanceInfo, clickInstanceInfo, timeScaleStore ) @@ -423,7 +438,7 @@ export default class OverlayView extends View { overlay: Overlay, bounding: Bounding, barSpace: BarSpace, - precision: Precision, + precision: OverlayPrecision, dateTimeFormat: Intl.DateTimeFormat, customApi: CustomApi, thousandsSeparator: string, @@ -512,7 +527,7 @@ export default class OverlayView extends View { coordinates: Coordinate[], bounding: Bounding, barSpace: BarSpace, - precision: Precision, + precision: OverlayPrecision, thousandsSeparator: string, decimalFoldThreshold: number, dateTimeFormat: Intl.DateTimeFormat, @@ -528,7 +543,7 @@ export default class OverlayView extends View { overlay: Overlay, coordinates: Coordinate[], _bounding: Bounding, - _precision: Precision, + _precision: OverlayPrecision, _dateTimeFormat: Intl.DateTimeFormat, _customApi: CustomApi, _thousandsSeparator: string, diff --git a/src/view/OverlayXAxisView.ts b/src/view/OverlayXAxisView.ts index 601e78eb1..0e7b20709 100644 --- a/src/view/OverlayXAxisView.ts +++ b/src/view/OverlayXAxisView.ts @@ -24,7 +24,7 @@ import { type CustomApi, FormatDateType } from '../Options' import type XAxis from '../component/XAxis' import type YAxis from '../component/YAxis' -import { type OverlayFigure } from '../component/Overlay' +import { type OverlayPrecision, type OverlayFigure } from '../component/Overlay' import type Overlay from '../component/Overlay' import { type EventOverlayInfo, type ProgressOverlayInfo } from '../store/OverlayStore' @@ -87,7 +87,7 @@ export default class OverlayXAxisView extends OverlayYAxisView { coordinates: Coordinate[], bounding: Bounding, barSpace: BarSpace, - precision: Precision, + precision: OverlayPrecision, thousandsSeparator: string, decimalFoldThreshold: number, dateTimeFormat: Intl.DateTimeFormat, diff --git a/src/view/OverlayYAxisView.ts b/src/view/OverlayYAxisView.ts index 20793249b..ee7636a91 100644 --- a/src/view/OverlayYAxisView.ts +++ b/src/view/OverlayYAxisView.ts @@ -16,7 +16,6 @@ import type Nullable from '../common/Nullable' import type Coordinate from '../common/Coordinate' import type Bounding from '../common/Bounding' import type BarSpace from '../common/BarSpace' -import type Precision from '../common/Precision' import { type OverlayStyle } from '../common/Styles' import { type CustomApi } from '../Options' import { formatPrecision, formatThousands, formatFoldDecimal } from '../common/utils/format' @@ -25,7 +24,7 @@ import { isNumber } from '../common/utils/typeChecks' import type Axis from '../component/Axis' import type XAxis from '../component/XAxis' import type YAxis from '../component/YAxis' -import { type OverlayFigure } from '../component/Overlay' +import { type OverlayPrecision, type OverlayFigure } from '../component/Overlay' import type Overlay from '../component/Overlay' import { type EventOverlayInfo } from '../store/OverlayStore' @@ -42,7 +41,7 @@ export default class OverlayYAxisView extends OverlayVie overlay: Overlay, coordinates: Coordinate[], bounding: Bounding, - precision: Precision, + precision: OverlayPrecision, dateTimeFormat: Intl.DateTimeFormat, customApi: CustomApi, thousandsSeparator: string, @@ -65,7 +64,7 @@ export default class OverlayYAxisView extends OverlayVie overlay: Overlay, coordinates: Coordinate[], bounding: Bounding, - precision: Precision, + precision: OverlayPrecision, _dateTimeFormat: Intl.DateTimeFormat, _customApi: CustomApi, thousandsSeparator: string, @@ -113,7 +112,7 @@ export default class OverlayYAxisView extends OverlayVie coordinates: Coordinate[], bounding: Bounding, barSpace: BarSpace, - precision: Precision, + precision: OverlayPrecision, thousandsSeparator: string, decimalFoldThreshold: number, dateTimeFormat: Intl.DateTimeFormat,