aboutsummaryrefslogtreecommitdiff
path: root/src/Chart.tsx
blob: d70e4f0e08b5e9faf854aacf7e4f08d2df01eeee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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 { ResponsivePie } from '@nivo/pie';
import { defaultChartColor } from './theme';
import { PatternGraphData } from './graph';

const styles = (theme: Theme) => ({
    pieChart: {
        margin: '0 auto',
    }
});

type PatternPieChartProps = {
    classes: {
        patternTableWrapper: string,
        pieChart: string
    },
    height?: number | string,
    data: PatternGraphData[],
    radialLabelsLinkStrokeWidth?: number,
    radialLabelsLinkDiagonalLength?: number,
    borderWidth: number,
    labelFontSize : number,
    marginTop: number,
    marginBottom: number,
    marginLeft: number,
    marginRight: number,
    padAngle: number
};

export class PatternPieChart extends React.Component<PatternPieChartProps> {
    public static defaultProps = {
        radialLabelsLinkStrokeWidth: 1,
        borderWidth: 1,
        radialLabelsLinkDiagonalLength: 16,
        labelFontSize: 12,
        marginTop: 40,
        marginBottom: 40,
        marginLeft: 80,
        marginRight: 80,
        padAngle: 0.7
    };
    render() {
        let { height, data, labelFontSize } = this.props;
        const theme = {
            labels: {
                text: {
                    fontSize: labelFontSize
                }
            }
        };
    return (
            <ResponsivePie
            data={data.map(p => ({
                id: p.name,
                label: p.name,
                value: p.value,
                color: p.color ? p.color: defaultChartColor
            }))}
            margin={{
                top: this.props.marginTop,
                right: this.props.marginRight,
                bottom: this.props.marginBottom,
                left: this.props.marginLeft
            }}
            innerRadius={0.5}
            padAngle={this.props.padAngle}
            cornerRadius={3}
            colorBy={d => d.color as string}
            borderWidth={this.props.borderWidth}
            borderColor="inherit:darker(0.2)"
            radialLabelsSkipAngle={10}
            radialLabelsTextXOffset={6}
            radialLabelsTextColor="#333333"
            radialLabelsLinkOffset={0}
            radialLabelsLinkDiagonalLength={this.props.radialLabelsLinkDiagonalLength}
            radialLabelsLinkHorizontalLength={24}
            radialLabelsLinkStrokeWidth={this.props.radialLabelsLinkStrokeWidth}
            radialLabelsLinkColor="inherit"
            sliceLabel={(d) => `${d.value.toFixed(2)} hr`}
            slicesLabelsSkipAngle={10}
            slicesLabelsTextColor="#ffffff"
            animate={true}
            motionStiffness={90}
            motionDamping={15}
            theme={theme}
            tooltipFormat={v => `${v.toFixed(2)} hr`} />
    );
    }
}

export const StyledPatternPieChart = withStyles(styles)(PatternPieChart);

type DoublePieChartProps = {
    classes: {
        patternTableWrapper: string,
        pieChart: string
    },
    patternGraphData: PatternGraphData[],
    calendarGraphData: PatternGraphData[]
};

function DoublePieChart(props: DoublePieChartProps) {
    return (
    <Grid container spacing={0}>
      <Grid item md={12} lg={12} style={{height: 300}}>
      <StyledPatternPieChart data={props.patternGraphData} />
      </Grid>
      <Grid item md={12} lg={12} style={{height: 300}}>
      <StyledPatternPieChart data={props.calendarGraphData} />
      </Grid>
    </Grid>);
}

export const AnalyzePieChart = withStyles(styles)(DoublePieChart);