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 global extrema in scalar #808

Merged
merged 1 commit into from
Sep 10, 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
5 changes: 3 additions & 2 deletions frontend/packages/core/public/locales/en/scalar.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"download-image": "Download image",
"ignore-outliers": "Ignore outliers in chart scaling",
"max": "Max",
"max": "Max.",
"maximize": "Maximize",
"min": "Min",
"min": "Min.",
"minimize": "Minimize",
"restore": "Selection restore",
"show-most-value": "Show global extrema",
"smoothed": "Smoothed",
"smoothed-data-only": "Smoothed Data Only",
"smoothing": "Smoothing",
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 @@ -6,6 +6,7 @@
"min": "最小值",
"minimize": "最小化",
"restore": "还原图表框选",
"show-most-value": "显示最值",
"smoothed": "Smoothed",
"smoothed-data-only": "仅显示平滑后数据",
"smoothing": "平滑度",
Expand Down
10 changes: 8 additions & 2 deletions frontend/packages/core/src/components/ScalarPage/ScalarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type ScalarChartProps = {
sortingMethod: SortingMethod;
outlier?: boolean;
smoothedOnly?: boolean;
showMostValue?: boolean;
running?: boolean;
};

Expand All @@ -99,6 +100,7 @@ const ScalarChart: FunctionComponent<ScalarChartProps> = ({
sortingMethod,
outlier,
smoothedOnly,
showMostValue,
running
}) => {
const {t, i18n} = useTranslation(['scalar', 'common']);
Expand Down Expand Up @@ -132,7 +134,10 @@ const ScalarChart: FunctionComponent<ScalarChartProps> = ({
[datasets, smoothing]
);
const smoothedDatasetsOrUndefined = useHeavyWork(smoothWasm, null, transform, transformParams);
const smoothedDatasets = useMemo(() => smoothedDatasetsOrUndefined ?? [], [smoothedDatasetsOrUndefined]);
const smoothedDatasets = useMemo<NonNullable<typeof smoothedDatasetsOrUndefined>>(
() => smoothedDatasetsOrUndefined ?? [],
[smoothedDatasetsOrUndefined]
);

const axisRangeParams = useMemo(
() => ({
Expand Down Expand Up @@ -164,11 +169,12 @@ const ScalarChart: FunctionComponent<ScalarChartProps> = ({
() =>
chartData({
data: smoothedDatasets.slice(0, runs.length),
ranges: showMostValue ? datasetRanges ?? [] : [],
runs,
xAxis,
smoothedOnly
}),
[smoothedDatasets, runs, xAxis, smoothedOnly]
[smoothedDatasets, datasetRanges, runs, xAxis, smoothedOnly, showMostValue]
);

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

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

const [showMostValue, setShowMostValue] = useState(false);

const aside = useMemo(
() =>
runs.length ? (
Expand All @@ -70,9 +72,16 @@ const Scalar: FunctionComponent = () => {
onToggleRunning={setRunning}
>
<AsideSection>
<Checkbox value={ignoreOutliers} onChange={setIgnoreOutliers}>
{t('scalar:ignore-outliers')}
</Checkbox>
<Field>
<Checkbox value={ignoreOutliers} onChange={setIgnoreOutliers}>
{t('scalar:ignore-outliers')}
</Checkbox>
</Field>
<Field>
<Checkbox value={showMostValue} onChange={setShowMostValue}>
{t('scalar:show-most-value')}
</Checkbox>
</Field>
<TooltipSortingDiv>
<span>{t('scalar:tooltip-sorting')}</span>
<Select
Expand Down Expand Up @@ -105,6 +114,7 @@ const Scalar: FunctionComponent = () => {
[
t,
ignoreOutliers,
showMostValue,
smoothedDataOnly,
onChangeRuns,
running,
Expand All @@ -127,10 +137,11 @@ const Scalar: FunctionComponent = () => {
sortingMethod={tooltipSorting}
outlier={ignoreOutliers}
smoothedOnly={smoothedDataOnly}
showMostValue={showMostValue}
running={running}
/>
),
[smoothing, xAxis, tooltipSorting, ignoreOutliers, smoothedDataOnly, running]
[smoothing, xAxis, tooltipSorting, ignoreOutliers, showMostValue, smoothedDataOnly, running]
);

return (
Expand Down
42 changes: 35 additions & 7 deletions frontend/packages/core/src/resource/scalar/chart.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Dataset, TooltipData, XAxis} from './types';
import type {Dataset, Range, TooltipData, XAxis} from './types';

import type I18n from 'i18next';
import type {Run} from '~/types';
Expand All @@ -19,11 +19,13 @@ export const options = {

export const chartData = ({
data,
ranges,
runs,
xAxis,
smoothedOnly
}: {
data: Dataset[];
ranges: Range[];
runs: Run[];
xAxis: XAxis;
smoothedOnly?: boolean;
Expand All @@ -39,7 +41,8 @@ export const chartData = ({
const name = runs[i].label;
const color = runs[i].colors[0];
const colorAlt = runs[i].colors[1];
const result = [
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const result: any[] = [
{
name,
z: runs.length + i,
Expand All @@ -57,6 +60,11 @@ export const chartData = ({
}
];
if (!smoothedOnly) {
const range = ranges[i];
// const mins = dataset.filter(item => item[2] === range?.min);
// const maxs = dataset.filter(item => item[2] === range?.max);
const min = dataset.find(item => item[2] === range?.min);
const max = dataset.find(item => item[2] === range?.max);
result.push({
name,
z: i,
Expand All @@ -70,6 +78,26 @@ export const chartData = ({
encode: {
x: [xAxisMap[xAxis]],
y: [2]
},
markPoint: {
symbol: 'circle',
symbolSize: 6,
itemStyle: {
color: '#fff',
borderColor: colorAlt,
borderWidth: 1
},
label: {
show: false
},
data: [
...(min ? [{coord: [min[xAxisMap[xAxis]], min[2]]}] : []),
...(max ? [{coord: [max[xAxisMap[xAxis]], max[2]]}] : [])
]
// data: [
// ...mins.map(item => ({coord: [item[xAxisMap[xAxis]], item[2]]})),
// ...maxs.map(item => ({coord: [item[xAxisMap[xAxis]], item[2]]}))
// ]
}
});
}
Expand All @@ -88,6 +116,10 @@ export const tooltip = (data: TooltipData[], stepLength: number, i18n: typeof I1
label: i18n.t('scalar:value'),
width: '4.285714286em'
},
{
label: i18n.t('common:time-mode.step'),
width: `${Math.max(stepLength * 0.571428571, 2.857142857)}em`
},
{
label: i18n.t('scalar:min'),
width: '4.285714286em'
Expand All @@ -96,10 +128,6 @@ export const tooltip = (data: TooltipData[], stepLength: number, i18n: typeof I1
label: i18n.t('scalar:max'),
width: '4.285714286em'
},
{
label: i18n.t('common:time-mode.step'),
width: `${Math.max(stepLength * 0.571428571, 2.857142857)}em`
},
{
label: i18n.t('common:time-mode.wall'),
width: '10.714285714em'
Expand All @@ -112,9 +140,9 @@ export const tooltip = (data: TooltipData[], stepLength: number, i18n: typeof I1
data: data.map(({min, max, item}) => [
valueFormatter(item[3] ?? Number.NaN),
valueFormatter(item[2] ?? Number.NaN),
item[1],
valueFormatter(min ?? Number.NaN),
valueFormatter(max ?? Number.NaN),
item[1],
formatTime(item[0], i18n.language),
Math.floor(item[4] * 60 * 60) + 's'
])
Expand Down
Loading