"examples/nas/oneshot/spos/supernet.py" did not exist on "d2605ca27c2ba65e03dc72126bce8c426faca3b2"
DefaultMetricPoint.tsx 4.32 KB
Newer Older
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import * as React from 'react';
import ReactEcharts from 'echarts-for-react';
import { TableObj, DetailAccurPoint, TooltipForAccuracy } from '../../static/interface';
require('echarts/lib/chart/scatter');
require('echarts/lib/component/tooltip');
require('echarts/lib/component/title');

interface DefaultPointProps {
    showSource: Array<TableObj>;
    height: number;
}

interface DefaultPointState {
    defaultSource: object;
    accNodata: string;
}

class DefaultPoint extends React.Component<DefaultPointProps, DefaultPointState> {
    public _isMounted = false;

    constructor(props: DefaultPointProps) {
        super(props);
        this.state = {
            defaultSource: {},
            accNodata: 'No data'
        };
    }

    defaultMetric = (showSource: Array<TableObj>) => {
        const accSource: Array<DetailAccurPoint> = [];
        Object.keys(showSource).map(item => {
            const temp = showSource[item];
            if (temp.status === 'SUCCEEDED' && temp.acc.default !== undefined) {
                const searchSpace = temp.description.parameters;
                accSource.push({
                    acc: temp.acc.default,
                    index: temp.sequenceId,
                    searchSpace: JSON.stringify(searchSpace)
                });
            }
        });
        const resultList: Array<number | string>[] = [];
        Object.keys(accSource).map(item => {
            const items = accSource[item];
            let temp: Array<number | string>;
            temp = [items.index, items.acc, JSON.parse(items.searchSpace)];
            resultList.push(temp);
        });

        const allAcuracy = {
            grid: {
                left: '8%'
            },
            tooltip: {
                trigger: 'item',
                enterable: true,
                position: function (point: Array<number>, data: TooltipForAccuracy) {
                    if (data.data[0] < resultList.length / 2) {
                        return [point[0], 80];
                    } else {
                        return [point[0] - 300, 80];
                    }
                },
                formatter: function (data: TooltipForAccuracy) {
                    const result = '<div class="tooldetailAccuracy">' +
                        '<div>Trial No: ' + data.data[0] + '</div>' +
                        '<div>Default Metric: ' + data.data[1] + '</div>' +
                        '<div>Parameters: ' +
                        '<pre>' + JSON.stringify(data.data[2], null, 4) + '</pre>' +
                        '</div>' +
                        '</div>';
                    return result;
                }
            },
            xAxis: {
                name: 'Trial',
                type: 'category',
            },
            yAxis: {
                name: 'Default Metric',
                type: 'value',
            },
            series: [{
                symbolSize: 6,
                type: 'scatter',
                data: resultList
            }]
        };
        if (this._isMounted === true) {
            this.setState({ defaultSource: allAcuracy }, () => {
                if (resultList.length === 0) {
                    this.setState({
                        accNodata: 'No data'
                    });
                } else {
                    this.setState({
                        accNodata: ''
                    });
                }
            });
        }
    }

    // update parent component state
    componentWillReceiveProps(nextProps: DefaultPointProps) {
        const showSource = nextProps.showSource;
        this.defaultMetric(showSource);
    }

    componentDidMount() {
        this._isMounted = true;
    }

    componentWillUnmount() {
        this._isMounted = false;
    }
    
    render() {
        const { height } = this.props;
        const { defaultSource, accNodata } = this.state;
        return (
            <div>
                <ReactEcharts
                    option={defaultSource}
                    style={{
                        width: '100%',
                        height: height,
                        margin: '0 auto',
                    }}
                    theme="my_theme"
                    notMerge={true} // update now
                />
                <div className="showMess">{accNodata}</div>
            </div>
        );
    }
}

export default DefaultPoint;