mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-10 21:36:34 +01:00
Refactor / bugfix event and goal drawing. (fixes #181)
This commit is contained in:
parent
49a7a02774
commit
6207c210ac
@ -230,31 +230,6 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
@drawEvents()
|
||||
@draw() if @draw
|
||||
|
||||
# draw goals horizontal lines
|
||||
#
|
||||
drawGoals: ->
|
||||
for goal, i in @options.goals
|
||||
@drawGoal("M#{@left},#{@transY(goal)}H#{@left + @width}")
|
||||
|
||||
# draw events vertical lines
|
||||
drawEvents: ->
|
||||
for event, i in @events
|
||||
@drawEvent("M#{@transX(event)},#{@bottom}V#{@top}")
|
||||
|
||||
# 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
|
||||
@drawYAxisLabel(@left - @options.padding / 2, y, @yAxisFormat(v))
|
||||
if @options.grid
|
||||
@drawGridLine("M#{@left},#{y}H#{@left + @width}")
|
||||
|
||||
# @private
|
||||
#
|
||||
measureText: (text, fontSize = 12) ->
|
||||
@ -280,14 +255,41 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
if hit?
|
||||
@hover.update(hit...)
|
||||
|
||||
drawGoal: (path) ->
|
||||
@raphael.path(path)
|
||||
.attr('stroke', @options.goalLineColors[i % @options.goalLineColors.length])
|
||||
# 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
|
||||
@drawYAxisLabel(@left - @options.padding / 2, y, @yAxisFormat(v))
|
||||
if @options.grid
|
||||
@drawGridLine("M#{@left},#{y}H#{@left + @width}")
|
||||
|
||||
# draw goals horizontal lines
|
||||
#
|
||||
drawGoals: ->
|
||||
for goal, i in @options.goals
|
||||
color = @options.goalLineColors[i % @options.goalLineColors.length]
|
||||
@drawGoal(goal, color)
|
||||
|
||||
# draw events vertical lines
|
||||
drawEvents: ->
|
||||
for event, i in @events
|
||||
color = @options.eventLineColors[i % @options.eventLineColors.length]
|
||||
@drawEvent(event, color)
|
||||
|
||||
drawGoal: (goal, color) ->
|
||||
@raphael.path("M#{@left},#{@transY(goal)}H#{@right}")
|
||||
.attr('stroke', color)
|
||||
.attr('stroke-width', @options.goalStrokeWidth)
|
||||
|
||||
drawEvent: (path) ->
|
||||
@raphael.path(path)
|
||||
.attr('stroke', @options.eventLineColors[i % @options.eventLineColors.length])
|
||||
drawEvent: (event, color) ->
|
||||
@raphael.path("M#{@transX(event)},#{@bottom}V#{@top}")
|
||||
.attr('stroke', color)
|
||||
.attr('stroke-width', @options.eventStrokeWidth)
|
||||
|
||||
drawYAxisLabel: (xPos, yPos, text) ->
|
||||
|
100
morris.js
100
morris.js
@ -335,51 +335,6 @@
|
||||
}
|
||||
};
|
||||
|
||||
Grid.prototype.drawGoals = function() {
|
||||
var goal, i, _i, _len, _ref, _results;
|
||||
_ref = this.options.goals;
|
||||
_results = [];
|
||||
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
|
||||
goal = _ref[i];
|
||||
_results.push(this.drawGoal("M" + this.left + "," + (this.transY(goal)) + "H" + (this.left + this.width)));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Grid.prototype.drawEvents = function() {
|
||||
var event, i, _i, _len, _ref, _results;
|
||||
_ref = this.events;
|
||||
_results = [];
|
||||
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
|
||||
event = _ref[i];
|
||||
_results.push(this.drawEvent("M" + (this.transX(event)) + "," + this.bottom + "V" + this.top));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
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.drawYAxisLabel(this.left - this.options.padding / 2, y, this.yAxisFormat(v));
|
||||
}
|
||||
if (this.options.grid) {
|
||||
_results.push(this.drawGridLine("M" + this.left + "," + y + "H" + (this.left + this.width)));
|
||||
} else {
|
||||
_results.push(void 0);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Grid.prototype.measureText = function(text, fontSize) {
|
||||
var ret, tt;
|
||||
if (fontSize == null) {
|
||||
@ -411,12 +366,59 @@
|
||||
}
|
||||
};
|
||||
|
||||
Grid.prototype.drawGoal = function(path) {
|
||||
return this.raphael.path(path).attr('stroke', this.options.goalLineColors[i % this.options.goalLineColors.length]).attr('stroke-width', this.options.goalStrokeWidth);
|
||||
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.drawYAxisLabel(this.left - this.options.padding / 2, y, this.yAxisFormat(v));
|
||||
}
|
||||
if (this.options.grid) {
|
||||
_results.push(this.drawGridLine("M" + this.left + "," + y + "H" + (this.left + this.width)));
|
||||
} else {
|
||||
_results.push(void 0);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Grid.prototype.drawEvent = function(path) {
|
||||
return this.raphael.path(path).attr('stroke', this.options.eventLineColors[i % this.options.eventLineColors.length]).attr('stroke-width', this.options.eventStrokeWidth);
|
||||
Grid.prototype.drawGoals = function() {
|
||||
var color, goal, i, _i, _len, _ref, _results;
|
||||
_ref = this.options.goals;
|
||||
_results = [];
|
||||
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
|
||||
goal = _ref[i];
|
||||
color = this.options.goalLineColors[i % this.options.goalLineColors.length];
|
||||
_results.push(this.drawGoal(goal, color));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Grid.prototype.drawEvents = function() {
|
||||
var color, event, i, _i, _len, _ref, _results;
|
||||
_ref = this.events;
|
||||
_results = [];
|
||||
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
|
||||
event = _ref[i];
|
||||
color = this.options.eventLineColors[i % this.options.eventLineColors.length];
|
||||
_results.push(this.drawEvent(event, color));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Grid.prototype.drawGoal = function(goal, color) {
|
||||
return this.raphael.path("M" + this.left + "," + (this.transY(goal)) + "H" + this.right).attr('stroke', color).attr('stroke-width', this.options.goalStrokeWidth);
|
||||
};
|
||||
|
||||
Grid.prototype.drawEvent = function(event, color) {
|
||||
return this.raphael.path("M" + (this.transX(event)) + "," + this.bottom + "V" + this.top).attr('stroke', color).attr('stroke-width', this.options.eventStrokeWidth);
|
||||
};
|
||||
|
||||
Grid.prototype.drawYAxisLabel = function(xPos, yPos, text) {
|
||||
|
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