Skip to content

Commit

Permalink
Refine UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Yu committed Dec 18, 2024
1 parent df056d7 commit 090b2b1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 59 deletions.
37 changes: 24 additions & 13 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,52 @@ import {
GridComponent,
TooltipComponent,
LegendComponent,
// DataZoomComponent,
} from 'echarts/components';
import { CanvasRenderer, } from 'echarts/renderers';
import './App.css'
import logo from './logo.png'
import data from './records'

echarts.use(
[TooltipComponent, GridComponent, LineChart, CanvasRenderer, LegendComponent]
[
TooltipComponent,
GridComponent,
LineChart,
CanvasRenderer,
LegendComponent,
// DataZoomComponent,
]
)

const numberWithCommas = (x) => {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
}

const valueRecords = Object.values(data)
const labelRecords = Object.keys(data)

const App = () => {
const total = useMemo(() => {
return numberWithCommas(
data[data.length - 1]?.values?.reduce((prev, curr) => {
valueRecords[valueRecords.length - 1]?.reduce((prev, curr) => {
return prev += curr
}, 0)
)
}, [])

const latestDate = useMemo(() => {
return dayjs(data[data.length - 1]?.date).format('MMM DD, YYYY')
return dayjs(labelRecords[labelRecords.length - 1]).format('MMM DD, YYYY')
}, [])

const latestValues = useMemo(() => {
return data[data.length - 1]?.values?.map(value => <span>{numberWithCommas(value)}</span>)
return valueRecords[valueRecords.length - 1]?.map((value, idx) => <span key={idx}>{numberWithCommas(value)}</span>)
}, [])

const chartOptions = useMemo(() => {
const valueCollector = idx =>
data.reduce((prev, curr) => {
prev.push(curr?.values?.[idx])
const valueCollector = idx =>
valueRecords.reduce((prev, curr) => {
prev.push(curr?.[idx])
return prev
}, [])

Expand Down Expand Up @@ -69,7 +80,7 @@ const App = () => {
{
type: 'category',
boundaryGap: false,
data: data.map(i => dayjs(i?.date).format('YYYY-MM-DD'))
data: labelRecords.map(i => dayjs(i).format('YYYY-MM-DD'))
}
],
yAxis: [
Expand All @@ -83,7 +94,7 @@ const App = () => {
type: 'line',
stack: 'Total',
itemStyle: {
// color: '#010101cf'
color: '#010101cf'
},
areaStyle: {},
emphasis: {
Expand All @@ -96,7 +107,7 @@ const App = () => {
type: 'line',
stack: 'Total',
itemStyle: {
// color: '#ff2543cf'
color: '#ff2543cf'
},
areaStyle: {},
emphasis: {
Expand All @@ -109,7 +120,7 @@ const App = () => {
type: 'line',
stack: 'Total',
itemStyle: {
// color: '#01a2d6cf'
color: '#01a2d6cf'
},
areaStyle: {},
emphasis: {
Expand All @@ -122,7 +133,7 @@ const App = () => {
type: 'line',
stack: 'Total',
itemStyle: {
// color: '#ff0000cf'
color: '#ff0000cf'
},
areaStyle: {},
emphasis: {
Expand All @@ -138,7 +149,7 @@ const App = () => {
<div className="app">
<img className='title' src={logo} alt="EfficLab logo" />
<div className='note'>We aim to be the biggest and the most professional Chinese channel of computer technology.</div>
<div className='note'>Please contact <a className='mail' href= "mailto: service@efficlab.com">service@efficlab.com</a> for any business cooperation.</div>
<div className='note'>Please contact <a className='mail' href="mailto: service@efficlab.com">service@efficlab.com</a> for any business cooperation.</div>
<div className='data'>
<div className='note'>Followers as of {latestDate}</div>
<div className='chart'>
Expand Down
61 changes: 15 additions & 46 deletions src/records.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,17 @@
const records = [
{
date: '2024-10-08',
values: [1820, 24134, 1885, 4644], // YT, B, RED, DOUYIN.
},
{
date: '2024-10-15',
values: [2718, 24472, 1909, 4680], // YT, B, RED, DOUYIN.
},
{
date: '2024-10-22',
values: [3182, 24791, 1926, 4710], // YT, B, RED, DOUYIN.
},
{
date: '2024-10-30',
values: [3514, 26159, 1931, 4733], // YT, B, RED, DOUYIN.
},
{
date: '2024-11-06',
values: [3680, 26712, 1928, 4746], // YT, B, RED, DOUYIN.
},
{
date: '2024-11-13',
values: [3793, 27339, 1929, 4755], // YT, B, RED, DOUYIN.
},
{
date: '2024-11-20',
values: [3862, 28032, 1932, 4757], // YT, B, RED, DOUYIN.
},
{
date: '2024-11-27',
values: [3899, 28685, 1932, 4788], // YT, B, RED, DOUYIN.
},
{
date: '2024-12-04',
values: [3952, 29047, 1933, 4790], // YT, B, RED, DOUYIN.
},
{
date: '2024-12-10',
values: [3971, 29715, 1936, 4783], // YT, B, RED, DOUYIN.
},
{
date: '2024-12-17',
values: [4184, 30344, 1938, 4789], // YT, B, RED, DOUYIN.
},
]
const records = {
// YT, B, RED, DOUYIN.
'2024-10-08': [1820, 24134, 1885, 4644],
'2024-10-15': [2718, 24472, 1909, 4680],
'2024-10-22': [3182, 24791, 1926, 4710],
'2024-10-30': [3514, 26159, 1931, 4733],
'2024-11-06': [3680, 26712, 1928, 4746],
'2024-11-13': [3793, 27339, 1929, 4755],
'2024-11-20': [3862, 28032, 1932, 4757],
'2024-11-27': [3899, 28685, 1932, 4788],
'2024-12-04': [3952, 29047, 1933, 4790],
'2024-12-10': [3971, 29715, 1936, 4783],
'2024-12-17': [4184, 30344, 1938, 4789],
// [TO GO WITH MORE RECORDS]
}

export default records

0 comments on commit 090b2b1

Please sign in to comment.