Skip to content
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

Echarts implementation #536

Merged
merged 29 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fda7717
feat: implement the payments graph with echarts
AmbossKeegan Jun 5, 2023
dffe6d1
fix: improve echarts import in next.config.js
AmbossKeegan Jun 6, 2023
8cf18bb
fix: formatting
AmbossKeegan Jun 6, 2023
1203e52
fix: no-implicity-any
AmbossKeegan Jun 6, 2023
be962ca
fix: tidy up inconsistencies in echarts implementation
AmbossKeegan Jun 11, 2023
655e747
Merge branch 'master' into echarts-implementation
AmbossKeegan Jun 11, 2023
79b4849
feat: improve a number of aspects about echarts implementation as per…
AmbossKeegan Jun 13, 2023
1b09e94
Merge branch 'master' into echarts-implementation
AmbossKeegan Jun 13, 2023
7f17736
feat: move forwards chart to echarts
AmbossKeegan Jun 20, 2023
6b8aff3
chore: move invoice, payment, forward graphs to new BarChart. move li…
AmbossKeegan Jun 21, 2023
6e7f928
chore: remove V2 from new graphs
AmbossKeegan Jun 21, 2023
974e1fd
feat: implement Sankey chart for forwards
AmbossKeegan Jun 21, 2023
9f52d36
chore: change justification on Sankey Graph
AmbossKeegan Jun 21, 2023
b7c64d2
feat: add Sankey graph
AmbossKeegan Jun 27, 2023
eac9753
chore: remove chord graph
AmbossKeegan Jun 27, 2023
9becda4
chore: remove chord graph and update package.json
AmbossKeegan Jun 27, 2023
b1cedd4
chore: remove stray console log
AmbossKeegan Jun 27, 2023
fbd31e2
chore: format numbers on y axis to be integer values
AmbossKeegan Jun 27, 2023
fa85ab7
Merge branch 'master' into echarts-implementation
apotdevin Jul 5, 2023
b70b040
feat: tidy echarts implementation
AmbossKeegan Jul 6, 2023
4c4acf5
feat: revamp tooltip
AmbossKeegan Jul 6, 2023
c9f1a5e
Merge branch 'master' into echarts-implementation
AmbossKeegan Jul 14, 2023
a740b75
Merge branch 'master' into echarts-implementation
apotdevin Jul 24, 2023
f08b28b
Merge branch 'master' into echarts-implementation
apotdevin Jul 25, 2023
78e5e13
feat: bound the size of the sankey chart
AmbossKeegan Jul 30, 2023
e362890
feat: provide function that creates a mock sankey dataset of arbitrar…
AmbossKeegan Jul 30, 2023
2859f29
fix: missing memo dependencies and css
secondl1ght Aug 1, 2023
7fd1dba
Merge branch 'master' into echarts-implementation
apotdevin Aug 18, 2023
ff95759
chore: small changes
apotdevin Aug 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"d3-time-format": "^4.1.0",
"date-fns": "^2.30.0",
"dotenv": "^16.0.3",
"echarts": "^5.4.2",
"echarts-for-react": "^3.0.2",
"ecpair": "^2.0.1",
"graphql": "^16.6.0",
"jest-fetch-mock": "^3.0.3",
Expand Down
1 change: 1 addition & 0 deletions src/client/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
reactStrictMode: true,
poweredByHeader: false,
basePath: process.env.BASE_PATH || '',
transpilePackages: ['echarts', 'echarts-for-react', 'zrender'],
AmbossKeegan marked this conversation as resolved.
Show resolved Hide resolved
compiler: {
styledComponents: true,
},
Expand Down
132 changes: 132 additions & 0 deletions src/client/src/components/chart/BarChartV2.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import { useContext, useMemo } from 'react';
import { BarChart } from 'echarts/charts';
import {
GraphicComponent,
GridComponent,
LegendComponent,
TitleComponent,
ToolboxComponent,
TooltipComponent,
} from 'echarts/components';
import * as echarts from 'echarts/core';
import { CanvasRenderer } from 'echarts/renderers';
import ReactEChartsCore from 'echarts-for-react/lib/core';
import { ThemeContext } from 'styled-components';
import numeral from 'numeral';
import { timeFormat, timeParse } from 'd3-time-format';

echarts.use([
BarChart,
CanvasRenderer,
GridComponent,
TooltipComponent,
GraphicComponent,
TitleComponent,
LegendComponent,
ToolboxComponent,
]);

interface BarChartProps {
colorRange: string[];
data: any;
yAxisLabel: string;
title: string;
}

export const BarChartV2 = ({
data,
colorRange,
yAxisLabel,
title,
}: BarChartProps) => {
const themeContext = useContext(ThemeContext);

const seriesData = useMemo(() => {
if (data.length === 0) return { dates: [], series: [] };

const series = [
{
name: title,
type: 'bar',
emphasis: { focus: 'series' },
data: data.map((d: any) => d.Invoices),
AmbossKeegan marked this conversation as resolved.
Show resolved Hide resolved
},
];

const dates = data.map((d: any) => d.date);

return { dates, series };
}, [data, title]);

const option = useMemo(() => {
const fontColor = themeContext.mode === 'light' ? 'black' : 'white';

return {
color: colorRange,
legend: {
textStyle: { color: fontColor },
orient: 'horizontal',
top: 0,
},
title: {
text: title,
textStyle: { color: fontColor },
},
grid: {
containLabel: true,
top: '50px',
left: '100px',
bottom: '0px',
right: '100px',
},
tooltip: {
trigger: 'axis',
axisPointer: {
animation: false,
},
},
xAxis: {
AmbossKeegan marked this conversation as resolved.
Show resolved Hide resolved
name: 'Dates',
nameLocation: 'center',
nameGap: 32,
type: 'category',
axisLine: { show: true, lineStyle: { color: fontColor } },
data: seriesData.dates,
axisLabel: {
formatter: function (value: string) {
const parseDate = timeParse('%Y-%m-%dT%H:%M:%S.%L%Z');
const formatDate = timeFormat('%b %d');
return formatDate(parseDate(value) as Date);
},
},
},
yAxis: {
name: yAxisLabel,
nameLocation: 'center',
nameGap: 48,
type: 'value',
axisLine: { show: true, lineStyle: { color: fontColor } },
splitLine: { show: false },
axisLabel: {
formatter: function (value: number) {
return numeral(value).format('0.0a');
},
},
},
series: seriesData.series,
};
}, [yAxisLabel, colorRange, themeContext, seriesData, title]);

return (
<ReactEChartsCore
echarts={echarts}
option={option}
notMerge={true}
lazyUpdate={true}
showLoading={false}
style={{
height: '100%',
}}
/>
);
};
7 changes: 4 additions & 3 deletions src/client/src/views/home/reports/flow/TransactionGraph.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { FC, useMemo } from 'react';
import { BarChart } from '../../../../components/chart/BarChart';
import { LoadingCard } from '../../../../components/loading/LoadingCard';
import { chartColors } from '../../../../styles/Themes';
import { getByTime } from '../../../../views/dashboard/widgets/helpers';
import styled from 'styled-components';
import { useGetInvoicesQuery } from '../../../../graphql/queries/__generated__/getInvoices.generated';
import { differenceInDays } from 'date-fns';
import { useGetPaymentsQuery } from '../../../../graphql/queries/__generated__/getPayments.generated';
import { BarChartV2 } from '../../../../components/chart/BarChartV2';

const S = {
row: styled.div`
Expand Down Expand Up @@ -116,15 +116,16 @@ export const TransactionsGraph: FC<TransactionsGraphProps> = ({
return (
<S.wrapper>
<S.content>
<BarChart
priceLabel={type !== 'amount'}
<BarChartV2
data={finalArray.map(f => {
return {
[showPay ? 'Payments' : 'Invoices']: f?.[type] || 0,
date: f.date,
};
})}
colorRange={finalColor}
yAxisLabel={showPay ? '# of Payments' : '# of Invoices'}
title={showPay ? `Payments ${type}` : `Invoices ${type}`}
/>
</S.content>
</S.wrapper>
Expand Down