|
| 1 | +<template> |
| 2 | + <PageHeader> |
| 3 | + Chart |
| 4 | + <template #description> |
| 5 | + A component for displaying line charts with smooth curves and interactive tooltips. |
| 6 | + </template> |
| 7 | + </PageHeader> |
| 8 | + |
| 9 | + <Heading :level="3"> |
| 10 | + Single Line Chart |
| 11 | + </Heading> |
| 12 | + |
| 13 | + <div class="charts"> |
| 14 | + <div class="charts__showcase"> |
| 15 | + <Chart |
| 16 | + :lines="[singleLine]" |
| 17 | + detalization="days" |
| 18 | + /> |
| 19 | + </div> |
| 20 | + </div> |
| 21 | + |
| 22 | + <Heading :level="3"> |
| 23 | + Multiple Lines Chart |
| 24 | + </Heading> |
| 25 | + |
| 26 | + <div class="charts"> |
| 27 | + <div class="charts__showcase"> |
| 28 | + <Chart |
| 29 | + :lines="multipleLines" |
| 30 | + detalization="days" |
| 31 | + /> |
| 32 | + </div> |
| 33 | + </div> |
| 34 | +</template> |
| 35 | + |
| 36 | +<script setup lang="ts"> |
| 37 | +import PageHeader from '../../components/PageHeader.vue'; |
| 38 | +import { Chart, ChartLineColor, Heading } from '../../../src/vue'; |
| 39 | +import type { ChartItem, ChartLine } from '../../../src/vue/components/chart'; |
| 40 | +
|
| 41 | +/** |
| 42 | + * Generate sample data for a given number of days |
| 43 | + * |
| 44 | + * @param days Number of days to generate data for. |
| 45 | + * @param baseValue Base value used to scale the random counts (default: 100). |
| 46 | + */ |
| 47 | +function generateData(days: number, baseValue: number = 100): ChartItem[] { |
| 48 | + const now = Math.floor(Date.now() / 1000); |
| 49 | + const dayInSeconds = 86400; |
| 50 | +
|
| 51 | + return Array.from({ length: days }, (_, i) => ({ |
| 52 | + timestamp: now - (days - i) * dayInSeconds, |
| 53 | + count: Math.floor(Math.random() * baseValue) + Math.floor(baseValue / 2), |
| 54 | + })); |
| 55 | +} |
| 56 | +
|
| 57 | +/** |
| 58 | + * Single line chart data |
| 59 | + */ |
| 60 | +const singleLine: ChartLine = { |
| 61 | + label: 'events', |
| 62 | + data: generateData(30, 200), |
| 63 | + color: ChartLineColor.Red, |
| 64 | +}; |
| 65 | +
|
| 66 | +/** |
| 67 | + * Multiple lines chart data |
| 68 | + */ |
| 69 | +const multipleLines: ChartLine[] = [ |
| 70 | + { |
| 71 | + label: 'accepted', |
| 72 | + data: generateData(30, 150), |
| 73 | + color: ChartLineColor.Red, |
| 74 | + }, |
| 75 | + { |
| 76 | + label: 'rate-limited', |
| 77 | + data: generateData(30, 50), |
| 78 | + color: ChartLineColor.LightGrey, |
| 79 | + }, |
| 80 | +]; |
| 81 | +</script> |
| 82 | + |
| 83 | +<style scoped> |
| 84 | +.charts { |
| 85 | + display: grid; |
| 86 | + grid-template-columns: 1fr; |
| 87 | + gap: var(--spacing-l); |
| 88 | + margin-bottom: var(--spacing-xl); |
| 89 | + &__showcase { |
| 90 | + width: 100%; |
| 91 | + height: 200px; |
| 92 | + background-color: var(--base--bg-secondary); |
| 93 | + border-radius: var(--radius-m); |
| 94 | + padding: var(--spacing-m); |
| 95 | + } |
| 96 | +} |
| 97 | +</style> |
0 commit comments