mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-11 05:46:37 +01:00
Merge branch 'master' of https://github.com/peteralaoui/morris.js into peteralaoui-master
Conflicts: morris.min.js
This commit is contained in:
commit
2cce7c43de
31
examples/donut-stroke-color.html
Normal file
31
examples/donut-stroke-color.html
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<head>
|
||||||
|
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
||||||
|
<script src="https://raw.github.com/DmitryBaranovskiy/raphael/300aa589f5a0ba7fce667cd62c7cdda0bd5ad904/raphael-min.js"></script>
|
||||||
|
<script src="../morris.js"></script>
|
||||||
|
<script src="lib/prettify.js"></script>
|
||||||
|
<script src="lib/example.js"></script>
|
||||||
|
<link rel="stylesheet" href="lib/example.css">
|
||||||
|
<link rel="stylesheet" href="lib/prettify.css">
|
||||||
|
<link rel="stylesheet" href="../morris.css">
|
||||||
|
<style>
|
||||||
|
body { background:#ccc; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Donut Chart</h1>
|
||||||
|
<div id="graph"></div>
|
||||||
|
<pre id="code" class="prettyprint linenums">
|
||||||
|
Morris.Donut({
|
||||||
|
element: 'graph',
|
||||||
|
data: [
|
||||||
|
{value: 70, label: 'foo'},
|
||||||
|
{value: 15, label: 'bar'},
|
||||||
|
{value: 10, label: 'baz'},
|
||||||
|
{value: 5, label: 'A really really long label'}
|
||||||
|
],
|
||||||
|
strokeColor: '#ccc',
|
||||||
|
formatter: function (x) { return x + "%"}
|
||||||
|
});
|
||||||
|
</pre>
|
||||||
|
</body>
|
2
grunt.js
2
grunt.js
@ -50,7 +50,7 @@ module.exports = function (grunt) {
|
|||||||
|
|
||||||
grunt.loadNpmTasks('grunt-coffee');
|
grunt.loadNpmTasks('grunt-coffee');
|
||||||
grunt.loadNpmTasks('grunt-mocha');
|
grunt.loadNpmTasks('grunt-mocha');
|
||||||
grunt.loadNpmTasks('grunt-less');
|
grunt.loadNpmTasks('grunt-contrib-less');
|
||||||
|
|
||||||
grunt.registerTask('default', 'concat coffee less min mocha');
|
grunt.registerTask('default', 'concat coffee less min mocha');
|
||||||
};
|
};
|
||||||
|
@ -22,6 +22,7 @@ class Morris.Donut
|
|||||||
'#052C48'
|
'#052C48'
|
||||||
'#042135'
|
'#042135'
|
||||||
],
|
],
|
||||||
|
strokeColor: '#FFFFFF',
|
||||||
formatter: Morris.commas
|
formatter: Morris.commas
|
||||||
|
|
||||||
# Create and render a donut chart.
|
# Create and render a donut chart.
|
||||||
@ -71,7 +72,7 @@ class Morris.Donut
|
|||||||
@segments = []
|
@segments = []
|
||||||
for d in @data
|
for d in @data
|
||||||
next = last + min + C * (d.value / total)
|
next = last + min + C * (d.value / total)
|
||||||
seg = new Morris.DonutSegment(cx, cy, w*2, w, last, next, @options.colors[idx % @options.colors.length], d)
|
seg = new Morris.DonutSegment(cx, cy, w*2, w, last, next, @options.colors[idx % @options.colors.length], @options.strokeColor, d)
|
||||||
seg.render @r
|
seg.render @r
|
||||||
@segments.push seg
|
@segments.push seg
|
||||||
seg.on 'hover', @select
|
seg.on 'hover', @select
|
||||||
@ -114,7 +115,7 @@ class Morris.Donut
|
|||||||
#
|
#
|
||||||
# @private
|
# @private
|
||||||
class Morris.DonutSegment extends Morris.EventEmitter
|
class Morris.DonutSegment extends Morris.EventEmitter
|
||||||
constructor: (@cx, @cy, @inner, @outer, p0, p1, @color, @data) ->
|
constructor: (@cx, @cy, @inner, @outer, p0, p1, @color, @strokeColor, @data) ->
|
||||||
@sin_p0 = Math.sin(p0)
|
@sin_p0 = Math.sin(p0)
|
||||||
@cos_p0 = Math.cos(p0)
|
@cos_p0 = Math.cos(p0)
|
||||||
@sin_p1 = Math.sin(p1)
|
@sin_p1 = Math.sin(p1)
|
||||||
@ -150,7 +151,7 @@ class Morris.DonutSegment extends Morris.EventEmitter
|
|||||||
render: (r) ->
|
render: (r) ->
|
||||||
@arc = r.path(@hilight).attr(stroke: @color, 'stroke-width': 2, opacity: 0)
|
@arc = r.path(@hilight).attr(stroke: @color, 'stroke-width': 2, opacity: 0)
|
||||||
@seg = r.path(@path)
|
@seg = r.path(@path)
|
||||||
.attr(fill: @color, stroke: 'white', 'stroke-width': 3)
|
.attr(fill: @color, stroke: @strokeColor, 'stroke-width': 3)
|
||||||
.hover(=> @fire('hover', @))
|
.hover(=> @fire('hover', @))
|
||||||
|
|
||||||
select: =>
|
select: =>
|
||||||
|
14
morris.js
14
morris.js
@ -1304,6 +1304,7 @@
|
|||||||
|
|
||||||
Donut.prototype.defaults = {
|
Donut.prototype.defaults = {
|
||||||
colors: ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'],
|
colors: ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'],
|
||||||
|
strokeColor: '#FFFFFF',
|
||||||
formatter: Morris.commas
|
formatter: Morris.commas
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1350,7 +1351,7 @@
|
|||||||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||||
d = _ref1[_j];
|
d = _ref1[_j];
|
||||||
next = last + min + C * (d.value / total);
|
next = last + min + C * (d.value / total);
|
||||||
seg = new Morris.DonutSegment(cx, cy, w * 2, w, last, next, this.options.colors[idx % this.options.colors.length], d);
|
seg = new Morris.DonutSegment(cx, cy, w * 2, w, last, next, this.options.colors[idx % this.options.colors.length], this.options.strokeColor, d);
|
||||||
seg.render(this.r);
|
seg.render(this.r);
|
||||||
this.segments.push(seg);
|
this.segments.push(seg);
|
||||||
seg.on('hover', this.select);
|
seg.on('hover', this.select);
|
||||||
@ -1438,12 +1439,13 @@
|
|||||||
|
|
||||||
__extends(DonutSegment, _super);
|
__extends(DonutSegment, _super);
|
||||||
|
|
||||||
function DonutSegment(cx, cy, inner, outer, p0, p1, color, data) {
|
function DonutSegment(cx, cy, inner, outer, p0, p1, color, strokeColor, data) {
|
||||||
this.cx = cx;
|
this.cx = cx;
|
||||||
this.cy = cy;
|
this.cy = cy;
|
||||||
this.inner = inner;
|
this.inner = inner;
|
||||||
this.outer = outer;
|
this.outer = outer;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
this.strokeColor = strokeColor;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.deselect = __bind(this.deselect, this);
|
this.deselect = __bind(this.deselect, this);
|
||||||
|
|
||||||
@ -1453,7 +1455,7 @@
|
|||||||
this.cos_p0 = Math.cos(p0);
|
this.cos_p0 = Math.cos(p0);
|
||||||
this.sin_p1 = Math.sin(p1);
|
this.sin_p1 = Math.sin(p1);
|
||||||
this.cos_p1 = Math.cos(p1);
|
this.cos_p1 = Math.cos(p1);
|
||||||
this.long = (p1 - p0) > Math.PI ? 1 : 0;
|
this.is_long = (p1 - p0) > Math.PI ? 1 : 0;
|
||||||
this.path = this.calcSegment(this.inner + 3, this.inner + this.outer - 5);
|
this.path = this.calcSegment(this.inner + 3, this.inner + this.outer - 5);
|
||||||
this.selectedPath = this.calcSegment(this.inner + 3, this.inner + this.outer);
|
this.selectedPath = this.calcSegment(this.inner + 3, this.inner + this.outer);
|
||||||
this.hilight = this.calcArc(this.inner);
|
this.hilight = this.calcArc(this.inner);
|
||||||
@ -1467,13 +1469,13 @@
|
|||||||
var ix0, ix1, iy0, iy1, ox0, ox1, oy0, oy1, _ref, _ref1;
|
var ix0, ix1, iy0, iy1, ox0, ox1, oy0, oy1, _ref, _ref1;
|
||||||
_ref = this.calcArcPoints(r1), ix0 = _ref[0], iy0 = _ref[1], ix1 = _ref[2], iy1 = _ref[3];
|
_ref = this.calcArcPoints(r1), ix0 = _ref[0], iy0 = _ref[1], ix1 = _ref[2], iy1 = _ref[3];
|
||||||
_ref1 = this.calcArcPoints(r2), ox0 = _ref1[0], oy0 = _ref1[1], ox1 = _ref1[2], oy1 = _ref1[3];
|
_ref1 = this.calcArcPoints(r2), ox0 = _ref1[0], oy0 = _ref1[1], ox1 = _ref1[2], oy1 = _ref1[3];
|
||||||
return ("M" + ix0 + "," + iy0) + ("A" + r1 + "," + r1 + ",0," + this.long + ",0," + ix1 + "," + iy1) + ("L" + ox1 + "," + oy1) + ("A" + r2 + "," + r2 + ",0," + this.long + ",1," + ox0 + "," + oy0) + "Z";
|
return ("M" + ix0 + "," + iy0) + ("A" + r1 + "," + r1 + ",0," + this.is_long + ",0," + ix1 + "," + iy1) + ("L" + ox1 + "," + oy1) + ("A" + r2 + "," + r2 + ",0," + this.is_long + ",1," + ox0 + "," + oy0) + "Z";
|
||||||
};
|
};
|
||||||
|
|
||||||
DonutSegment.prototype.calcArc = function(r) {
|
DonutSegment.prototype.calcArc = function(r) {
|
||||||
var ix0, ix1, iy0, iy1, _ref;
|
var ix0, ix1, iy0, iy1, _ref;
|
||||||
_ref = this.calcArcPoints(r), ix0 = _ref[0], iy0 = _ref[1], ix1 = _ref[2], iy1 = _ref[3];
|
_ref = this.calcArcPoints(r), ix0 = _ref[0], iy0 = _ref[1], ix1 = _ref[2], iy1 = _ref[3];
|
||||||
return ("M" + ix0 + "," + iy0) + ("A" + r + "," + r + ",0," + this.long + ",0," + ix1 + "," + iy1);
|
return ("M" + ix0 + "," + iy0) + ("A" + r + "," + r + ",0," + this.is_long + ",0," + ix1 + "," + iy1);
|
||||||
};
|
};
|
||||||
|
|
||||||
DonutSegment.prototype.render = function(r) {
|
DonutSegment.prototype.render = function(r) {
|
||||||
@ -1485,7 +1487,7 @@
|
|||||||
});
|
});
|
||||||
return this.seg = r.path(this.path).attr({
|
return this.seg = r.path(this.path).attr({
|
||||||
fill: this.color,
|
fill: this.color,
|
||||||
stroke: 'white',
|
stroke: this.strokeColor,
|
||||||
'stroke-width': 3
|
'stroke-width': 3
|
||||||
}).hover(function() {
|
}).hover(function() {
|
||||||
return _this.fire('hover', _this);
|
return _this.fire('hover', _this);
|
||||||
|
2
morris.min.js
vendored
2
morris.min.js
vendored
File diff suppressed because one or more lines are too long
@ -17,6 +17,6 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"grunt-coffee": "~> 0.0.6",
|
"grunt-coffee": "~> 0.0.6",
|
||||||
"grunt-mocha": "~> 0.1.7",
|
"grunt-mocha": "~> 0.1.7",
|
||||||
"grunt-less": "~> 0.1.7"
|
"grunt-contrib-less": "~> 0.3.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user