Skip to content

Commit 88e4db0

Browse files
chore: use built-in vue-data-ui pattern component (#2359)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent a28563b commit 88e4db0

File tree

8 files changed

+55
-699
lines changed

8 files changed

+55
-699
lines changed

app/components/Chart/PatternSlot.vue

Lines changed: 0 additions & 32 deletions
This file was deleted.

app/components/Chart/SplitSparkline.vue

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<script setup lang="ts">
22
import { VueUiSparkline } from 'vue-data-ui/vue-ui-sparkline'
3+
import { VueUiPatternSeed } from 'vue-data-ui/vue-ui-pattern-seed'
34
import { useCssVariables } from '~/composables/useColors'
45
import {
56
type VueUiSparklineConfig,
67
type VueUiSparklineDatasetItem,
78
type VueUiXyDatasetItem,
89
} from 'vue-data-ui'
910
import { getPalette, lightenColor } from 'vue-data-ui/utils'
11+
import { CHART_PATTERN_CONFIG } from '~/utils/charts'
1012
1113
import('vue-data-ui/style.css')
1214
@@ -194,19 +196,37 @@ const configs = computed(() => {
194196
<ClientOnly v-for="(config, i) in configs" :key="`config_${i}`">
195197
<div @mouseleave="resetHover" @keydown.esc="resetHover" class="w-full max-w-[400px] mx-auto">
196198
<div class="flex gap-2 place-items-center">
197-
<div class="h-3 w-3">
198-
<svg viewBox="0 0 2 2" class="w-full">
199+
<div class="h-5 w-5">
200+
<svg viewBox="0 0 30 30" class="w-full">
201+
<defs>
202+
<VueUiPatternSeed
203+
v-if="i != 0"
204+
:id="`marker_${i}`"
205+
:seed="i"
206+
:foreground-color="colors.bg!"
207+
:background-color="
208+
dataset?.[i]?.color ??
209+
palette[i] ??
210+
palette[i % palette.length] ??
211+
palette[0] ??
212+
'transparent'
213+
"
214+
:max-size="CHART_PATTERN_CONFIG.maxSize"
215+
:min-size="CHART_PATTERN_CONFIG.minSize"
216+
:disambiguator="CHART_PATTERN_CONFIG.disambiguator"
217+
/>
218+
</defs>
199219
<rect
200220
x="0"
201221
y="0"
202-
width="2"
203-
height="2"
204-
rx="0.3"
205-
:fill="dataset?.[i]?.color ?? palette[i]"
222+
width="30"
223+
height="30"
224+
rx="3"
225+
:fill="i === 0 ? (dataset?.[0]?.color ?? palette[0]) : `url(#marker_${i})`"
206226
/>
207227
</svg>
208228
</div>
209-
{{ applyEllipsis(dataset?.[i]?.name ?? '', 28) }}
229+
{{ applyEllipsis(dataset?.[i]?.name ?? '', 27) }}
210230
</div>
211231
<VueUiSparkline
212232
:key="`${i}_${step}`"

app/components/Compare/FacetBarChart.vue

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<script setup lang="ts">
22
import { ref, computed } from 'vue'
33
import { VueUiHorizontalBar } from 'vue-data-ui/vue-ui-horizontal-bar'
4+
import { VueUiPatternSeed } from 'vue-data-ui/vue-ui-pattern-seed'
45
import type { VueUiHorizontalBarConfig, VueUiHorizontalBarDatasetItem } from 'vue-data-ui'
56
import { getFrameworkColor, isListedFramework } from '~/utils/frameworks'
6-
import { createChartPatternSlotMarkup } from '~/utils/charts'
7+
import { createPatternDef } from 'vue-data-ui/utils'
78
import { drawSmallNpmxLogoAndTaglineWatermark } from '~/composables/useChartWatermark'
89
910
import {
@@ -12,6 +13,7 @@ import {
1213
sanitise,
1314
applyEllipsis,
1415
copyAltTextForCompareFacetBarChart,
16+
CHART_PATTERN_CONFIG,
1517
} from '~/utils/charts'
1618
1719
import('vue-data-ui/style.css')
@@ -227,14 +229,15 @@ const config = computed<VueUiHorizontalBarConfig>(() => {
227229
const patternId = `tooltip-pattern-${safeSeriesIndex}`
228230
const usePattern = safeSeriesIndex !== 0
229231
230-
const patternMarkup = usePattern
231-
? createChartPatternSlotMarkup({
232+
const patternDef = usePattern
233+
? createPatternDef({
232234
id: patternId,
233235
seed: safeSeriesIndex,
234236
foregroundColor: colors.value.bg!,
235-
fallbackColor: 'transparent',
236-
maxSize: 24,
237-
minSize: 16,
237+
backgroundColor: 'transparent',
238+
maxSize: CHART_PATTERN_CONFIG.maxSize,
239+
minSize: CHART_PATTERN_CONFIG.minSize,
240+
disambiguator: CHART_PATTERN_CONFIG.disambiguator,
238241
})
239242
: ''
240243
@@ -252,9 +255,7 @@ const config = computed<VueUiHorizontalBarConfig>(() => {
252255
<div class="grid grid-cols-[12px_minmax(0,1fr)_max-content] items-center gap-x-3">
253256
<div class="w-3 h-3">
254257
<svg viewBox="0 0 20 20" class="w-full h-full" aria-hidden="true">
255-
<defs>
256-
${patternMarkup}
257-
</defs>
258+
${patternDef}
258259
${markerMarkup}
259260
</svg>
260261
</div>
@@ -286,14 +287,15 @@ const config = computed<VueUiHorizontalBarConfig>(() => {
286287
</template>
287288

288289
<template #pattern="{ patternId, seriesIndex }">
289-
<ChartPatternSlot
290+
<VueUiPatternSeed
290291
v-if="seriesIndex != 0"
291292
:id="patternId"
292293
:seed="seriesIndex"
293294
:foreground-color="colors.bg!"
294-
fallback-color="transparent"
295-
:max-size="24"
296-
:min-size="16"
295+
background-color="transparent"
296+
:max-size="CHART_PATTERN_CONFIG.maxSize"
297+
:min-size="CHART_PATTERN_CONFIG.minSize"
298+
:disambiguator="CHART_PATTERN_CONFIG.disambiguator"
297299
/>
298300
</template>
299301

0 commit comments

Comments
 (0)