Skip to content

sorting chart xValues by metric sum#8397

Merged
ppisljar merged 6 commits intoelastic:masterfrom
ppisljar:fix/reorderBuckets
Nov 9, 2016
Merged

sorting chart xValues by metric sum#8397
ppisljar merged 6 commits intoelastic:masterfrom
ppisljar:fix/reorderBuckets

Conversation

@ppisljar
Copy link
Contributor

@ppisljar ppisljar commented Sep 21, 2016

fixes #5512
fixes #3314

reorder values on ordinal x axis from largest to smallest

@ppisljar
Copy link
Contributor Author

currently this will reorder values on x-axis no matter the sorting method selected. sorting method only applies to elasticsearch query (so if for example i am aggregating by geo.src instead of getting the buckets with highest counts i will get first 5 countries alphabetically) but then kibana would always order them from biggest to smallest.

i think its correct we dont take query sort order into account, but maybe we could add another option: sort buckets (or dont) in the visualization.

@epixa epixa added v5.0.0 and removed v5.0.0-beta1 labels Sep 21, 2016
@cjcenizal cjcenizal self-assigned this Sep 21, 2016
@ppisljar
Copy link
Contributor Author

i think im gonna add the option to enable/disable this first thing in the morning

@cjcenizal
Copy link
Contributor

@ppisljar what's your assessment of this zero injection library? There are a few smells here which make me wonder if we should improve this code more fundamentally:

  1. We're making changes contrary to the Open/Closed Principle. I think this probably means the code wasn't originally written in a way that's easy to extend. If we're just adjusting sorting logic, shouldn't we ideally be able to call some kind of sorting function and just pass in a new comparator?
  2. We have to change the test assertions to reflect the changes in code. Ideally, shouldn't we just be able to add new test cases to reflect the functionality we're adding?

Also, after looking at the code more carefully, I find it confusing and difficult to follow. There are numerous conditions, return values of differing types, variables that hold different types of values based on different conditions, and references to specific array elements without any explanations of what those elements are.

On one hand it would be great to clean this up and make it easier to read (and review). On the other hand, cleaning this code up seems like a major task. Clearly you understood it well enough to make this change, so maybe we can compromise with some comments to document the things you learned about it, if a more thorough cleanup effort isn't worth it at this time?

@ppisljar
Copy link
Contributor Author

ppisljar commented Sep 22, 2016

@cjcenizal i agree the library is not the best, but in this PR i am not gonna rewrite it. its not the only part of kibana that cries for rewrite ...

  • i think the open/closed principle is hard to apply, but not just in this specific file but in other parts of kibana as well (for sure the vislib part). i did infact update the comparator to order on sum instead of index. the second change is making this sum available on the objects we are sorting and the test fixes ....

  • regarding assertions ... the issue this fixes is considered a bug. i changed the original code to make it work and i also needed to change some tests which (from this perspective) were actually checking if the code contains a bug.

    im adding option to enable/disable this .... so the tests will go back to where they were and im gonna add a new one to test for new scenario.

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

Looks great! Just had a few small suggestions for making the code easier to follow.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think renaming this to orderBucketsBySum everywhere will make it a little clearer, since technically the buckets are going to be sorted anyway, right? They'll just be sorted by their index by default.

Copy link
Contributor

@cjcenizal cjcenizal Sep 22, 2016

Choose a reason for hiding this comment

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

"Correct order" isn't very precise. Let's make this description more explicit, so people reading this will know exactly what to expect of this text:

it('should return an array of values ordered by their sum when orderBucketsBySum is true', function () {

I think it's worth updating the preceding test's description to provide better contrast:

it('should return an array of values ordered by their index by default', function () {

Copy link
Contributor

Choose a reason for hiding this comment

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

How about "Order buckets by descending sum"?

@ppisljar ppisljar added v5.1.0 and removed v5.0.0 labels Oct 3, 2016
@thomasneirynck thomasneirynck self-assigned this Nov 8, 2016
Copy link
Contributor

@thomasneirynck thomasneirynck left a comment

Choose a reason for hiding this comment

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

LGTM

@ppisljar ppisljar merged commit 60e62c7 into elastic:master Nov 9, 2016
elastic-jasper added a commit that referenced this pull request Nov 9, 2016
Backports PR #8397

**Commit 1:**
sorting chart xValues by metric sum

* Original sha: 64db47e
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-21T09:14:49Z

**Commit 2:**
fixing tests

* Original sha: b6bcd55
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-21T09:40:54Z

**Commit 3:**
adding order buckets by value option to point series charts

* Original sha: c03bc99
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-22T07:50:02Z

**Commit 4:**
fixing tests

* Original sha: 5917293
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-22T15:11:40Z

**Commit 5:**
fixing tests

* Original sha: 19bcdfe
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-22T15:21:07Z

**Commit 6:**
Updating based on CJs comments and adding documentation

* Original sha: cccc06f
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-23T06:06:06Z
ppisljar pushed a commit that referenced this pull request Nov 9, 2016
Backports PR #8397

**Commit 1:**
sorting chart xValues by metric sum

* Original sha: 64db47e
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-21T09:14:49Z

**Commit 2:**
fixing tests

* Original sha: b6bcd55
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-21T09:40:54Z

**Commit 3:**
adding order buckets by value option to point series charts

* Original sha: c03bc99
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-22T07:50:02Z

**Commit 4:**
fixing tests

* Original sha: 5917293
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-22T15:11:40Z

**Commit 5:**
fixing tests

* Original sha: 19bcdfe
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-22T15:21:07Z

**Commit 6:**
Updating based on CJs comments and adding documentation

* Original sha: cccc06f
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-23T06:06:06Z
nreese pushed a commit to nreese/kibana that referenced this pull request Nov 10, 2016
* sorting chart xValues by metric sum

* fixing tests

* adding order buckets by value option to point series charts

* fixing tests

* fixing tests

* Updating based on CJs comments and adding documentation
@epixa epixa added v5.1.1 and removed v5.1.0 labels Dec 8, 2016
airow pushed a commit to airow/kibana that referenced this pull request Feb 16, 2017
Backports PR elastic#8397

**Commit 1:**
sorting chart xValues by metric sum

* Original sha: 64db47e
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-21T09:14:49Z

**Commit 2:**
fixing tests

* Original sha: b6bcd55
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-21T09:40:54Z

**Commit 3:**
adding order buckets by value option to point series charts

* Original sha: c03bc99
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-22T07:50:02Z

**Commit 4:**
fixing tests

* Original sha: 5917293
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-22T15:11:40Z

**Commit 5:**
fixing tests

* Original sha: 19bcdfe
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-22T15:21:07Z

**Commit 6:**
Updating based on CJs comments and adding documentation

* Original sha: cccc06f
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-23T06:06:06Z

Former-commit-id: 4a76abc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bar graph "order by" incorrect with double split terms Incorrect bar ordering for unique count with terms sub aggregation

4 participants