Option for hiding axes.

This commit is contained in:
Olly Smith 2012-12-20 07:50:16 +00:00
parent c82d335976
commit 06a2ab3501
6 changed files with 35 additions and 25 deletions

View File

@ -16,7 +16,7 @@
// Use Morris.Bar
Morris.Bar({
element: 'graph',
grid: false,
axes: false,
data: [
{x: '2011 Q1', y: 3, z: 2, a: 3},
{x: '2011 Q2', y: 2, z: null, a: 1},

View File

@ -46,7 +46,7 @@ class Morris.Bar extends Morris.Grid
# Draws the bar chart.
#
draw: ->
@drawXAxis() if @options.grid
@drawXAxis() if @options.axes
@drawSeries()
# draw the x-axis labels

View File

@ -59,6 +59,7 @@ class Morris.Grid extends Morris.EventEmitter
#
gridDefaults:
dateFormat: null
axes: true
grid: true
gridLineColor: '#aaa'
gridStrokeWidth: 0.5
@ -199,12 +200,12 @@ class Morris.Grid extends Morris.EventEmitter
@right = @elementWidth - @options.padding
@top = @options.padding
@bottom = @elementHeight - @options.padding
if @options.grid
if @options.axes
maxYLabelWidth = Math.max(
@measureText(@yAxisFormat(@ymin), @options.gridTextSize).width,
@measureText(@yAxisFormat(@ymax), @options.gridTextSize).width)
@left += maxYLabelWidth
@bottom -= 1.5 * @options.gridTextSize if @options.grid
@bottom -= 1.5 * @options.gridTextSize
@width = @right - @left
@height = @bottom - @top
@dx = @width / (@xmax - @xmin)
@ -227,7 +228,7 @@ class Morris.Grid extends Morris.EventEmitter
redraw: ->
@r.clear()
@_calc()
@drawGrid() if @options.grid
@drawGrid()
@drawGoals()
@drawEvents()
@draw() if @draw
@ -250,15 +251,18 @@ class Morris.Grid extends Morris.EventEmitter
# draw y axis labels, horizontal lines
#
drawGrid: ->
return if @options.grid is false and @options.axes is false
firstY = @ymin
lastY = @ymax
for lineY in [firstY..lastY] by @yInterval
v = parseFloat(lineY.toFixed(@precision))
y = @transY(v)
if @options.axes
@r.text(@left - @options.padding / 2, y, @yAxisFormat(v))
.attr('font-size', @options.gridTextSize)
.attr('fill', @options.gridTextColor)
.attr('text-anchor', 'end')
if @options.grid
@r.path("M#{@left},#{y}H#{@left + @width}")
.attr('stroke', @options.gridLineColor)
.attr('stroke-width', @options.gridStrokeWidth)

View File

@ -124,7 +124,7 @@ class Morris.Line extends Morris.Grid
# Draws the line chart.
#
draw: ->
@drawXAxis() if @options.grid
@drawXAxis() if @options.axes
@drawSeries()
if @options.hideHover is false
@displayHoverForRow(@data.length - 1)

View File

@ -117,6 +117,7 @@
Grid.prototype.gridDefaults = {
dateFormat: null,
axes: true,
grid: true,
gridLineColor: '#aaa',
gridStrokeWidth: 0.5,
@ -294,13 +295,11 @@
this.right = this.elementWidth - this.options.padding;
this.top = this.options.padding;
this.bottom = this.elementHeight - this.options.padding;
if (this.options.grid) {
if (this.options.axes) {
maxYLabelWidth = Math.max(this.measureText(this.yAxisFormat(this.ymin), this.options.gridTextSize).width, this.measureText(this.yAxisFormat(this.ymax), this.options.gridTextSize).width);
this.left += maxYLabelWidth;
if (this.options.grid) {
this.bottom -= 1.5 * this.options.gridTextSize;
}
}
this.width = this.right - this.left;
this.height = this.bottom - this.top;
this.dx = this.width / (this.xmax - this.xmin);
@ -326,9 +325,7 @@
Grid.prototype.redraw = function() {
this.r.clear();
this._calc();
if (this.options.grid) {
this.drawGrid();
}
this.drawGoals();
this.drawEvents();
if (this.draw) {
@ -360,14 +357,23 @@
Grid.prototype.drawGrid = function() {
var firstY, lastY, lineY, v, y, _i, _ref, _results;
if (this.options.grid === false && this.options.axes === false) {
return;
}
firstY = this.ymin;
lastY = this.ymax;
_results = [];
for (lineY = _i = firstY, _ref = this.yInterval; firstY <= lastY ? _i <= lastY : _i >= lastY; lineY = _i += _ref) {
v = parseFloat(lineY.toFixed(this.precision));
y = this.transY(v);
if (this.options.axes) {
this.r.text(this.left - this.options.padding / 2, y, this.yAxisFormat(v)).attr('font-size', this.options.gridTextSize).attr('fill', this.options.gridTextColor).attr('text-anchor', 'end');
}
if (this.options.grid) {
_results.push(this.r.path("M" + this.left + "," + y + "H" + (this.left + this.width)).attr('stroke', this.options.gridLineColor).attr('stroke-width', this.options.gridStrokeWidth));
} else {
_results.push(void 0);
}
}
return _results;
};
@ -707,7 +713,7 @@
};
Line.prototype.draw = function() {
if (this.options.grid) {
if (this.options.axes) {
this.drawXAxis();
}
this.drawSeries();
@ -1158,7 +1164,7 @@
};
Bar.prototype.draw = function() {
if (this.options.grid) {
if (this.options.axes) {
this.drawXAxis();
}
return this.drawSeries();

2
morris.min.js vendored

File diff suppressed because one or more lines are too long