Skip to content

Commit

Permalink
Change the data format from [x,y] to {x:x,y:y}. This allows us to do …
Browse files Browse the repository at this point in the history
…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
rfunduk committed Aug 18, 2008
1 parent 48e28c1 commit dff8644
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 152 deletions.
50 changes: 26 additions & 24 deletions examples/basic.html
@@ -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>
6 changes: 3 additions & 3 deletions examples/big-data.html
Expand Up @@ -47,8 +47,8 @@ <h1>Flot Examples</h1>
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();
Expand All @@ -60,7 +60,7 @@ <h1>Flot Examples</h1>
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>";
}
}
};
Expand Down
13 changes: 6 additions & 7 deletions examples/graph-types.html
Expand Up @@ -23,7 +23,7 @@ <h1>Flot Examples</h1>
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)
Expand All @@ -37,11 +37,10 @@ <h1>Flot Examples</h1>
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"), [
{
Expand All @@ -62,16 +61,16 @@ <h1>Flot Examples</h1>
},
{
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"
}
Expand Down
19 changes: 15 additions & 4 deletions examples/interacting.html
Expand Up @@ -19,19 +19,30 @@ <h1>Flot Examples</h1>
$(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',
Expand Down

0 comments on commit dff8644

Please sign in to comment.