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

Render Zero Values in Percent Charts Properly #3086

Merged
merged 3 commits into from
Feb 23, 2015
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@ define(function (require) {
while ((result = result.$parent) && result.aggConfig) {
var agg = result.aggConfig;
var value = result.value;
if (agg === datum.aggConfigResult.aggConfig && datum.yScale != null) value *= datum.yScale;

details.push({
var detail = {
value: agg.fieldFormatter()(value),
label: agg.makeLabel()
});
};

if (agg === datum.aggConfigResult.aggConfig) {
detail.percent = event.percent;
if (datum.yScale != null) {
detail.value = agg.fieldFormatter()(value * datum.yScale);
}
}

details.push(detail);
}

$tooltipScope.$apply();
Expand Down
27 changes: 14 additions & 13 deletions src/kibana/components/vislib/lib/dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,7 @@ define(function (require) {
var color = handler.data.color;
var isPercentage = (handler._attr.mode === 'percentage');

if (isSeries) {
// Find object with the actual d value and add it to the point object
var object = _.find(series, { 'label': d.label });
d.value = +object.values[i].y;

if (isPercentage) {

// Add the formatted percentage to the point object
d.percent = (100 * d.y).toFixed(1) + '%';
}
}

return {
var eventData = {
value: d.y,
point: datum,
datum: datum,
Expand All @@ -69,6 +57,19 @@ define(function (require) {
e: d3.event,
handler: handler
};

if (isSeries) {
// Find object with the actual d value and add it to the point object
var object = _.find(series, { 'label': d.label });
eventData.value = +object.values[i].y;

if (isPercentage) {
// Add the formatted percentage to the point object
eventData.percent = (100 * d.y).toFixed(1) + '%';
}
}

return eventData;
};

/**
Expand Down
7 changes: 7 additions & 0 deletions src/kibana/components/vislib/visualizations/column_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ define(function (require) {
return Math.abs(yScale(d.y0 + d.y) - yScale(d.y0));
}

// Due to an issue with D3 not returning zeros correctly when using
// an offset='expand', need to add conditional statement to handle zeros
// appropriately
if (d._input.y === 0) {
return 0;
}

// for split bars or for one series,
// last series will have d.y0 = 0
if (d.y0 === 0 && yMin > 0) {
Expand Down