From 63fe414b6bf556fcc69e7065cfe96a642e54cf7f Mon Sep 17 00:00:00 2001 From: Determinant Date: Mon, 18 Feb 2019 01:13:04 -0500 Subject: use nivo charts --- src/Analyze.tsx | 2 +- src/Chart.tsx | 103 ++++++++++++++++++++++---------------------------------- 2 files changed, 42 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/src/Analyze.tsx b/src/Analyze.tsx index 4e2df49..cf87cb3 100644 --- a/src/Analyze.tsx +++ b/src/Analyze.tsx @@ -113,7 +113,7 @@ class Analyze extends React.Component { this.loadPatterns(patterns); }; - async getCalEvents(id: string, start: Date, end: Date): Promise { + getCalEvents = async (id: string, start: Date, end: Date): Promise => { let { data } = await this.msgClient.sendMsg({ opt: MsgType.getCalEvents, data: { id, diff --git a/src/Chart.tsx b/src/Chart.tsx index e17bc4e..af439f9 100644 --- a/src/Chart.tsx +++ b/src/Chart.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { Theme, withStyles } from '@material-ui/core/styles'; import Grid from '@material-ui/core/Grid'; import cyan from '@material-ui/core/colors/cyan'; -import { PieChart, Pie, Cell, Tooltip } from 'recharts'; +import { ResponsivePie } from '@nivo/pie'; import { defaultChartColor } from './theme'; import { PatternGraphData } from './graph'; @@ -12,59 +12,55 @@ const styles = (theme: Theme) => ({ } }); -function customizedLabel(props: { - cx: number, cy: number, - x: number, y: number, - fill: string, name: string}) { - const {cx, cy, x, y, fill, name} = props; - let anchor = "middle"; - const EPS = 2; - let dx = 0; - let dy = 0; - if (x < cx - EPS) { - dx = -5; - anchor = "end" - } else if (x > cx + EPS) { - dx = 5; - anchor = "start"; - } - - if (y < cy - EPS) { - dy = -5; - } else if (y > cy + EPS) { - dy = 10; - } - - return ({`${name}`}); -} - type PatternPieChartProps = { classes: { patternTableWrapper: string, pieChart: string }, + height?: number, data: PatternGraphData[] }; function PatternPieChart(props: PatternPieChartProps) { return ( - -
- - - {props.data.map((d, i) => )} - - `${value.toFixed(2)} hr`}/> - + +
+ ({ + id: p.name, + label: p.name, + value: p.value, + color: p.color ? p.color: defaultChartColor + }))} + margin={{ + top: 40, + right: 80, + bottom: 40, + left: 80 + }} + innerRadius={0.5} + padAngle={0.7} + cornerRadius={3} + colorBy={d => d.color as string} + borderWidth={1} + borderColor="inherit:darker(0.2)" + radialLabelsSkipAngle={10} + radialLabelsTextXOffset={6} + radialLabelsTextColor="#333333" + radialLabelsLinkOffset={0} + radialLabelsLinkDiagonalLength={16} + radialLabelsLinkHorizontalLength={24} + radialLabelsLinkStrokeWidth={1} + radialLabelsLinkColor="inherit" + sliceLabel={(d) => `${d.value.toFixed(2)} hr`} + slicesLabelsSkipAngle={10} + slicesLabelsTextColor="#ffffff" + animate={true} + motionStiffness={90} + motionDamping={15} + tooltipFormat={v => `${v.toFixed(2)} hr`} />
-
+ ); } @@ -82,25 +78,8 @@ type DoublePieChartProps = { function DoublePieChart(props: DoublePieChartProps) { return ( - - -
- - - {props.calendarGraphData.map((d, i) => )} - - `${value.toFixed(2)} hr`}/> - -
-
+ +
); } -- cgit v1.2.3-70-g09d2