generated from DenysShchypt/Template-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from DenysShchypt/feat/area_chart
Feat/area chart
- Loading branch information
Showing
11 changed files
with
688 additions
and
352 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
@@ -1,11 +1,45 @@ | ||
export interface IAsset { | ||
asset_id: string; | ||
name: string; | ||
price_usd: number; | ||
volume_1hrs_usd: number; | ||
Data: { | ||
ID: number; | ||
LOGO_URL: string; | ||
NAME: string; | ||
ASSET_DESCRIPTION: string; | ||
PRICE_USD: number; | ||
SEO_TITLE: string; | ||
TOTAL_MKT_CAP_USD: number; | ||
CIRCULATING_MKT_CAP_USD: number; | ||
SEO_DESCRIPTION: string; | ||
PRICE_USD_LAST_UPDATE_TS: number; | ||
}; | ||
} | ||
|
||
export interface IAssetPriceData { | ||
close: number; | ||
high: number; | ||
low: number; | ||
open: number; | ||
time: number; | ||
} | ||
|
||
export interface IAssetPrice { | ||
Aggregated: boolean; | ||
TimeFrom: number; | ||
TimeTo: number; | ||
Data: IAssetPriceData[]; | ||
} | ||
|
||
export interface IAssetsState { | ||
assets: IAsset[]; | ||
favoriteAssets: IAsset[]; | ||
assets: IAssetFavoriteResponses[]; | ||
favoriteAssets: IAssetFavoriteResponses[]; | ||
historyPrice: IAssetPriceResponses[]; | ||
} | ||
|
||
export interface IAssetFavoriteResponses { | ||
name: string; | ||
data: IAsset; | ||
} | ||
|
||
export interface IAssetPriceResponses { | ||
name: string; | ||
data: IAssetPrice; | ||
} |
This file contains 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 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 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,91 @@ | ||
import { FC } from 'react'; | ||
import { | ||
Chart as ChartJS, | ||
CategoryScale, | ||
LinearScale, | ||
PointElement, | ||
LineElement, | ||
Title, | ||
Tooltip, | ||
Filler, | ||
Legend, | ||
} from 'chart.js'; | ||
import type { ChartData, ChartOptions, ScriptableContext } from 'chart.js'; | ||
import { Line } from 'react-chartjs-2'; | ||
import { IAssetPriceData } from '../../../common/types/assets'; | ||
|
||
ChartJS.register( | ||
CategoryScale, | ||
LinearScale, | ||
PointElement, | ||
LineElement, | ||
Title, | ||
Tooltip, | ||
Filler, | ||
Legend, | ||
); | ||
interface IAreaChartProps { | ||
data: IAssetPriceData[]; | ||
} | ||
|
||
const options: ChartOptions<'line'> = { | ||
responsive: true, | ||
scales: { | ||
x: { | ||
display: false, | ||
grid: { | ||
display: false, | ||
}, | ||
}, | ||
y: { | ||
display: false, | ||
grid: { | ||
display: false, | ||
}, | ||
}, | ||
}, | ||
plugins: { | ||
legend: { | ||
display: false, | ||
}, | ||
title: { | ||
display: true, | ||
text: new Date().toLocaleDateString('en-us', { | ||
weekday: 'long', | ||
year: 'numeric', | ||
month: 'short', | ||
day: 'numeric', | ||
}), | ||
}, | ||
}, | ||
}; | ||
|
||
const AreaChart: FC<IAreaChartProps> = ({ data }) => { | ||
const values: ChartData<'line'> = { | ||
labels: data.map(el => { | ||
const timeDay = Number(`${el.time}000`); | ||
return new Date(timeDay).toLocaleDateString('en-us', { | ||
year: 'numeric', | ||
month: 'short', | ||
day: 'numeric', | ||
}); | ||
}), | ||
datasets: [ | ||
{ | ||
label: 'Price', | ||
data: data.map(el => el.close), | ||
fill: 'start', | ||
backgroundColor: (context: ScriptableContext<'line'>) => { | ||
const ctx = context.chart.ctx; | ||
const gradient = ctx.createLinearGradient(0, 50, 0, 180); | ||
gradient.addColorStop(0, '#C1EF00'); | ||
gradient.addColorStop(1, '#232323'); | ||
return gradient; | ||
}, | ||
}, | ||
], | ||
}; | ||
return <Line options={options} data={values} width={300} height={125} />; | ||
}; | ||
|
||
export default AreaChart; |
This file contains 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 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 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
Oops, something went wrong.