@363045841yyt/klinechart 0.7.4 → 0.7.5-alpha.2
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 +149 -153
- package/dist/index.cjs +2 -2
- package/dist/index.js +15 -9
- package/dist/klinechart.css +1 -1
- package/package.json +82 -76
- package/src/__tests__/_mockController.ts +192 -192
- package/src/__tests__/contract.test.ts +132 -132
- package/src/components/DrawingStyleToolbar.vue +199 -199
- package/src/components/IndicatorParams.vue +570 -570
- package/src/components/IndicatorSelector.vue +1169 -1169
- package/src/components/KLineChart.vue +1570 -1570
- package/src/components/KLineTooltip.vue +200 -200
- package/src/components/LeftToolbar.vue +844 -844
- package/src/components/MarkerTooltip.vue +155 -155
- package/src/components/index.ts +7 -7
- package/src/composables/useFullscreenTeleportTarget.ts +18 -18
- package/src/debug/canvasProfiler.ts +296 -296
- package/src/index.ts +402 -402
- package/src/version.ts +3 -3
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div
|
|
3
|
-
v-if="marker"
|
|
4
|
-
:ref="onRef"
|
|
5
|
-
class="marker-tooltip"
|
|
6
|
-
:class="[{ 'use-anchor': useAnchor }, anchorPlacementClass]"
|
|
7
|
-
:style="useAnchor ? undefined : { left: `${pos.x + 12}px`, top: `${pos.y + 12}px` }"
|
|
8
|
-
>
|
|
9
|
-
<div class="marker-tooltip__title">{{ title }}</div>
|
|
10
|
-
<div v-if="hasMetadata" class="marker-tooltip__content">
|
|
11
|
-
<div v-for="(value, key) in metadata" :key="key" class="row">
|
|
12
|
-
<span>{{ key }}</span>
|
|
13
|
-
<span>{{ formatValue(value) }}</span>
|
|
14
|
-
</div>
|
|
15
|
-
</div>
|
|
16
|
-
</div>
|
|
17
|
-
</template>
|
|
18
|
-
|
|
19
|
-
<script setup lang="ts">
|
|
20
|
-
import { computed } from 'vue'
|
|
21
|
-
import type { ComponentPublicInstance } from 'vue'
|
|
22
|
-
|
|
23
|
-
interface MarkerEntity {
|
|
24
|
-
markerType: string
|
|
25
|
-
metadata: Record<string, unknown>
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface CustomMarkerEntity {
|
|
29
|
-
date: string
|
|
30
|
-
shape: string
|
|
31
|
-
label?: { text: string }
|
|
32
|
-
metadata: Record<string, unknown>
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const MARKER_TYPE_LABELS: Record<string, string> = {
|
|
36
|
-
support: '支撑位',
|
|
37
|
-
resistance: '阻力位',
|
|
38
|
-
top: '顶部',
|
|
39
|
-
bottom: '底部',
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const props = defineProps<{
|
|
43
|
-
marker: MarkerEntity | CustomMarkerEntity | null
|
|
44
|
-
pos: { x: number; y: number }
|
|
45
|
-
useAnchor?: boolean
|
|
46
|
-
anchorPlacement?: 'right-bottom' | 'left-bottom'
|
|
47
|
-
setEl?: (el: HTMLDivElement | null) => void
|
|
48
|
-
}>()
|
|
49
|
-
|
|
50
|
-
const useAnchor = computed(() => props.useAnchor === true)
|
|
51
|
-
const anchorPlacementClass = computed(() =>
|
|
52
|
-
props.anchorPlacement === 'left-bottom' ? 'anchor-left-bottom' : 'anchor-right-bottom',
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
function onRef(el: Element | ComponentPublicInstance | null) {
|
|
56
|
-
props.setEl?.(el as HTMLDivElement | null)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const isCustomMarker = computed(() => {
|
|
60
|
-
return props.marker && 'date' in props.marker
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
const title = computed(() => {
|
|
64
|
-
if (!props.marker) return ''
|
|
65
|
-
if (isCustomMarker.value) {
|
|
66
|
-
const custom = props.marker as CustomMarkerEntity
|
|
67
|
-
return custom.label?.text || custom.shape
|
|
68
|
-
}
|
|
69
|
-
const standard = props.marker as MarkerEntity
|
|
70
|
-
return MARKER_TYPE_LABELS[standard.markerType] || standard.markerType
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
const metadata = computed(() => {
|
|
74
|
-
if (!props.marker) return {}
|
|
75
|
-
if (isCustomMarker.value) {
|
|
76
|
-
const custom = props.marker as CustomMarkerEntity
|
|
77
|
-
return {
|
|
78
|
-
日期: custom.date,
|
|
79
|
-
...custom.metadata,
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return (props.marker as MarkerEntity).metadata
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
const hasMetadata = computed(() => {
|
|
86
|
-
return Object.keys(metadata.value).length > 0
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
function formatValue(value: unknown): string {
|
|
90
|
-
if (typeof value === 'number') {
|
|
91
|
-
return value.toFixed(2)
|
|
92
|
-
}
|
|
93
|
-
return String(value)
|
|
94
|
-
}
|
|
95
|
-
</script>
|
|
96
|
-
|
|
97
|
-
<style scoped>
|
|
98
|
-
.marker-tooltip {
|
|
99
|
-
position: absolute;
|
|
100
|
-
z-index: 10;
|
|
101
|
-
min-width: 180px;
|
|
102
|
-
max-width: 260px;
|
|
103
|
-
padding: 10px 12px;
|
|
104
|
-
border-radius: 8px;
|
|
105
|
-
background: rgba(255, 255, 255, 0.92);
|
|
106
|
-
border: 1px solid rgba(0, 0, 0, 0.12);
|
|
107
|
-
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
|
|
108
|
-
color: rgba(0, 0, 0, 0.78);
|
|
109
|
-
font-size: 12px;
|
|
110
|
-
line-height: 1.4;
|
|
111
|
-
pointer-events: none;
|
|
112
|
-
backdrop-filter: blur(6px);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
.marker-tooltip__title {
|
|
116
|
-
display: flex;
|
|
117
|
-
justify-content: space-between;
|
|
118
|
-
gap: 10px;
|
|
119
|
-
font-weight: 600;
|
|
120
|
-
margin-bottom: 6px;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
.marker-tooltip__content {
|
|
124
|
-
display: grid;
|
|
125
|
-
grid-template-columns: 1fr;
|
|
126
|
-
gap: 2px;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
.marker-tooltip__content .row {
|
|
130
|
-
display: flex;
|
|
131
|
-
justify-content: space-between;
|
|
132
|
-
gap: 10px;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
.marker-tooltip__content .row span:first-child {
|
|
136
|
-
color: rgba(0, 0, 0, 0.56);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
@supports (anchor-name: --kmap-anchor) and (position-anchor: --kmap-anchor) {
|
|
140
|
-
.marker-tooltip.use-anchor {
|
|
141
|
-
position: absolute;
|
|
142
|
-
position-anchor: --marker-tooltip-anchor;
|
|
143
|
-
left: anchor(left);
|
|
144
|
-
top: anchor(top);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
.marker-tooltip.use-anchor.anchor-right-bottom {
|
|
148
|
-
transform: translate(12px, 12px);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
.marker-tooltip.use-anchor.anchor-left-bottom {
|
|
152
|
-
transform: translate(calc(-100% - 12px), 12px);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
v-if="marker"
|
|
4
|
+
:ref="onRef"
|
|
5
|
+
class="marker-tooltip"
|
|
6
|
+
:class="[{ 'use-anchor': useAnchor }, anchorPlacementClass]"
|
|
7
|
+
:style="useAnchor ? undefined : { left: `${pos.x + 12}px`, top: `${pos.y + 12}px` }"
|
|
8
|
+
>
|
|
9
|
+
<div class="marker-tooltip__title">{{ title }}</div>
|
|
10
|
+
<div v-if="hasMetadata" class="marker-tooltip__content">
|
|
11
|
+
<div v-for="(value, key) in metadata" :key="key" class="row">
|
|
12
|
+
<span>{{ key }}</span>
|
|
13
|
+
<span>{{ formatValue(value) }}</span>
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<script setup lang="ts">
|
|
20
|
+
import { computed } from 'vue'
|
|
21
|
+
import type { ComponentPublicInstance } from 'vue'
|
|
22
|
+
|
|
23
|
+
interface MarkerEntity {
|
|
24
|
+
markerType: string
|
|
25
|
+
metadata: Record<string, unknown>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface CustomMarkerEntity {
|
|
29
|
+
date: string
|
|
30
|
+
shape: string
|
|
31
|
+
label?: { text: string }
|
|
32
|
+
metadata: Record<string, unknown>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const MARKER_TYPE_LABELS: Record<string, string> = {
|
|
36
|
+
support: '支撑位',
|
|
37
|
+
resistance: '阻力位',
|
|
38
|
+
top: '顶部',
|
|
39
|
+
bottom: '底部',
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const props = defineProps<{
|
|
43
|
+
marker: MarkerEntity | CustomMarkerEntity | null
|
|
44
|
+
pos: { x: number; y: number }
|
|
45
|
+
useAnchor?: boolean
|
|
46
|
+
anchorPlacement?: 'right-bottom' | 'left-bottom'
|
|
47
|
+
setEl?: (el: HTMLDivElement | null) => void
|
|
48
|
+
}>()
|
|
49
|
+
|
|
50
|
+
const useAnchor = computed(() => props.useAnchor === true)
|
|
51
|
+
const anchorPlacementClass = computed(() =>
|
|
52
|
+
props.anchorPlacement === 'left-bottom' ? 'anchor-left-bottom' : 'anchor-right-bottom',
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
function onRef(el: Element | ComponentPublicInstance | null) {
|
|
56
|
+
props.setEl?.(el as HTMLDivElement | null)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const isCustomMarker = computed(() => {
|
|
60
|
+
return props.marker && 'date' in props.marker
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const title = computed(() => {
|
|
64
|
+
if (!props.marker) return ''
|
|
65
|
+
if (isCustomMarker.value) {
|
|
66
|
+
const custom = props.marker as CustomMarkerEntity
|
|
67
|
+
return custom.label?.text || custom.shape
|
|
68
|
+
}
|
|
69
|
+
const standard = props.marker as MarkerEntity
|
|
70
|
+
return MARKER_TYPE_LABELS[standard.markerType] || standard.markerType
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
const metadata = computed(() => {
|
|
74
|
+
if (!props.marker) return {}
|
|
75
|
+
if (isCustomMarker.value) {
|
|
76
|
+
const custom = props.marker as CustomMarkerEntity
|
|
77
|
+
return {
|
|
78
|
+
日期: custom.date,
|
|
79
|
+
...custom.metadata,
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return (props.marker as MarkerEntity).metadata
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const hasMetadata = computed(() => {
|
|
86
|
+
return Object.keys(metadata.value).length > 0
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
function formatValue(value: unknown): string {
|
|
90
|
+
if (typeof value === 'number') {
|
|
91
|
+
return value.toFixed(2)
|
|
92
|
+
}
|
|
93
|
+
return String(value)
|
|
94
|
+
}
|
|
95
|
+
</script>
|
|
96
|
+
|
|
97
|
+
<style scoped>
|
|
98
|
+
.marker-tooltip {
|
|
99
|
+
position: absolute;
|
|
100
|
+
z-index: 10;
|
|
101
|
+
min-width: 180px;
|
|
102
|
+
max-width: 260px;
|
|
103
|
+
padding: 10px 12px;
|
|
104
|
+
border-radius: 8px;
|
|
105
|
+
background: rgba(255, 255, 255, 0.92);
|
|
106
|
+
border: 1px solid rgba(0, 0, 0, 0.12);
|
|
107
|
+
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
|
|
108
|
+
color: rgba(0, 0, 0, 0.78);
|
|
109
|
+
font-size: 12px;
|
|
110
|
+
line-height: 1.4;
|
|
111
|
+
pointer-events: none;
|
|
112
|
+
backdrop-filter: blur(6px);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.marker-tooltip__title {
|
|
116
|
+
display: flex;
|
|
117
|
+
justify-content: space-between;
|
|
118
|
+
gap: 10px;
|
|
119
|
+
font-weight: 600;
|
|
120
|
+
margin-bottom: 6px;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.marker-tooltip__content {
|
|
124
|
+
display: grid;
|
|
125
|
+
grid-template-columns: 1fr;
|
|
126
|
+
gap: 2px;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.marker-tooltip__content .row {
|
|
130
|
+
display: flex;
|
|
131
|
+
justify-content: space-between;
|
|
132
|
+
gap: 10px;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.marker-tooltip__content .row span:first-child {
|
|
136
|
+
color: rgba(0, 0, 0, 0.56);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
@supports (anchor-name: --kmap-anchor) and (position-anchor: --kmap-anchor) {
|
|
140
|
+
.marker-tooltip.use-anchor {
|
|
141
|
+
position: absolute;
|
|
142
|
+
position-anchor: --marker-tooltip-anchor;
|
|
143
|
+
left: anchor(left);
|
|
144
|
+
top: anchor(top);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.marker-tooltip.use-anchor.anchor-right-bottom {
|
|
148
|
+
transform: translate(12px, 12px);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.marker-tooltip.use-anchor.anchor-left-bottom {
|
|
152
|
+
transform: translate(calc(-100% - 12px), 12px);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
</style>
|
package/src/components/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { default as DrawingStyleToolbar } from './DrawingStyleToolbar.vue'
|
|
2
|
-
export { default as IndicatorParams } from './IndicatorParams.vue'
|
|
3
|
-
export { default as IndicatorSelector } from './IndicatorSelector.vue'
|
|
4
|
-
export { default as KLineChartVue } from './KLineChart.vue'
|
|
5
|
-
export { default as KLineTooltip } from './KLineTooltip.vue'
|
|
6
|
-
export { default as LeftToolbar } from './LeftToolbar.vue'
|
|
7
|
-
export { default as MarkerTooltip } from './MarkerTooltip.vue'
|
|
1
|
+
export { default as DrawingStyleToolbar } from './DrawingStyleToolbar.vue'
|
|
2
|
+
export { default as IndicatorParams } from './IndicatorParams.vue'
|
|
3
|
+
export { default as IndicatorSelector } from './IndicatorSelector.vue'
|
|
4
|
+
export { default as KLineChartVue } from './KLineChart.vue'
|
|
5
|
+
export { default as KLineTooltip } from './KLineTooltip.vue'
|
|
6
|
+
export { default as LeftToolbar } from './LeftToolbar.vue'
|
|
7
|
+
export { default as MarkerTooltip } from './MarkerTooltip.vue'
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { inject, provide, computed, type Ref, type InjectionKey } from 'vue'
|
|
2
|
-
|
|
3
|
-
const FULLSCREEN_TARGET_KEY: InjectionKey<Ref<HTMLElement | null>> =
|
|
4
|
-
Symbol('fullscreen-teleport-target')
|
|
5
|
-
|
|
6
|
-
export function provideFullscreenTeleportTarget(targetRef: Ref<HTMLElement | null>): void {
|
|
7
|
-
provide(FULLSCREEN_TARGET_KEY, targetRef)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function useFullscreenTeleportTarget() {
|
|
11
|
-
// null = no provider in ancestor tree (degraded scenario)
|
|
12
|
-
const targetRef = inject(FULLSCREEN_TARGET_KEY, null)
|
|
13
|
-
|
|
14
|
-
return computed<HTMLElement | string>(() => {
|
|
15
|
-
// targetRef null → no provider; targetRef.value null → container not mounted yet
|
|
16
|
-
return targetRef?.value ?? 'body'
|
|
17
|
-
})
|
|
18
|
-
}
|
|
1
|
+
import { inject, provide, computed, type Ref, type InjectionKey } from 'vue'
|
|
2
|
+
|
|
3
|
+
const FULLSCREEN_TARGET_KEY: InjectionKey<Ref<HTMLElement | null>> =
|
|
4
|
+
Symbol('fullscreen-teleport-target')
|
|
5
|
+
|
|
6
|
+
export function provideFullscreenTeleportTarget(targetRef: Ref<HTMLElement | null>): void {
|
|
7
|
+
provide(FULLSCREEN_TARGET_KEY, targetRef)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function useFullscreenTeleportTarget() {
|
|
11
|
+
// null = no provider in ancestor tree (degraded scenario)
|
|
12
|
+
const targetRef = inject(FULLSCREEN_TARGET_KEY, null)
|
|
13
|
+
|
|
14
|
+
return computed<HTMLElement | string>(() => {
|
|
15
|
+
// targetRef null → no provider; targetRef.value null → container not mounted yet
|
|
16
|
+
return targetRef?.value ?? 'body'
|
|
17
|
+
})
|
|
18
|
+
}
|