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 6 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
136 changes: 136 additions & 0 deletions src/client/src/components/chart/BarChartV2.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
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';
import { getFormatDate } from '../generic/helpers';

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

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

export const BarChartV2 = ({
data,
colorRange,
yAxisLabel,
title,
dataKey,
}: 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[dataKey]),
},
];

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,
title: {
text: title,
textStyle: { color: fontColor },
},
grid: {
containLabel: true,
top: '50px',
left: '100px',
bottom: '0px',
right: '100px',
},
tooltip: {
trigger: 'axis',
axisPointer: {
animation: false,
},
formatter: (params: any) => {
return `Date: ${getFormatDate(params[0].axisValue)}<br />
${params[0].seriesName}: ${params[0].value}<br />`;
},
},
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',
minInterval: 1,
splitLine: { show: false },
axisLine: { show: true, lineStyle: { color: fontColor } },
axisTick: { show: true },
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%',
}}
/>
);
};
5 changes: 3 additions & 2 deletions src/client/src/components/generic/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ export const getPastFutureStr = (
};

export const getFormatDate = (
date: string | null | undefined
date: string | null | undefined,
style?: string
): string | null => {
if (!date) return null;
return format(new Date(date), 'dd/MM/yyyy - HH:mm:ss');
return format(new Date(date), style || 'dd/MM/yyyy - HH:mm:ss');
AmbossKeegan marked this conversation as resolved.
Show resolved Hide resolved
};

export const getMessageDate = (
Expand Down
12 changes: 11 additions & 1 deletion src/client/src/views/dashboard/widgets/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { widgetList, WidgetProps } from './widgetList';
import { GetInvoicesQuery } from '../../../graphql/queries/__generated__/getInvoices.generated';
import { GetPaymentsQuery } from '../../../graphql/queries/__generated__/getPayments.generated';

const ONE_WEEK = 7;

const getColumns = (width: number): number => {
const { lg, md, sm, xs } = defaultGrid.breakpoints;

Expand Down Expand Up @@ -82,12 +84,14 @@ export const getByTime = (array: ArrayType, time: number): any[] => {
fee?: number;
}[] = [];

// check to see if we're working in days (isDay = false) or hours (isDay = true)
const isDay = time <= 1;

const today = isDay
? new Date().setMinutes(0, 0, 0)
: new Date().setHours(0, 0, 0, 0);

// Look through each transaction in the array and build an array of transactions with the difference between today and the day (or hour) that the tx occurred
array.forEach((transaction: ArrayType[0]) => {
if (!transaction?.__typename) return;

Expand Down Expand Up @@ -149,10 +153,16 @@ export const getByTime = (array: ArrayType, time: number): any[] => {

if (!transactions?.length) return [];

// Group the transactionw in the array according to the 'difference' property of the object
const grouped = groupBy(transactions, 'difference');

const final: any[] = [];
const differences = Array.from({ length: isDay ? 24 : time }, (_, i) => i);

// If were working with a single day, divide the array in 24 pieces, one for each hour, otherwise, go back 7 days
const differences = Array.from(
{ length: isDay ? 24 : ONE_WEEK },
(_, i) => i
);

differences.forEach(key => {
const group = grouped[key];
Expand Down
Loading