aboutsummaryrefslogtreecommitdiff
path: root/src/Grid.tsx
blob: f68c5507401b0778a8fb26678c60eb1eaff1c59e (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
import React from 'react';
import 'typeface-roboto';
import MGrid from '@material-ui/core/Grid';
import orange from '@material-ui/core/colors/orange';
import blue from '@material-ui/core/colors/blue';
import { Theme, withStyles, StyleRules } from '@material-ui/core/styles';
import Color from 'color';

const styles = (theme: Theme): StyleRules => ({
    gridRow: {
        height: 24,
        textAlign: 'center'
    },
    gridCell: {
        height: 20,
        width: 20,
        margin: 2,
        display: 'inline-block'
    }
});

interface GridProps {
    classes: {
        gridRow: string,
        gridCell: string
    },
    data: {d: number[], col: number}[][]
}

class Grid extends React.Component<GridProps> {
    static getColor(s: {d: number[], col: number}) {
        const color = [orange[300], blue[300]];
        let {d, col} = s;
        return Color(color[col]).darken(Math.min(d[col] / 10, 0.6)).hex();
    }
    render() {
        const { classes, data } = this.props;
        return (
            <div style={{margin: '0 auto'}}>
            {
                data.map((row, i) => (
                    <div key={i} className={classes.gridRow}>
                    {
                        row.map((cell, j) => (
                            <div key={j} className={classes.gridCell} style={{backgroundColor: Grid.getColor(cell)}}>
                            </div>
                        ))
                    }
                    </div>
                ))
            }
            </div>
        );
    }
}

export default withStyles(styles)(Grid);