Skip to content

Commit

Permalink
Refactor updateAxisTitle
Browse files Browse the repository at this point in the history
  • Loading branch information
maryia-lapata committed Mar 3, 2020
1 parent d319e60 commit 45a7a21
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ function MetricsAxisOptions(props: ValidationVisOptionsProps<BasicVislibParams>)
const updateAxisTitle = useCallback(
(seriesParams?: SeriesParam[]) => {
const series = seriesParams || stateParams.seriesParams;
const axes = cloneDeep(stateParams.valueAxes);
let isAxesChanged = false;
let lastValuesChanged = false;
const lastLabels = { ...lastCustomLabels };
const lastMatchingSeriesAgg = { ...lastSeriesAgg };

stateParams.valueAxes.forEach((axis, axisNumber) => {
const axes = stateParams.valueAxes.map((axis, axisNumber) => {
let newCustomLabel = '';
let updatedAxis;
const matchingSeries: IAggConfig[] = [];

series.forEach((serie, seriesIndex) => {
Expand Down Expand Up @@ -135,16 +135,19 @@ function MetricsAxisOptions(props: ValidationVisOptionsProps<BasicVislibParams>)
(aggTypeIsChanged ||
aggFieldIsChanged ||
axis.title.text === '' ||
lastCustomLabels[axis.id] === axis.title.text)
lastCustomLabels[axis.id] === axis.title.text) &&
newCustomLabel !== axis.title.text
) {
// Override axis title with new custom label
axes[axisNumber] = {
updatedAxis = {
...axis,
title: { ...axis.title, text: newCustomLabel },
};
isAxesChanged = true;
}
}

return updatedAxis || axis;
});

if (isAxesChanged) {
Expand Down

0 comments on commit 45a7a21

Please sign in to comment.