Skip to content

Commit

Permalink
changing the default logic for yMin and yMax values, removing unused …
Browse files Browse the repository at this point in the history
…variables, fixing issues with yScale for area and column charts
  • Loading branch information
stormpython committed Jan 20, 2015
1 parent 3105008 commit ebe4e22
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
12 changes: 1 addition & 11 deletions src/kibana/components/vislib/lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,10 @@ define(function (require) {
var grouped = (this._attr.mode === 'grouped');

if (this._attr.mode === 'percentage' || this._attr.mode === 'wiggle' ||
this._attr.mode === 'silhouette' || this._attr.defaultYMin) {
this._attr.mode === 'silhouette') {
return 0;
}

// User defined y axis min value
if (this._attr.userDefinedYMin) {
return this.validateUserDefinedYMin(this._attr.userDefinedYMin);
}

// When there is only one data point,
// the yMin should default to zero.
if (this.flatten()[0][0].length === 1 && this.flatten()[0][0][0].y > 0) {
Expand Down Expand Up @@ -264,11 +259,6 @@ define(function (require) {
return 1;
}

// User defined y axis min value
if (this._attr.userDefinedYMin) {
return this.validateUserDefinedYMin(this._attr.userDefinedYMin);
}

// if there is only one data point and its less than zero,
// return 0 as the yMax value.
if (this.flatten()[0][0].length === 1 && this.flatten()[0][0][0].y < 0) {
Expand Down
12 changes: 12 additions & 0 deletions src/kibana/components/vislib/lib/y_axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ define(function (require) {
}
}

if (!this._attr.defaultYExtents) {
// if yMin and yMax are both positive, then yMin should be zero
if (this.yMin > 0 && this.yMax > 0) {
this.yMin = 0;
}

// if yMin and yMax are both negative, then yMax should be zero
if (this.yMin < 0 && this.yMax < 0) {
this.yMax = 0;
}
}

// save reference to y scale
this.yScale = d3.scale.linear()
.domain([this.yMin, this.yMax])
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/components/vislib/vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ define(function (require) {
this.el = $el.get ? $el.get(0) : $el;
this.ChartClass = chartTypes[config.type];
this._attr = _.defaults({}, config || {}, {
defaultYMin: true
defaultYExtents: true
});
this.eventTypes = {
enabled: []
Expand Down
6 changes: 1 addition & 5 deletions src/kibana/components/vislib/visualizations/area_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ define(function (require) {
var color = this.handler.data.getColorFunc();
var xScale = this.handler.xAxis.xScale;
var yScale = this.handler.yAxis.yScale;
var height = yScale.range()[0];
var defaultOpacity = this._attr.defaultOpacity;

var area = d3.svg.area()
Expand All @@ -95,10 +94,7 @@ define(function (require) {
})
.y0(function (d) {
if (isOverlapping) {
if (!self._attr.defaultYMin) {
return yScale(0);
}
return height;
return yScale(0);
}

return yScale(d.y0);
Expand Down
9 changes: 4 additions & 5 deletions src/kibana/components/vislib/visualizations/column_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ define(function (require) {
return xScale.rangeBand();
})
.attr('y', function (d) {
if (d.y < 0 && !self._attr.defaultYMin) {
if (d.y < 0) {
return yScale(d.y0);
}

return yScale(d.y0 + d.y);
})
.attr('height', function (d) {
if (d.y < 0 && !self._attr.defaultYMin) {
if (d.y < 0) {
return Math.abs(yScale(d.y0 + d.y) - yScale(d.y0));
}

Expand Down Expand Up @@ -198,7 +198,6 @@ define(function (require) {
var groupSpacingPercentage = 0.15;
var isTimeScale = (data.ordered && data.ordered.date);
var minWidth = 1;
var self = this;
var barWidth;

// update
Expand Down Expand Up @@ -226,14 +225,14 @@ define(function (require) {
return xScale.rangeBand() / n;
})
.attr('y', function (d) {
if (d.y < 0 && !self._attr.defaultYMin) {
if (d.y < 0) {
return yScale(0);
}

return yScale(d.y);
})
.attr('height', function (d) {
if (d.y < 0 && !self._attr.defaultYMin) {
if (d.y < 0) {
return Math.abs(yScale(0) - yScale(d.y));
}

Expand Down

0 comments on commit ebe4e22

Please sign in to comment.