mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-10 21:36:34 +01:00
Better decimal number support.
This commit is contained in:
parent
5ee41e16e2
commit
634179d9e8
30
examples/decimal.html
Normal file
30
examples/decimal.html
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<!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">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Decimal Data</h1>
|
||||||
|
<div id="graph"></div>
|
||||||
|
<pre id="code" class="prettyprint linenums">
|
||||||
|
var decimal_data = [];
|
||||||
|
for (var x = 0; x <= 360; x += 10) {
|
||||||
|
decimal_data.push({
|
||||||
|
x: x,
|
||||||
|
y: Math.sin(Math.PI * x / 180).toFixed(4)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
window.m = Morris.Line({
|
||||||
|
element: 'graph',
|
||||||
|
data: decimal_data,
|
||||||
|
xkey: 'x',
|
||||||
|
ykeys: ['y'],
|
||||||
|
labels: ['sin(x)']
|
||||||
|
});
|
||||||
|
</pre>
|
||||||
|
</body>
|
@ -348,7 +348,13 @@ class Morris.Line
|
|||||||
#
|
#
|
||||||
commas: (num) ->
|
commas: (num) ->
|
||||||
ret = if num < 0 then "-" else ""
|
ret = if num < 0 then "-" else ""
|
||||||
ret + Math.abs(num).toFixed(0).replace(/(?=(?:\d{3})+$)(?!^)/g, ',')
|
absnum = Math.abs(num)
|
||||||
|
intnum = Math.floor(absnum).toFixed(0)
|
||||||
|
ret += intnum.replace(/(?=(?:\d{3})+$)(?!^)/g, ',')
|
||||||
|
strabsnum = absnum.toString()
|
||||||
|
if strabsnum.length > intnum.length
|
||||||
|
ret += strabsnum.slice(intnum.length)
|
||||||
|
ret
|
||||||
|
|
||||||
window.Morris = Morris
|
window.Morris = Morris
|
||||||
# vim: set et ts=2 sw=2 sts=2
|
# vim: set et ts=2 sw=2 sts=2
|
||||||
|
@ -375,9 +375,14 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
Line.prototype.commas = function(num) {
|
Line.prototype.commas = function(num) {
|
||||||
var ret;
|
var absnum, intnum, ret, strabsnum;
|
||||||
ret = num < 0 ? "-" : "";
|
ret = num < 0 ? "-" : "";
|
||||||
return ret + Math.abs(num).toFixed(0).replace(/(?=(?:\d{3})+$)(?!^)/g, ',');
|
absnum = Math.abs(num);
|
||||||
|
intnum = Math.floor(absnum).toFixed(0);
|
||||||
|
ret += intnum.replace(/(?=(?:\d{3})+$)(?!^)/g, ',');
|
||||||
|
strabsnum = absnum.toString();
|
||||||
|
if (strabsnum.length > intnum.length) ret += strabsnum.slice(intnum.length);
|
||||||
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
return Line;
|
return Line;
|
||||||
|
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