Skip to content

Commit 2d7df54

Browse files
committed
feat: add svg pattern component
1 parent b12729f commit 2d7df54

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<script setup lang="ts">
2+
/**
3+
* This component is designed to create various patterns from seeds, and included
4+
* inside vue-data-ui charts in the #pattern slots.
5+
* Using patterns helps users with vision deficency (like achromatopsia) to distinguish
6+
* series in the context of data visualisation.
7+
*/
8+
import { computed } from "vue";
9+
import { createSeededSvgPattern } from '~/utils/charts'
10+
11+
const props = defineProps<{
12+
id: string
13+
seed: string | number
14+
color?: string
15+
foregroundColor: string
16+
fallbackColor: string
17+
maxSize: number
18+
minSize: number
19+
}>()
20+
21+
const pattern = computed(() =>
22+
createSeededSvgPattern(props.seed, {
23+
foregroundColor: props.foregroundColor,
24+
backgroundColor: props.color ?? props.fallbackColor,
25+
minimumSize: props.minSize,
26+
maximumSize: props.maxSize,
27+
}),
28+
)
29+
30+
</script>
31+
32+
<template>
33+
<pattern
34+
:id
35+
patternUnits="userSpaceOnUse"
36+
:width="pattern.width"
37+
:height="pattern.height"
38+
:patternTransform="`rotate(${pattern.rotation})`"
39+
v-html="pattern.contentMarkup"
40+
/>
41+
</template>

test/nuxt/a11y.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ import {
136136
ButtonBase,
137137
LinkBase,
138138
CallToAction,
139+
ChartPatternSlot,
139140
CodeDirectoryListing,
140141
CodeFileTree,
141142
CodeMobileTreeDrawer,
@@ -2149,6 +2150,23 @@ describe('component accessibility audits', () => {
21492150
})
21502151
})
21512152

2153+
describe('ChartPatternSlot', () => {
2154+
it('should have no accessibility violations', async () => {
2155+
const component = await mountSuspended(ChartPatternSlot, {
2156+
props: {
2157+
id: 'perennius',
2158+
seed: 1,
2159+
foregroundColor: 'black',
2160+
fallbackColor: 'transparent',
2161+
maxSize: 24,
2162+
minSize: 16
2163+
}
2164+
})
2165+
const results = await runAxe(component)
2166+
expect(results.violations).toEqual([])
2167+
})
2168+
})
2169+
21522170
describe('CopyToClipboardButton', () => {
21532171
it('should have no accessibility violations in default state', async () => {
21542172
const component = await mountSuspended(CopyToClipboardButton, {

0 commit comments

Comments
 (0)