mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-10 21:36:34 +01:00
Add xaxis and yaxis options for disabling axes individually
This commit is contained in:
parent
b98ae8ab1d
commit
cccf319f38
@ -48,7 +48,7 @@ class Morris.Bar extends Morris.Grid
|
||||
# Draws the bar chart.
|
||||
#
|
||||
draw: ->
|
||||
@drawXAxis() if @options.axes
|
||||
@drawXAxis() if @options.xaxis
|
||||
@drawSeries()
|
||||
|
||||
# draw the x-axis labels
|
||||
|
@ -21,6 +21,11 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
if typeof @options.units is 'string'
|
||||
@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
|
||||
@raphael = new Raphael(@el[0])
|
||||
|
||||
@ -59,7 +64,8 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
#
|
||||
gridDefaults:
|
||||
dateFormat: null
|
||||
axes: true
|
||||
xaxis: true
|
||||
yaxis: true
|
||||
grid: true
|
||||
gridLineColor: '#aaa'
|
||||
gridStrokeWidth: 0.5
|
||||
@ -172,7 +178,7 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
@ymin -= 1 if ymin
|
||||
@ymax += 1
|
||||
|
||||
if @options.axes is true or @options.grid is true
|
||||
if @options.yaxis is true or @options.grid is true
|
||||
if (@options.ymax == @gridDefaults.ymax and
|
||||
@options.ymin == @gridDefaults.ymin)
|
||||
# calculate 'magic' grid placement
|
||||
@ -241,10 +247,11 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
@right = @elementWidth - @options.padding
|
||||
@top = @options.padding
|
||||
@bottom = @elementHeight - @options.padding
|
||||
if @options.axes
|
||||
if @options.yaxis
|
||||
yLabelWidths = for gridLine in @grid
|
||||
@measureText(@yAxisFormat(gridLine)).width
|
||||
@left += Math.max(yLabelWidths...)
|
||||
if @options.xaxis
|
||||
bottomOffsets = for i in [0...@data.length]
|
||||
@measureText(@data[i].text, -@options.xLabelAngle).height
|
||||
@bottom -= Math.max(bottomOffsets...)
|
||||
@ -307,10 +314,10 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
# draw y axis labels, horizontal lines
|
||||
#
|
||||
drawGrid: ->
|
||||
return if @options.grid is false and @options.axes is false
|
||||
return if @options.grid is false and @options.yaxis is false
|
||||
for lineY in @grid
|
||||
y = @transY(lineY)
|
||||
if @options.axes
|
||||
if @options.yaxis
|
||||
@drawYAxisLabel(@left - @options.padding / 2, y, @yAxisFormat(lineY))
|
||||
if @options.grid
|
||||
@drawGridLine("M#{@left},#{y}H#{@left + @width}")
|
||||
|
@ -133,7 +133,7 @@ class Morris.Line extends Morris.Grid
|
||||
# Draws the line chart.
|
||||
#
|
||||
draw: ->
|
||||
@drawXAxis() if @options.axes
|
||||
@drawXAxis() if @options.xaxis
|
||||
@drawSeries()
|
||||
if @options.hideHover is false
|
||||
@displayHoverForRow(@data.length - 1)
|
||||
|
21
morris.js
21
morris.js
@ -85,6 +85,10 @@
|
||||
if (typeof this.options.units === 'string') {
|
||||
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.elementWidth = null;
|
||||
this.elementHeight = null;
|
||||
@ -120,7 +124,8 @@
|
||||
|
||||
Grid.prototype.gridDefaults = {
|
||||
dateFormat: null,
|
||||
axes: true,
|
||||
xaxis: true,
|
||||
yaxis: true,
|
||||
grid: true,
|
||||
gridLineColor: '#aaa',
|
||||
gridStrokeWidth: 0.5,
|
||||
@ -260,7 +265,7 @@
|
||||
}
|
||||
this.ymax += 1;
|
||||
}
|
||||
if (this.options.axes === true || this.options.grid === true) {
|
||||
if (this.options.yaxis === true || this.options.grid === true) {
|
||||
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.ymin = Math.min(this.ymin, this.grid[0]);
|
||||
@ -360,7 +365,7 @@
|
||||
this.right = this.elementWidth - this.options.padding;
|
||||
this.top = this.options.padding;
|
||||
this.bottom = this.elementHeight - this.options.padding;
|
||||
if (this.options.axes) {
|
||||
if (this.options.yaxis) {
|
||||
yLabelWidths = (function() {
|
||||
var _i, _len, _ref, _results;
|
||||
_ref = this.grid;
|
||||
@ -372,6 +377,8 @@
|
||||
return _results;
|
||||
}).call(this);
|
||||
this.left += Math.max.apply(Math, yLabelWidths);
|
||||
}
|
||||
if (this.options.xaxis) {
|
||||
bottomOffsets = (function() {
|
||||
var _i, _ref, _results;
|
||||
_results = [];
|
||||
@ -448,7 +455,7 @@
|
||||
|
||||
Grid.prototype.drawGrid = function() {
|
||||
var lineY, y, _i, _len, _ref, _results;
|
||||
if (this.options.grid === false && this.options.axes === false) {
|
||||
if (this.options.grid === false && this.options.yaxis === false) {
|
||||
return;
|
||||
}
|
||||
_ref = this.grid;
|
||||
@ -456,7 +463,7 @@
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
lineY = _ref[_i];
|
||||
y = this.transY(lineY);
|
||||
if (this.options.axes) {
|
||||
if (this.options.yaxis) {
|
||||
this.drawYAxisLabel(this.left - this.options.padding / 2, y, this.yAxisFormat(lineY));
|
||||
}
|
||||
if (this.options.grid) {
|
||||
@ -828,7 +835,7 @@
|
||||
};
|
||||
|
||||
Line.prototype.draw = function() {
|
||||
if (this.options.axes) {
|
||||
if (this.options.xaxis) {
|
||||
this.drawXAxis();
|
||||
}
|
||||
this.drawSeries();
|
||||
@ -1349,7 +1356,7 @@
|
||||
};
|
||||
|
||||
Bar.prototype.draw = function() {
|
||||
if (this.options.axes) {
|
||||
if (this.options.xaxis) {
|
||||
this.drawXAxis();
|
||||
}
|
||||
return this.drawSeries();
|
||||
|
2
morris.min.js
vendored
2
morris.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user