fix: crosshair issue
This commit is contained in:
parent
06dd21b05f
commit
4296624cdb
|
|
@ -28,6 +28,7 @@
|
||||||
--ring: 240 5% 64.9%;
|
--ring: 240 5% 64.9%;
|
||||||
--radius: 0.5rem;
|
--radius: 0.5rem;
|
||||||
|
|
||||||
|
--vis-secondary-color: 160 81% 40%;
|
||||||
--vis-font-family: inherit !important;
|
--vis-font-family: inherit !important;
|
||||||
--vis-area-stroke-width: 2px !important;
|
--vis-area-stroke-width: 2px !important;
|
||||||
--vis-donut-central-label-text-color: hsl(var(--muted-foreground)) !important;
|
--vis-donut-central-label-text-color: hsl(var(--muted-foreground)) !important;
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@ description: Displays a callout for user attention.
|
||||||
label: Alpha
|
label: Alpha
|
||||||
---
|
---
|
||||||
|
|
||||||
|
<ComponentPreview name="AreaChartDemo" />
|
||||||
<ComponentPreview name="AreaChartDemo" />
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|
@ -13,7 +12,6 @@ label: Alpha
|
||||||
Only works with Vue >3.3
|
Only works with Vue >3.3
|
||||||
</Callout>
|
</Callout>
|
||||||
|
|
||||||
|
|
||||||
<Steps>
|
<Steps>
|
||||||
|
|
||||||
### Run the following command
|
### Run the following command
|
||||||
|
|
@ -26,10 +24,11 @@ npx shadcn-vue@latest add chart-area
|
||||||
|
|
||||||
Add the following tooltip styling to your `tailwind.css` file:
|
Add the following tooltip styling to your `tailwind.css` file:
|
||||||
|
|
||||||
```css
|
```css
|
||||||
@layer base {
|
@layer base {
|
||||||
:root {
|
:root {
|
||||||
/* ... */
|
/* ... */
|
||||||
|
--vis-secondary-color: 160 81% 40%;
|
||||||
--vis-tooltip-background-color: none !important;
|
--vis-tooltip-background-color: none !important;
|
||||||
--vis-tooltip-border-color: none !important;
|
--vis-tooltip-border-color: none !important;
|
||||||
--vis-tooltip-text-color: none !important;
|
--vis-tooltip-text-color: none !important;
|
||||||
|
|
@ -38,7 +37,5 @@ Add the following tooltip styling to your `tailwind.css` file:
|
||||||
--vis-tooltip-padding: none !important;
|
--vis-tooltip-padding: none !important;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
</Steps>
|
</Steps>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@ description: Displays a callout for user attention.
|
||||||
label: Alpha
|
label: Alpha
|
||||||
---
|
---
|
||||||
|
|
||||||
|
<ComponentPreview name="BarChartDemo" />
|
||||||
<ComponentPreview name="BarChartDemo" />
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|
@ -25,10 +24,11 @@ npx shadcn-vue@latest add chart-bar
|
||||||
|
|
||||||
Add the following tooltip styling to your `tailwind.css` file:
|
Add the following tooltip styling to your `tailwind.css` file:
|
||||||
|
|
||||||
```css
|
```css
|
||||||
@layer base {
|
@layer base {
|
||||||
:root {
|
:root {
|
||||||
/* ... */
|
/* ... */
|
||||||
|
--vis-secondary-color: 160 81% 40%;
|
||||||
--vis-tooltip-background-color: none !important;
|
--vis-tooltip-background-color: none !important;
|
||||||
--vis-tooltip-border-color: none !important;
|
--vis-tooltip-border-color: none !important;
|
||||||
--vis-tooltip-text-color: none !important;
|
--vis-tooltip-text-color: none !important;
|
||||||
|
|
@ -37,7 +37,5 @@ Add the following tooltip styling to your `tailwind.css` file:
|
||||||
--vis-tooltip-padding: none !important;
|
--vis-tooltip-padding: none !important;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
</Steps>
|
</Steps>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@ description: Displays a callout for user attention.
|
||||||
label: Alpha
|
label: Alpha
|
||||||
---
|
---
|
||||||
|
|
||||||
|
<ComponentPreview name="DonutChartDemo" />
|
||||||
<ComponentPreview name="DonutChartDemo" />
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|
@ -13,7 +12,6 @@ label: Alpha
|
||||||
Only works with Vue >3.3
|
Only works with Vue >3.3
|
||||||
</Callout>
|
</Callout>
|
||||||
|
|
||||||
|
|
||||||
<Steps>
|
<Steps>
|
||||||
|
|
||||||
### Run the following command
|
### Run the following command
|
||||||
|
|
@ -26,10 +24,11 @@ npx shadcn-vue@latest add chart-donut
|
||||||
|
|
||||||
Add the following tooltip styling to your `tailwind.css` file:
|
Add the following tooltip styling to your `tailwind.css` file:
|
||||||
|
|
||||||
```css
|
```css
|
||||||
@layer base {
|
@layer base {
|
||||||
:root {
|
:root {
|
||||||
/* ... */
|
/* ... */
|
||||||
|
--vis-secondary-color: 160 81% 40%;
|
||||||
--vis-tooltip-background-color: none !important;
|
--vis-tooltip-background-color: none !important;
|
||||||
--vis-tooltip-border-color: none !important;
|
--vis-tooltip-border-color: none !important;
|
||||||
--vis-tooltip-text-color: none !important;
|
--vis-tooltip-text-color: none !important;
|
||||||
|
|
@ -38,7 +37,5 @@ Add the following tooltip styling to your `tailwind.css` file:
|
||||||
--vis-tooltip-padding: none !important;
|
--vis-tooltip-padding: none !important;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
</Steps>
|
</Steps>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@ description: Displays a callout for user attention.
|
||||||
label: Alpha
|
label: Alpha
|
||||||
---
|
---
|
||||||
|
|
||||||
|
<ComponentPreview name="LineChartDemo" />
|
||||||
<ComponentPreview name="LineChartDemo" />
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|
@ -25,10 +24,11 @@ npx shadcn-vue@latest add chart-line
|
||||||
|
|
||||||
Add the following tooltip styling to your `tailwind.css` file:
|
Add the following tooltip styling to your `tailwind.css` file:
|
||||||
|
|
||||||
```css
|
```css
|
||||||
@layer base {
|
@layer base {
|
||||||
:root {
|
:root {
|
||||||
/* ... */
|
/* ... */
|
||||||
|
--vis-secondary-color: 160 81% 40%;
|
||||||
--vis-tooltip-background-color: none !important;
|
--vis-tooltip-background-color: none !important;
|
||||||
--vis-tooltip-border-color: none !important;
|
--vis-tooltip-border-color: none !important;
|
||||||
--vis-tooltip-text-color: none !important;
|
--vis-tooltip-text-color: none !important;
|
||||||
|
|
@ -37,7 +37,5 @@ Add the following tooltip styling to your `tailwind.css` file:
|
||||||
--vis-tooltip-padding: none !important;
|
--vis-tooltip-padding: none !important;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
</Steps>
|
</Steps>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,10 @@ const props = withDefaults(defineProps<{
|
||||||
showGradiant: true,
|
showGradiant: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const emits = defineEmits<{
|
||||||
|
legendItemClick: [d: BulletLegendItemInterface, i: number]
|
||||||
|
}>()
|
||||||
|
|
||||||
type KeyOfT = Extract<keyof T, string>
|
type KeyOfT = Extract<keyof T, string>
|
||||||
type Data = typeof props.data[number]
|
type Data = typeof props.data[number]
|
||||||
|
|
||||||
|
|
@ -92,7 +96,7 @@ const legendItems = ref<BulletLegendItemInterface[]>(props.categories.map((categ
|
||||||
const isMounted = useMounted()
|
const isMounted = useMounted()
|
||||||
|
|
||||||
function handleLegendItemClick(d: BulletLegendItemInterface, i: number) {
|
function handleLegendItemClick(d: BulletLegendItemInterface, i: number) {
|
||||||
// do something when clicked on legend
|
emits('legendItemClick', d, i)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -129,7 +133,9 @@ function handleLegendItemClick(d: BulletLegendItemInterface, i: number) {
|
||||||
}"
|
}"
|
||||||
:opacity="legendItems.find(item => item.name === category)?.inactive ? filterOpacity : 1"
|
:opacity="legendItems.find(item => item.name === category)?.inactive ? filterOpacity : 1"
|
||||||
/>
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-for="(category, i) in categories" :key="category">
|
||||||
<VisLine
|
<VisLine
|
||||||
:x="(d: Data, i: number) => i"
|
:x="(d: Data, i: number) => i"
|
||||||
:y="(d: Data) => d[category]"
|
:y="(d: Data) => d[category]"
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { VisCrosshair, VisTooltip } from '@unovis/vue'
|
||||||
import type { BulletLegendItemInterface } from '@unovis/ts'
|
import type { BulletLegendItemInterface } from '@unovis/ts'
|
||||||
import { omit } from '@unovis/ts'
|
import { omit } from '@unovis/ts'
|
||||||
import { createApp, watch } from 'vue'
|
import { createApp, watch } from 'vue'
|
||||||
import { ChartTooltip } from '@/lib/registry/default/ui/chart'
|
import { ChartTooltip } from '@/lib/registry/new-york/ui/chart'
|
||||||
|
|
||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
colors: string[]
|
colors: string[]
|
||||||
|
|
@ -30,9 +30,13 @@ function template(d: any) {
|
||||||
return componentDiv.innerHTML
|
return componentDiv.innerHTML
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function color(d: unknown, i: number) {
|
||||||
|
return props.colors[i] ?? 'transparent'
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<VisTooltip :horizontal-shift="20" :vertical-shift="20" />
|
<VisTooltip :horizontal-shift="20" :vertical-shift="20" />
|
||||||
<VisCrosshair :color="colors" :template="template" />
|
<VisCrosshair :template="template" :color="color" />
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ const props = withDefaults(defineProps<{ items: BulletLegendItemInterface[] }>()
|
||||||
})
|
})
|
||||||
|
|
||||||
const emits = defineEmits<{
|
const emits = defineEmits<{
|
||||||
legendItemClick: [d: BulletLegendItemInterface, i: number]
|
'legendItemClick': [d: BulletLegendItemInterface, i: number]
|
||||||
'update:items': [payload: BulletLegendItemInterface[]]
|
'update:items': [payload: BulletLegendItemInterface[]]
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
|
@ -21,7 +21,6 @@ onMounted(() => {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
const elements = elRef.value?.querySelectorAll(selector)
|
const elements = elRef.value?.querySelectorAll(selector)
|
||||||
const classes = buttonVariants({ variant: 'ghost', size: 'xs' }).split(' ')
|
const classes = buttonVariants({ variant: 'ghost', size: 'xs' }).split(' ')
|
||||||
console.log(elements, classes)
|
|
||||||
elements?.forEach(el => el.classList.add(...classes, '!inline-flex', '!mr-2'))
|
elements?.forEach(el => el.classList.add(...classes, '!inline-flex', '!mr-2'))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ export { default as ChartSingleTooltip } from './ChartSingleTooltip.vue'
|
||||||
export { default as ChartLegend } from './ChartLegend.vue'
|
export { default as ChartLegend } from './ChartLegend.vue'
|
||||||
export { default as ChartCrosshair } from './ChartCrosshair.vue'
|
export { default as ChartCrosshair } from './ChartCrosshair.vue'
|
||||||
|
|
||||||
const SECONDARY_COLOR = '153 48% 49%'
|
|
||||||
|
|
||||||
export function defaultColors(count: number = 3) {
|
export function defaultColors(count: number = 3) {
|
||||||
const quotient = Math.floor(count / 2)
|
const quotient = Math.floor(count / 2)
|
||||||
const remainder = count % 2
|
const remainder = count % 2
|
||||||
|
|
@ -13,6 +11,6 @@ export function defaultColors(count: number = 3) {
|
||||||
const secondaryCount = quotient
|
const secondaryCount = quotient
|
||||||
return [
|
return [
|
||||||
...Array.from(Array(primaryCount).keys()).map(i => `hsl(var(--primary) / ${1 - (1 / primaryCount) * i})`),
|
...Array.from(Array(primaryCount).keys()).map(i => `hsl(var(--primary) / ${1 - (1 / primaryCount) * i})`),
|
||||||
...Array.from(Array(secondaryCount).keys()).map(i => `hsl(${SECONDARY_COLOR} / ${1 - (1 / secondaryCount) * i})`),
|
...Array.from(Array(secondaryCount).keys()).map(i => `hsl(var(--vis-secondary-color) / ${1 - (1 / secondaryCount) * i})`),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,10 @@ const props = withDefaults(defineProps<{
|
||||||
showGradiant: true,
|
showGradiant: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const emits = defineEmits<{
|
||||||
|
legendItemClick: [d: BulletLegendItemInterface, i: number]
|
||||||
|
}>()
|
||||||
|
|
||||||
type KeyOfT = Extract<keyof T, string>
|
type KeyOfT = Extract<keyof T, string>
|
||||||
type Data = typeof props.data[number]
|
type Data = typeof props.data[number]
|
||||||
|
|
||||||
|
|
@ -92,7 +96,7 @@ const legendItems = ref<BulletLegendItemInterface[]>(props.categories.map((categ
|
||||||
const isMounted = useMounted()
|
const isMounted = useMounted()
|
||||||
|
|
||||||
function handleLegendItemClick(d: BulletLegendItemInterface, i: number) {
|
function handleLegendItemClick(d: BulletLegendItemInterface, i: number) {
|
||||||
// do something when clicked on legend
|
emits('legendItemClick', d, i)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -129,7 +133,9 @@ function handleLegendItemClick(d: BulletLegendItemInterface, i: number) {
|
||||||
}"
|
}"
|
||||||
:opacity="legendItems.find(item => item.name === category)?.inactive ? filterOpacity : 1"
|
:opacity="legendItems.find(item => item.name === category)?.inactive ? filterOpacity : 1"
|
||||||
/>
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-for="(category, i) in categories" :key="category">
|
||||||
<VisLine
|
<VisLine
|
||||||
:x="(d: Data, i: number) => i"
|
:x="(d: Data, i: number) => i"
|
||||||
:y="(d: Data) => d[category]"
|
:y="(d: Data) => d[category]"
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,13 @@ function template(d: any) {
|
||||||
return componentDiv.innerHTML
|
return componentDiv.innerHTML
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function color(d: unknown, i: number) {
|
||||||
|
return props.colors[i] ?? 'transparent'
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<VisTooltip :horizontal-shift="20" :vertical-shift="20" />
|
<VisTooltip :horizontal-shift="20" :vertical-shift="20" />
|
||||||
<VisCrosshair :template="template" />
|
<VisCrosshair :template="template" :color="color" />
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ export { default as ChartSingleTooltip } from './ChartSingleTooltip.vue'
|
||||||
export { default as ChartLegend } from './ChartLegend.vue'
|
export { default as ChartLegend } from './ChartLegend.vue'
|
||||||
export { default as ChartCrosshair } from './ChartCrosshair.vue'
|
export { default as ChartCrosshair } from './ChartCrosshair.vue'
|
||||||
|
|
||||||
const SECONDARY_COLOR = '153 48% 49%'
|
|
||||||
|
|
||||||
export function defaultColors(count: number = 3) {
|
export function defaultColors(count: number = 3) {
|
||||||
const quotient = Math.floor(count / 2)
|
const quotient = Math.floor(count / 2)
|
||||||
const remainder = count % 2
|
const remainder = count % 2
|
||||||
|
|
@ -13,6 +11,6 @@ export function defaultColors(count: number = 3) {
|
||||||
const secondaryCount = quotient
|
const secondaryCount = quotient
|
||||||
return [
|
return [
|
||||||
...Array.from(Array(primaryCount).keys()).map(i => `hsl(var(--primary) / ${1 - (1 / primaryCount) * i})`),
|
...Array.from(Array(primaryCount).keys()).map(i => `hsl(var(--primary) / ${1 - (1 / primaryCount) * i})`),
|
||||||
...Array.from(Array(secondaryCount).keys()).map(i => `hsl(${SECONDARY_COLOR} / ${1 - (1 / secondaryCount) * i})`),
|
...Array.from(Array(secondaryCount).keys()).map(i => `hsl(var(--vis-secondary-color) / ${1 - (1 / secondaryCount) * i})`),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user