All files / apps/developer-portal/layers/workflows/app/components WorkflowActivitySpark.vue

100% Statements 14/14
50% Branches 1/2
100% Functions 6/6
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51  3x                                                             3x 3x   3x 3x   6x           6x 3x 3x   3x    
<template>
    <svg
        :viewBox="`0 0 ${WIDTH} ${HEIGHT}`"
        class="h-7 w-28 shrink-0 overflow-visible"
        role="img"
        :aria-label="label"
    >
        <title>{{ label }}</title>
        <path :d="area" fill="currentColor" opacity="0.25" />
        <polyline
            :points
            fill="none"
            stroke="currentColor"
            stroke-width="2"
            stroke-linejoin="round"
            stroke-linecap="round"
        />
        <circle :cx="end.x" :cy="end.y" r="2.5" fill="currentColor" />
    </svg>
</template>
 
<script setup lang="ts">
interface Props {
    /** Active days per week, on the project's shared timeline. */
    weeks: number[];
    /** The shared top, so every card's line is drawn to one scale. */
    peak: number;
    label: string;
}
 
const { weeks, peak, label } = defineProps<Props>();
 
const WIDTH = 112;
const HEIGHT = 24;
 
const coordinates = computed(() => {
    const step = WIDTH / Math.max(weeks.length - 1, 1);
 
    return weeks.map((active, index) => ({
        x: Math.round(index * step * 10) / 10,
        y: Math.round((HEIGHT - (active / peak) * HEIGHT) * 10) / 10,
    }));
});
 
const points = computed(() => coordinates.value.map(({ x, y }) => `${x},${y}`).join(" "));
const area = computed(
    () => `M0,${HEIGHT} L${points.value.replaceAll(" ", " L")} L${WIDTH},${HEIGHT} Z`,
);
const end = computed(() => coordinates.value.at(-1) ?? { x: 0, y: HEIGHT });
</script>