未验证 提交 21fcae82 编写于 作者: P Peter Pan 提交者: GitHub

feat: add smoothed data only option in scalar page (#795)

上级 19ac0b3c
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
"minimize": "Minimize", "minimize": "Minimize",
"restore": "Selection restore", "restore": "Selection restore",
"smoothed": "Smoothed", "smoothed": "Smoothed",
"smoothed-data-only": "Smoothed Data Only",
"smoothing": "Smoothing", "smoothing": "Smoothing",
"toggle-log-axis": "Logarithmic axis", "toggle-log-axis": "Logarithmic axis",
"tooltip-sorting": "Tooltip Sorting", "tooltip-sorting": "Tooltip Sorting",
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
"minimize": "最小化", "minimize": "最小化",
"restore": "还原图表框选", "restore": "还原图表框选",
"smoothed": "Smoothed", "smoothed": "Smoothed",
"smoothed-data-only": "仅显示平滑后数据",
"smoothing": "平滑度", "smoothing": "平滑度",
"toggle-log-axis": "切换对数坐标轴", "toggle-log-axis": "切换对数坐标轴",
"tooltip-sorting": "详情数据排序", "tooltip-sorting": "详情数据排序",
......
...@@ -86,6 +86,7 @@ type ScalarChartProps = { ...@@ -86,6 +86,7 @@ type ScalarChartProps = {
xAxis: XAxis; xAxis: XAxis;
sortingMethod: SortingMethod; sortingMethod: SortingMethod;
outlier?: boolean; outlier?: boolean;
smoothedOnly?: boolean;
running?: boolean; running?: boolean;
}; };
...@@ -97,6 +98,7 @@ const ScalarChart: FunctionComponent<ScalarChartProps> = ({ ...@@ -97,6 +98,7 @@ const ScalarChart: FunctionComponent<ScalarChartProps> = ({
xAxis, xAxis,
sortingMethod, sortingMethod,
outlier, outlier,
smoothedOnly,
running running
}) => { }) => {
const {t, i18n} = useTranslation(['scalar', 'common']); const {t, i18n} = useTranslation(['scalar', 'common']);
...@@ -163,9 +165,10 @@ const ScalarChart: FunctionComponent<ScalarChartProps> = ({ ...@@ -163,9 +165,10 @@ const ScalarChart: FunctionComponent<ScalarChartProps> = ({
chartData({ chartData({
data: smoothedDatasets.slice(0, runs.length), data: smoothedDatasets.slice(0, runs.length),
runs, runs,
xAxis xAxis,
smoothedOnly
}), }),
[smoothedDatasets, runs, xAxis] [smoothedDatasets, runs, xAxis, smoothedOnly]
); );
const maxStepLength = useMemo( const maxStepLength = useMemo(
......
...@@ -46,6 +46,8 @@ const Scalar: FunctionComponent = () => { ...@@ -46,6 +46,8 @@ const Scalar: FunctionComponent = () => {
const [ignoreOutliers, setIgnoreOutliers] = useState(false); const [ignoreOutliers, setIgnoreOutliers] = useState(false);
const [smoothedDataOnly, setSmoothedDataOnly] = useState(false);
const aside = useMemo( const aside = useMemo(
() => () =>
runs.length ? ( runs.length ? (
...@@ -76,6 +78,11 @@ const Scalar: FunctionComponent = () => { ...@@ -76,6 +78,11 @@ const Scalar: FunctionComponent = () => {
<Field label={t('scalar:smoothing')}> <Field label={t('scalar:smoothing')}>
<Slider min={0} max={0.99} step={0.01} value={smoothing} onChangeComplete={setSmoothing} /> <Slider min={0} max={0.99} step={0.01} value={smoothing} onChangeComplete={setSmoothing} />
</Field> </Field>
<Field>
<Checkbox value={smoothedDataOnly} onChange={setSmoothedDataOnly}>
{t('scalar:smoothed-data-only')}
</Checkbox>
</Field>
</AsideSection> </AsideSection>
<AsideSection> <AsideSection>
<Field label={t('scalar:x-axis')}> <Field label={t('scalar:x-axis')}>
...@@ -84,7 +91,18 @@ const Scalar: FunctionComponent = () => { ...@@ -84,7 +91,18 @@ const Scalar: FunctionComponent = () => {
</AsideSection> </AsideSection>
</RunAside> </RunAside>
) : null, ) : null,
[t, ignoreOutliers, onChangeRuns, running, runs, selectedRuns, smoothing, tooltipSorting, xAxis] [
t,
ignoreOutliers,
smoothedDataOnly,
onChangeRuns,
running,
runs,
selectedRuns,
smoothing,
tooltipSorting,
xAxis
]
); );
const withChart = useCallback<WithChart<Tag>>( const withChart = useCallback<WithChart<Tag>>(
...@@ -97,10 +115,11 @@ const Scalar: FunctionComponent = () => { ...@@ -97,10 +115,11 @@ const Scalar: FunctionComponent = () => {
xAxis={xAxis} xAxis={xAxis}
sortingMethod={tooltipSorting} sortingMethod={tooltipSorting}
outlier={ignoreOutliers} outlier={ignoreOutliers}
smoothedOnly={smoothedDataOnly}
running={running} running={running}
/> />
), ),
[smoothing, xAxis, tooltipSorting, ignoreOutliers, running] [smoothing, xAxis, tooltipSorting, ignoreOutliers, smoothedDataOnly, running]
); );
return ( return (
......
...@@ -17,7 +17,17 @@ export const options = { ...@@ -17,7 +17,17 @@ export const options = {
} }
}; };
export const chartData = ({data, runs, xAxis}: {data: Dataset[]; runs: Run[]; xAxis: XAxis}) => export const chartData = ({
data,
runs,
xAxis,
smoothedOnly
}: {
data: Dataset[];
runs: Run[];
xAxis: XAxis;
smoothedOnly?: boolean;
}) =>
data data
.map((dataset, i) => { .map((dataset, i) => {
// smoothed data: // smoothed data:
...@@ -29,38 +39,41 @@ export const chartData = ({data, runs, xAxis}: {data: Dataset[]; runs: Run[]; xA ...@@ -29,38 +39,41 @@ export const chartData = ({data, runs, xAxis}: {data: Dataset[]; runs: Run[]; xA
const name = runs[i].label; const name = runs[i].label;
const color = runs[i].colors[0]; const color = runs[i].colors[0];
const colorAlt = runs[i].colors[1]; const colorAlt = runs[i].colors[1];
return [ const result = [
{ {
name, name,
z: i, z: runs.length + i,
itemStyle: { itemStyle: {
color: colorAlt color
}, },
lineStyle: { lineStyle: {
color: colorAlt color
}, },
data: dataset, data: dataset,
encode: { encode: {
x: [xAxisMap[xAxis]], x: [xAxisMap[xAxis]],
y: [2] y: [3]
} }
}, }
{ ];
if (!smoothedOnly) {
result.push({
name, name,
z: runs.length + i, z: i,
itemStyle: { itemStyle: {
color color: colorAlt
}, },
lineStyle: { lineStyle: {
color color: colorAlt
}, },
data: dataset, data: dataset,
encode: { encode: {
x: [xAxisMap[xAxis]], x: [xAxisMap[xAxis]],
y: [3] y: [2]
} }
} });
]; }
return result;
}) })
.flat(); .flat();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册