Permalink
Browse files

Change the data format from [x,y] to {x:x,y:y}. This allows us to do …

…things like {x:x,y:y,delta:d} without having to 'hack' extra data in. This is especially handy for access inside hints. You can use datapoint.whatever for whatever you like. Backwards compatibility is kept with the old data format (it will get normalized inside the library to the new style).

This commit also fixes/changes a couple of the examples to demonstrate/make them work (in the case of deltas, for example).
  • Loading branch information...
1 parent 48e28c1 commit dff86444cda0856012347576179228eb92f32cb7 @rfunduk committed Aug 18, 2008
Showing with 138 additions and 152 deletions.
  1. +26 −24 examples/basic.html
  2. +3 −3 examples/big-data.html
  3. +6 −7 examples/graph-types.html
  4. +15 −4 examples/interacting.html
  5. +88 −114 jquery.flot.js
View
@@ -1,38 +1,40 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+
<html>
- <head>
+ <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css"></link>
<!--[if IE]><script language="javascript" type="text/javascript" src="../excanvas.pack.js"></script><![endif]-->
- <script language="javascript" type="text/javascript" src="../jquery.js"></script>
+ <script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
- </head>
- <body>
- <h1>Flot Examples</h1>
-
- <div id="placeholder" style="width:600px;height:300px;"></div>
+ <script type="text/javascript">
+ $(document).ready( function () {
+ var d1 = [];
+ for( var i = 0; i < 14; i += 0.5 ) {
+ d1.push( { x: i, y: Math.sin(i) } );
+ }
- <p>Simple example. You don't need to specify much to get an
- attractive look. Put in a placeholder, make sure you set its
- dimensions (otherwise the plot library will barf) and call the
- plot function with the data. The axes are automatically
- scaled.</p>
+ var d2 = [ [0, 3], [4, 8], [8, 5], [9, 13] ];
-<script id="source" language="javascript" type="text/javascript">
-$(function () {
- var d1 = [];
- for (var i = 0; i < 14; i += 0.5)
- d1.push([i, Math.sin(i)]);
+ // a null signifies separate line segments
+ var d3 = [[0, 12], [7, 12], null, [7, 2.5], [12, 2.5]];
- var d2 = [[0, 3], [4, 8], [8, 5], [9, 13]];
+ $.plot( $("#placeholder"), [ d1, d2, d3 ] );
+ } );
+ </script>
+ </head>
+ <body>
+ <h1>Flot Examples</h1>
- // a null signifies separate line segments
- var d3 = [[0, 12], [7, 12], null, [7, 2.5], [12, 2.5]];
-
- $.plot($("#placeholder"), [ d1, d2, d3 ]);
-});
-</script>
+ <div id="placeholder" style="width:600px;height:300px;"></div>
+ <p>
+ Simple example. You don't need to specify much to get an
+ attractive look. Put in a placeholder, make sure you set its
+ dimensions (otherwise the plot library will barf) and call the
+ plot function with the data. The axes are automatically
+ scaled.
+ </p>
</body>
</html>
View
@@ -47,8 +47,8 @@
function labelFormatter(label) {
return "<span style='font-size:0.8em;'>" + label + "</span>";
},
- hintFormatter: function hintFormatter(x, y) {
- var datetime = new Date(x);
+ hintFormatter: function hintFormatter( datapoint ) {
+ var datetime = new Date( datapoint.x );
var hour = datetime.getHours();
var minute = datetime.getMinutes();
@@ -60,7 +60,7 @@
return "<table><tr><td><strong>Time:</strong></td><td>" +
datetime.toDateString() + "<br/>@" + time + "</td></tr>" +
"<tr><td><strong>Value:</strong></td><td>" +
- y.toFixed(2) + "</td></tr></table>";
+ datapoint.y.toFixed(2) + "</td></tr></table>";
}
}
};
View
@@ -23,7 +23,7 @@
for (var i = 0; i < 14; i += 0.5)
d1.push([i, Math.sin(i)]);
- var d2 = [[0, 3], [5, 8], [8, 5], [10, 13]];
+ var d2 = [ [8, 5], [0, 3], [10, 13], [5, 8] ];
var d3 = [];
for (var i = 0; i < 14; i += 0.5)
@@ -37,11 +37,10 @@
for (var i = 0; i < 14; i += 0.5)
d5.push([i, Math.sqrt(i)]);
-
var d6 = [];
for (var i = 0; i < 14; i += 0.5)
- d6.push([i, Math.round(Math.sin(i)+5.5), (i%2+6)]);
- d6.push([14,6,2]);
+ d6.push( { x: i, y: Math.round(Math.sin(i)+5.5), delta: (i%2+6) } );
+ d6.push( { x: 14, y: 6, delta: 2 } );
$.plot($("#placeholder"), [
{
@@ -62,16 +61,16 @@
},
{
data: d5,
- lines: { show: true },
- points: { show: true }
+ lines: { show: false },
+ points: { show: true, radius: 7 }
},
{
data: d6,
deltas: {
show: true,
markerWidth: 4,
color: {
- above: "red",
+ above: "black",
below: "transparent",
equal: "blue"
}
View
@@ -19,19 +19,30 @@
$(function () {
var d1 = [];
for (var i = 0; i < 14; i += 0.5)
- d1.push([i, Math.sin(i)]);
+ d1.push( { x: i, y: Math.sin(i) } );
var d2 = [];
for (var i = 0; i < 14; i += 0.5)
- d2.push([i, Math.cos(i)]);
+ d2.push( { x: i, y: Math.cos(i) } );
plot = $.plot($("#placeholder"), [ { data: d1, label: "Yellow" },
{ data: d2, label: "Blue" } ], {
- hints: { show: true },
+ hints: {
+ show: true,
+ hintFormatter: function( datapoint ) {
+ hintStr = "";
+ for( var key in datapoint ) {
+ if( key[0] == '_' ) { continue; } // skip internal members
+ hintStr += "<strong>" + key + ":</strong> " +
+ datapoint[key].toFixed(2) + "<br/>";
+ }
+ return hintStr;
+ }
+ },
points: { show: true },
lines: { show: true },
legend: { position: 'sw' },
- grid: {
+ grid: {
clickable: true,
hoverable: true,
hoverFill: '#444',
Oops, something went wrong.

0 comments on commit dff8644

Please sign in to comment.