-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: Add Bar Chart Setup and styles #191
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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,201 @@ | ||
import moment from "moment"; | ||
import { flushSync } from "react-dom"; | ||
import { createRoot } from "react-dom/client"; | ||
import { themeColors } from "src/globalStyles/themes"; | ||
|
||
type TApexChartWindow = { | ||
globals: { | ||
seriesNames: string[]; | ||
}; | ||
}; | ||
|
||
const renderToString = (node: JSX.Element): string => { | ||
const wrapper = document.createElement("div"); | ||
const root = createRoot(wrapper); | ||
flushSync(() => root.render(node)); | ||
return wrapper.innerHTML; | ||
}; | ||
|
||
const BarChartData = [ | ||
["01-Feb-2024 GMT+1", 14], | ||
["02-Feb-2024 GMT+1", 14], | ||
["03-Feb-2024 GMT+1", 20], | ||
["04-Feb-2024 GMT+1", 16], | ||
["05-Feb-2024 GMT+1", 11], | ||
["06-Feb-2024 GMT+1", 19], | ||
["07-Feb-2024 GMT+1", 14], | ||
["08-Feb-2024 GMT+1", 8], | ||
["09-Feb-2024 GMT+1", 12], | ||
["10-Feb-2024 GMT+1", 20], | ||
["11-Feb-2024 GMT+1", 14], | ||
["12-Feb-2024 GMT+1", 7], | ||
["13-Feb-2024 GMT+1", 6], | ||
["14-Feb-2024 GMT+1", 21], | ||
]; | ||
|
||
const BarChartOptions = { | ||
chart: { | ||
type: "area", | ||
stacked: true, | ||
zoom: { | ||
enabled: true, | ||
type: "x", | ||
autoScaleYaxis: false, | ||
zoomedArea: { | ||
fill: { | ||
color: themeColors.btnRingVariant400, | ||
opacity: 0.4, | ||
}, | ||
stroke: { | ||
color: themeColors.btnRingVariant200, | ||
opacity: 0.4, | ||
width: 1, | ||
}, | ||
}, | ||
}, | ||
toolbar: { | ||
show: false, | ||
}, | ||
redrawOnParentResize: true, | ||
}, | ||
colors: ["rgba(109, 210, 48, 0.5)", "rgba(109, 210, 48, 0.5)"], | ||
dataLabels: { | ||
enabled: false, | ||
}, | ||
stroke: { | ||
curve: "smooth", | ||
width: 1.5, | ||
}, | ||
fill: { | ||
type: "gradient", | ||
gradient: { | ||
type: "vertical", | ||
gradientToColors: [themeColors.success, themeColors.success], | ||
shadeIntensity: 1, | ||
opacityFrom: 0.85, | ||
opacityTo: 0.85, | ||
stops: [0, 100], | ||
}, | ||
}, | ||
legend: { | ||
show: false, | ||
}, | ||
xaxis: { | ||
type: "datetime", | ||
tooltip: { | ||
enabled: false, | ||
}, | ||
axisTicks: { | ||
show: false, | ||
}, | ||
tickPlacement: "between", | ||
tickAmount: Math.min(BarChartData.length, 8) - 1, | ||
labels: { | ||
datetimeUTC: false, | ||
formatter(_val: string, timestamp: number) { | ||
return moment(timestamp).format("DD-MM-YYYY"); | ||
}, | ||
style: { | ||
colors: themeColors.btnRingVariant500, | ||
fontSize: "10px", | ||
fontFamily: "Arial, sans-serif", | ||
fontWeight: 700, | ||
cssClass: "apexcharts-xaxis-label", | ||
}, | ||
}, | ||
}, | ||
yaxis: { | ||
show: false, | ||
tickAmount: 3, | ||
min: 0, | ||
max: (max: number) => { | ||
return max * 1.001; | ||
}, | ||
decimalsInFloat: false, | ||
}, | ||
grid: { | ||
borderColor: themeColors.btnRingVariant500, | ||
strokeDashArray: 5, | ||
xaxis: { | ||
lines: { | ||
show: true, | ||
}, | ||
}, | ||
yaxis: { | ||
lines: { | ||
show: false, | ||
}, | ||
}, | ||
column: { | ||
colors: themeColors.btnRingVariant500, | ||
opacity: 1, | ||
}, | ||
}, | ||
tooltip: { | ||
fillSeriesColor: themeColors.white, | ||
title: { | ||
formatter: (seriesName: string) => `$${seriesName}`, | ||
}, | ||
y: { | ||
formatter: undefined, | ||
title: { | ||
formatter: (val: string) => { | ||
return renderToString( | ||
<span className="text-white">${val}:</span> | ||
); | ||
}, | ||
}, | ||
}, | ||
custom: ({ | ||
series, | ||
seriesIndex, | ||
dataPointIndex, | ||
w, | ||
}: { | ||
series: number[][]; | ||
seriesIndex: number; | ||
dataPointIndex: number; | ||
w: TApexChartWindow; | ||
}) => { | ||
return renderToString( | ||
<div className="px-3 py-2 flex flex-col break-word bg-primaryVariant200 fontGroup-support text-primary"> | ||
<span className="fontGroup-supportBold [&_span]:fontGroup-support"> | ||
{w.globals.seriesNames[0]}: {} | ||
{new Intl.NumberFormat("en-US", { | ||
style: "currency", | ||
currency: "USD", | ||
maximumFractionDigits: 2, | ||
}).format(series[seriesIndex][dataPointIndex])} | ||
</span> | ||
<span className="pt-[1px]"> | ||
{moment(BarChartData[dataPointIndex][0]).format( | ||
"YYYY-MM-DD HH:mm" | ||
)} | ||
</span> | ||
</div> | ||
); | ||
}, | ||
}, | ||
responsive: [ | ||
{ | ||
breakpoint: 575, | ||
options: { | ||
chart: { | ||
height: 200, | ||
}, | ||
xaxis: { | ||
show: false, | ||
}, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
export const BarChartSampleSeries = [ | ||
{ | ||
name: "Price", | ||
data: BarChartData, | ||
}, | ||
]; | ||
|
||
export const BarChartSampleOptions = BarChartOptions; |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm certain we have this same util in
frontend
package.Any reason why we're not importing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cyclic importation.
frontend
imports components fromui-kit