Merge branch 'master' of github.com:oesmith/morris.js

Conflicts:
	morris.min.js
This commit is contained in:
Olly Smith 2012-09-26 21:30:25 +01:00
commit 9bb723057f
6 changed files with 43 additions and 34 deletions

View File

@ -1,10 +1,8 @@
language: node_js
node_js:
- 0.6
- 0.8
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- "npm install -g grunt"
- "npm install"
script:
- "DISPLAY=:99.0 grunt"
- "grunt coffee mocha"

View File

@ -19,7 +19,8 @@ Morris.Donut({
{value: 15, label: 'bar'},
{value: 10, label: 'baz'},
{value: 5, label: 'A really really long label'}
]
],
formatter: function (x) { return x + "%"}
});
</pre>
</body>

View File

@ -9,18 +9,20 @@
# ]
# });
class Morris.Donut
colors: [
'#0B62A4'
'#3980B5'
'#679DC6'
'#95BBD7'
'#B0CCE1'
'#095791'
'#095085'
'#083E67'
'#052C48'
'#042135'
]
defaults:
colors: [
'#0B62A4'
'#3980B5'
'#679DC6'
'#95BBD7'
'#B0CCE1'
'#095791'
'#095085'
'#083E67'
'#052C48'
'#042135'
],
formatter: Morris.commas
# Create and render a donut chart.
#
@ -33,8 +35,7 @@ class Morris.Donut
else
@el = $ options.element
if options.colors?
@colors = options.colors
@options = $.extend {}, @defaults, options
if @el == null || @el.length == 0
throw new Error("Graph placeholder not found.")
@ -72,7 +73,7 @@ class Morris.Donut
@segments = []
for d in @data
next = last + min + C * (d.value / total)
seg = new Morris.DonutSegment(cx, cy, w*2, w, last, next, @colors[idx % @colors.length], d)
seg = new Morris.DonutSegment(cx, cy, w*2, w, last, next, @options.colors[idx % @options.colors.length], d)
seg.render @r
@segments.push seg
seg.on 'hover', @select
@ -92,7 +93,7 @@ class Morris.Donut
select: (segment) =>
s.deselect() for s in @segments
segment.select()
@setLabels segment.data.label, Morris.commas(segment.data.value)
@setLabels segment.data.label, @options.formatter(segment.data.value)
# @private
setLabels: (label1, label2) ->

View File

@ -283,7 +283,7 @@ class Morris.Line
if coords.length > 1
path = @createPath coords, @options.marginTop, @left, @options.marginTop + @height, @left + @width
@r.path(path)
.attr('stroke', @options.lineColors[i])
.attr('stroke', @colorForSeries(i))
.attr('stroke-width', @options.lineWidth)
@seriesPoints = ([] for i in [0..@seriesCoords.length-1])
for i in [@seriesCoords.length-1..0]
@ -292,7 +292,7 @@ class Morris.Line
circle = null
else
circle = @r.circle(c.x, c.y, @options.pointSize)
.attr('fill', @options.lineColors[i])
.attr('fill', @colorForSeries(i))
.attr('stroke-width', 1)
.attr('stroke', '#ffffff')
@seriesPoints[i].push(circle)
@ -355,7 +355,7 @@ class Morris.Line
@yLabels = []
for i in [0..@series.length-1]
yLabel = @r.text(0, @options.hoverFontSize * 1.5 * (i + 1.5) - @hoverHeight / 2, '')
.attr('fill', @options.lineColors[i])
.attr('fill', @colorForSeries(i))
.attr('font-size', @options.hoverFontSize)
@yLabels.push(yLabel)
@hoverSet.push(yLabel)
@ -423,6 +423,10 @@ class Morris.Line
yLabelFormat: (label) ->
"#{@options.preUnits}#{Morris.commas(label)}#{@options.postUnits}"
# @private
colorForSeries: (index) ->
@options.lineColors[index % @options.lineColors.length]
# Parse a date into a javascript timestamp
#

View File

@ -64,7 +64,10 @@
Morris.Donut = (function() {
Donut.prototype.colors = ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'];
Donut.prototype.defaults = {
colors: ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'],
formatter: Morris.commas
};
function Donut(options) {
this.select = __bind(this.select, this);
@ -76,9 +79,7 @@
} else {
this.el = $(options.element);
}
if (options.colors != null) {
this.colors = options.colors;
}
this.options = $.extend({}, this.defaults, options);
if (this.el === null || this.el.length === 0) {
throw new Error("Graph placeholder not found.");
}
@ -112,7 +113,7 @@
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
d = _ref1[_j];
next = last + min + C * (d.value / total);
seg = new Morris.DonutSegment(cx, cy, w * 2, w, last, next, this.colors[idx % this.colors.length], d);
seg = new Morris.DonutSegment(cx, cy, w * 2, w, last, next, this.options.colors[idx % this.options.colors.length], d);
seg.render(this.r);
this.segments.push(seg);
seg.on('hover', this.select);
@ -158,7 +159,7 @@
s.deselect();
}
segment.select();
return this.setLabels(segment.data.label, Morris.commas(segment.data.value));
return this.setLabels(segment.data.label, this.options.formatter(segment.data.value));
};
Donut.prototype.setLabels = function(label1, label2) {
@ -604,7 +605,7 @@
});
if (coords.length > 1) {
path = this.createPath(coords, this.options.marginTop, this.left, this.options.marginTop + this.height, this.left + this.width);
this.r.path(path).attr('stroke', this.options.lineColors[i]).attr('stroke-width', this.options.lineWidth);
this.r.path(path).attr('stroke', this.colorForSeries(i)).attr('stroke-width', this.options.lineWidth);
}
}
this.seriesPoints = (function() {
@ -626,7 +627,7 @@
if (c === null) {
circle = null;
} else {
circle = this.r.circle(c.x, c.y, this.options.pointSize).attr('fill', this.options.lineColors[i]).attr('stroke-width', 1).attr('stroke', '#ffffff');
circle = this.r.circle(c.x, c.y, this.options.pointSize).attr('fill', this.colorForSeries(i)).attr('stroke-width', 1).attr('stroke', '#ffffff');
}
_results1.push(this.seriesPoints[i].push(circle));
}
@ -688,7 +689,7 @@
this.yLabels = [];
_results = [];
for (i = _i = 0, _ref = this.series.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
yLabel = this.r.text(0, this.options.hoverFontSize * 1.5 * (i + 1.5) - this.hoverHeight / 2, '').attr('fill', this.options.lineColors[i]).attr('font-size', this.options.hoverFontSize);
yLabel = this.r.text(0, this.options.hoverFontSize * 1.5 * (i + 1.5) - this.hoverHeight / 2, '').attr('fill', this.colorForSeries(i)).attr('font-size', this.options.hoverFontSize);
this.yLabels.push(yLabel);
_results.push(this.hoverSet.push(yLabel));
}
@ -781,6 +782,10 @@
return "" + this.options.preUnits + (Morris.commas(label)) + this.options.postUnits;
};
Line.prototype.colorForSeries = function(index) {
return this.options.lineColors[index % this.options.lineColors.length];
};
return Line;
})();

2
morris.min.js vendored

File diff suppressed because one or more lines are too long