-
Notifications
You must be signed in to change notification settings - Fork 6
feat: add componets chart and animatedCounter #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b1d9f61
feat: add componets chart and animatedCounter
quangtuanitmo18 d0f116b
feat: describe detalization param (component chart) and illustrate ho…
quangtuanitmo18 6496b69
fix: address review feedback
quangtuanitmo18 5cd75dd
fix: address reviews feedback
quangtuanitmo18 ba6bd6d
minor colors adjustments
neSpecc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,234 @@ | ||
| <template> | ||
| <PageHeader> | ||
| Chart | ||
| <template #description> | ||
| A component for displaying line charts with smooth curves and interactive tooltips. | ||
| </template> | ||
| </PageHeader> | ||
|
|
||
| <div class="chart-props"> | ||
| <div class="chart-props__item"> | ||
| <h4 class="chart-props__name"> | ||
| lines | ||
| </h4> | ||
| <p class="chart-props__description"> | ||
| An array of line objects to display on the chart. | ||
| </p> | ||
| </div> | ||
|
|
||
| <div class="chart-props__item"> | ||
| <h4 class="chart-props__name"> | ||
| detalization | ||
| </h4> | ||
| <p class="chart-props__description"> | ||
| Controls how timestamps are formatted on the X-axis legend and tooltip. | ||
| Does not affect data aggregation — only the display format. | ||
| </p> | ||
| <ul class="chart-props__list"> | ||
| <li><code>'days'</code> — shows day and month (e.g., "19 dec")</li> | ||
| <li><code>'hours'</code> — shows day, month, and time (e.g., "19 dec, 14:00")</li> | ||
| <li><code>'minutes'</code> — shows day, month, and time (e.g., "19 dec, 14:30")</li> | ||
| </ul> | ||
| <div class="chart-props__control"> | ||
| <span class="chart-props__control-label">Try it:</span> | ||
| <Select | ||
| v-model="detalizationSelected" | ||
| :align="{ vertically: 'below', horizontally: 'left' }" | ||
| :is-disabled="false" | ||
| :items="detalizationItems" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <Heading :level="3"> | ||
| Single Line | ||
| </Heading> | ||
| <div class="chart-example"> | ||
| <div class="chart-example__showcase"> | ||
| <Chart | ||
| :lines="[singleLineData]" | ||
| :detalization="currentDetalization" | ||
| /> | ||
| </div> | ||
| </div> | ||
|
|
||
| <Heading :level="3"> | ||
| Multiple Lines | ||
| </Heading> | ||
| <div class="chart-example"> | ||
| <div class="chart-example__showcase"> | ||
| <Chart | ||
| :lines="multipleLinesData" | ||
| :detalization="currentDetalization" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { ref, computed } from 'vue'; | ||
| import PageHeader from '../../components/PageHeader.vue'; | ||
| import { Chart, ChartLineColor, Heading, Select } from '../../../src/vue'; | ||
| import type { ChartItem, ChartLine } from '../../../src/vue/components/chart'; | ||
| import type { ContextMenuItem, DefaultItem } from '../../../src/vue/components/context-menu/ContextMenu.types'; | ||
|
|
||
| /** | ||
| * Detalization types for chart timestamp formatting | ||
| */ | ||
| type DetalizationValue = 'minutes' | 'hours' | 'days'; | ||
|
|
||
| /** | ||
| * Mapping from Select title to detalization value | ||
| */ | ||
| const detalizationMap: Record<string, DetalizationValue> = { | ||
| days: 'days', | ||
| hours: 'hours', | ||
| minutes: 'minutes', | ||
| }; | ||
|
|
||
| /** | ||
| * Generate sample chart data | ||
| * | ||
| * @param points - Number of data points to generate | ||
| * @param intervalSeconds - Time interval between points in seconds | ||
| * @param baseValue - Base value for random count generation | ||
| */ | ||
| function generateData(points: number, intervalSeconds: number, baseValue = 100): ChartItem[] { | ||
| const now = Math.floor(Date.now() / 1000); | ||
|
|
||
| return Array.from({ length: points }, (_, i) => ({ | ||
| timestamp: now - (points - i) * intervalSeconds, | ||
| count: Math.floor(Math.random() * baseValue) + Math.floor(baseValue / 2), | ||
| })); | ||
| } | ||
|
|
||
| /** | ||
| * Empty handler for select option activation | ||
| */ | ||
| const onActivate = (): void => {}; | ||
|
|
||
| /** | ||
| * Currently selected detalization option | ||
| */ | ||
| const detalizationSelected = ref<DefaultItem>({ | ||
| title: 'days', | ||
| onActivate, | ||
| }); | ||
|
|
||
| /** | ||
| * Available detalization options for the Select component | ||
| */ | ||
| const detalizationItems: ContextMenuItem[] = [ | ||
| { title: 'days', | ||
| onActivate }, | ||
| { title: 'hours', | ||
| onActivate }, | ||
| { title: 'minutes', | ||
| onActivate }, | ||
| ]; | ||
|
|
||
| /** | ||
| * Current detalization value derived from selected option | ||
| */ | ||
| const currentDetalization = computed<DetalizationValue>(() => { | ||
| return detalizationMap[detalizationSelected.value.title] || 'days'; | ||
| }); | ||
|
|
||
| /** | ||
| * Single line chart data - 30 days of events | ||
| */ | ||
| const singleLineData = computed<ChartLine>(() => ({ | ||
| label: 'events', | ||
| data: generateData(30, 86400, 2000), | ||
| color: ChartLineColor.Red, | ||
| })); | ||
|
|
||
| /** | ||
| * Multiple lines chart data - accepted and filtered events | ||
| */ | ||
| const multipleLinesData = computed<ChartLine[]>(() => [ | ||
| { | ||
| label: 'accepted', | ||
| data: generateData(30, 86400, 150), | ||
| color: ChartLineColor.Red, | ||
| }, | ||
| { | ||
| label: 'filtered', | ||
| data: generateData(30, 86400, 50), | ||
| color: ChartLineColor.LightGrey, | ||
| }, | ||
| ]); | ||
| </script> | ||
|
|
||
| <style scoped> | ||
| .chart-props { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: var(--spacing-l); | ||
| margin-bottom: var(--spacing-xl); | ||
|
|
||
| &__item { | ||
| padding: var(--spacing-m); | ||
| background-color: var(--base--bg-secondary); | ||
| border-radius: var(--radius-m); | ||
| } | ||
|
|
||
| &__name { | ||
| margin: 0 0 var(--spacing-s); | ||
| } | ||
|
|
||
| &__description { | ||
| margin: 0 0 var(--spacing-s); | ||
| color: var(--base--text-secondary); | ||
| } | ||
|
|
||
| &__code { | ||
| margin: 0; | ||
| padding: var(--spacing-s); | ||
| background-color: var(--base--bg-primary); | ||
| border-radius: var(--radius-s); | ||
| overflow-x: auto; | ||
| } | ||
|
|
||
| &__list { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: var(--spacing-s); | ||
| margin: 0 0 var(--spacing-m); | ||
| padding-left: var(--spacing-l); | ||
| color: var(--base--text-secondary); | ||
|
|
||
| code { | ||
| padding: var(--spacing-xxs) var(--spacing-ms); | ||
| background-color: var(--base--bg-primary); | ||
| border-radius: var(--radius-s); | ||
| } | ||
| } | ||
|
|
||
| &__control { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: var(--spacing-s); | ||
| } | ||
|
|
||
| &__control-label { | ||
| color: var(--base--text-secondary); | ||
| } | ||
| } | ||
|
|
||
| .chart-example { | ||
| display: grid; | ||
| grid-template-columns: 1fr; | ||
| gap: var(--spacing-l); | ||
| margin-bottom: var(--spacing-xl); | ||
| position: relative; | ||
|
|
||
| &__showcase { | ||
| width: 100%; | ||
| background-color: var(--base--bg-secondary); | ||
| border-radius: var(--radius-m); | ||
| } | ||
|
|
||
| } | ||
| </style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| <template> | ||
| <PageHeader> | ||
| Counter | ||
| <template #description> | ||
| A component that animates value changes with a smooth slide transition effect. | ||
| </template> | ||
| </PageHeader> | ||
|
|
||
| <div class="counters"> | ||
| <div class="counters__value"> | ||
| <Counter :value="animatedValue" /> | ||
| </div> | ||
| <div class="counters__btn"> | ||
| <Button | ||
|
|
||
| @click="animatedValue += 100" | ||
| > | ||
| +100 | ||
| </Button> | ||
| <Button | ||
|
|
||
| @click="animatedValue -= 100" | ||
| > | ||
| -100 | ||
| </Button> | ||
| <Button | ||
| secondary | ||
| @click="animatedValue = 0" | ||
| > | ||
| Reset | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { ref } from 'vue'; | ||
| import PageHeader from '../../components/PageHeader.vue'; | ||
| import { Counter, Button } from '../../../src/vue'; | ||
|
|
||
| const animatedValue = ref(100); | ||
|
|
||
| </script> | ||
|
|
||
| <style scoped> | ||
| .counters { | ||
| display: grid; | ||
| grid-template-columns: repeat(2, max-content); | ||
| gap: var(--spacing-xxl); | ||
| align-items: center; | ||
| &__value{ | ||
| width: 3rem; | ||
| } | ||
| &__btn{ | ||
| display: flex; | ||
| gap: var(--spacing-m); | ||
| align-items: center; | ||
| } | ||
| } | ||
|
|
||
| </style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
neSpecc marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { ChartLineColor } from './Chart.types'; | ||
| import type { ChartLineColors } from './Chart.types'; | ||
|
|
||
| /** | ||
| * Colors for dark color scheme. | ||
| */ | ||
| export const chartColorsDark: ChartLineColors[] = [ | ||
| { | ||
| name: ChartLineColor.LightGrey, | ||
| strokeStart: 'rgba(75, 90, 121, 0.33)', | ||
| strokeEnd: 'rgba(71, 72, 85, 0.16)', | ||
| fillStart: 'rgba(63, 136, 255, 0.01)', | ||
| fillEnd: 'rgba(66, 78, 93, 0.05)', | ||
| pointerColor: '#717289', | ||
| }, | ||
| { | ||
| name: ChartLineColor.Red, | ||
| strokeStart: '#FF2E51', | ||
| strokeEnd: '#424565', | ||
| fillStart: 'rgba(255, 46, 81, 0.3)', | ||
| fillEnd: 'rgba(66, 69, 101, 0)', | ||
| pointerColor: '#FF2E51', | ||
| }, | ||
| ]; | ||
|
|
||
| /** | ||
| * Colors for light color scheme. | ||
| */ | ||
| export const chartColorsLight: ChartLineColors[] = [ | ||
| { | ||
| name: ChartLineColor.LightGrey, | ||
| strokeStart: 'rgba(75, 90, 121, 0.22)', | ||
| strokeEnd: 'rgba(71, 72, 85, 0.08)', | ||
| fillStart: 'rgba(225, 236, 255, 0.12)', | ||
| fillEnd: 'rgba(66, 78, 93, 0.02)', | ||
| pointerColor: '#717289', | ||
| }, | ||
| { | ||
| name: ChartLineColor.Red, | ||
| strokeStart: '#FF4A68', | ||
| strokeEnd: 'rgba(119, 136, 198, 0.4)', | ||
| fillStart: 'rgba(255, 94, 121, 0.46)', | ||
| fillEnd: 'rgba(255, 190, 198, 0)', | ||
| pointerColor: '#FF4A68', | ||
| }, | ||
| ]; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.