-
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 1 commit
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,97 @@ | ||
| <template> | ||
| <PageHeader> | ||
| Chart | ||
| <template #description> | ||
| A component for displaying line charts with smooth curves and interactive tooltips. | ||
| </template> | ||
| </PageHeader> | ||
|
|
||
| <Heading :level="3"> | ||
| Single Line Chart | ||
| </Heading> | ||
|
|
||
| <div class="charts"> | ||
| <div class="charts__showcase"> | ||
| <Chart | ||
| :lines="[singleLine]" | ||
| detalization="days" | ||
| /> | ||
| </div> | ||
| </div> | ||
|
|
||
| <Heading :level="3"> | ||
| Multiple Lines Chart | ||
| </Heading> | ||
|
|
||
| <div class="charts"> | ||
| <div class="charts__showcase"> | ||
| <Chart | ||
| :lines="multipleLines" | ||
| detalization="days" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import PageHeader from '../../components/PageHeader.vue'; | ||
| import { Chart, ChartLineColor, Heading } from '../../../src/vue'; | ||
| import type { ChartItem, ChartLine } from '../../../src/vue/components/chart'; | ||
|
|
||
| /** | ||
| * Generate sample data for a given number of days | ||
| * | ||
| * @param days Number of days to generate data for. | ||
| * @param baseValue Base value used to scale the random counts (default: 100). | ||
| */ | ||
| function generateData(days: number, baseValue: number = 100): ChartItem[] { | ||
| const now = Math.floor(Date.now() / 1000); | ||
| const dayInSeconds = 86400; | ||
|
|
||
| return Array.from({ length: days }, (_, i) => ({ | ||
| timestamp: now - (days - i) * dayInSeconds, | ||
| count: Math.floor(Math.random() * baseValue) + Math.floor(baseValue / 2), | ||
| })); | ||
| } | ||
|
|
||
| /** | ||
| * Single line chart data | ||
| */ | ||
| const singleLine: ChartLine = { | ||
| label: 'events', | ||
| data: generateData(30, 200), | ||
| color: ChartLineColor.Red, | ||
| }; | ||
|
|
||
| /** | ||
| * Multiple lines chart data | ||
| */ | ||
| const multipleLines: ChartLine[] = [ | ||
| { | ||
| label: 'accepted', | ||
| data: generateData(30, 150), | ||
| color: ChartLineColor.Red, | ||
| }, | ||
| { | ||
| label: 'rate-limited', | ||
| data: generateData(30, 50), | ||
| color: ChartLineColor.LightGrey, | ||
| }, | ||
| ]; | ||
| </script> | ||
|
|
||
| <style scoped> | ||
| .charts { | ||
| display: grid; | ||
| grid-template-columns: 1fr; | ||
| gap: var(--spacing-l); | ||
| margin-bottom: var(--spacing-xl); | ||
| &__showcase { | ||
| width: 100%; | ||
| height: 200px; | ||
| background-color: var(--base--bg-secondary); | ||
| border-radius: var(--radius-m); | ||
| padding: var(--spacing-m); | ||
neSpecc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| </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
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,24 @@ | ||
| import { ChartLineColor } from './Chart.types'; | ||
| import type { ChartLineColors } from './Chart.types'; | ||
|
|
||
| /** | ||
| * Colors set for several chart lines | ||
| */ | ||
| export const chartColors: 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', | ||
| }, | ||
| ]; |
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,80 @@ | ||
| /** | ||
| * Name of the color for the chart line stroke and fill. | ||
| */ | ||
| export enum ChartLineColor { | ||
| /** | ||
| * Accent color for primary line | ||
| */ | ||
| Red = 'red', | ||
|
|
||
| /** | ||
| * Accent color for secondary line | ||
| */ | ||
| LightGrey = 'light-grey' | ||
| } | ||
|
|
||
| /** | ||
| * Chart element in common case | ||
| */ | ||
| export interface ChartItem { | ||
| /** | ||
| * Day midnight | ||
neSpecc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| timestamp: number; | ||
|
|
||
| /** | ||
| * How many events occurred in that day | ||
neSpecc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
neSpecc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| count: number; | ||
| } | ||
|
|
||
| /** | ||
| * Chart line with label and data points | ||
| */ | ||
| export interface ChartLine { | ||
| /** | ||
| * Series label (e.g., "accepted", "rate-limited") | ||
| */ | ||
| label: string; | ||
|
|
||
| /** | ||
| * Data points for the series | ||
| */ | ||
| data: ChartItem[]; | ||
|
|
||
| /** | ||
| * Name of the color for the line stroke and fill. | ||
| */ | ||
| color?: ChartLineColor; | ||
| } | ||
|
|
||
| /** | ||
| * A particular color params | ||
| */ | ||
| export interface ChartLineColors { | ||
| /** | ||
| * Name of the color | ||
| */ | ||
| name: ChartLineColor; | ||
| /** | ||
| * Starting color for stroke gradient (top) | ||
| */ | ||
| strokeStart: string; | ||
| /** | ||
| * Ending color for stroke gradient (bottom) | ||
| */ | ||
| strokeEnd: string; | ||
| /** | ||
| * Starting color for fill gradient (top, with opacity) | ||
| */ | ||
| fillStart: string; | ||
| /** | ||
| * Ending color for fill gradient (bottom, usually transparent) | ||
| */ | ||
| fillEnd: string; | ||
|
|
||
| /** | ||
| * Pointer + legend color | ||
| */ | ||
| pointerColor: string; | ||
| } | ||
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.