From 2fd031454b08931a34c0101b98dd78defa5daf85 Mon Sep 17 00:00:00 2001 From: liihuu Date: Tue, 26 Mar 2024 01:05:26 +0800 Subject: [PATCH] opt: opt default styles --- src/common/Animation.ts | 7 +------ src/common/Styles.ts | 11 +++++++++-- src/view/CandleAreaView.ts | 1 - src/view/CandleTooltipView.ts | 11 ++--------- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/common/Animation.ts b/src/common/Animation.ts index f32a28cb6..b121ad4d0 100644 --- a/src/common/Animation.ts +++ b/src/common/Animation.ts @@ -37,16 +37,11 @@ export default class Animation { merge(this._options, options) } - _getTime (): number { - return new Date().getTime() - } - _loop (): void { this._running = true const step: (() => void) = () => { if (this._running) { - const time = this._getTime() - const diffTime = time - this._time + const diffTime = new Date().getTime() - this._time if (diffTime < this._options.duration) { this._doFrameCallback?.(diffTime) requestAnimationFrame(step) diff --git a/src/common/Styles.ts b/src/common/Styles.ts index cb5ae680b..4d527d76e 100644 --- a/src/common/Styles.ts +++ b/src/common/Styles.ts @@ -232,7 +232,7 @@ export interface CandleTooltipCustomCallbackData { export type CandleTooltipCustomCallback = (data: CandleTooltipCustomCallbackData, styles: CandleStyle) => TooltipData[] export interface CandleTooltipStyle extends TooltipStyle { - custom: Nullable | Nullable + custom: CandleTooltipCustomCallback | TooltipData[] rect: CandleTooltipRectStyle } @@ -496,7 +496,14 @@ function getDefaultCandleStyle (): CandleStyle { tooltip: { showRule: TooltipShowRule.Always, showType: TooltipShowType.Standard, - custom: null, + custom: [ + { title: 'time', value: '{time}' }, + { title: 'open', value: '{open}' }, + { title: 'high', value: '{high}' }, + { title: 'low', value: '{low}' }, + { title: 'close', value: '{close}' }, + { title: 'volume', value: '{volume}' } + ], defaultValue: 'n/a', rect: { position: CandleTooltipRectPosition.Fixed, diff --git a/src/view/CandleAreaView.ts b/src/view/CandleAreaView.ts index 4eed1ddb5..c53c061e2 100644 --- a/src/view/CandleAreaView.ts +++ b/src/view/CandleAreaView.ts @@ -52,7 +52,6 @@ export default class CandleAreaView extends ChildrenView { let indicatePointCoordinate: Nullable = null this.eachChildren((data: VisibleData, _: BarSpace, i: number) => { const { data: kLineData, x } = data - // const { halfGapBar } = barSpace const value = kLineData?.[styles.value] if (isNumber(value)) { const y = yAxis.convertToPixel(value) diff --git a/src/view/CandleTooltipView.ts b/src/view/CandleTooltipView.ts index cb35279c7..d3047b5a2 100644 --- a/src/view/CandleTooltipView.ts +++ b/src/view/CandleTooltipView.ts @@ -460,16 +460,9 @@ export default class CandleTooltipView extends IndicatorTooltipView { } const labelValues = ( isFunction(tooltipStyles.custom) - ? tooltipStyles.custom?.(data, styles) + ? tooltipStyles.custom(data, styles) : tooltipStyles.custom - ) ?? [ - { title: 'time', value: '{time}' }, - { title: 'open', value: '{open}' }, - { title: 'high', value: '{high}' }, - { title: 'low', value: '{low}' }, - { title: 'close', value: '{close}' }, - { title: 'volume', value: '{volume}' } - ] + ) ?? [] return labelValues.map(({ title, value }) => { let t: TooltipDataChild = { text: '', color: '' } if (isObject(title)) {