|
| 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 | + <div class="chart-props"> |
| 10 | + <div class="chart-props__item"> |
| 11 | + <h4 class="chart-props__name"> |
| 12 | + lines |
| 13 | + </h4> |
| 14 | + <p class="chart-props__description"> |
| 15 | + An array of line objects to display on the chart. |
| 16 | + </p> |
| 17 | + </div> |
| 18 | + |
| 19 | + <div class="chart-props__item"> |
| 20 | + <h4 class="chart-props__name"> |
| 21 | + detalization |
| 22 | + </h4> |
| 23 | + <p class="chart-props__description"> |
| 24 | + Controls how timestamps are formatted on the X-axis legend and tooltip. |
| 25 | + Does not affect data aggregation — only the display format. |
| 26 | + </p> |
| 27 | + <ul class="chart-props__list"> |
| 28 | + <li><code>'days'</code> — shows day and month (e.g., "19 dec")</li> |
| 29 | + <li><code>'hours'</code> — shows day, month, and time (e.g., "19 dec, 14:00")</li> |
| 30 | + <li><code>'minutes'</code> — shows day, month, and time (e.g., "19 dec, 14:30")</li> |
| 31 | + </ul> |
| 32 | + <div class="chart-props__control"> |
| 33 | + <span class="chart-props__control-label">Try it:</span> |
| 34 | + <Select |
| 35 | + v-model="detalizationSelected" |
| 36 | + :align="{ vertically: 'below', horizontally: 'left' }" |
| 37 | + :is-disabled="false" |
| 38 | + :items="detalizationItems" |
| 39 | + /> |
| 40 | + </div> |
| 41 | + </div> |
| 42 | + </div> |
| 43 | + |
| 44 | + <Heading :level="3"> |
| 45 | + Single Line |
| 46 | + </Heading> |
| 47 | + <div class="chart-example"> |
| 48 | + <div class="chart-example__showcase"> |
| 49 | + <Chart |
| 50 | + :lines="[singleLineData]" |
| 51 | + :detalization="currentDetalization" |
| 52 | + /> |
| 53 | + </div> |
| 54 | + </div> |
| 55 | + |
| 56 | + <Heading :level="3"> |
| 57 | + Multiple Lines |
| 58 | + </Heading> |
| 59 | + <div class="chart-example"> |
| 60 | + <div class="chart-example__showcase"> |
| 61 | + <Chart |
| 62 | + :lines="multipleLinesData" |
| 63 | + :detalization="currentDetalization" |
| 64 | + /> |
| 65 | + </div> |
| 66 | + </div> |
| 67 | +</template> |
| 68 | + |
| 69 | +<script setup lang="ts"> |
| 70 | +import { ref, computed } from 'vue'; |
| 71 | +import PageHeader from '../../components/PageHeader.vue'; |
| 72 | +import { Chart, ChartLineColor, Heading, Select } from '../../../src/vue'; |
| 73 | +import type { ChartItem, ChartLine } from '../../../src/vue/components/chart'; |
| 74 | +import type { ContextMenuItem, DefaultItem } from '../../../src/vue/components/context-menu/ContextMenu.types'; |
| 75 | +
|
| 76 | +/** |
| 77 | + * Detalization types for chart timestamp formatting |
| 78 | + */ |
| 79 | +type DetalizationValue = 'minutes' | 'hours' | 'days'; |
| 80 | +
|
| 81 | +/** |
| 82 | + * Mapping from Select title to detalization value |
| 83 | + */ |
| 84 | +const detalizationMap: Record<string, DetalizationValue> = { |
| 85 | + days: 'days', |
| 86 | + hours: 'hours', |
| 87 | + minutes: 'minutes', |
| 88 | +}; |
| 89 | +
|
| 90 | +/** |
| 91 | + * Generate sample chart data |
| 92 | + * |
| 93 | + * @param points - Number of data points to generate |
| 94 | + * @param intervalSeconds - Time interval between points in seconds |
| 95 | + * @param baseValue - Base value for random count generation |
| 96 | + */ |
| 97 | +function generateData(points: number, intervalSeconds: number, baseValue = 100): ChartItem[] { |
| 98 | + const now = Math.floor(Date.now() / 1000); |
| 99 | +
|
| 100 | + return Array.from({ length: points }, (_, i) => ({ |
| 101 | + timestamp: now - (points - i) * intervalSeconds, |
| 102 | + count: Math.floor(Math.random() * baseValue) + Math.floor(baseValue / 2), |
| 103 | + })); |
| 104 | +} |
| 105 | +
|
| 106 | +/** |
| 107 | + * Empty handler for select option activation |
| 108 | + */ |
| 109 | +const onActivate = (): void => {}; |
| 110 | +
|
| 111 | +/** |
| 112 | + * Currently selected detalization option |
| 113 | + */ |
| 114 | +const detalizationSelected = ref<DefaultItem>({ |
| 115 | + title: 'days', |
| 116 | + onActivate, |
| 117 | +}); |
| 118 | +
|
| 119 | +/** |
| 120 | + * Available detalization options for the Select component |
| 121 | + */ |
| 122 | +const detalizationItems: ContextMenuItem[] = [ |
| 123 | + { title: 'days', |
| 124 | + onActivate }, |
| 125 | + { title: 'hours', |
| 126 | + onActivate }, |
| 127 | + { title: 'minutes', |
| 128 | + onActivate }, |
| 129 | +]; |
| 130 | +
|
| 131 | +/** |
| 132 | + * Current detalization value derived from selected option |
| 133 | + */ |
| 134 | +const currentDetalization = computed<DetalizationValue>(() => { |
| 135 | + return detalizationMap[detalizationSelected.value.title] || 'days'; |
| 136 | +}); |
| 137 | +
|
| 138 | +/** |
| 139 | + * Single line chart data - 30 days of events |
| 140 | + */ |
| 141 | +const singleLineData = computed<ChartLine>(() => ({ |
| 142 | + label: 'events', |
| 143 | + data: generateData(30, 86400, 2000), |
| 144 | + color: ChartLineColor.Red, |
| 145 | +})); |
| 146 | +
|
| 147 | +/** |
| 148 | + * Multiple lines chart data - accepted and filtered events |
| 149 | + */ |
| 150 | +const multipleLinesData = computed<ChartLine[]>(() => [ |
| 151 | + { |
| 152 | + label: 'accepted', |
| 153 | + data: generateData(30, 86400, 150), |
| 154 | + color: ChartLineColor.Red, |
| 155 | + }, |
| 156 | + { |
| 157 | + label: 'filtered', |
| 158 | + data: generateData(30, 86400, 50), |
| 159 | + color: ChartLineColor.LightGrey, |
| 160 | + }, |
| 161 | +]); |
| 162 | +</script> |
| 163 | + |
| 164 | +<style scoped> |
| 165 | +.chart-props { |
| 166 | + display: flex; |
| 167 | + flex-direction: column; |
| 168 | + gap: var(--spacing-l); |
| 169 | + margin-bottom: var(--spacing-xl); |
| 170 | +
|
| 171 | + &__item { |
| 172 | + padding: var(--spacing-m); |
| 173 | + background-color: var(--base--bg-secondary); |
| 174 | + border-radius: var(--radius-m); |
| 175 | + } |
| 176 | +
|
| 177 | + &__name { |
| 178 | + margin: 0 0 var(--spacing-s); |
| 179 | + } |
| 180 | +
|
| 181 | + &__description { |
| 182 | + margin: 0 0 var(--spacing-s); |
| 183 | + color: var(--base--text-secondary); |
| 184 | + } |
| 185 | +
|
| 186 | + &__code { |
| 187 | + margin: 0; |
| 188 | + padding: var(--spacing-s); |
| 189 | + background-color: var(--base--bg-primary); |
| 190 | + border-radius: var(--radius-s); |
| 191 | + overflow-x: auto; |
| 192 | + } |
| 193 | +
|
| 194 | + &__list { |
| 195 | + display: flex; |
| 196 | + flex-direction: column; |
| 197 | + gap: var(--spacing-s); |
| 198 | + margin: 0 0 var(--spacing-m); |
| 199 | + padding-left: var(--spacing-l); |
| 200 | + color: var(--base--text-secondary); |
| 201 | +
|
| 202 | + code { |
| 203 | + padding: var(--spacing-xxs) var(--spacing-ms); |
| 204 | + background-color: var(--base--bg-primary); |
| 205 | + border-radius: var(--radius-s); |
| 206 | + } |
| 207 | + } |
| 208 | +
|
| 209 | + &__control { |
| 210 | + display: flex; |
| 211 | + align-items: center; |
| 212 | + gap: var(--spacing-s); |
| 213 | + } |
| 214 | +
|
| 215 | + &__control-label { |
| 216 | + color: var(--base--text-secondary); |
| 217 | + } |
| 218 | +} |
| 219 | +
|
| 220 | +.chart-example { |
| 221 | + display: grid; |
| 222 | + grid-template-columns: 1fr; |
| 223 | + gap: var(--spacing-l); |
| 224 | + margin-bottom: var(--spacing-xl); |
| 225 | + position: relative; |
| 226 | +
|
| 227 | + &__showcase { |
| 228 | + width: 100%; |
| 229 | + background-color: var(--base--bg-secondary); |
| 230 | + border-radius: var(--radius-m); |
| 231 | + } |
| 232 | +
|
| 233 | +} |
| 234 | +</style> |
0 commit comments