Skip to content

Commit

Permalink
Update sample data for echarts
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTTY committed Dec 23, 2023
1 parent 1b429db commit 249e1b5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 128 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta, StoryObj } from '@storybook/react';
import { LineGraph } from './LineGraph';
import { echartOptions } from './SampleLineData';
import { SampleLineData } from './SampleLineData';

const meta: Meta<typeof LineGraph> = {
component: LineGraph,
Expand All @@ -13,7 +13,7 @@ type Story = StoryObj<typeof LineGraph>;
export const Default: Story = {
render: () => (
<div style={{ height: '95vh' }}>
<LineGraph option={echartOptions} />
<LineGraph option={SampleLineData} />
</div>
),
};
Expand Down
159 changes: 35 additions & 124 deletions src/client/src/components/graphs/line-graph/SampleLineData.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
import { EChartProps } from '@components/graphs/line-graph/EChartProps';

export const echartOptions: EChartProps["option"] = {
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [
{
data: [150, 230, 224, 218, 135, 147, 260],
type: 'line'
},
],
};

const endDate = new Date();
const netWorth = [3360, 4241, 5816, 7115, 7567, 8374, 9564, 11835, 11532, 12315, 13147, 13421];

Expand All @@ -36,113 +20,40 @@ const portfolioValue = [
getPortfolioValue(11),
];

export const SampleLineData = [
{
id: 'Net Worth',
color: 'hsl(289, 70%, 50%)',
data: [
{
x: new Date(endDate.getTime() - 12 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: netWorth[0],
},
{
x: new Date(endDate.getTime() - 11 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: netWorth[1],
},
{
x: new Date(endDate.getTime() - 10 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: netWorth[2],
},
{
x: new Date(endDate.getTime() - 9 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: netWorth[3],
},
{
x: new Date(endDate.getTime() - 8 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: netWorth[4],
},
{
x: new Date(endDate.getTime() - 7 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: netWorth[5],
},
{
x: new Date(endDate.getTime() - 6 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: netWorth[6],
},
{
x: new Date(endDate.getTime() - 5 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: netWorth[7],
},
{
x: new Date(endDate.getTime() - 4 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: netWorth[8],
},
{
x: new Date(endDate.getTime() - 3 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: netWorth[9],
},
{
x: new Date(endDate.getTime() - 2 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: netWorth[10],
},
{
x: new Date(endDate.getTime() - 1 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: netWorth[11],
},
],
const dates = [
new Date(endDate.getTime() - 12 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
new Date(endDate.getTime() - 11 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
new Date(endDate.getTime() - 10 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
new Date(endDate.getTime() - 9 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
new Date(endDate.getTime() - 8 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
new Date(endDate.getTime() - 7 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
new Date(endDate.getTime() - 6 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
new Date(endDate.getTime() - 5 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
new Date(endDate.getTime() - 4 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
new Date(endDate.getTime() - 3 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
new Date(endDate.getTime() - 2 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
new Date(endDate.getTime() - 1 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
];

export const SampleLineData: EChartProps['option'] = {
tooltip: {
trigger: 'axis',
},
{
id: 'Stocks',
color: 'hsl(306, 70%, 50%)',
data: [
{
x: new Date(endDate.getTime() - 12 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: portfolioValue[0],
},
{
x: new Date(endDate.getTime() - 11 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: portfolioValue[1],
},
{
x: new Date(endDate.getTime() - 10 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: portfolioValue[2],
},
{
x: new Date(endDate.getTime() - 9 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: portfolioValue[3],
},
{
x: new Date(endDate.getTime() - 8 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: portfolioValue[4],
},
{
x: new Date(endDate.getTime() - 7 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: portfolioValue[5],
},
{
x: new Date(endDate.getTime() - 6 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: portfolioValue[6],
},
{
x: new Date(endDate.getTime() - 5 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: portfolioValue[7],
},
{
x: new Date(endDate.getTime() - 4 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: portfolioValue[8],
},
{
x: new Date(endDate.getTime() - 3 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: portfolioValue[9],
},
{
x: new Date(endDate.getTime() - 2 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: portfolioValue[10],
},
{
x: new Date(endDate.getTime() - 1 * 24 * 60 * 60 * 1000).toLocaleDateString('de'),
y: portfolioValue[11],
},
],
xAxis: {
type: 'category',
data: dates,
},
];
yAxis: {
type: 'value',
},
series: [
{
data: [3360, 4241, 5816, 7115, 7567, 8374, 9564, 11835, 11532, 12315, 13147, 13421],
type: 'line',
},
{
data: portfolioValue,
type: 'line',
},
],
};
4 changes: 2 additions & 2 deletions src/client/src/routes/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Box, Space } from '@mantine/core';
import { StatCardProps } from '@components/stat-card/StatCardProps';
import { LineGraph } from '@components/graphs/line-graph/LineGraph';
import { StatsGrid } from '@components/stat-grid/StatsGrid';
import { echartOptions } from '@/components/graphs/line-graph/SampleLineData';
import { SampleLineData } from '@/components/graphs/line-graph/SampleLineData';

export const Dashboard = () => {
const gridprops: StatCardProps[] = [
Expand All @@ -19,7 +19,7 @@ export const Dashboard = () => {

return (
<Box p="md" style={{ height: '100%' }}>
<LineGraph option={echartOptions} />
<LineGraph option={SampleLineData} />
<Space h="md" />
<StatsGrid data={gridprops} />
</Box>
Expand Down

0 comments on commit 249e1b5

Please sign in to comment.