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

Ensure custom set axis titles are preserved when loading a saved vis. #24176

Merged
merged 5 commits into from
Nov 15, 2018

Conversation

lukeelmers
Copy link
Member

Fixes #24145

Summary

Previously, the visualization editor would lose a custom set axis title every
time you opened the editor and loaded a visualization or if you changed the
actual aggregation label. This was due to the way that agg labels were
overwriting custom axis titles.

This change simply checks to ensure the custom title hasn't already been
changed before overwriting it with an updated agg label.

Testing

  1. Create a new point series vis with one y-axis agg.
  2. In the editor Data tab, set a custom label "A" for your y-axis agg.
  3. Go to the editor Metrics & Axes tab, and you will see the custom label "A" has been copied as the custom y-axis title.
  4. Now change the custom y-axis title to "B" and click apply.
  5. Note that changes display in the vis as expected.
  6. Click save, exit the editor, go back to visualizations and re-open the vis.
  7. Note that the custom y-axis title "B" is still displayed on the vis.
  8. When navigating to the Metrics & Axes tab, you should continue to see the same title "B" (this is what was broken prior to this PR -- previously you would have seen "A" in the input field).

Checklist

For maintainers

$parentScope.updateAxisTitle();
expect($parentScope.editorState.params.valueAxes[0].title.text).to.equal('Count');
});

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the above 2 tests to validate existing editor behavior which was previously untested

$parentScope.editorState.aggs[0].params.customLabel = 'Custom Label';
$parentScope.updateAxisTitle();
expect($parentScope.editorState.params.valueAxes[0].title.text).to.equal('Custom Title');
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the test that validates the actual change made in this PR

@lukeelmers lukeelmers added Team:Visualizations Visualization editors, elastic-charts and infrastructure review Feature:Vis Editor Visualization editor issues labels Oct 17, 2018
@elasticmachine
Copy link
Contributor

💔 Build Failed

@lukeelmers
Copy link
Member Author

Jenkins, test this

@elasticmachine
Copy link
Contributor

💔 Build Failed

Copy link
Contributor

@timroes timroes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just a bit worried about the tests. They currently (and most likely already have beforehand) relied on a specific execution order, even though they are unit tests. Do you think we could modify the tests, to actually setup the scope from scratch for every test into the state it needs to be?

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM. Tested on OSX/Chrome.
As Tim suggested it would be also useful to have a functional test, where the test follow the exact path you have described on the PR description, involving saving of the visualization going back to the visualization list and back again to the visualization.

@markov00
Copy link
Member

retest

@elasticmachine
Copy link
Contributor

💔 Build Failed

@lukeelmers
Copy link
Member Author

retest

@elasticmachine
Copy link
Contributor

💔 Build Failed

@timroes timroes requested a review from ppisljar November 7, 2018 08:06
@markov00
Copy link
Member

markov00 commented Nov 7, 2018

@lukeelmers can you merge master? I've already seen this CI error (https://kibana-ci.elastic.co/job/elastic+kibana+pull-request+multijob-x-pack/7590/console). Not sure if was the merging or the retesting that solves that problem

@@ -158,8 +158,11 @@ module.directive('vislibValueAxes', function () {
label = matchingSeries[0].makeLabel();
}
if (lastAxisTitles[axis.id] !== label && label !== '') {
// Only overwrite the custom title with the value axis label if it hasn't been changed
if (lastAxisTitles[axis.id] === axis.title.text) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't we want to change the title automatically if the actual aggregation was changed, or a field ?

  • select sum over bytes field
  • go to axes, change title from sum of bytes to sum of bytes downloaded
  • go back to data tab, and change field to something else ... what would you expect in this case ?
  • what about if you completely changed aggregation ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ppisljar Good catch -- it feels to me the expected behavior in the cases you've described would be that the custom title gets cleared when the agg type or field changes. I will give it some thought and follow up in a bit.

@lukeelmers
Copy link
Member Author

lukeelmers commented Nov 8, 2018

Okay, I think I finally got to some behavior that I feel makes sense while still solving the original issue:

  • When an axis title is set manually, it will always override the custom label set on the agg
  • Otherwise, the axis title will be set to whatever the custom label is on the agg
  • If no custom label is specified on the agg, the axis title will be set to the default for the agg (i.e. whatever aggConfig.makeLabel() returns)
  • If the agg type is changed, axis titles are reset to aggConfg.makeLabel() (this prevents the weird state @ppisljar describes above)

See below and notice how the axis title & legend change based on what is changed in the editor:
kapture 2018-11-07 at 17 07 18

I've also rebased on the latest master so (hopefully) we will get a green build now. Updated tests to follow shortly.

The one item this doesn't address is resetting the axis title when the agg field changes. This issue affects master already... I'll see if I can look further into this, or perhaps we capture that edge case as a separate issue.

@@ -136,10 +136,11 @@ module.directive('vislibValueAxes', function () {
}, 1);
};

const lastAxisTitles = {};
const lastCustomLabels = {};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed some variable names to make this all a little easier to follow.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tested on chrome linux

@lukeelmers
Copy link
Member Author

Updated unit tests, added functional tests, rebased on latest master. @timroes @markov00 let me know if you have any other feedback.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

…alization.

Previously, the visualization editor would lose a custom set axis title every
time you opened the editor and loaded a visualization or if you changed the
actual aggregation label. This was due to the way that agg labels were
overwriting custom axis titles.

This change simply checks to ensure the custom title hasn't already been
changed before overwriting it with an updated agg label.
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@timroes
Copy link
Contributor

timroes commented Nov 15, 2018

No further notes from my side, please feel free to merge and also backport to 6.x and 6.5

@lukeelmers lukeelmers merged commit e75bcda into elastic:master Nov 15, 2018
@lukeelmers lukeelmers deleted the fix-axis-title branch November 15, 2018 15:57
@lukeelmers lukeelmers restored the fix-axis-title branch November 15, 2018 15:57
@lukeelmers lukeelmers deleted the fix-axis-title branch November 15, 2018 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Vis Editor Visualization editor issues Team:Visualizations Visualization editors, elastic-charts and infrastructure v6.5.2 v6.6.0 v7.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants