Skip to content

Commit ff02285

Browse files
authored
Merge pull request #664 from klinecharts/pr/bandaralsehli/657
feat: update TooltipIcon, CandleTooltipView, and IndicatorTooltipView
2 parents 8397a7b + 01cc1d5 commit ff02285

File tree

10 files changed

+495
-113
lines changed

10 files changed

+495
-113
lines changed

src/Store.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import type Precision from './common/Precision'
2525
import Action from './common/Action'
2626
import { ActionType, type ActionCallback } from './common/Action'
2727
import { formatValue, formatTimestampToString, formatBigNumber, formatThousands, formatFoldDecimal } from './common/utils/format'
28-
import { getDefaultStyles, type Styles, type TooltipLegend } from './common/Styles'
28+
import { getDefaultStyles, type TooltipFeatureStyle, type Styles, type TooltipLegend } from './common/Styles'
2929
import { isArray, isString, isValid, isNumber, isBoolean, isFunction, merge } from './common/utils/typeChecks'
3030
import { createId } from './common/utils/id'
3131
import { binarySearchNearest } from './common/utils/number'
@@ -38,7 +38,7 @@ import { classifyTimeWeightTicks, createTimeWeightTickList } from './common/Time
3838

3939
import type { Options, CustomApi, ThousandsSeparator, DecimalFold } from './Options'
4040

41-
import { IndicatorDataState, type IndicatorOverride, type IndicatorCreate, type IndicatorFilter } from './component/Indicator'
41+
import { IndicatorDataState, type IndicatorOverride, type IndicatorCreate, type IndicatorFilter, type Indicator } from './component/Indicator'
4242
import type IndicatorImp from './component/Indicator'
4343
import { IndicatorSeries } from './component/Indicator'
4444
import { getIndicatorClass } from './extension/indicator/index'
@@ -64,10 +64,10 @@ const enum ScrollLimitRole {
6464
Distance
6565
}
6666

67-
export interface TooltipIcon {
67+
export interface TooltipFeatureInfo {
6868
paneId: string
69-
indicatorName: string
70-
iconId: string
69+
indicator: Nullable<Indicator>
70+
feature: TooltipFeatureStyle
7171
}
7272

7373
export interface ProgressOverlayInfo {
@@ -292,7 +292,7 @@ export default class StoreImp implements Store {
292292
/**
293293
* Active tooltip icon info
294294
*/
295-
private _activeTooltipIcon: Nullable<TooltipIcon> = null
295+
private _activeTooltipFeatureInfo: Nullable<TooltipFeatureInfo> = null
296296

297297
/**
298298
* Actions
@@ -947,12 +947,12 @@ export default class StoreImp implements Store {
947947
return this._crosshair
948948
}
949949

950-
setActiveTooltipIcon (icon?: TooltipIcon): void {
951-
this._activeTooltipIcon = icon ?? null
950+
setActiveTooltipFeatureInfo (info?: TooltipFeatureInfo): void {
951+
this._activeTooltipFeatureInfo = info ?? null
952952
}
953953

954-
getActiveTooltipIcon (): Nullable<TooltipIcon> {
955-
return this._activeTooltipIcon
954+
getActiveTooltipFeatureInfo (): Nullable<TooltipFeatureInfo> {
955+
return this._activeTooltipFeatureInfo
956956
}
957957

958958
executeAction (type: ActionType, data?: unknown): void {
@@ -1447,7 +1447,7 @@ export default class StoreImp implements Store {
14471447
this._timeWeightTickMap.clear()
14481448
this._timeWeightTickList = []
14491449
this._crosshair = {}
1450-
this._activeTooltipIcon = null
1450+
this._activeTooltipFeatureInfo = null
14511451
}
14521452

14531453
getChart (): Chart {

src/common/Action.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export enum ActionType {
2020
OnZoom = 'onZoom',
2121
OnScroll = 'onScroll',
2222
OnVisibleRangeChange = 'onVisibleRangeChange',
23-
OnTooltipIconClick = 'onTooltipIconClick',
23+
OnCandleTooltipFeatureClick = 'onCandleTooltipFeatureClick',
2424
OnCrosshairChange = 'onCrosshairChange',
2525
OnCandleBarClick = 'onCandleBarClick',
2626
OnPaneDrag = 'onPaneDrag'

src/common/Styles.ts

+39-11
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ export interface StateLineStyle extends LineStyle {
6060
show: boolean
6161
}
6262

63+
export enum PathType {
64+
Stroke = 'stroke',
65+
Fill = 'fill',
66+
}
67+
68+
export interface PathStyle {
69+
style: PathType
70+
color: string
71+
lineWidth: number
72+
}
73+
6374
export enum PolygonType {
6475
Stroke = 'stroke',
6576
Fill = 'fill',
@@ -139,29 +150,46 @@ export interface TooltipLegend {
139150
value: string | TooltipLegendChild
140151
}
141152

142-
export enum TooltipIconPosition {
153+
export enum TooltipFeatureType {
154+
Path = 'path',
155+
IconFont = 'icon_font'
156+
}
157+
158+
export enum TooltipFeaturePosition {
143159
Left = 'left',
144160
Middle = 'middle',
145161
Right = 'right'
146162
}
147-
export interface TooltipIconStyle extends Padding, Margin {
163+
164+
export interface TooltipFeaturePathStyle extends Omit<PathStyle, 'color'> {
165+
path: string
166+
}
167+
168+
export interface TooltipFeatureIconFontStyle {
169+
family: string
170+
content: string
171+
}
172+
173+
export interface TooltipFeatureStyle extends Padding, Margin {
148174
id: string
149-
position: TooltipIconPosition
150-
color: string
151-
activeColor: string
152-
size: number
153-
fontFamily: string
154-
icon: string
175+
position: TooltipFeaturePosition
155176
backgroundColor: string
156177
activeBackgroundColor: string
178+
size: number
179+
color: string
180+
activeColor: string
181+
borderRadius: number | number[]
182+
type: TooltipFeatureType
183+
path: TooltipFeaturePathStyle
184+
iconFont: TooltipFeatureIconFontStyle
157185
}
158186

159187
export interface TooltipStyle {
160188
showRule: TooltipShowRule
161189
showType: TooltipShowType
162190
defaultValue: string
163191
text: TooltipTextStyle
164-
icons: TooltipIconStyle[]
192+
features: TooltipFeatureStyle[]
165193
}
166194

167195
export interface CandleAreaPointStyle {
@@ -501,7 +529,7 @@ function getDefaultCandleStyle (): CandleStyle {
501529
marginRight: 8,
502530
marginBottom: 4
503531
},
504-
icons: []
532+
features: []
505533
}
506534
}
507535
}
@@ -584,7 +612,7 @@ function getDefaultIndicatorStyle (): IndicatorStyle {
584612
marginRight: 8,
585613
marginBottom: 4
586614
},
587-
icons: []
615+
features: []
588616
}
589617
}
590618
}

src/component/Indicator.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type { KLineData, NeighborData } from '../common/Data'
1919
import type Bounding from '../common/Bounding'
2020
import type BarSpace from '../common/BarSpace'
2121
import type Crosshair from '../common/Crosshair'
22-
import type { IndicatorStyle, IndicatorPolygonStyle, SmoothLineStyle, RectStyle, TextStyle, TooltipIconStyle, LineStyle, LineType, TooltipLegend } from '../common/Styles'
22+
import type { IndicatorStyle, IndicatorPolygonStyle, SmoothLineStyle, RectStyle, TextStyle, TooltipFeatureStyle, LineStyle, LineType, TooltipLegend } from '../common/Styles'
2323
import { isNumber, isValid, merge, isBoolean, isString, clone, isFunction } from '../common/utils/typeChecks'
2424

2525
import type { XAxis } from './XAxis'
@@ -75,13 +75,12 @@ export type IndicatorRegenerateFiguresCallback<D, C> = (calcParams: C[]) => Arra
7575
export interface IndicatorTooltipData {
7676
name: string
7777
calcParamsText: string
78-
icons: TooltipIconStyle[]
78+
features: TooltipFeatureStyle[]
7979
legends: TooltipLegend[]
8080
}
8181

8282
export interface IndicatorCreateTooltipDataSourceParams<D> {
8383
chart: Chart
84-
8584
indicator: Indicator<D>
8685
bounding: Bounding
8786
crosshair: Crosshair
@@ -91,6 +90,17 @@ export interface IndicatorCreateTooltipDataSourceParams<D> {
9190

9291
export type IndicatorCreateTooltipDataSourceCallback<D> = (params: IndicatorCreateTooltipDataSourceParams<D>) => IndicatorTooltipData
9392

93+
export enum IndicatorEventTarget {
94+
Feature = 'feature'
95+
}
96+
97+
export interface IndicatorEvent {
98+
target: IndicatorEventTarget
99+
[key: string]: unknown
100+
}
101+
102+
export type IndicatorEventCallback = (params: IndicatorEvent) => void
103+
94104
export interface IndicatorDrawParams<D, C, E> {
95105
ctx: CanvasRenderingContext2D
96106
chart: Chart
@@ -231,6 +241,11 @@ export interface Indicator<D = unknown, C = unknown, E = unknown> {
231241
*/
232242
onDataStateChange: Nullable<IndicatorOnDataStateChangeCallback<D>>
233243

244+
/**
245+
* Event
246+
*/
247+
onClick: Nullable<IndicatorEventCallback>
248+
234249
/**
235250
* Calculation result
236251
*/
@@ -359,6 +374,8 @@ export default class IndicatorImp<D = unknown, C = unknown, E = unknown> impleme
359374
createTooltipDataSource: Nullable<IndicatorCreateTooltipDataSourceCallback<D>> = null
360375
draw: Nullable<IndicatorDrawCallback<D, C, E>> = null
361376

377+
onClick: Nullable<IndicatorEventCallback> = null
378+
362379
onDataStateChange: Nullable<IndicatorOnDataStateChangeCallback<D>> = null
363380

364381
result: D[] = []

src/extension/figure/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ import polygon from './polygon'
2222
import rect from './rect'
2323
import text from './text'
2424
import arc from './arc'
25+
import path from './path'
2526

2627
const figures: Record<string, FigureInnerConstructor> = {}
2728

28-
const extensions = [circle, line, polygon, rect, text, arc]
29+
const extensions = [circle, line, polygon, rect, text, arc, path]
2930
extensions.forEach((figure: FigureTemplate) => {
3031
figures[figure.name] = FigureImp.extend(figure)
3132
})

0 commit comments

Comments
 (0)