Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Sep 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/packages/core/public/locales/en/scalar.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"minimize": "Minimize",
"restore": "Selection restore",
"smoothed": "Smoothed",
"smoothed-data-only": "Smoothed Data Only",
"smoothing": "Smoothing",
"toggle-log-axis": "Logarithmic axis",
"tooltip-sorting": "Tooltip Sorting",
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/core/public/locales/zh/scalar.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"minimize": "最小化",
"restore": "还原图表框选",
"smoothed": "Smoothed",
"smoothed-data-only": "仅显示平滑后数据",
"smoothing": "平滑度",
"toggle-log-axis": "切换对数坐标轴",
"tooltip-sorting": "详情数据排序",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type ScalarChartProps = {
xAxis: XAxis;
sortingMethod: SortingMethod;
outlier?: boolean;
smoothedOnly?: boolean;
running?: boolean;
};

Expand All @@ -97,6 +98,7 @@ const ScalarChart: FunctionComponent<ScalarChartProps> = ({
xAxis,
sortingMethod,
outlier,
smoothedOnly,
running
}) => {
const {t, i18n} = useTranslation(['scalar', 'common']);
Expand Down Expand Up @@ -163,9 +165,10 @@ const ScalarChart: FunctionComponent<ScalarChartProps> = ({
chartData({
data: smoothedDatasets.slice(0, runs.length),
runs,
xAxis
xAxis,
smoothedOnly
}),
[smoothedDatasets, runs, xAxis]
[smoothedDatasets, runs, xAxis, smoothedOnly]
);

const maxStepLength = useMemo(
Expand Down
23 changes: 21 additions & 2 deletions frontend/packages/core/src/pages/scalar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const Scalar: FunctionComponent = () => {

const [ignoreOutliers, setIgnoreOutliers] = useState(false);

const [smoothedDataOnly, setSmoothedDataOnly] = useState(false);

const aside = useMemo(
() =>
runs.length ? (
Expand Down Expand Up @@ -76,6 +78,11 @@ const Scalar: FunctionComponent = () => {
<Field label={t('scalar:smoothing')}>
<Slider min={0} max={0.99} step={0.01} value={smoothing} onChangeComplete={setSmoothing} />
</Field>
<Field>
<Checkbox value={smoothedDataOnly} onChange={setSmoothedDataOnly}>
{t('scalar:smoothed-data-only')}
</Checkbox>
</Field>
</AsideSection>
<AsideSection>
<Field label={t('scalar:x-axis')}>
Expand All @@ -84,7 +91,18 @@ const Scalar: FunctionComponent = () => {
</AsideSection>
</RunAside>
) : 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>>(
Expand All @@ -97,10 +115,11 @@ const Scalar: FunctionComponent = () => {
xAxis={xAxis}
sortingMethod={tooltipSorting}
outlier={ignoreOutliers}
smoothedOnly={smoothedDataOnly}
running={running}
/>
),
[smoothing, xAxis, tooltipSorting, ignoreOutliers, running]
[smoothing, xAxis, tooltipSorting, ignoreOutliers, smoothedDataOnly, running]
);

return (
Expand Down
41 changes: 27 additions & 14 deletions frontend/packages/core/src/resource/scalar/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
.map((dataset, i) => {
// smoothed data:
Expand All @@ -29,38 +39,41 @@ export const chartData = ({data, runs, xAxis}: {data: Dataset[]; runs: Run[]; xA
const name = runs[i].label;
const color = runs[i].colors[0];
const colorAlt = runs[i].colors[1];
return [
const result = [
{
name,
z: i,
z: runs.length + i,
itemStyle: {
color: colorAlt
color
},
lineStyle: {
color: colorAlt
color
},
data: dataset,
encode: {
x: [xAxisMap[xAxis]],
y: [2]
y: [3]
}
},
{
}
];
if (!smoothedOnly) {
result.push({
name,
z: runs.length + i,
z: i,
itemStyle: {
color
color: colorAlt
},
lineStyle: {
color
color: colorAlt
},
data: dataset,
encode: {
x: [xAxisMap[xAxis]],
y: [3]
y: [2]
}
}
];
});
}
return result;
})
.flat();

Expand Down