@363045841yyt/klinechart-core 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +201 -201
- package/README.zh-CN.md +201 -201
- package/dist/controllers/index.d.ts +1 -0
- package/dist/controllers/index.d.ts.map +1 -1
- package/dist/controllers/index.js +1 -0
- package/dist/controllers/index.js.map +1 -1
- package/dist/engine/chart.d.ts +11 -19
- package/dist/engine/chart.d.ts.map +1 -1
- package/dist/engine/chart.js +92 -109
- package/dist/engine/chart.js.map +1 -1
- package/dist/engine/renderers/Indicator/indicatorData.d.ts +1 -0
- package/dist/engine/renderers/Indicator/indicatorData.d.ts.map +1 -1
- package/dist/engine/renderers/Indicator/indicatorData.js +1 -1
- package/dist/engine/renderers/Indicator/indicatorData.js.map +1 -1
- package/dist/engine/renderers/webgl/candleSurface.js +47 -47
- package/dist/engine/subPaneManager.d.ts +4 -0
- package/dist/engine/subPaneManager.d.ts.map +1 -1
- package/dist/engine/subPaneManager.js +13 -0
- package/dist/engine/subPaneManager.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -2
- package/dist/version.js.map +1 -1
- package/package.json +129 -122
- package/src/__tests__/signal.test.ts +124 -124
- package/src/config/chartSettings.ts +66 -66
- package/src/controllers/__tests__/drawing.test.ts +214 -214
- package/src/controllers/__tests__/indicatorSelector.test.ts +481 -481
- package/src/controllers/__tests__/toolbar.test.ts +225 -225
- package/src/controllers/createChartController.ts +665 -665
- package/src/controllers/createDrawingController.ts +96 -96
- package/src/controllers/createIndicatorSelectorController.ts +307 -307
- package/src/controllers/createToolbarController.ts +146 -146
- package/src/controllers/index.ts +20 -19
- package/src/controllers/types.ts +284 -284
- package/src/engine/__tests__/chart.dpr.test.ts +401 -401
- package/src/engine/__tests__/paneRenderer.resize.test.ts +92 -92
- package/src/engine/chart-store.ts +121 -121
- package/src/engine/chart.d.ts +617 -617
- package/src/engine/chart.ts +2803 -2815
- package/src/engine/controller/__tests__/interaction.dpr.test.ts +259 -259
- package/src/engine/controller/interaction.ts +722 -722
- package/src/engine/controller/markerInteraction.ts +130 -130
- package/src/engine/controller/pinchTracker.ts +82 -82
- package/src/engine/controller/tooltipPosition.ts +48 -48
- package/src/engine/draw/__tests__/pixelAlign.spec.ts +176 -176
- package/src/engine/draw/pixelAlign.ts +259 -259
- package/src/engine/drawing/index.ts +655 -655
- package/src/engine/drawing/interaction.ts +842 -842
- package/src/engine/drawing/plugin.ts +343 -343
- package/src/engine/indicators/__tests__/__fixtures__/golden/atr.json +38 -38
- package/src/engine/indicators/__tests__/__fixtures__/golden/dema.json +14 -14
- package/src/engine/indicators/__tests__/__fixtures__/golden/hma.json +14 -14
- package/src/engine/indicators/__tests__/__fixtures__/golden/index.ts +55 -55
- package/src/engine/indicators/__tests__/__fixtures__/golden/kama.json +14 -14
- package/src/engine/indicators/__tests__/__fixtures__/golden/tema.json +14 -14
- package/src/engine/indicators/__tests__/__fixtures__/golden/wma.json +40 -40
- package/src/engine/indicators/__tests__/__fixtures__/synthetic.ts +65 -65
- package/src/engine/indicators/__tests__/_propertyAssertions.ts +76 -76
- package/src/engine/indicators/__tests__/atr.test.ts +153 -153
- package/src/engine/indicators/__tests__/calculators.test.ts +614 -614
- package/src/engine/indicators/__tests__/cmf-mfi.test.ts +100 -100
- package/src/engine/indicators/__tests__/dema.test.ts +73 -73
- package/src/engine/indicators/__tests__/donchian.test.ts +70 -70
- package/src/engine/indicators/__tests__/hma.test.ts +73 -73
- package/src/engine/indicators/__tests__/ichimoku.test.ts +105 -105
- package/src/engine/indicators/__tests__/kama.test.ts +80 -80
- package/src/engine/indicators/__tests__/keltner.test.ts +65 -65
- package/src/engine/indicators/__tests__/pivot-fib.test.ts +110 -110
- package/src/engine/indicators/__tests__/roc.test.ts +68 -68
- package/src/engine/indicators/__tests__/sar.test.ts +86 -86
- package/src/engine/indicators/__tests__/scheduler.test.ts +831 -831
- package/src/engine/indicators/__tests__/soa.test.ts +533 -533
- package/src/engine/indicators/__tests__/structure.test.ts +110 -110
- package/src/engine/indicators/__tests__/supertrend.test.ts +65 -65
- package/src/engine/indicators/__tests__/tema.test.ts +68 -68
- package/src/engine/indicators/__tests__/trix.test.ts +70 -70
- package/src/engine/indicators/__tests__/volatility.test.ts +117 -117
- package/src/engine/indicators/__tests__/volume.test.ts +115 -115
- package/src/engine/indicators/__tests__/volumeProfile.test.ts +74 -74
- package/src/engine/indicators/__tests__/vwap.test.ts +69 -69
- package/src/engine/indicators/__tests__/wma.test.ts +112 -112
- package/src/engine/indicators/__tests__/zones.test.ts +95 -95
- package/src/engine/indicators/atrState.ts +27 -27
- package/src/engine/indicators/bollState.ts +51 -51
- package/src/engine/indicators/calculators.ts +2593 -2593
- package/src/engine/indicators/cciState.ts +25 -25
- package/src/engine/indicators/chaikinVolState.ts +32 -32
- package/src/engine/indicators/cmfState.ts +27 -27
- package/src/engine/indicators/demaState.ts +27 -27
- package/src/engine/indicators/donchianState.ts +43 -43
- package/src/engine/indicators/eneState.ts +43 -43
- package/src/engine/indicators/expmaState.ts +43 -43
- package/src/engine/indicators/fastkState.ts +25 -25
- package/src/engine/indicators/fibState.ts +41 -41
- package/src/engine/indicators/hmaState.ts +27 -27
- package/src/engine/indicators/hvState.ts +28 -28
- package/src/engine/indicators/ichimokuState.ts +70 -70
- package/src/engine/indicators/indicator.worker.ts +169 -169
- package/src/engine/indicators/indicatorDefinitionRegistry.ts +62 -62
- package/src/engine/indicators/indicatorMetadata.ts +110 -110
- package/src/engine/indicators/indicatorRegistry.ts +106 -106
- package/src/engine/indicators/indicatorRuntime.ts +1548 -1548
- package/src/engine/indicators/kamaState.ts +34 -34
- package/src/engine/indicators/keltnerState.ts +49 -49
- package/src/engine/indicators/kstState.ts +42 -42
- package/src/engine/indicators/maState.ts +36 -36
- package/src/engine/indicators/macdState.ts +76 -76
- package/src/engine/indicators/mfiState.ts +27 -27
- package/src/engine/indicators/momState.ts +25 -25
- package/src/engine/indicators/obvState.ts +25 -25
- package/src/engine/indicators/parkinsonState.ts +28 -28
- package/src/engine/indicators/pivotState.ts +51 -51
- package/src/engine/indicators/pvtState.ts +25 -25
- package/src/engine/indicators/rocState.ts +27 -27
- package/src/engine/indicators/rsiState.ts +65 -65
- package/src/engine/indicators/sarState.ts +41 -41
- package/src/engine/indicators/scheduler.ts +1205 -1205
- package/src/engine/indicators/soa.ts +352 -352
- package/src/engine/indicators/stateComposer.ts +1262 -1262
- package/src/engine/indicators/stochState.ts +26 -26
- package/src/engine/indicators/structureState.ts +69 -69
- package/src/engine/indicators/supertrendState.ts +37 -37
- package/src/engine/indicators/temaState.ts +27 -27
- package/src/engine/indicators/trixState.ts +35 -35
- package/src/engine/indicators/vmaState.ts +27 -27
- package/src/engine/indicators/volumeProfileState.ts +63 -63
- package/src/engine/indicators/vwapState.ts +29 -29
- package/src/engine/indicators/wmaState.ts +27 -27
- package/src/engine/indicators/wmsrState.ts +25 -25
- package/src/engine/indicators/workerProtocol.ts +613 -613
- package/src/engine/indicators/zonesState.ts +47 -47
- package/src/engine/layout/pane.ts +161 -161
- package/src/engine/marker/registry.ts +265 -265
- package/src/engine/paneRenderer.ts +169 -169
- package/src/engine/renderers/Indicator/atr.ts +237 -237
- package/src/engine/renderers/Indicator/boll.ts +317 -317
- package/src/engine/renderers/Indicator/cci.ts +275 -275
- package/src/engine/renderers/Indicator/chaikinVol.ts +138 -138
- package/src/engine/renderers/Indicator/cmf.ts +137 -137
- package/src/engine/renderers/Indicator/dema.ts +136 -136
- package/src/engine/renderers/Indicator/donchian.ts +137 -137
- package/src/engine/renderers/Indicator/ene.ts +271 -271
- package/src/engine/renderers/Indicator/expma.ts +197 -197
- package/src/engine/renderers/Indicator/fastk.ts +316 -316
- package/src/engine/renderers/Indicator/fib.ts +141 -141
- package/src/engine/renderers/Indicator/hma.ts +136 -136
- package/src/engine/renderers/Indicator/hv.ts +124 -124
- package/src/engine/renderers/Indicator/ichimoku.ts +181 -181
- package/src/engine/renderers/Indicator/index.ts +241 -241
- package/src/engine/renderers/Indicator/indicatorData.ts +650 -650
- package/src/engine/renderers/Indicator/kama.ts +136 -136
- package/src/engine/renderers/Indicator/keltner.ts +137 -137
- package/src/engine/renderers/Indicator/kst.ts +302 -302
- package/src/engine/renderers/Indicator/ma.ts +200 -200
- package/src/engine/renderers/Indicator/macd.ts +477 -477
- package/src/engine/renderers/Indicator/macdLegend.ts +141 -141
- package/src/engine/renderers/Indicator/mainIndicatorLegend.ts +272 -272
- package/src/engine/renderers/Indicator/mfi.ts +142 -142
- package/src/engine/renderers/Indicator/mom.ts +311 -311
- package/src/engine/renderers/Indicator/obv.ts +123 -123
- package/src/engine/renderers/Indicator/parkinson.ts +124 -124
- package/src/engine/renderers/Indicator/pivot.ts +131 -131
- package/src/engine/renderers/Indicator/pvt.ts +123 -123
- package/src/engine/renderers/Indicator/roc.ts +143 -143
- package/src/engine/renderers/Indicator/rsi.ts +390 -390
- package/src/engine/renderers/Indicator/sar.ts +113 -113
- package/src/engine/renderers/Indicator/scale/atr_scale.ts +19 -19
- package/src/engine/renderers/Indicator/scale/cci_scale.ts +19 -19
- package/src/engine/renderers/Indicator/scale/fastk_scale.ts +19 -19
- package/src/engine/renderers/Indicator/scale/indicator_scale.ts +204 -204
- package/src/engine/renderers/Indicator/scale/kst_scale.ts +19 -19
- package/src/engine/renderers/Indicator/scale/macd_scale.ts +22 -22
- package/src/engine/renderers/Indicator/scale/mom_scale.ts +19 -19
- package/src/engine/renderers/Indicator/scale/rsi_scale.ts +19 -19
- package/src/engine/renderers/Indicator/scale/stoch_scale.ts +19 -19
- package/src/engine/renderers/Indicator/scale/volume_scale.ts +26 -26
- package/src/engine/renderers/Indicator/scale/wmsr_scale.ts +19 -19
- package/src/engine/renderers/Indicator/stoch.ts +359 -359
- package/src/engine/renderers/Indicator/structure.ts +126 -126
- package/src/engine/renderers/Indicator/subPaneConfig.ts +265 -265
- package/src/engine/renderers/Indicator/supertrend.ts +115 -115
- package/src/engine/renderers/Indicator/tema.ts +136 -136
- package/src/engine/renderers/Indicator/trix.ts +158 -158
- package/src/engine/renderers/Indicator/vma.ts +124 -124
- package/src/engine/renderers/Indicator/volumeProfile.ts +125 -125
- package/src/engine/renderers/Indicator/vwap.ts +123 -123
- package/src/engine/renderers/Indicator/wma.ts +136 -136
- package/src/engine/renderers/Indicator/wmsr.ts +328 -328
- package/src/engine/renderers/Indicator/zones.ts +104 -104
- package/src/engine/renderers/__tests__/boll.renderer.test.ts +314 -314
- package/src/engine/renderers/__tests__/ene.renderer.test.ts +305 -305
- package/src/engine/renderers/__tests__/expma.renderer.test.ts +279 -279
- package/src/engine/renderers/__tests__/ma.renderer.test.ts +426 -426
- package/src/engine/renderers/__tests__/mainIndicatorLegend.renderer.test.ts +502 -502
- package/src/engine/renderers/__tests__/yAxis.renderer.test.ts +173 -173
- package/src/engine/renderers/candle.ts +459 -459
- package/src/engine/renderers/crosshair.ts +69 -69
- package/src/engine/renderers/customMarkers.ts +162 -162
- package/src/engine/renderers/extremaMarkers.ts +246 -246
- package/src/engine/renderers/gridLines.ts +90 -90
- package/src/engine/renderers/lastPrice.ts +97 -97
- package/src/engine/renderers/paneTitle.ts +136 -136
- package/src/engine/renderers/subVolume.ts +236 -236
- package/src/engine/renderers/timeAxis.ts +121 -121
- package/src/engine/renderers/webgl/candleSurface.ts +955 -955
- package/src/engine/renderers/webgl/sharedWebGLSurface.ts +146 -146
- package/src/engine/renderers/yAxis.ts +105 -105
- package/src/engine/scale/__tests__/logFormula.spec.ts +148 -148
- package/src/engine/scale/logFormula.ts +130 -130
- package/src/engine/scale/price.ts +39 -39
- package/src/engine/scale/priceScale.ts +264 -264
- package/src/engine/subPaneManager.ts +442 -427
- package/src/engine/theme/colors.ts +642 -642
- package/src/engine/theme/fonts.ts +20 -20
- package/src/engine/utils/klineConfig.ts +49 -49
- package/src/engine/utils/tickCount.ts +11 -11
- package/src/engine/utils/tickPosition.ts +214 -214
- package/src/engine/utils/zoom.ts +83 -83
- package/src/engine/viewport/viewport.ts +67 -67
- package/src/index.ts +3 -3
- package/src/plugin/ConfigManager.ts +93 -93
- package/src/plugin/EventBus.ts +77 -77
- package/src/plugin/HookSystem.ts +106 -106
- package/src/plugin/PluginHost.ts +243 -243
- package/src/plugin/PluginRegistry.ts +92 -92
- package/src/plugin/StateStore.ts +73 -73
- package/src/plugin/index.ts +19 -19
- package/src/plugin/rendererPluginManager.ts +368 -368
- package/src/plugin/stateKeys.ts +8 -8
- package/src/plugin/types.ts +526 -526
- package/src/reactivity/index.ts +2 -2
- package/src/reactivity/signal.ts +119 -119
- package/src/semantic/controller.ts +251 -251
- package/src/semantic/drawShape.ts +260 -260
- package/src/semantic/index.ts +28 -28
- package/src/semantic/schema.json +256 -256
- package/src/semantic/types.ts +251 -251
- package/src/semantic/validator.ts +349 -349
- package/src/types/kLine.ts +13 -13
- package/src/types/price.ts +56 -56
- package/src/types/volumePrice.ts +33 -33
- package/src/utils/dateFormat.ts +208 -208
- package/src/utils/kLineDraw/axis.ts +562 -562
- package/src/utils/priceToY.ts +34 -34
- package/src/utils/volumePrice.ts +202 -202
- package/src/version.ts +1 -1
|
@@ -1,204 +1,204 @@
|
|
|
1
|
-
import type { RendererPluginWithHost, PluginHost, RenderContext, BaseIndicatorState } from '../../../../plugin'
|
|
2
|
-
import { RENDERER_PRIORITY } from '../../../../plugin'
|
|
3
|
-
import { createIndicatorStateKey } from '../../../../plugin/stateKeys'
|
|
4
|
-
import { getColors, type ThemeColors } from '../../../theme/colors'
|
|
5
|
-
import { getFont, setCanvasFont } from '../../../theme/fonts'
|
|
6
|
-
import { calculateValueTickPositions, type ScaleType } from '../../../utils/tickPosition'
|
|
7
|
-
import { drawCrosshairPriceLabel } from '../../../../utils/kLineDraw/axis'
|
|
8
|
-
import { roundToPhysicalPixel, alignToPhysicalPixelCenter } from '../../../draw/pixelAlign'
|
|
9
|
-
|
|
10
|
-
interface IndicatorScaleRenderState extends BaseIndicatorState {
|
|
11
|
-
valueMin: number
|
|
12
|
-
valueMax: number
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Canvas 状态缓存,避免读取 ctx 属性(读取会触发颜色序列化,很慢)
|
|
16
|
-
interface CanvasState {
|
|
17
|
-
font?: string
|
|
18
|
-
fillStyle?: string
|
|
19
|
-
textAlign?: string
|
|
20
|
-
textBaseline?: string
|
|
21
|
-
}
|
|
22
|
-
const ctxState = new WeakMap<CanvasRenderingContext2D, CanvasState>()
|
|
23
|
-
|
|
24
|
-
function getCanvasState(ctx: CanvasRenderingContext2D): CanvasState {
|
|
25
|
-
let s = ctxState.get(ctx)
|
|
26
|
-
if (!s) {
|
|
27
|
-
s = {}
|
|
28
|
-
ctxState.set(ctx, s)
|
|
29
|
-
}
|
|
30
|
-
return s
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface IndicatorScaleRendererOptions {
|
|
34
|
-
axisWidth: number
|
|
35
|
-
paneId: string
|
|
36
|
-
indicatorKey: string
|
|
37
|
-
label: string
|
|
38
|
-
decimals?: number
|
|
39
|
-
yPaddingPx?: number
|
|
40
|
-
scaleType?: ScaleType
|
|
41
|
-
getCrosshair?: () => { y: number; price: number; activePaneId: string | null } | null
|
|
42
|
-
formatTickLabel?: (value: number) => string
|
|
43
|
-
formatCrosshairLabel?: (value: number) => string
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface DrawScaleTicksOptions {
|
|
47
|
-
ctx: CanvasRenderingContext2D
|
|
48
|
-
dpr: number
|
|
49
|
-
axisWidth: number
|
|
50
|
-
height: number
|
|
51
|
-
paddingTop: number
|
|
52
|
-
paddingBottom: number
|
|
53
|
-
valueMin: number
|
|
54
|
-
valueMax: number
|
|
55
|
-
isMain: boolean
|
|
56
|
-
decimals?: number
|
|
57
|
-
hideEdgeTicks?: boolean
|
|
58
|
-
scaleType?: ScaleType
|
|
59
|
-
formatLabel?: (value: number) => string
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const BASELINE_MIDDLE = 'middle' as const
|
|
63
|
-
const ALIGN_CENTER = 'center' as const
|
|
64
|
-
|
|
65
|
-
export function drawScaleTicks(options: DrawScaleTicksOptions & { colors: ThemeColors }): void {
|
|
66
|
-
const {
|
|
67
|
-
ctx,
|
|
68
|
-
dpr,
|
|
69
|
-
axisWidth,
|
|
70
|
-
height,
|
|
71
|
-
paddingTop,
|
|
72
|
-
paddingBottom,
|
|
73
|
-
valueMin,
|
|
74
|
-
valueMax,
|
|
75
|
-
isMain,
|
|
76
|
-
decimals = 2,
|
|
77
|
-
hideEdgeTicks = true,
|
|
78
|
-
scaleType = 'linear',
|
|
79
|
-
formatLabel,
|
|
80
|
-
} = options
|
|
81
|
-
|
|
82
|
-
ctx.clearRect(0, 0, axisWidth, height)
|
|
83
|
-
|
|
84
|
-
const font = getFont(12)
|
|
85
|
-
setCanvasFont(ctx, font)
|
|
86
|
-
ctx.textBaseline = BASELINE_MIDDLE
|
|
87
|
-
ctx.textAlign = ALIGN_CENTER
|
|
88
|
-
ctx.fillStyle = options.colors.TEXT.SECONDARY
|
|
89
|
-
|
|
90
|
-
const centerX = axisWidth / 2
|
|
91
|
-
const centerXPx = roundToPhysicalPixel(centerX, dpr)
|
|
92
|
-
|
|
93
|
-
const positions = calculateValueTickPositions({
|
|
94
|
-
height,
|
|
95
|
-
paddingTop,
|
|
96
|
-
paddingBottom,
|
|
97
|
-
isMain,
|
|
98
|
-
hideEdgeTicks,
|
|
99
|
-
valueMin,
|
|
100
|
-
valueMax,
|
|
101
|
-
scaleType,
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
// 提前提取 format 函数,避免循环内重复判断
|
|
105
|
-
const format = formatLabel ?? ((v: number) => v.toFixed(decimals))
|
|
106
|
-
|
|
107
|
-
for (let i = 0; i < positions.length; i++) {
|
|
108
|
-
const { y, value } = positions[i]!
|
|
109
|
-
ctx.fillText(format(value), centerXPx, alignToPhysicalPixelCenter(y, dpr))
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export function createIndicatorScaleRendererPlugin(options: IndicatorScaleRendererOptions): RendererPluginWithHost {
|
|
114
|
-
const {
|
|
115
|
-
axisWidth,
|
|
116
|
-
paneId,
|
|
117
|
-
indicatorKey,
|
|
118
|
-
label,
|
|
119
|
-
decimals = 2,
|
|
120
|
-
yPaddingPx = 0,
|
|
121
|
-
scaleType = 'linear',
|
|
122
|
-
getCrosshair,
|
|
123
|
-
formatTickLabel,
|
|
124
|
-
formatCrosshairLabel,
|
|
125
|
-
} = options
|
|
126
|
-
const stateKey = createIndicatorStateKey(indicatorKey, paneId)
|
|
127
|
-
let pluginHost: PluginHost | null = null
|
|
128
|
-
|
|
129
|
-
return {
|
|
130
|
-
name: `${indicatorKey}Scale_${paneId}`,
|
|
131
|
-
version: '1.0.0',
|
|
132
|
-
description: `${label} 刻度渲染器`,
|
|
133
|
-
debugName: `${label}刻度`,
|
|
134
|
-
paneId,
|
|
135
|
-
priority: RENDERER_PRIORITY.INDICATOR_SCALE,
|
|
136
|
-
layer: 'overlay',
|
|
137
|
-
|
|
138
|
-
onInstall(host: PluginHost) {
|
|
139
|
-
pluginHost = host
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
draw(context: RenderContext) {
|
|
143
|
-
const { yAxisCtx, pane, dpr } = context
|
|
144
|
-
if (!yAxisCtx || !pluginHost) return
|
|
145
|
-
|
|
146
|
-
const state = pluginHost.getSharedState<IndicatorScaleRenderState>(stateKey)
|
|
147
|
-
if (!state) return
|
|
148
|
-
|
|
149
|
-
const effectiveScaleType: ScaleType = pane.yAxis.getScaleType() ?? scaleType
|
|
150
|
-
const effectiveAxisWidth = yAxisCtx.canvas ? (yAxisCtx.canvas.width / dpr) : axisWidth
|
|
151
|
-
const colors = getColors(context.theme)
|
|
152
|
-
|
|
153
|
-
const displayRange = pane.yAxis.getDisplayRange({
|
|
154
|
-
minPrice: state.valueMin,
|
|
155
|
-
maxPrice: state.valueMax,
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
drawScaleTicks({
|
|
159
|
-
colors,
|
|
160
|
-
ctx: yAxisCtx,
|
|
161
|
-
dpr,
|
|
162
|
-
axisWidth: effectiveAxisWidth,
|
|
163
|
-
height: pane.height,
|
|
164
|
-
paddingTop: pane.yAxis.getPaddingTop(),
|
|
165
|
-
paddingBottom: pane.yAxis.getPaddingBottom(),
|
|
166
|
-
valueMin: displayRange.minPrice,
|
|
167
|
-
valueMax: displayRange.maxPrice,
|
|
168
|
-
isMain: false,
|
|
169
|
-
decimals,
|
|
170
|
-
hideEdgeTicks: false,
|
|
171
|
-
scaleType: effectiveScaleType,
|
|
172
|
-
formatLabel: formatTickLabel,
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
const crosshair = getCrosshair?.()
|
|
176
|
-
if (!crosshair || crosshair.activePaneId !== pane.id) return
|
|
177
|
-
|
|
178
|
-
const localY = crosshair.y - pane.top
|
|
179
|
-
const paddingTop = pane.yAxis.getPaddingTop()
|
|
180
|
-
const paddingBottom = pane.yAxis.getPaddingBottom()
|
|
181
|
-
const yStart = paddingTop
|
|
182
|
-
const yEnd = Math.max(paddingTop, pane.height - paddingBottom)
|
|
183
|
-
const viewH = Math.max(1, yEnd - yStart)
|
|
184
|
-
const clampedY = Math.min(Math.max(localY, yStart), yEnd)
|
|
185
|
-
const t = (clampedY - yStart) / viewH
|
|
186
|
-
const displayPrice = displayRange.maxPrice - t * (displayRange.maxPrice - displayRange.minPrice)
|
|
187
|
-
|
|
188
|
-
drawCrosshairPriceLabel(yAxisCtx, {
|
|
189
|
-
x: 0,
|
|
190
|
-
y: 0,
|
|
191
|
-
width: effectiveAxisWidth,
|
|
192
|
-
height: pane.height,
|
|
193
|
-
crosshairY: localY,
|
|
194
|
-
priceRange: displayRange,
|
|
195
|
-
yPaddingPx,
|
|
196
|
-
dpr,
|
|
197
|
-
fontSize: 12,
|
|
198
|
-
priceOffset: 0,
|
|
199
|
-
price: displayPrice,
|
|
200
|
-
formatPrice: formatCrosshairLabel,
|
|
201
|
-
})
|
|
202
|
-
},
|
|
203
|
-
}
|
|
204
|
-
}
|
|
1
|
+
import type { RendererPluginWithHost, PluginHost, RenderContext, BaseIndicatorState } from '../../../../plugin'
|
|
2
|
+
import { RENDERER_PRIORITY } from '../../../../plugin'
|
|
3
|
+
import { createIndicatorStateKey } from '../../../../plugin/stateKeys'
|
|
4
|
+
import { getColors, type ThemeColors } from '../../../theme/colors'
|
|
5
|
+
import { getFont, setCanvasFont } from '../../../theme/fonts'
|
|
6
|
+
import { calculateValueTickPositions, type ScaleType } from '../../../utils/tickPosition'
|
|
7
|
+
import { drawCrosshairPriceLabel } from '../../../../utils/kLineDraw/axis'
|
|
8
|
+
import { roundToPhysicalPixel, alignToPhysicalPixelCenter } from '../../../draw/pixelAlign'
|
|
9
|
+
|
|
10
|
+
interface IndicatorScaleRenderState extends BaseIndicatorState {
|
|
11
|
+
valueMin: number
|
|
12
|
+
valueMax: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Canvas 状态缓存,避免读取 ctx 属性(读取会触发颜色序列化,很慢)
|
|
16
|
+
interface CanvasState {
|
|
17
|
+
font?: string
|
|
18
|
+
fillStyle?: string
|
|
19
|
+
textAlign?: string
|
|
20
|
+
textBaseline?: string
|
|
21
|
+
}
|
|
22
|
+
const ctxState = new WeakMap<CanvasRenderingContext2D, CanvasState>()
|
|
23
|
+
|
|
24
|
+
function getCanvasState(ctx: CanvasRenderingContext2D): CanvasState {
|
|
25
|
+
let s = ctxState.get(ctx)
|
|
26
|
+
if (!s) {
|
|
27
|
+
s = {}
|
|
28
|
+
ctxState.set(ctx, s)
|
|
29
|
+
}
|
|
30
|
+
return s
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface IndicatorScaleRendererOptions {
|
|
34
|
+
axisWidth: number
|
|
35
|
+
paneId: string
|
|
36
|
+
indicatorKey: string
|
|
37
|
+
label: string
|
|
38
|
+
decimals?: number
|
|
39
|
+
yPaddingPx?: number
|
|
40
|
+
scaleType?: ScaleType
|
|
41
|
+
getCrosshair?: () => { y: number; price: number; activePaneId: string | null } | null
|
|
42
|
+
formatTickLabel?: (value: number) => string
|
|
43
|
+
formatCrosshairLabel?: (value: number) => string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface DrawScaleTicksOptions {
|
|
47
|
+
ctx: CanvasRenderingContext2D
|
|
48
|
+
dpr: number
|
|
49
|
+
axisWidth: number
|
|
50
|
+
height: number
|
|
51
|
+
paddingTop: number
|
|
52
|
+
paddingBottom: number
|
|
53
|
+
valueMin: number
|
|
54
|
+
valueMax: number
|
|
55
|
+
isMain: boolean
|
|
56
|
+
decimals?: number
|
|
57
|
+
hideEdgeTicks?: boolean
|
|
58
|
+
scaleType?: ScaleType
|
|
59
|
+
formatLabel?: (value: number) => string
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const BASELINE_MIDDLE = 'middle' as const
|
|
63
|
+
const ALIGN_CENTER = 'center' as const
|
|
64
|
+
|
|
65
|
+
export function drawScaleTicks(options: DrawScaleTicksOptions & { colors: ThemeColors }): void {
|
|
66
|
+
const {
|
|
67
|
+
ctx,
|
|
68
|
+
dpr,
|
|
69
|
+
axisWidth,
|
|
70
|
+
height,
|
|
71
|
+
paddingTop,
|
|
72
|
+
paddingBottom,
|
|
73
|
+
valueMin,
|
|
74
|
+
valueMax,
|
|
75
|
+
isMain,
|
|
76
|
+
decimals = 2,
|
|
77
|
+
hideEdgeTicks = true,
|
|
78
|
+
scaleType = 'linear',
|
|
79
|
+
formatLabel,
|
|
80
|
+
} = options
|
|
81
|
+
|
|
82
|
+
ctx.clearRect(0, 0, axisWidth, height)
|
|
83
|
+
|
|
84
|
+
const font = getFont(12)
|
|
85
|
+
setCanvasFont(ctx, font)
|
|
86
|
+
ctx.textBaseline = BASELINE_MIDDLE
|
|
87
|
+
ctx.textAlign = ALIGN_CENTER
|
|
88
|
+
ctx.fillStyle = options.colors.TEXT.SECONDARY
|
|
89
|
+
|
|
90
|
+
const centerX = axisWidth / 2
|
|
91
|
+
const centerXPx = roundToPhysicalPixel(centerX, dpr)
|
|
92
|
+
|
|
93
|
+
const positions = calculateValueTickPositions({
|
|
94
|
+
height,
|
|
95
|
+
paddingTop,
|
|
96
|
+
paddingBottom,
|
|
97
|
+
isMain,
|
|
98
|
+
hideEdgeTicks,
|
|
99
|
+
valueMin,
|
|
100
|
+
valueMax,
|
|
101
|
+
scaleType,
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
// 提前提取 format 函数,避免循环内重复判断
|
|
105
|
+
const format = formatLabel ?? ((v: number) => v.toFixed(decimals))
|
|
106
|
+
|
|
107
|
+
for (let i = 0; i < positions.length; i++) {
|
|
108
|
+
const { y, value } = positions[i]!
|
|
109
|
+
ctx.fillText(format(value), centerXPx, alignToPhysicalPixelCenter(y, dpr))
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function createIndicatorScaleRendererPlugin(options: IndicatorScaleRendererOptions): RendererPluginWithHost {
|
|
114
|
+
const {
|
|
115
|
+
axisWidth,
|
|
116
|
+
paneId,
|
|
117
|
+
indicatorKey,
|
|
118
|
+
label,
|
|
119
|
+
decimals = 2,
|
|
120
|
+
yPaddingPx = 0,
|
|
121
|
+
scaleType = 'linear',
|
|
122
|
+
getCrosshair,
|
|
123
|
+
formatTickLabel,
|
|
124
|
+
formatCrosshairLabel,
|
|
125
|
+
} = options
|
|
126
|
+
const stateKey = createIndicatorStateKey(indicatorKey, paneId)
|
|
127
|
+
let pluginHost: PluginHost | null = null
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
name: `${indicatorKey}Scale_${paneId}`,
|
|
131
|
+
version: '1.0.0',
|
|
132
|
+
description: `${label} 刻度渲染器`,
|
|
133
|
+
debugName: `${label}刻度`,
|
|
134
|
+
paneId,
|
|
135
|
+
priority: RENDERER_PRIORITY.INDICATOR_SCALE,
|
|
136
|
+
layer: 'overlay',
|
|
137
|
+
|
|
138
|
+
onInstall(host: PluginHost) {
|
|
139
|
+
pluginHost = host
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
draw(context: RenderContext) {
|
|
143
|
+
const { yAxisCtx, pane, dpr } = context
|
|
144
|
+
if (!yAxisCtx || !pluginHost) return
|
|
145
|
+
|
|
146
|
+
const state = pluginHost.getSharedState<IndicatorScaleRenderState>(stateKey)
|
|
147
|
+
if (!state) return
|
|
148
|
+
|
|
149
|
+
const effectiveScaleType: ScaleType = pane.yAxis.getScaleType() ?? scaleType
|
|
150
|
+
const effectiveAxisWidth = yAxisCtx.canvas ? (yAxisCtx.canvas.width / dpr) : axisWidth
|
|
151
|
+
const colors = getColors(context.theme)
|
|
152
|
+
|
|
153
|
+
const displayRange = pane.yAxis.getDisplayRange({
|
|
154
|
+
minPrice: state.valueMin,
|
|
155
|
+
maxPrice: state.valueMax,
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
drawScaleTicks({
|
|
159
|
+
colors,
|
|
160
|
+
ctx: yAxisCtx,
|
|
161
|
+
dpr,
|
|
162
|
+
axisWidth: effectiveAxisWidth,
|
|
163
|
+
height: pane.height,
|
|
164
|
+
paddingTop: pane.yAxis.getPaddingTop(),
|
|
165
|
+
paddingBottom: pane.yAxis.getPaddingBottom(),
|
|
166
|
+
valueMin: displayRange.minPrice,
|
|
167
|
+
valueMax: displayRange.maxPrice,
|
|
168
|
+
isMain: false,
|
|
169
|
+
decimals,
|
|
170
|
+
hideEdgeTicks: false,
|
|
171
|
+
scaleType: effectiveScaleType,
|
|
172
|
+
formatLabel: formatTickLabel,
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
const crosshair = getCrosshair?.()
|
|
176
|
+
if (!crosshair || crosshair.activePaneId !== pane.id) return
|
|
177
|
+
|
|
178
|
+
const localY = crosshair.y - pane.top
|
|
179
|
+
const paddingTop = pane.yAxis.getPaddingTop()
|
|
180
|
+
const paddingBottom = pane.yAxis.getPaddingBottom()
|
|
181
|
+
const yStart = paddingTop
|
|
182
|
+
const yEnd = Math.max(paddingTop, pane.height - paddingBottom)
|
|
183
|
+
const viewH = Math.max(1, yEnd - yStart)
|
|
184
|
+
const clampedY = Math.min(Math.max(localY, yStart), yEnd)
|
|
185
|
+
const t = (clampedY - yStart) / viewH
|
|
186
|
+
const displayPrice = displayRange.maxPrice - t * (displayRange.maxPrice - displayRange.minPrice)
|
|
187
|
+
|
|
188
|
+
drawCrosshairPriceLabel(yAxisCtx, {
|
|
189
|
+
x: 0,
|
|
190
|
+
y: 0,
|
|
191
|
+
width: effectiveAxisWidth,
|
|
192
|
+
height: pane.height,
|
|
193
|
+
crosshairY: localY,
|
|
194
|
+
priceRange: displayRange,
|
|
195
|
+
yPaddingPx,
|
|
196
|
+
dpr,
|
|
197
|
+
fontSize: 12,
|
|
198
|
+
priceOffset: 0,
|
|
199
|
+
price: displayPrice,
|
|
200
|
+
formatPrice: formatCrosshairLabel,
|
|
201
|
+
})
|
|
202
|
+
},
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { RendererPluginWithHost } from '../../../../plugin'
|
|
2
|
-
import { createIndicatorScaleRendererPlugin } from './indicator_scale'
|
|
3
|
-
|
|
4
|
-
export function createKstScaleRendererPlugin(options: {
|
|
5
|
-
axisWidth: number
|
|
6
|
-
paneId: string
|
|
7
|
-
yPaddingPx?: number
|
|
8
|
-
getCrosshair?: () => { y: number; price: number; activePaneId: string | null } | null
|
|
9
|
-
}): RendererPluginWithHost {
|
|
10
|
-
return createIndicatorScaleRendererPlugin({
|
|
11
|
-
axisWidth: options.axisWidth,
|
|
12
|
-
paneId: options.paneId,
|
|
13
|
-
indicatorKey: 'kst',
|
|
14
|
-
label: 'KST',
|
|
15
|
-
decimals: 2,
|
|
16
|
-
yPaddingPx: options.yPaddingPx,
|
|
17
|
-
getCrosshair: options.getCrosshair,
|
|
18
|
-
})
|
|
19
|
-
}
|
|
1
|
+
import type { RendererPluginWithHost } from '../../../../plugin'
|
|
2
|
+
import { createIndicatorScaleRendererPlugin } from './indicator_scale'
|
|
3
|
+
|
|
4
|
+
export function createKstScaleRendererPlugin(options: {
|
|
5
|
+
axisWidth: number
|
|
6
|
+
paneId: string
|
|
7
|
+
yPaddingPx?: number
|
|
8
|
+
getCrosshair?: () => { y: number; price: number; activePaneId: string | null } | null
|
|
9
|
+
}): RendererPluginWithHost {
|
|
10
|
+
return createIndicatorScaleRendererPlugin({
|
|
11
|
+
axisWidth: options.axisWidth,
|
|
12
|
+
paneId: options.paneId,
|
|
13
|
+
indicatorKey: 'kst',
|
|
14
|
+
label: 'KST',
|
|
15
|
+
decimals: 2,
|
|
16
|
+
yPaddingPx: options.yPaddingPx,
|
|
17
|
+
getCrosshair: options.getCrosshair,
|
|
18
|
+
})
|
|
19
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import type { RendererPluginWithHost } from '../../../../plugin'
|
|
2
|
-
import { createIndicatorScaleRendererPlugin } from './indicator_scale'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 创建 MACD 刻度渲染器插件
|
|
6
|
-
*/
|
|
7
|
-
export function createMacdScaleRendererPlugin(options: {
|
|
8
|
-
axisWidth: number
|
|
9
|
-
paneId: string
|
|
10
|
-
yPaddingPx?: number
|
|
11
|
-
getCrosshair?: () => { y: number; price: number; activePaneId: string | null } | null
|
|
12
|
-
}): RendererPluginWithHost {
|
|
13
|
-
return createIndicatorScaleRendererPlugin({
|
|
14
|
-
axisWidth: options.axisWidth,
|
|
15
|
-
paneId: options.paneId,
|
|
16
|
-
indicatorKey: 'macd',
|
|
17
|
-
label: 'MACD',
|
|
18
|
-
decimals: 2,
|
|
19
|
-
yPaddingPx: options.yPaddingPx,
|
|
20
|
-
getCrosshair: options.getCrosshair,
|
|
21
|
-
})
|
|
22
|
-
}
|
|
1
|
+
import type { RendererPluginWithHost } from '../../../../plugin'
|
|
2
|
+
import { createIndicatorScaleRendererPlugin } from './indicator_scale'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 创建 MACD 刻度渲染器插件
|
|
6
|
+
*/
|
|
7
|
+
export function createMacdScaleRendererPlugin(options: {
|
|
8
|
+
axisWidth: number
|
|
9
|
+
paneId: string
|
|
10
|
+
yPaddingPx?: number
|
|
11
|
+
getCrosshair?: () => { y: number; price: number; activePaneId: string | null } | null
|
|
12
|
+
}): RendererPluginWithHost {
|
|
13
|
+
return createIndicatorScaleRendererPlugin({
|
|
14
|
+
axisWidth: options.axisWidth,
|
|
15
|
+
paneId: options.paneId,
|
|
16
|
+
indicatorKey: 'macd',
|
|
17
|
+
label: 'MACD',
|
|
18
|
+
decimals: 2,
|
|
19
|
+
yPaddingPx: options.yPaddingPx,
|
|
20
|
+
getCrosshair: options.getCrosshair,
|
|
21
|
+
})
|
|
22
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { RendererPluginWithHost } from '../../../../plugin'
|
|
2
|
-
import { createIndicatorScaleRendererPlugin } from './indicator_scale'
|
|
3
|
-
|
|
4
|
-
export function createMomScaleRendererPlugin(options: {
|
|
5
|
-
axisWidth: number
|
|
6
|
-
paneId: string
|
|
7
|
-
yPaddingPx?: number
|
|
8
|
-
getCrosshair?: () => { y: number; price: number; activePaneId: string | null } | null
|
|
9
|
-
}): RendererPluginWithHost {
|
|
10
|
-
return createIndicatorScaleRendererPlugin({
|
|
11
|
-
axisWidth: options.axisWidth,
|
|
12
|
-
paneId: options.paneId,
|
|
13
|
-
indicatorKey: 'mom',
|
|
14
|
-
label: 'MOM',
|
|
15
|
-
decimals: 2,
|
|
16
|
-
yPaddingPx: options.yPaddingPx,
|
|
17
|
-
getCrosshair: options.getCrosshair,
|
|
18
|
-
})
|
|
19
|
-
}
|
|
1
|
+
import type { RendererPluginWithHost } from '../../../../plugin'
|
|
2
|
+
import { createIndicatorScaleRendererPlugin } from './indicator_scale'
|
|
3
|
+
|
|
4
|
+
export function createMomScaleRendererPlugin(options: {
|
|
5
|
+
axisWidth: number
|
|
6
|
+
paneId: string
|
|
7
|
+
yPaddingPx?: number
|
|
8
|
+
getCrosshair?: () => { y: number; price: number; activePaneId: string | null } | null
|
|
9
|
+
}): RendererPluginWithHost {
|
|
10
|
+
return createIndicatorScaleRendererPlugin({
|
|
11
|
+
axisWidth: options.axisWidth,
|
|
12
|
+
paneId: options.paneId,
|
|
13
|
+
indicatorKey: 'mom',
|
|
14
|
+
label: 'MOM',
|
|
15
|
+
decimals: 2,
|
|
16
|
+
yPaddingPx: options.yPaddingPx,
|
|
17
|
+
getCrosshair: options.getCrosshair,
|
|
18
|
+
})
|
|
19
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { RendererPluginWithHost } from '../../../../plugin'
|
|
2
|
-
import { createIndicatorScaleRendererPlugin } from './indicator_scale'
|
|
3
|
-
|
|
4
|
-
export function createRsiScaleRendererPlugin(options: {
|
|
5
|
-
axisWidth: number
|
|
6
|
-
paneId: string
|
|
7
|
-
yPaddingPx?: number
|
|
8
|
-
getCrosshair?: () => { y: number; price: number; activePaneId: string | null } | null
|
|
9
|
-
}): RendererPluginWithHost {
|
|
10
|
-
return createIndicatorScaleRendererPlugin({
|
|
11
|
-
axisWidth: options.axisWidth,
|
|
12
|
-
paneId: options.paneId,
|
|
13
|
-
indicatorKey: 'rsi',
|
|
14
|
-
label: 'RSI',
|
|
15
|
-
decimals: 2,
|
|
16
|
-
yPaddingPx: options.yPaddingPx,
|
|
17
|
-
getCrosshair: options.getCrosshair,
|
|
18
|
-
})
|
|
19
|
-
}
|
|
1
|
+
import type { RendererPluginWithHost } from '../../../../plugin'
|
|
2
|
+
import { createIndicatorScaleRendererPlugin } from './indicator_scale'
|
|
3
|
+
|
|
4
|
+
export function createRsiScaleRendererPlugin(options: {
|
|
5
|
+
axisWidth: number
|
|
6
|
+
paneId: string
|
|
7
|
+
yPaddingPx?: number
|
|
8
|
+
getCrosshair?: () => { y: number; price: number; activePaneId: string | null } | null
|
|
9
|
+
}): RendererPluginWithHost {
|
|
10
|
+
return createIndicatorScaleRendererPlugin({
|
|
11
|
+
axisWidth: options.axisWidth,
|
|
12
|
+
paneId: options.paneId,
|
|
13
|
+
indicatorKey: 'rsi',
|
|
14
|
+
label: 'RSI',
|
|
15
|
+
decimals: 2,
|
|
16
|
+
yPaddingPx: options.yPaddingPx,
|
|
17
|
+
getCrosshair: options.getCrosshair,
|
|
18
|
+
})
|
|
19
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { RendererPluginWithHost } from '../../../../plugin'
|
|
2
|
-
import { createIndicatorScaleRendererPlugin } from './indicator_scale'
|
|
3
|
-
|
|
4
|
-
export function createStochScaleRendererPlugin(options: {
|
|
5
|
-
axisWidth: number
|
|
6
|
-
paneId: string
|
|
7
|
-
yPaddingPx?: number
|
|
8
|
-
getCrosshair?: () => { y: number; price: number; activePaneId: string | null } | null
|
|
9
|
-
}): RendererPluginWithHost {
|
|
10
|
-
return createIndicatorScaleRendererPlugin({
|
|
11
|
-
axisWidth: options.axisWidth,
|
|
12
|
-
paneId: options.paneId,
|
|
13
|
-
indicatorKey: 'stoch',
|
|
14
|
-
label: 'STOCH',
|
|
15
|
-
decimals: 2,
|
|
16
|
-
yPaddingPx: options.yPaddingPx,
|
|
17
|
-
getCrosshair: options.getCrosshair,
|
|
18
|
-
})
|
|
19
|
-
}
|
|
1
|
+
import type { RendererPluginWithHost } from '../../../../plugin'
|
|
2
|
+
import { createIndicatorScaleRendererPlugin } from './indicator_scale'
|
|
3
|
+
|
|
4
|
+
export function createStochScaleRendererPlugin(options: {
|
|
5
|
+
axisWidth: number
|
|
6
|
+
paneId: string
|
|
7
|
+
yPaddingPx?: number
|
|
8
|
+
getCrosshair?: () => { y: number; price: number; activePaneId: string | null } | null
|
|
9
|
+
}): RendererPluginWithHost {
|
|
10
|
+
return createIndicatorScaleRendererPlugin({
|
|
11
|
+
axisWidth: options.axisWidth,
|
|
12
|
+
paneId: options.paneId,
|
|
13
|
+
indicatorKey: 'stoch',
|
|
14
|
+
label: 'STOCH',
|
|
15
|
+
decimals: 2,
|
|
16
|
+
yPaddingPx: options.yPaddingPx,
|
|
17
|
+
getCrosshair: options.getCrosshair,
|
|
18
|
+
})
|
|
19
|
+
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import type { RendererPluginWithHost } from '../../../../plugin'
|
|
2
|
-
import { createIndicatorScaleRendererPlugin } from './indicator_scale'
|
|
3
|
-
|
|
4
|
-
const YI = 1e8
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 创建成交量刻度渲染器插件
|
|
8
|
-
*/
|
|
9
|
-
export function createVolumeScaleRendererPlugin(options: {
|
|
10
|
-
axisWidth: number
|
|
11
|
-
paneId: string
|
|
12
|
-
yPaddingPx?: number
|
|
13
|
-
getCrosshair?: () => { y: number; price: number; activePaneId: string | null } | null
|
|
14
|
-
}): RendererPluginWithHost {
|
|
15
|
-
return createIndicatorScaleRendererPlugin({
|
|
16
|
-
axisWidth: options.axisWidth,
|
|
17
|
-
paneId: options.paneId,
|
|
18
|
-
indicatorKey: 'volume',
|
|
19
|
-
label: 'VOL',
|
|
20
|
-
decimals: 2,
|
|
21
|
-
yPaddingPx: options.yPaddingPx,
|
|
22
|
-
getCrosshair: options.getCrosshair,
|
|
23
|
-
formatTickLabel: (value) => `${(value / YI).toFixed(2)}B`,
|
|
24
|
-
formatCrosshairLabel: (value) => `${(value / YI).toFixed(2)}B`,
|
|
25
|
-
})
|
|
26
|
-
}
|
|
1
|
+
import type { RendererPluginWithHost } from '../../../../plugin'
|
|
2
|
+
import { createIndicatorScaleRendererPlugin } from './indicator_scale'
|
|
3
|
+
|
|
4
|
+
const YI = 1e8
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 创建成交量刻度渲染器插件
|
|
8
|
+
*/
|
|
9
|
+
export function createVolumeScaleRendererPlugin(options: {
|
|
10
|
+
axisWidth: number
|
|
11
|
+
paneId: string
|
|
12
|
+
yPaddingPx?: number
|
|
13
|
+
getCrosshair?: () => { y: number; price: number; activePaneId: string | null } | null
|
|
14
|
+
}): RendererPluginWithHost {
|
|
15
|
+
return createIndicatorScaleRendererPlugin({
|
|
16
|
+
axisWidth: options.axisWidth,
|
|
17
|
+
paneId: options.paneId,
|
|
18
|
+
indicatorKey: 'volume',
|
|
19
|
+
label: 'VOL',
|
|
20
|
+
decimals: 2,
|
|
21
|
+
yPaddingPx: options.yPaddingPx,
|
|
22
|
+
getCrosshair: options.getCrosshair,
|
|
23
|
+
formatTickLabel: (value) => `${(value / YI).toFixed(2)}B`,
|
|
24
|
+
formatCrosshairLabel: (value) => `${(value / YI).toFixed(2)}B`,
|
|
25
|
+
})
|
|
26
|
+
}
|