Unverified Commit 173d49e5 authored by Lijiaoa's avatar Lijiaoa Committed by GitHub
Browse files

Add optimized_mode dropdown for Default metric chart in detail page (#4926)

parent 11aff9df
import * as React from 'react'; import * as React from 'react';
import { Toggle, Stack } from '@fluentui/react'; import { Stack, Dropdown, Toggle, IDropdownOption } from '@fluentui/react';
import ReactEcharts from 'echarts-for-react'; import ReactEcharts from 'echarts-for-react';
import { Trial } from '@model/trial'; import { Trial } from '@model/trial';
import { EXPERIMENT, TRIALS } from '@static/datamodel'; import { EXPERIMENT, TRIALS } from '@static/datamodel';
import { TooltipForAccuracy, EventMap } from '@static/interface'; import { TooltipForAccuracy, EventMap } from '@static/interface';
import { reformatRetiariiParameter } from '@static/function'; import { reformatRetiariiParameter } from '@static/function';
import { gap15 } from '@components/fluent/ChildrenGap';
import 'echarts/lib/chart/scatter'; import 'echarts/lib/chart/scatter';
import 'echarts/lib/component/tooltip'; import 'echarts/lib/component/tooltip';
import 'echarts/lib/component/title'; import 'echarts/lib/component/title';
...@@ -34,6 +35,7 @@ interface DefaultPointState { ...@@ -34,6 +35,7 @@ interface DefaultPointState {
bestCurveEnabled?: boolean | undefined; bestCurveEnabled?: boolean | undefined;
startY: number; // dataZoomY startY: number; // dataZoomY
endY: number; endY: number;
userSelectOptimizeMode: string;
} }
class DefaultPoint extends React.Component<DefaultPointProps, DefaultPointState> { class DefaultPoint extends React.Component<DefaultPointProps, DefaultPointState> {
...@@ -42,7 +44,8 @@ class DefaultPoint extends React.Component<DefaultPointProps, DefaultPointState> ...@@ -42,7 +44,8 @@ class DefaultPoint extends React.Component<DefaultPointProps, DefaultPointState>
this.state = { this.state = {
bestCurveEnabled: false, bestCurveEnabled: false,
startY: 0, // dataZoomY startY: 0, // dataZoomY
endY: 100 endY: 100,
userSelectOptimizeMode: EXPERIMENT.optimizeMode || 'maximize'
}; };
} }
...@@ -124,6 +127,7 @@ class DefaultPoint extends React.Component<DefaultPointProps, DefaultPointState> ...@@ -124,6 +127,7 @@ class DefaultPoint extends React.Component<DefaultPointProps, DefaultPointState>
} }
generateBestCurveSeries(trials: Trial[]): any { generateBestCurveSeries(trials: Trial[]): any {
const { userSelectOptimizeMode } = this.state;
let best = trials[0]; let best = trials[0];
const data = [[best.sequenceId, best.accuracy, best.id, best.description.parameters]]; const data = [[best.sequenceId, best.accuracy, best.id, best.description.parameters]];
...@@ -131,7 +135,7 @@ class DefaultPoint extends React.Component<DefaultPointProps, DefaultPointState> ...@@ -131,7 +135,7 @@ class DefaultPoint extends React.Component<DefaultPointProps, DefaultPointState>
const trial = trials[i]; const trial = trials[i];
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const delta = trial.accuracy! - best.accuracy!; const delta = trial.accuracy! - best.accuracy!;
const better = EXPERIMENT.optimizeMode === 'minimize' ? delta < 0 : delta > 0; const better = userSelectOptimizeMode === 'minimize' ? delta < 0 : delta > 0;
if (better) { if (better) {
data.push([trial.sequenceId, trial.accuracy, best.id, trial.description.parameters]); data.push([trial.sequenceId, trial.accuracy, best.id, trial.description.parameters]);
best = trial; best = trial;
...@@ -147,8 +151,16 @@ class DefaultPoint extends React.Component<DefaultPointProps, DefaultPointState> ...@@ -147,8 +151,16 @@ class DefaultPoint extends React.Component<DefaultPointProps, DefaultPointState>
}; };
} }
// get user mode number 'max' or 'min'
updateUserOptimizeMode = (event: React.FormEvent<HTMLDivElement>, item?: IDropdownOption): void => {
if (item !== undefined) {
this.setState({ userSelectOptimizeMode: item.key.toString() });
}
};
render(): React.ReactNode { render(): React.ReactNode {
const { hasBestCurve, chartHeight } = this.props; const { hasBestCurve, chartHeight } = this.props;
const { userSelectOptimizeMode } = this.state;
const graph = this.generateGraph(); const graph = this.generateGraph();
const accNodata = graph === EmptyGraph ? 'No data' : ''; const accNodata = graph === EmptyGraph ? 'No data' : '';
const onEvents = { dataZoom: this.metricDataZoom, click: this.pointClick }; const onEvents = { dataZoom: this.metricDataZoom, click: this.pointClick };
...@@ -156,8 +168,18 @@ class DefaultPoint extends React.Component<DefaultPointProps, DefaultPointState> ...@@ -156,8 +168,18 @@ class DefaultPoint extends React.Component<DefaultPointProps, DefaultPointState>
return ( return (
<div> <div>
{hasBestCurve && ( {hasBestCurve && (
<Stack horizontalAlign='end' className='default-metric'> <Stack horizontal reversed tokens={gap15} className='default-metric'>
<Toggle label='Optimization curve' inlineLabel onChange={this.loadDefault} /> <Toggle label='Optimization curve' inlineLabel onChange={this.loadDefault} />
<Dropdown
selectedKey={userSelectOptimizeMode}
onChange={this.updateUserOptimizeMode}
options={[
{ key: 'maximize', text: 'Maximize' },
{ key: 'minimize', text: 'Minimize' }
]}
styles={{ dropdown: { width: 100 } }}
className='para-filter-percent'
/>
</Stack> </Stack>
)} )}
<div className='default-metric-graph graph'> <div className='default-metric-graph graph'>
......
...@@ -261,14 +261,16 @@ class Intermediate extends React.Component<IntermediateProps, IntermediateState> ...@@ -261,14 +261,16 @@ class Intermediate extends React.Component<IntermediateProps, IntermediateState>
// placeholder="range" // placeholder="range"
ref={(input): any => (this.maxValInput = input)} ref={(input): any => (this.maxValInput = input)}
/> />
<PrimaryButton text='Confirm' onClick={this.filterLines} disabled={isLoadconfirmBtn} /> <PrimaryButton
className='intermeidateconfirm'
text='Confirm'
onClick={this.filterLines}
disabled={isLoadconfirmBtn}
/>
</div> </div>
) : null} ) : null}
{/* filter message */} {/* filter message */}
<Stack horizontal className='filter-toggle'> <Toggle label='Filter' inlineLabel onChange={this.switchTurn} />
<span>Filter</span>
<Toggle onChange={this.switchTurn} />
</Stack>
</Stack> </Stack>
<div className='intermediate-graph graph'> <div className='intermediate-graph graph'>
<ReactEcharts <ReactEcharts
...@@ -277,7 +279,7 @@ class Intermediate extends React.Component<IntermediateProps, IntermediateState> ...@@ -277,7 +279,7 @@ class Intermediate extends React.Component<IntermediateProps, IntermediateState>
notMerge={true} // update now notMerge={true} // update now
onEvents={IntermediateEvents} onEvents={IntermediateEvents}
/> />
<div className='fontColor333'># Intermediate result</div> <div className='fontColor333 xAxis'># Intermediate result</div>
</div> </div>
</div> </div>
); );
......
...@@ -65,10 +65,6 @@ ...@@ -65,10 +65,6 @@
.filter-x { .filter-x {
margin-left: 15px; margin-left: 15px;
} }
.filter-toggle {
line-height: 32px;
}
} }
.parcoords { .parcoords {
......
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
} }
.default-metric { .default-metric {
width: 90%; width: 93%;
text-align: right; text-align: right;
margin-top: 15px; margin-top: 15px;
...@@ -129,11 +129,15 @@ ...@@ -129,11 +129,15 @@
.xAxis { .xAxis {
position: absolute; position: absolute;
left: 50%; left: 50%;
top: 88%; top: 80%;
transform: translate(-50%); transform: translate(-50%);
} }
} }
.intermeidateconfirm .ms-Button-textContainer {
margin-top: -1px;
}
.detail-table { .detail-table {
.ms-Button { .ms-Button {
padding: 0; padding: 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment