Skip to content

Commit

Permalink
opt: opt default styles
Browse files Browse the repository at this point in the history
  • Loading branch information
liihuu committed Mar 25, 2024
1 parent 2322053 commit 2fd0314
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
7 changes: 1 addition & 6 deletions src/common/Animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions src/common/Styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export interface CandleTooltipCustomCallbackData {
export type CandleTooltipCustomCallback = (data: CandleTooltipCustomCallbackData, styles: CandleStyle) => TooltipData[]

export interface CandleTooltipStyle extends TooltipStyle {
custom: Nullable<CandleTooltipCustomCallback> | Nullable<TooltipData[]>
custom: CandleTooltipCustomCallback | TooltipData[]
rect: CandleTooltipRectStyle
}

Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/view/CandleAreaView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export default class CandleAreaView extends ChildrenView {
let indicatePointCoordinate: Nullable<Coordinate> = 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)
Expand Down
11 changes: 2 additions & 9 deletions src/view/CandleTooltipView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 2fd0314

Please sign in to comment.