-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
#7446: Total Metric Count inside donut pie charts #16820
#7446: Total Metric Count inside donut pie charts #16820
Conversation
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the donut descriptor should be controlled by a setting in the "Pie Settings" panel, src/core_plugins/kbn_vislib_vis_types/public/editors/pie.html
. There may be times when it's not desirable to show this
@Bargs (commented on original issue) and @elastic/kibana-visualizations would you mind doing a review on this? |
Having an empty space doesn't actually give any benefit per se, moreover would you be okay with the addition of another setting (Clutter)? If yes then I can do that. |
I would prefer seeing the first label in the middle. Or maybe the value for the highest result (kind of like a gauge). |
thanks @varundbest! jenkins, test this. |
💔 Build Failed |
Fixing the issues. |
Weird, should've been caught by the linter. No more issues (In my local). |
I second @tsullivan here. We try to keep the charts as configurable as possible, since there is no such thing as a universal desire people have. Even though you say: you don't need whitespace in your pie charts, I can see a lot of people who say, they don't want the label inside their pie charts. So I would kindly ask you to add an option to show the label. I also think there should be a label for this. Without looking at the sources I wouldn't have been able to figure out what the number means exactly. When you use I think a tooltip at least could help solve that confusion for users. |
Okay, will add an option and label. |
Hi @varundbest. Do you currently still have time to work on this? Otherwise I would like to close it, if you can't spend the time in it at the moment, but of course we could reopen it as soon as you want to continue working on this. Cheers, |
Hi @timroes, I've been a little busy lately. Will add an Option (Enabled by default) and an onHover label over the weekend. |
Thanks for the quick response. Glad you will do that. Also feel free to close PRs yourself if you feel you can't spend time in the near future working on them again, and feel free to reopen them or open a new one for the same feature. That way we better have an overview what PRs are actually still active and need our attention :-) |
It will be the total of whatever metric the Pie is being split on. @timroes Pushed the desired changes (an Option (Enabled by default) and an onHover label). How do you feel about it now? |
@@ -32,7 +33,7 @@ export function VislibVisualizationsPieChartProvider(Private) { | |||
|
|||
const charts = this.handler.data.getVisData(); | |||
this._validatePieData(charts); | |||
|
|||
this.ABBREVIATIONS = ['', 'k', 'Mil', 'Bn', 'Tn']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should rather use the common unit prefixes as in other places, i.e. k
, M
, G
, T
, P
.
These are imho better understand and less prone to misunderstanding due to cultural/language differences.
Example time: In German we have a bit different system to naming millions and above:
- Million [EN] -> Million [DE]
- Billion [EN] -> Milliarde [DE]
- Trillion [EN] -> Billion [DE]
- Quadrillion [EN] -> Billiarde [DE]
- Quintillion [EN] -> Trillion [DE]
- ...
Even while speaking English most of the time, I have a hard time, thinking when seeing a billion or Bn about an English billion rather than a German billion. Also Tn
could be easily misunderstood as the abbreviation of "Tausend" (the German word for thousand).
In general using the well acknowledged prefixes, would imho be a better solution and better aligned with the rest of Kibana.
readableNumber(number) { | ||
let tier = Math.log10(Math.abs(number)) / 3 | 0; | ||
if(tier === 0) return number; | ||
if(tier > 4) tier = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't hardcode 4
here, but rather use this.ABBREVIATIONS.length
if(tier === 0) return number; | ||
if(tier > 4) tier = 4; | ||
const postfix = this.ABBREVIATIONS[tier]; | ||
const scale = Math.pow(10, tier * 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to use modern JS where possible: 10 ** (tier * 3)
const postfix = this.ABBREVIATIONS[tier]; | ||
const scale = Math.pow(10, tier * 3); | ||
const scaled = number / scale; | ||
let formatted = String(scaled.toFixed(1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The String
is unnecessary, since toFixed
already returns a string.
const scale = Math.pow(10, tier * 3); | ||
const scaled = number / scale; | ||
let formatted = String(scaled.toFixed(1)); | ||
if (/\.0$/.test(formatted)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can get rid of the whole (expensive) regex operations, string cutting and even using let
, by doing the following instead:
// Converting a string to a numeric value will cut off any unnecessary trailing zeroes
const formatted = Number(scaled.toFixed(1));
return `${formatted}${postfix}`;
} | ||
|
||
addDonutDescriptor(svg, width, height) { | ||
const self = this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't. Just use arrow functions, which will preserve the this
context.
For new code we don't try to fall back to hacky ES5 solutions anymore.
@@ -21,6 +21,7 @@ export default function HistogramVisType(Private) { | |||
addLegend: true, | |||
legendPosition: 'right', | |||
isDonut: true, | |||
showTotal: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make the default false
, so we don't change behavior on existing charts.
.text(function (chartData) { | ||
return self.readableNumber(chartData.slices.sumOfChildren); | ||
}); | ||
let tooltip; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion we could get rid of the tooltip altogether. The user already enabled "Show total", so I would assume they would be aware, that it's the total of the chart. If we want to keep the tooltip, we need to add a better styling for it, because currently it's having no padding at all. A solution could be adding a table into it with a "Total {label}" and a "{value}" column in it.
In general I don't like that we mess around with the tooltip like that. We don't try to manually modify the tooltip in any other chart like that, so I would really prefer getting rid of it for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, the person creating the dashboards isn't the one using them. It would aid dashboard users. Perhaps I should add a table? Or we have a better way to add such a tooltip?
.style('text-anchor', 'middle') | ||
.attr('font-size', function (chartData) { | ||
const dividend = Math.min(width, height); | ||
let length = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const length = chartData.raw ? chartData.raw.columns.length : 0;
And one let
less .. :-)
if(chartData.raw) { | ||
length = chartData.raw.columns.length; | ||
} | ||
const divisor = Math.max(length, 4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please explain (and ideally add a comment) what this part does exactly? Why are we using 4
here as a minimum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code determines the size of font for descriptor. As we add sub-buckets, it increases divisor to accommodate more pie layers. 4 is the minimum number derived by trial and error, the divisor should be set to. Would you have any suggestion for a better logic to determine font size (It has to be dynamic, based on size of the panel and number of sub-buckets)?
a94cae2
to
ec0bb69
Compare
Any other pressing issue you can see in this PR? |
ping @timroes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks a lot for this contribution @varunsharma27
i left some comments, let me know what you think.
@@ -32,7 +33,7 @@ export function VislibVisualizationsPieChartProvider(Private) { | |||
|
|||
const charts = this.handler.data.getVisData(); | |||
this._validatePieData(charts); | |||
|
|||
this.ABBREVIATIONS = ['', 'k', 'M', 'G', 'T', 'P']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually we rely on field formatters to do this kind of formatting. The reason is that this can be field dependent, for example if you used sum of bytes
for your pie chart 1k will mean 1024, but if you used sum of price
1k will mean 1000 ...
at the moment this would be the only chart handling this on its own, what do you think @timroes ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we decide to keep this logic here i would suggest using numeral.js
which is already used in other parts of kibana to handle this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"1k will mean 1024", we are denoting it in standard convention of naming large numbers but to clarify it further, we might as well show the full number in the tooltip :- "Sum of Bytes: 1000"
Would it make sense for you?
@@ -327,6 +328,54 @@ export function VislibVisualizationsPieChartProvider(Private) { | |||
} | |||
} | |||
|
|||
readableNumber(number) { | |||
let tier = Math.log10(Math.abs(number)) / 3 | 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where does the 3
come from ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our tiers step up by 10^3 :- Thousand (10^3), Million (10^6), Billion (10^9). So 3 signifies a step up.
.text((chartData) => { | ||
return this.readableNumber(chartData.slices.sumOfChildren); | ||
}); | ||
let tooltip; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i suggest to replace the whole section below with:
descriptor.call(this.tooltip.render(`<table><tr><td>Total ${metricLabel}</td></tr></table>`));
this way we let our tooltip service take care of showing/hiding and positioning of tooltips.
this will require some changes to the ui/vis/components/tooltip/tooltip.js
:
- on line 132 you should add a parameter to the render method:
defaultHtml
- on line 186 you could then use this to render the tooltip:
if (defaultHtml) {
return render(defaultHtml);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes Sense, Will be on to it.
hi @varunsharma27 - can you address the failures and pull master into your branch and re- run the tests? |
Hi again @varunsharma27, nice to see so much improvement coming into our pie charts here! Another requirement for us to be able to merge this is a license agreement you'll need to look at and sign: http://www.elasticsearch.org/contributor-agreement/ |
💔 Build Failed |
Hi @varunsharma27, it seems we lost touch on this PR. Are you still interested in taking care of the feedback and merging master? |
💚 Build Succeeded |
@tsullivan Yes I'd like to do so! Maybe start with rebasing my code to kibana 7 master. However I've been seeing PRs getting lost in kibana repository. For example : #29086 |
Hi, sorry about that. It's getting hard to triage newcoming PRs. I', not saying this is acceptable, but you will probably get more traction on PRs if there is an issue that the PR closes, as issues get more attention and triaging. |
Thanks! I'll rebase and redo this implementation in accordance with 7.x and suggestions from this pr. |
Pinging @elastic/kibana-app |
It seems this was never rebased back on master since February. I would close this PR for now, but if you want to pick this up again, please feel free to reopen. @markov00 could we also keep a feature like that in mind for elastic-charts pie chart implementation? |
#7446 I believe the name of the metric would be implicit and not required to be mentioned in the inner text or perhaps we could add a tooltip?. How do you feel about the logic for 'font-size' at LOC 346?
Preview:-