mirror of
https://github.com/klinecharts/KLineChart.git
synced 2024-11-25 16:22:43 +08:00
impr: some custom callbacks add chart instance
This commit is contained in:
parent
9a4bba1176
commit
4b0b05c878
@ -47,6 +47,7 @@ import { type PaneOptions, PANE_DEFAULT_HEIGHT, PaneIdConstants, PaneState, PANE
|
||||
|
||||
import type AxisImp from './component/Axis'
|
||||
import { AxisPosition } from './component/Axis'
|
||||
import type { YAxis } from './component/YAxis'
|
||||
|
||||
import type { IndicatorFilter, Indicator, IndicatorCreate } from './component/Indicator'
|
||||
import type { OverlayFilter, Overlay, OverlayCreate } from './component/Overlay'
|
||||
@ -54,7 +55,6 @@ import type { OverlayFilter, Overlay, OverlayCreate } from './component/Overlay'
|
||||
import { getIndicatorClass } from './extension/indicator/index'
|
||||
|
||||
import Event from './Event'
|
||||
import type { YAxis } from './component/YAxis'
|
||||
|
||||
export enum DomPosition {
|
||||
Root = 'root',
|
||||
|
14
src/Store.ts
14
src/Store.ts
@ -1263,7 +1263,7 @@ export default class Store {
|
||||
this._overlays.get(paneId)?.push(overlay)
|
||||
}
|
||||
if (overlay.isStart()) {
|
||||
overlay.onDrawStart?.(({ overlay }))
|
||||
overlay.onDrawStart?.(({ overlay, chart: this._chart }))
|
||||
}
|
||||
return id
|
||||
}
|
||||
@ -1345,7 +1345,7 @@ export default class Store {
|
||||
filterMap.forEach((overlays, paneId) => {
|
||||
const paneOverlays = this.getOverlaysByPaneId(paneId)
|
||||
overlays.forEach(overlay => {
|
||||
overlay.onRemoved?.({ overlay })
|
||||
overlay.onRemoved?.({ overlay, chart: this._chart })
|
||||
if (!updatePaneIds.includes(paneId)) {
|
||||
updatePaneIds.push(paneId)
|
||||
}
|
||||
@ -1393,7 +1393,7 @@ export default class Store {
|
||||
if (overlay !== null) {
|
||||
sortFlag = true
|
||||
if (isFunction(overlay.onMouseLeave)) {
|
||||
overlay.onMouseLeave({ overlay, figureKey, figureIndex, ...event })
|
||||
overlay.onMouseLeave({ chart: this._chart, overlay, figureKey, figureIndex, ...event })
|
||||
ignoreUpdateFlag = true
|
||||
}
|
||||
}
|
||||
@ -1401,7 +1401,7 @@ export default class Store {
|
||||
if (infoOverlay !== null) {
|
||||
sortFlag = true
|
||||
if (isFunction(infoOverlay.onMouseEnter)) {
|
||||
infoOverlay.onMouseEnter({ overlay: infoOverlay, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event })
|
||||
infoOverlay.onMouseEnter({ chart: this._chart, overlay: infoOverlay, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event })
|
||||
ignoreUpdateFlag = true
|
||||
}
|
||||
}
|
||||
@ -1423,13 +1423,13 @@ export default class Store {
|
||||
const { paneId, overlay, figureType, figureKey, figureIndex } = this._clickOverlayInfo
|
||||
const infoOverlay = info.overlay
|
||||
if (!(infoOverlay?.isDrawing() ?? false)) {
|
||||
infoOverlay?.onClick?.({ overlay: infoOverlay, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event })
|
||||
infoOverlay?.onClick?.({ chart: this._chart, overlay: infoOverlay, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event })
|
||||
}
|
||||
if (overlay?.id !== infoOverlay?.id || figureType !== info.figureType || figureIndex !== info.figureIndex) {
|
||||
this._clickOverlayInfo = info
|
||||
if (overlay?.id !== infoOverlay?.id) {
|
||||
overlay?.onDeselected?.({ overlay, figureKey, figureIndex, ...event })
|
||||
infoOverlay?.onSelected?.({ overlay: infoOverlay, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event })
|
||||
overlay?.onDeselected?.({ chart: this._chart, overlay, figureKey, figureIndex, ...event })
|
||||
infoOverlay?.onSelected?.({ chart: this._chart, overlay: infoOverlay, figureKey: info.figureKey, figureIndex: info.figureIndex, ...event })
|
||||
this._chart.updatePane(UpdateLevel.Overlay, info.paneId)
|
||||
if (paneId !== info.paneId) {
|
||||
this._chart.updatePane(UpdateLevel.Overlay, paneId)
|
||||
|
@ -17,8 +17,7 @@ import type VisibleRange from '../common/VisibleRange'
|
||||
import type DrawPane from '../pane/DrawPane'
|
||||
|
||||
import type Bounding from '../common/Bounding'
|
||||
import type { KLineData } from '../common/Data'
|
||||
import type { Indicator } from './Indicator'
|
||||
import type { Chart } from '../Chart'
|
||||
|
||||
export interface AxisTick {
|
||||
coord: number
|
||||
@ -51,10 +50,8 @@ export interface AxisValueToValueParams {
|
||||
export type AxisValueToValueCallback = (value: number, params: AxisValueToValueParams) => number
|
||||
|
||||
export interface AxisCreateRangeParams {
|
||||
chart: Chart
|
||||
paneId: string
|
||||
kLineDataList: KLineData[]
|
||||
indicators: Indicator[]
|
||||
dataVisibleRange: VisibleRange
|
||||
defaultRange: AxisRange
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@ import type Nullable from '../common/Nullable'
|
||||
import type ExcludePickPartial from '../common/ExcludePickPartial'
|
||||
import type { KLineData } from '../common/Data'
|
||||
import type Bounding from '../common/Bounding'
|
||||
import type VisibleRange from '../common/VisibleRange'
|
||||
import type BarSpace from '../common/BarSpace'
|
||||
import type Crosshair from '../common/Crosshair'
|
||||
import type { IndicatorStyle, IndicatorPolygonStyle, SmoothLineStyle, RectStyle, TextStyle, TooltipIconStyle, LineStyle, LineType, TooltipLegend } from '../common/Styles'
|
||||
@ -31,6 +30,7 @@ import type { ArcAttrs } from '../extension/figure/arc'
|
||||
import type { RectAttrs } from '../extension/figure/rect'
|
||||
import type { TextAttrs } from '../extension/figure/text'
|
||||
import type { LoadDataType } from '../common/LoadDataCallback'
|
||||
import type { Chart } from '../Chart'
|
||||
|
||||
export enum IndicatorSeries {
|
||||
Normal = 'normal',
|
||||
@ -90,12 +90,10 @@ export interface IndicatorTooltipData {
|
||||
}
|
||||
|
||||
export interface IndicatorCreateTooltipDataSourceParams<D> {
|
||||
kLineDataList: KLineData[]
|
||||
chart: Chart
|
||||
indicator: Indicator<D>
|
||||
visibleRange: VisibleRange
|
||||
bounding: Bounding
|
||||
crosshair: Crosshair
|
||||
defaultStyles: IndicatorStyle
|
||||
xAxis: XAxis
|
||||
yAxis: YAxis
|
||||
}
|
||||
@ -104,12 +102,9 @@ export type IndicatorCreateTooltipDataSourceCallback<D> = (params: IndicatorCrea
|
||||
|
||||
export interface IndicatorDrawParams<D> {
|
||||
ctx: CanvasRenderingContext2D
|
||||
kLineDataList: KLineData[]
|
||||
chart: Chart
|
||||
indicator: Indicator<D>
|
||||
visibleRange: VisibleRange
|
||||
bounding: Bounding
|
||||
barSpace: BarSpace
|
||||
defaultStyles: IndicatorStyle
|
||||
xAxis: XAxis
|
||||
yAxis: YAxis
|
||||
}
|
||||
|
@ -18,8 +18,6 @@ import type ExcludePickPartial from '../common/ExcludePickPartial'
|
||||
import type Point from '../common/Point'
|
||||
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 { MouseTouchEvent } from '../common/SyntheticEvent'
|
||||
import { clone, isArray, isFunction, isNumber, isString, isValid, merge } from '../common/utils/typeChecks'
|
||||
@ -27,7 +25,7 @@ import { clone, isArray, isFunction, isNumber, isString, isValid, merge } from '
|
||||
import type { XAxis } from './XAxis'
|
||||
import type { YAxis } from './YAxis'
|
||||
import type ChartStore from '../Store'
|
||||
import type { Options } from '../Options'
|
||||
import type { Chart } from '../Chart'
|
||||
|
||||
export enum OverlayMode {
|
||||
Normal = 'normal',
|
||||
@ -67,21 +65,11 @@ 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 {
|
||||
options: Options
|
||||
chart: Chart
|
||||
overlay: Overlay
|
||||
coordinates: Coordinate[]
|
||||
bounding: Bounding
|
||||
barSpace: BarSpace
|
||||
precision: OverlayPrecision
|
||||
xAxis: Nullable<XAxis>
|
||||
yAxis: Nullable<YAxis>
|
||||
}
|
||||
@ -90,6 +78,7 @@ export interface OverlayEvent extends Partial<MouseTouchEvent> {
|
||||
figureKey?: string
|
||||
figureIndex?: number
|
||||
overlay: Overlay
|
||||
chart: Chart
|
||||
}
|
||||
|
||||
export type OverlayEventCallback = (event: OverlayEvent) => boolean
|
||||
|
@ -169,10 +169,8 @@ export default abstract class YAxisImp extends AxisImp implements YAxis {
|
||||
}
|
||||
|
||||
const range = this.createRange({
|
||||
chart,
|
||||
paneId,
|
||||
kLineDataList: chartStore.getDataList(),
|
||||
dataVisibleRange: chartStore.getVisibleRange(),
|
||||
indicators,
|
||||
defaultRange
|
||||
})
|
||||
let realFrom = range.realFrom
|
||||
|
@ -25,22 +25,31 @@ const fibonacciLine: OverlayTemplate = {
|
||||
needDefaultPointFigure: true,
|
||||
needDefaultXAxisFigure: true,
|
||||
needDefaultYAxisFigure: true,
|
||||
createPointFigures: ({ coordinates, bounding, overlay, precision, options, yAxis }) => {
|
||||
createPointFigures: ({ chart, coordinates, bounding, overlay, yAxis }) => {
|
||||
const points = overlay.points
|
||||
|
||||
if (coordinates.length > 0) {
|
||||
const currentPrecision = (yAxis?.isInCandle() ?? true) ? precision.price : precision.excludePriceVolumeMax
|
||||
let precision = 0
|
||||
if (yAxis?.isInCandle() ?? true) {
|
||||
precision = chart.getPriceVolumePrecision().price
|
||||
} else {
|
||||
const indicators = chart.getIndicators({ paneId: overlay.paneId }).get(overlay.paneId) ?? []
|
||||
indicators.forEach(indicator => {
|
||||
precision = Math.max(precision, indicator.precision)
|
||||
})
|
||||
}
|
||||
const lines: LineAttrs[] = []
|
||||
const texts: TextAttrs[] = []
|
||||
const startX = 0
|
||||
const endX = bounding.width
|
||||
if (coordinates.length > 1 && isNumber(points[0].value) && isNumber(points[1].value)) {
|
||||
const { decimalFold, thousandsSeparator } = options
|
||||
const { decimalFold, thousandsSeparator } = chart.getOptions()
|
||||
const percents = [1, 0.786, 0.618, 0.5, 0.382, 0.236, 0]
|
||||
const yDif = coordinates[0].y - coordinates[1].y
|
||||
const valueDif = points[0].value - points[1].value
|
||||
percents.forEach(percent => {
|
||||
const y = coordinates[1].y + yDif * percent
|
||||
const value = decimalFold.format(thousandsSeparator.format(((points[1].value ?? 0) + valueDif * percent).toFixed(currentPrecision)))
|
||||
const value = decimalFold.format(thousandsSeparator.format(((points[1].value ?? 0) + valueDif * percent).toFixed(precision)))
|
||||
lines.push({ coordinates: [{ x: startX, y }, { x: endX, y }] })
|
||||
texts.push({
|
||||
x: startX,
|
||||
|
@ -20,10 +20,18 @@ const priceLine: OverlayTemplate = {
|
||||
needDefaultPointFigure: true,
|
||||
needDefaultXAxisFigure: true,
|
||||
needDefaultYAxisFigure: true,
|
||||
createPointFigures: ({ coordinates, bounding, precision, overlay, options, yAxis }) => {
|
||||
const { decimalFold, thousandsSeparator } = options
|
||||
createPointFigures: ({ chart, coordinates, bounding, overlay, yAxis }) => {
|
||||
let precision = 0
|
||||
if (yAxis?.isInCandle() ?? true) {
|
||||
precision = chart.getPriceVolumePrecision().price
|
||||
} else {
|
||||
const indicators = chart.getIndicators({ paneId: overlay.paneId }).get(overlay.paneId) ?? []
|
||||
indicators.forEach(indicator => {
|
||||
precision = Math.max(precision, indicator.precision)
|
||||
})
|
||||
}
|
||||
const { decimalFold, thousandsSeparator } = chart.getOptions()
|
||||
const { value = 0 } = (overlay.points)[0]
|
||||
const currentPrecision = (yAxis?.isInCandle() ?? true) ? precision.price : precision.excludePriceVolumeMax
|
||||
return [
|
||||
{
|
||||
type: 'line',
|
||||
@ -35,7 +43,7 @@ const priceLine: OverlayTemplate = {
|
||||
attrs: {
|
||||
x: coordinates[0].x,
|
||||
y: coordinates[0].y,
|
||||
text: decimalFold.format(thousandsSeparator.format(value.toFixed(currentPrecision))),
|
||||
text: decimalFold.format(thousandsSeparator.format(value.toFixed(precision))),
|
||||
baseline: 'bottom'
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ const simpleTag: OverlayTemplate = {
|
||||
ignoreEvent: true
|
||||
}
|
||||
},
|
||||
createYAxisFigures: ({ overlay, coordinates, bounding, yAxis, precision }) => {
|
||||
createYAxisFigures: ({ chart, overlay, coordinates, bounding, yAxis }) => {
|
||||
const isFromZero = yAxis?.isFromZero() ?? false
|
||||
let textAlign: CanvasTextAlign = 'left'
|
||||
let x = 0
|
||||
@ -58,7 +58,7 @@ const simpleTag: OverlayTemplate = {
|
||||
}
|
||||
}
|
||||
if (!isValid(text) && isNumber(overlay.points[0].value)) {
|
||||
text = formatPrecision(overlay.points[0].value, precision.price)
|
||||
text = formatPrecision(overlay.points[0].value, chart.getPriceVolumePrecision().price)
|
||||
}
|
||||
return { type: 'text', attrs: { x, y: coordinates[0].y, text, align: textAlign, baseline: 'middle' } }
|
||||
}
|
||||
|
@ -26,8 +26,10 @@ const percentage: AxisTemplate = {
|
||||
realValueToValue: (value, { range }) => {
|
||||
return (value - range.realFrom) / range.realRange * range.range + range.from
|
||||
},
|
||||
createRange: ({ defaultRange, dataVisibleRange, kLineDataList }) => {
|
||||
const kLineData = kLineDataList[dataVisibleRange.from]
|
||||
createRange: ({ chart, defaultRange }) => {
|
||||
const kLineDataList = chart.getDataList()
|
||||
const visibleRange = chart.getVisibleRange()
|
||||
const kLineData = kLineDataList[visibleRange.from]
|
||||
if (isValid(kLineData)) {
|
||||
const { from, to, range } = defaultRange
|
||||
const realFrom = (defaultRange.from - kLineData.close) / kLineData.close * 100
|
||||
|
@ -295,14 +295,12 @@ export default class IndicatorTooltipView extends View<YAxis> {
|
||||
if (isFunction(indicator.createTooltipDataSource)) {
|
||||
const widget = this.getWidget()
|
||||
const pane = widget.getPane()
|
||||
const chartStore = pane.getChart().getChartStore()
|
||||
const chart = pane.getChart()
|
||||
const { name: customName, calcParamsText: customCalcParamsText, legends: customLegends, icons: customIcons } = indicator.createTooltipDataSource({
|
||||
kLineDataList: dataList,
|
||||
chart,
|
||||
indicator,
|
||||
visibleRange: chartStore.getVisibleRange(),
|
||||
bounding: widget.getBounding(),
|
||||
crosshair,
|
||||
defaultStyles: styles,
|
||||
xAxis: pane.getChart().getXAxisPane().getAxisComponent(),
|
||||
yAxis: pane.getAxisComponent()
|
||||
})
|
||||
|
@ -68,7 +68,6 @@ export default class IndicatorView extends CandleBarView {
|
||||
const yAxis = pane.getAxisComponent()
|
||||
const chartStore = chart.getChartStore()
|
||||
const dataList = chartStore.getDataList()
|
||||
const visibleRange = chartStore.getVisibleRange()
|
||||
const indicators = chartStore.getIndicatorsByPaneId(pane.getId())
|
||||
const defaultStyles = chartStore.getOptions().styles.indicator
|
||||
ctx.save()
|
||||
@ -84,12 +83,9 @@ export default class IndicatorView extends CandleBarView {
|
||||
ctx.save()
|
||||
isCover = indicator.draw({
|
||||
ctx,
|
||||
kLineDataList: dataList,
|
||||
chart,
|
||||
indicator,
|
||||
visibleRange,
|
||||
bounding,
|
||||
barSpace: chartStore.getBarSpace(),
|
||||
defaultStyles,
|
||||
xAxis,
|
||||
yAxis
|
||||
})
|
||||
|
@ -16,7 +16,6 @@ import type Nullable from '../common/Nullable'
|
||||
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 { OverlayStyle } from '../common/Styles'
|
||||
import type { EventHandler, EventName, MouseTouchEvent, MouseTouchEventCallback } from '../common/SyntheticEvent'
|
||||
import { isBoolean, isNumber, isValid } from '../common/utils/typeChecks'
|
||||
@ -26,7 +25,7 @@ import type { Options } from '../Options'
|
||||
import type { Axis } from '../component/Axis'
|
||||
import type { XAxis } from '../component/XAxis'
|
||||
import type { YAxis } from '../component/YAxis'
|
||||
import type { OverlayPrecision, OverlayFigure, OverlayFigureIgnoreEventType, Overlay } from '../component/Overlay'
|
||||
import type { OverlayFigure, OverlayFigureIgnoreEventType, Overlay } from '../component/Overlay'
|
||||
import type OverlayImp from '../component/Overlay'
|
||||
import { OVERLAY_FIGURE_KEY_PREFIX, OverlayMode, getAllOverlayFigureIgnoreEventTypes } from '../component/Overlay'
|
||||
|
||||
@ -40,6 +39,8 @@ import type DrawWidget from '../widget/DrawWidget'
|
||||
import type DrawPane from '../pane/DrawPane'
|
||||
|
||||
import View from './View'
|
||||
import type { Chart } from '../Chart'
|
||||
import type Precision from '../common/Precision'
|
||||
|
||||
export default class OverlayView<C extends Axis = YAxis> extends View<C> {
|
||||
constructor (widget: DrawWidget<DrawPane<C>>) {
|
||||
@ -50,7 +51,8 @@ export default class OverlayView<C extends Axis = YAxis> extends View<C> {
|
||||
private _initEvent (): void {
|
||||
const pane = this.getWidget().getPane()
|
||||
const paneId = pane.getId()
|
||||
const chartStore = pane.getChart().getChartStore()
|
||||
const chart = pane.getChart()
|
||||
const chartStore = chart.getChartStore()
|
||||
this.registerEvent('mouseMoveEvent', (event: MouseTouchEvent) => {
|
||||
const progressOverlayInfo = chartStore.getProgressOverlayInfo()
|
||||
if (progressOverlayInfo !== null) {
|
||||
@ -64,7 +66,7 @@ export default class OverlayView<C extends Axis = YAxis> extends View<C> {
|
||||
const key = `${OVERLAY_FIGURE_KEY_PREFIX}point_${index}`
|
||||
if (overlay.isDrawing() && progressOverlayPaneId === paneId) {
|
||||
overlay.eventMoveForDrawing(this._coordinateToPoint(overlay, event))
|
||||
overlay.onDrawing?.({ overlay, figureKey: key, figureIndex: index, ...event })
|
||||
overlay.onDrawing?.({ chart, overlay, figureKey: key, figureIndex: index, ...event })
|
||||
}
|
||||
return this._figureMouseMoveEvent(
|
||||
overlay,
|
||||
@ -96,11 +98,11 @@ export default class OverlayView<C extends Axis = YAxis> extends View<C> {
|
||||
const key = `${OVERLAY_FIGURE_KEY_PREFIX}point_${index}`
|
||||
if (overlay.isDrawing() && progressOverlayPaneId === paneId) {
|
||||
overlay.eventMoveForDrawing(this._coordinateToPoint(overlay, event))
|
||||
overlay.onDrawing?.({ overlay, figureKey: key, figureIndex: index, ...event })
|
||||
overlay.onDrawing?.({ chart, overlay, figureKey: key, figureIndex: index, ...event })
|
||||
overlay.nextStep()
|
||||
if (!overlay.isDrawing()) {
|
||||
chartStore.progressOverlayComplete()
|
||||
overlay.onDrawEnd?.({ overlay, figureKey: key, figureIndex: index, ...event })
|
||||
overlay.onDrawEnd?.({ chart, overlay, figureKey: key, figureIndex: index, ...event })
|
||||
}
|
||||
}
|
||||
return this._figureMouseClickEvent(
|
||||
@ -131,7 +133,7 @@ export default class OverlayView<C extends Axis = YAxis> extends View<C> {
|
||||
chartStore.progressOverlayComplete()
|
||||
const index = overlay.points.length - 1
|
||||
const key = `${OVERLAY_FIGURE_KEY_PREFIX}point_${index}`
|
||||
overlay.onDrawEnd?.({ overlay, figureKey: key, figureIndex: index, ...event })
|
||||
overlay.onDrawEnd?.({ chart, overlay, figureKey: key, figureIndex: index, ...event })
|
||||
}
|
||||
}
|
||||
const index = overlay.points.length - 1
|
||||
@ -163,7 +165,7 @@ export default class OverlayView<C extends Axis = YAxis> extends View<C> {
|
||||
}).registerEvent('mouseUpEvent', (event: MouseTouchEvent) => {
|
||||
const { overlay, figureIndex, figureKey } = chartStore.getPressedOverlayInfo()
|
||||
if (overlay !== null) {
|
||||
overlay.onPressedMoveEnd?.({ overlay, figureKey, figureIndex, ...event })
|
||||
overlay.onPressedMoveEnd?.({ chart, overlay, figureKey, figureIndex, ...event })
|
||||
}
|
||||
chartStore.setPressedOverlayInfo({
|
||||
paneId,
|
||||
@ -178,7 +180,7 @@ export default class OverlayView<C extends Axis = YAxis> extends View<C> {
|
||||
const { overlay, figureType, figureIndex, figureKey } = chartStore.getPressedOverlayInfo()
|
||||
if (overlay !== null) {
|
||||
if (!overlay.lock) {
|
||||
if (!(overlay.onPressedMoving?.({ overlay, figureIndex, figureKey, ...event }) ?? false)) {
|
||||
if (!(overlay.onPressedMoving?.({ chart, overlay, figureIndex, figureKey, ...event }) ?? false)) {
|
||||
const point = this._coordinateToPoint(overlay, event)
|
||||
if (figureType === EventOverlayInfoFigureType.Point) {
|
||||
overlay.eventPressedPointMove(point, figureIndex)
|
||||
@ -262,7 +264,7 @@ export default class OverlayView<C extends Axis = YAxis> extends View<C> {
|
||||
const pane = this.getWidget().getPane()
|
||||
const paneId = pane.getId()
|
||||
overlay.startPressedMove(this._coordinateToPoint(overlay, event))
|
||||
overlay.onPressedMoveStart?.({ overlay, figureIndex, figureKey, ...event })
|
||||
overlay.onPressedMoveStart?.({ chart: pane.getChart(), overlay, figureIndex, figureKey, ...event })
|
||||
pane.getChart().getChartStore().setPressedOverlayInfo({ paneId, overlay, figureType, figureKey, figureIndex, attrsIndex })
|
||||
return true
|
||||
}
|
||||
@ -279,14 +281,14 @@ export default class OverlayView<C extends Axis = YAxis> extends View<C> {
|
||||
|
||||
private _figureMouseDoubleClickEvent (overlay: OverlayImp, _figureType: EventOverlayInfoFigureType, figureKey: string, figureIndex: number, _attrsIndex: number): MouseTouchEventCallback {
|
||||
return (event: MouseTouchEvent) => {
|
||||
overlay.onDoubleClick?.({ ...event, figureIndex, figureKey, overlay })
|
||||
overlay.onDoubleClick?.({ ...event, chart: this.getWidget().getPane().getChart(), figureIndex, figureKey, overlay })
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
private _figureMouseRightClickEvent (overlay: OverlayImp, _figureType: EventOverlayInfoFigureType, figureKey: string, figureIndex: number, _attrsIndex: number): MouseTouchEventCallback {
|
||||
return (event: MouseTouchEvent) => {
|
||||
if (!(overlay.onRightClick?.({ overlay, figureIndex, figureKey, ...event }) ?? false)) {
|
||||
if (!(overlay.onRightClick?.({ chart: this.getWidget().getPane().getChart(), overlay, figureIndex, figureKey, ...event }) ?? false)) {
|
||||
this.getWidget().getPane().getChart().getChartStore().removeOverlay(overlay)
|
||||
}
|
||||
return true
|
||||
@ -390,32 +392,15 @@ export default class OverlayView<C extends Axis = YAxis> extends View<C> {
|
||||
const bounding = widget.getBounding()
|
||||
const chartStore = chart.getChartStore()
|
||||
const options = chartStore.getOptions()
|
||||
const barSpace = chartStore.getBarSpace()
|
||||
const precision = chartStore.getPrecision()
|
||||
const hoverOverlayInfo = chartStore.getHoverOverlayInfo()
|
||||
const clickOverlayInfo = chartStore.getClickOverlayInfo()
|
||||
const overlays = this.getCompleteOverlays(chartStore, paneId)
|
||||
const paneIndicators = chartStore.getIndicatorsByPaneId(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,
|
||||
overlayPrecision, options, xAxis, yAxis,
|
||||
ctx, overlay, bounding,
|
||||
precision, options, xAxis, yAxis,
|
||||
hoverOverlayInfo, clickOverlayInfo, chartStore
|
||||
)
|
||||
}
|
||||
@ -426,8 +411,8 @@ export default class OverlayView<C extends Axis = YAxis> extends View<C> {
|
||||
|
||||
if (isValid(overlay) && overlay.visible) {
|
||||
this._drawOverlay(
|
||||
ctx, overlay, bounding, barSpace,
|
||||
overlayPrecision, options, xAxis, yAxis,
|
||||
ctx, overlay, bounding,
|
||||
precision, options, xAxis, yAxis,
|
||||
hoverOverlayInfo, clickOverlayInfo, chartStore
|
||||
)
|
||||
}
|
||||
@ -438,8 +423,7 @@ export default class OverlayView<C extends Axis = YAxis> extends View<C> {
|
||||
ctx: CanvasRenderingContext2D,
|
||||
overlay: OverlayImp,
|
||||
bounding: Bounding,
|
||||
barSpace: BarSpace,
|
||||
precision: OverlayPrecision,
|
||||
precision: Precision,
|
||||
options: Options,
|
||||
xAxis: Nullable<XAxis>,
|
||||
yAxis: Nullable<YAxis>,
|
||||
@ -465,7 +449,7 @@ export default class OverlayView<C extends Axis = YAxis> extends View<C> {
|
||||
if (coordinates.length > 0) {
|
||||
const figures = new Array<OverlayFigure>().concat(
|
||||
this.getFigures(
|
||||
overlay, coordinates, bounding, barSpace, precision, options, xAxis, yAxis
|
||||
chartStore.getChart(), overlay, coordinates, bounding, xAxis, yAxis
|
||||
)
|
||||
)
|
||||
this.drawFigures(
|
||||
@ -520,16 +504,14 @@ export default class OverlayView<C extends Axis = YAxis> extends View<C> {
|
||||
}
|
||||
|
||||
protected getFigures (
|
||||
chart: Chart,
|
||||
o: Overlay,
|
||||
coordinates: Coordinate[],
|
||||
bounding: Bounding,
|
||||
barSpace: BarSpace,
|
||||
precision: OverlayPrecision,
|
||||
options: Options,
|
||||
xAxis: Nullable<XAxis>,
|
||||
yAxis: Nullable<YAxis>
|
||||
): OverlayFigure | OverlayFigure[] {
|
||||
return o.createPointFigures?.({ overlay: o, coordinates, bounding, barSpace, precision, options, xAxis, yAxis }) ?? []
|
||||
return o.createPointFigures?.({ chart, overlay: o, coordinates, bounding, xAxis, yAxis }) ?? []
|
||||
}
|
||||
|
||||
protected drawDefaultFigures (
|
||||
@ -537,7 +519,7 @@ export default class OverlayView<C extends Axis = YAxis> extends View<C> {
|
||||
overlay: OverlayImp,
|
||||
coordinates: Coordinate[],
|
||||
_bounding: Bounding,
|
||||
_precision: OverlayPrecision,
|
||||
_precision: Precision,
|
||||
options: Options,
|
||||
_xAxis: Nullable<XAxis>,
|
||||
_yAxis: Nullable<YAxis>,
|
||||
|
@ -15,7 +15,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 { isNumber } from '../common/utils/typeChecks'
|
||||
|
||||
@ -23,13 +22,14 @@ import { FormatDateType, type Options } from '../Options'
|
||||
|
||||
import type { XAxis } from '../component/XAxis'
|
||||
import type { YAxis } from '../component/YAxis'
|
||||
import type { OverlayPrecision, OverlayFigure, Overlay } from '../component/Overlay'
|
||||
import type { OverlayFigure, Overlay } from '../component/Overlay'
|
||||
import type OverlayImp from '../component/Overlay'
|
||||
|
||||
import type { EventOverlayInfo, ProgressOverlayInfo } from '../Store'
|
||||
import type ChartStore from '../Store'
|
||||
|
||||
import OverlayYAxisView from './OverlayYAxisView'
|
||||
import type { Chart } from '../Chart'
|
||||
|
||||
export default class OverlayXAxisView extends OverlayYAxisView<XAxis> {
|
||||
override coordinateToPointTimestampDataIndexFlag (): boolean {
|
||||
@ -79,15 +79,13 @@ export default class OverlayXAxisView extends OverlayYAxisView<XAxis> {
|
||||
}
|
||||
|
||||
override getFigures (
|
||||
chart: Chart,
|
||||
o: Overlay,
|
||||
coordinates: Coordinate[],
|
||||
bounding: Bounding,
|
||||
barSpace: BarSpace,
|
||||
precision: OverlayPrecision,
|
||||
options: Options,
|
||||
xAxis: Nullable<XAxis>,
|
||||
yAxis: Nullable<YAxis>
|
||||
): OverlayFigure | OverlayFigure[] {
|
||||
return o.createXAxisFigures?.({ overlay: o, coordinates, bounding, barSpace, precision, options, xAxis, yAxis }) ?? []
|
||||
return o.createXAxisFigures?.({ chart, overlay: o, coordinates, bounding, xAxis, yAxis }) ?? []
|
||||
}
|
||||
}
|
||||
|
@ -15,21 +15,23 @@
|
||||
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 { Options } from '../Options'
|
||||
import { formatPrecision } from '../common/utils/format'
|
||||
import { isNumber } from '../common/utils/typeChecks'
|
||||
import type Precision from '../common/Precision'
|
||||
|
||||
import type { Axis } from '../component/Axis'
|
||||
import type { XAxis } from '../component/XAxis'
|
||||
import type { YAxis } from '../component/YAxis'
|
||||
import type { OverlayPrecision, OverlayFigure, Overlay } from '../component/Overlay'
|
||||
import type { OverlayFigure, Overlay } from '../component/Overlay'
|
||||
import type OverlayImp from '../component/Overlay'
|
||||
|
||||
import type { EventOverlayInfo } from '../Store'
|
||||
|
||||
import OverlayView from './OverlayView'
|
||||
|
||||
import type { Chart } from '../Chart'
|
||||
|
||||
export default class OverlayYAxisView<C extends Axis = YAxis> extends OverlayView<C> {
|
||||
override coordinateToPointTimestampDataIndexFlag (): boolean {
|
||||
return false
|
||||
@ -40,7 +42,7 @@ export default class OverlayYAxisView<C extends Axis = YAxis> extends OverlayVie
|
||||
overlay: OverlayImp,
|
||||
coordinates: Coordinate[],
|
||||
bounding: Bounding,
|
||||
precision: OverlayPrecision,
|
||||
precision: Precision,
|
||||
options: Options,
|
||||
xAxis: Nullable<XAxis>,
|
||||
yAxis: Nullable<YAxis>,
|
||||
@ -59,7 +61,7 @@ export default class OverlayYAxisView<C extends Axis = YAxis> extends OverlayVie
|
||||
overlay: Overlay,
|
||||
coordinates: Coordinate[],
|
||||
bounding: Bounding,
|
||||
precision: OverlayPrecision,
|
||||
precision: Precision,
|
||||
options: Options,
|
||||
_xAxis: Nullable<XAxis>,
|
||||
yAxis: Nullable<YAxis>,
|
||||
@ -101,15 +103,13 @@ export default class OverlayYAxisView<C extends Axis = YAxis> extends OverlayVie
|
||||
}
|
||||
|
||||
override getFigures (
|
||||
chart: Chart,
|
||||
overlay: Overlay,
|
||||
coordinates: Coordinate[],
|
||||
bounding: Bounding,
|
||||
barSpace: BarSpace,
|
||||
precision: OverlayPrecision,
|
||||
options: Options,
|
||||
xAxis: Nullable<XAxis>,
|
||||
yAxis: Nullable<YAxis>
|
||||
): OverlayFigure | OverlayFigure[] {
|
||||
return overlay.createYAxisFigures?.({ overlay, coordinates, bounding, barSpace, precision, options, xAxis, yAxis }) ?? []
|
||||
return overlay.createYAxisFigures?.({ chart, overlay, coordinates, bounding, xAxis, yAxis }) ?? []
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user