axes option can be true, false, 'both', 'x', 'y'

This commit is contained in:
Omar Khan 2013-06-23 22:47:44 +01:00
parent cccf319f38
commit d1420482f1
5 changed files with 33 additions and 42 deletions

View File

@ -48,7 +48,7 @@ class Morris.Bar extends Morris.Grid
# Draws the bar chart. # Draws the bar chart.
# #
draw: -> draw: ->
@drawXAxis() if @options.xaxis @drawXAxis() if @options.axes in [true, 'both', 'x']
@drawSeries() @drawSeries()
# draw the x-axis labels # draw the x-axis labels

View File

@ -21,11 +21,6 @@ class Morris.Grid extends Morris.EventEmitter
if typeof @options.units is 'string' if typeof @options.units is 'string'
@options.postUnits = options.units @options.postUnits = options.units
# backwards compatibility for axes -> xaxis, yaxis
if @options.axes is false
@options.xaxis = false
@options.yaxis = false
# the raphael drawing instance # the raphael drawing instance
@raphael = new Raphael(@el[0]) @raphael = new Raphael(@el[0])
@ -64,8 +59,7 @@ class Morris.Grid extends Morris.EventEmitter
# #
gridDefaults: gridDefaults:
dateFormat: null dateFormat: null
xaxis: true axes: true
yaxis: true
grid: true grid: true
gridLineColor: '#aaa' gridLineColor: '#aaa'
gridStrokeWidth: 0.5 gridStrokeWidth: 0.5
@ -178,7 +172,7 @@ class Morris.Grid extends Morris.EventEmitter
@ymin -= 1 if ymin @ymin -= 1 if ymin
@ymax += 1 @ymax += 1
if @options.yaxis is true or @options.grid is true if @options.axes in [true, 'both', 'y'] or @options.grid is true
if (@options.ymax == @gridDefaults.ymax and if (@options.ymax == @gridDefaults.ymax and
@options.ymin == @gridDefaults.ymin) @options.ymin == @gridDefaults.ymin)
# calculate 'magic' grid placement # calculate 'magic' grid placement
@ -247,11 +241,11 @@ class Morris.Grid extends Morris.EventEmitter
@right = @elementWidth - @options.padding @right = @elementWidth - @options.padding
@top = @options.padding @top = @options.padding
@bottom = @elementHeight - @options.padding @bottom = @elementHeight - @options.padding
if @options.yaxis if @options.axes in [true, 'both', 'y']
yLabelWidths = for gridLine in @grid yLabelWidths = for gridLine in @grid
@measureText(@yAxisFormat(gridLine)).width @measureText(@yAxisFormat(gridLine)).width
@left += Math.max(yLabelWidths...) @left += Math.max(yLabelWidths...)
if @options.xaxis if @options.axes in [true, 'both', 'x']
bottomOffsets = for i in [0...@data.length] bottomOffsets = for i in [0...@data.length]
@measureText(@data[i].text, -@options.xLabelAngle).height @measureText(@data[i].text, -@options.xLabelAngle).height
@bottom -= Math.max(bottomOffsets...) @bottom -= Math.max(bottomOffsets...)
@ -314,10 +308,10 @@ class Morris.Grid extends Morris.EventEmitter
# draw y axis labels, horizontal lines # draw y axis labels, horizontal lines
# #
drawGrid: -> drawGrid: ->
return if @options.grid is false and @options.yaxis is false return if @options.grid is false and @options.axes not in [true, 'both', 'y']
for lineY in @grid for lineY in @grid
y = @transY(lineY) y = @transY(lineY)
if @options.yaxis if @options.axes in [true, 'both', 'y']
@drawYAxisLabel(@left - @options.padding / 2, y, @yAxisFormat(lineY)) @drawYAxisLabel(@left - @options.padding / 2, y, @yAxisFormat(lineY))
if @options.grid if @options.grid
@drawGridLine("M#{@left},#{y}H#{@left + @width}") @drawGridLine("M#{@left},#{y}H#{@left + @width}")

View File

@ -133,7 +133,7 @@ class Morris.Line extends Morris.Grid
# Draws the line chart. # Draws the line chart.
# #
draw: -> draw: ->
@drawXAxis() if @options.xaxis @drawXAxis() if @options.axes in [true, 'both', 'x']
@drawSeries() @drawSeries()
if @options.hideHover is false if @options.hideHover is false
@displayHoverForRow(@data.length - 1) @displayHoverForRow(@data.length - 1)

View File

@ -85,10 +85,6 @@
if (typeof this.options.units === 'string') { if (typeof this.options.units === 'string') {
this.options.postUnits = options.units; this.options.postUnits = options.units;
} }
if (this.options.axes === false) {
this.options.xaxis = false;
this.options.yaxis = false;
}
this.raphael = new Raphael(this.el[0]); this.raphael = new Raphael(this.el[0]);
this.elementWidth = null; this.elementWidth = null;
this.elementHeight = null; this.elementHeight = null;
@ -124,8 +120,7 @@
Grid.prototype.gridDefaults = { Grid.prototype.gridDefaults = {
dateFormat: null, dateFormat: null,
xaxis: true, axes: true,
yaxis: true,
grid: true, grid: true,
gridLineColor: '#aaa', gridLineColor: '#aaa',
gridStrokeWidth: 0.5, gridStrokeWidth: 0.5,
@ -152,7 +147,7 @@
}; };
Grid.prototype.setData = function(data, redraw) { Grid.prototype.setData = function(data, redraw) {
var e, idx, index, maxGoal, minGoal, ret, row, step, total, y, ykey, ymax, ymin, yval; var e, idx, index, maxGoal, minGoal, ret, row, step, total, y, ykey, ymax, ymin, yval, _ref;
if (redraw == null) { if (redraw == null) {
redraw = true; redraw = true;
} }
@ -265,7 +260,7 @@
} }
this.ymax += 1; this.ymax += 1;
} }
if (this.options.yaxis === true || this.options.grid === true) { if (((_ref = this.options.axes) === true || _ref === 'both' || _ref === 'y') || this.options.grid === true) {
if (this.options.ymax === this.gridDefaults.ymax && this.options.ymin === this.gridDefaults.ymin) { if (this.options.ymax === this.gridDefaults.ymax && this.options.ymin === this.gridDefaults.ymin) {
this.grid = this.autoGridLines(this.ymin, this.ymax, this.options.numLines); this.grid = this.autoGridLines(this.ymin, this.ymax, this.options.numLines);
this.ymin = Math.min(this.ymin, this.grid[0]); this.ymin = Math.min(this.ymin, this.grid[0]);
@ -273,9 +268,9 @@
} else { } else {
step = (this.ymax - this.ymin) / (this.options.numLines - 1); step = (this.ymax - this.ymin) / (this.options.numLines - 1);
this.grid = (function() { this.grid = (function() {
var _i, _ref, _ref1, _results; var _i, _ref1, _ref2, _results;
_results = []; _results = [];
for (y = _i = _ref = this.ymin, _ref1 = this.ymax; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; y = _i += step) { for (y = _i = _ref1 = this.ymin, _ref2 = this.ymax; _ref1 <= _ref2 ? _i <= _ref2 : _i >= _ref2; y = _i += step) {
_results.push(y); _results.push(y);
} }
return _results; return _results;
@ -354,7 +349,7 @@
}; };
Grid.prototype._calc = function() { Grid.prototype._calc = function() {
var bottomOffsets, gridLine, h, i, w, yLabelWidths; var bottomOffsets, gridLine, h, i, w, yLabelWidths, _ref, _ref1;
w = this.el.width(); w = this.el.width();
h = this.el.height(); h = this.el.height();
if (this.elementWidth !== w || this.elementHeight !== h || this.dirty) { if (this.elementWidth !== w || this.elementHeight !== h || this.dirty) {
@ -365,24 +360,24 @@
this.right = this.elementWidth - this.options.padding; this.right = this.elementWidth - this.options.padding;
this.top = this.options.padding; this.top = this.options.padding;
this.bottom = this.elementHeight - this.options.padding; this.bottom = this.elementHeight - this.options.padding;
if (this.options.yaxis) { if ((_ref = this.options.axes) === true || _ref === 'both' || _ref === 'y') {
yLabelWidths = (function() { yLabelWidths = (function() {
var _i, _len, _ref, _results; var _i, _len, _ref1, _results;
_ref = this.grid; _ref1 = this.grid;
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
gridLine = _ref[_i]; gridLine = _ref1[_i];
_results.push(this.measureText(this.yAxisFormat(gridLine)).width); _results.push(this.measureText(this.yAxisFormat(gridLine)).width);
} }
return _results; return _results;
}).call(this); }).call(this);
this.left += Math.max.apply(Math, yLabelWidths); this.left += Math.max.apply(Math, yLabelWidths);
} }
if (this.options.xaxis) { if ((_ref1 = this.options.axes) === true || _ref1 === 'both' || _ref1 === 'x') {
bottomOffsets = (function() { bottomOffsets = (function() {
var _i, _ref, _results; var _i, _ref2, _results;
_results = []; _results = [];
for (i = _i = 0, _ref = this.data.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { for (i = _i = 0, _ref2 = this.data.length; 0 <= _ref2 ? _i < _ref2 : _i > _ref2; i = 0 <= _ref2 ? ++_i : --_i) {
_results.push(this.measureText(this.data[i].text, -this.options.xLabelAngle).height); _results.push(this.measureText(this.data[i].text, -this.options.xLabelAngle).height);
} }
return _results; return _results;
@ -454,16 +449,16 @@
}; };
Grid.prototype.drawGrid = function() { Grid.prototype.drawGrid = function() {
var lineY, y, _i, _len, _ref, _results; var lineY, y, _i, _len, _ref, _ref1, _ref2, _results;
if (this.options.grid === false && this.options.yaxis === false) { if (this.options.grid === false && ((_ref = this.options.axes) !== true && _ref !== 'both' && _ref !== 'y')) {
return; return;
} }
_ref = this.grid; _ref1 = this.grid;
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
lineY = _ref[_i]; lineY = _ref1[_i];
y = this.transY(lineY); y = this.transY(lineY);
if (this.options.yaxis) { if ((_ref2 = this.options.axes) === true || _ref2 === 'both' || _ref2 === 'y') {
this.drawYAxisLabel(this.left - this.options.padding / 2, y, this.yAxisFormat(lineY)); this.drawYAxisLabel(this.left - this.options.padding / 2, y, this.yAxisFormat(lineY));
} }
if (this.options.grid) { if (this.options.grid) {
@ -835,7 +830,8 @@
}; };
Line.prototype.draw = function() { Line.prototype.draw = function() {
if (this.options.xaxis) { var _ref;
if ((_ref = this.options.axes) === true || _ref === 'both' || _ref === 'x') {
this.drawXAxis(); this.drawXAxis();
} }
this.drawSeries(); this.drawSeries();
@ -1356,7 +1352,8 @@
}; };
Bar.prototype.draw = function() { Bar.prototype.draw = function() {
if (this.options.xaxis) { var _ref;
if ((_ref = this.options.axes) === true || _ref === 'both' || _ref === 'x') {
this.drawXAxis(); this.drawXAxis();
} }
return this.drawSeries(); return this.drawSeries();

2
morris.min.js vendored

File diff suppressed because one or more lines are too long