From cb2e3d2743c0f88b430f14b7a396aa1a583dc978 Mon Sep 17 00:00:00 2001 From: Igor Sfiligoi Date: Tue, 22 Mar 2011 07:30:12 -0400 Subject: flot-0.7 --- API.txt | 301 +- FAQ.txt | 23 +- Makefile | 10 +- NEWS.txt | 170 +- PLUGINS.txt | 68 +- README.txt | 25 +- examples/ajax.html | 6 +- examples/annotating.html | 6 +- examples/basic.html | 6 +- examples/data-eu-gdp-growth-1.json | 4 +- examples/data-eu-gdp-growth-2.json | 4 +- examples/data-eu-gdp-growth-3.json | 4 +- examples/data-eu-gdp-growth-4.json | 4 +- examples/data-eu-gdp-growth-5.json | 4 +- examples/data-eu-gdp-growth.json | 4 +- examples/data-japan-gdp-growth.json | 4 +- examples/data-usa-gdp-growth.json | 4 +- examples/dual-axis.html | 39 - examples/graph-types.html | 6 +- examples/image.html | 6 +- examples/index.html | 17 +- examples/interacting-axes.html | 97 + examples/interacting.html | 10 +- examples/multiple-axes.html | 60 + examples/navigate.html | 8 +- examples/percentiles.html | 57 + examples/pie.html | 756 +++ examples/realtime.html | 83 + examples/resize.html | 61 + examples/selection.html | 10 +- examples/setting-options.html | 18 +- examples/stacking.html | 6 +- examples/symbols.html | 49 + examples/thresholding.html | 6 +- examples/time.html | 12 +- examples/tracking.html | 6 +- examples/turning-series.html | 6 +- examples/visitors.html | 6 +- examples/zooming.html | 14 +- jquery.colorhelpers.js | 39 +- jquery.colorhelpers.min.js | 2 +- jquery.flot.crosshair.js | 71 +- jquery.flot.crosshair.min.js | 2 +- jquery.flot.fillbetween.js | 183 + jquery.flot.fillbetween.min.js | 1 + jquery.flot.image.js | 179 +- jquery.flot.image.min.js | 2 +- jquery.flot.js | 1416 +++-- jquery.flot.min.js | 7 +- jquery.flot.navigate.js | 292 +- jquery.flot.navigate.min.js | 2 +- jquery.flot.pie.js | 750 +++ jquery.flot.pie.min.js | 1 + jquery.flot.resize.js | 60 + jquery.flot.resize.min.js | 1 + jquery.flot.selection.js | 149 +- jquery.flot.selection.min.js | 2 +- jquery.flot.stack.js | 84 +- jquery.flot.stack.min.js | 2 +- jquery.flot.symbol.js | 70 + jquery.flot.symbol.min.js | 1 + jquery.js | 10514 +++++++++++++++++++++++----------- jquery.min.js | 24 +- 63 files changed, 11497 insertions(+), 4337 deletions(-) delete mode 100644 examples/dual-axis.html create mode 100644 examples/interacting-axes.html create mode 100644 examples/multiple-axes.html create mode 100644 examples/percentiles.html create mode 100644 examples/pie.html create mode 100644 examples/realtime.html create mode 100644 examples/resize.html create mode 100644 examples/symbols.html create mode 100644 jquery.flot.fillbetween.js create mode 100644 jquery.flot.fillbetween.min.js create mode 100644 jquery.flot.pie.js create mode 100644 jquery.flot.pie.min.js create mode 100644 jquery.flot.resize.js create mode 100644 jquery.flot.resize.min.js create mode 100644 jquery.flot.symbol.js create mode 100644 jquery.flot.symbol.min.js diff --git a/API.txt b/API.txt index bd0c663..8a8dbc2 100644 --- a/API.txt +++ b/API.txt @@ -15,8 +15,8 @@ you apply to the div, e.g. background images have been reported to be a problem on IE 7. The format of the data is documented below, as is the available -options. The "plot" object returned has some methods you can call. -These are documented separately below. +options. The plot object returned from the call has some methods you +can call. These are documented separately below. Note that in general Flot gives no guarantees if you change any of the objects you pass in to the plot function or get out of it since @@ -52,8 +52,9 @@ drawing. As a special case, a null value for lines is interpreted as a line segment end, i.e. the points before and after the null value are not connected. -Lines and points take two coordinates. For bars, you can specify a -third coordinate which is the bottom of the bar (defaults to 0). +Lines and points take two coordinates. For filled lines and bars, you +can specify a third coordinate which is the bottom of the filled +area/bar (defaults to 0). The format of a single series object is as follows: @@ -64,8 +65,8 @@ The format of a single series object is as follows: lines: specific lines options bars: specific bars options points: specific points options - xaxis: 1 or 2 - yaxis: 1 or 2 + xaxis: number + yaxis: number clickable: boolean hoverable: boolean shadowSize: number @@ -92,10 +93,9 @@ The latter is mostly useful if you let the user add and remove series, in which case you can hard-code the color index to prevent the colors from jumping around between the series. -The "xaxis" and "yaxis" options specify which axis to use, specify 2 -to get the secondary axis (x axis at top or y axis to the right). -E.g., you can use this to make a dual axis plot by specifying -{ yaxis: 2 } for one data series. +The "xaxis" and "yaxis" options specify which axis to use. The axes +are numbered from 1 (default), so { yaxis: 2} means that the series +should be plotted against the second y axis. "clickable" and "hoverable" can be set to false to disable interactivity for specific series if interactivity is turned on in @@ -171,15 +171,18 @@ ignored. Note that Flot will overwrite the contents of the container. Customizing the axes ==================== - xaxis, yaxis, x2axis, y2axis: { + xaxis, yaxis: { + show: null or true/false + position: "bottom" or "top" or "left" or "right" mode: null or "time" + + color: null or color spec + tickColor: null or color spec + min: null or number max: null or number autoscaleMargin: null or number - labelWidth: null or number - labelHeight: null or number - transform: null or fn: number -> number inverseTransform: null or fn: number -> number @@ -188,27 +191,51 @@ Customizing the axes minTickSize: number or array tickFormatter: (fn: number, object -> string) or string tickDecimals: null or number + + labelWidth: null or number + labelHeight: null or number + reserveSpace: null or true + + tickLength: null or number + + alignTicksWithAxis: null or number } -All axes have the same kind of options. The "mode" option -determines how the data is interpreted, the default of null means as -decimal numbers. Use "time" for time series data, see the next section. +All axes have the same kind of options. The following describes how to +configure one axis, see below for what to do if you've got more than +one x axis or y axis. + +If you don't set the "show" option (i.e. it is null), visibility is +auto-detected, i.e. the axis will show up if there's data associated +with it. You can override this by setting the "show" option to true or +false. + +The "position" option specifies where the axis is placed, bottom or +top for x axes, left or right for y axes. The "mode" option determines +how the data is interpreted, the default of null means as decimal +numbers. Use "time" for time series data, see the time series data +section. + +The "color" option determines the color of the labels and ticks for +the axis (default is the grid color). For more fine-grained control +you can also set the color of the ticks separately with "tickColor" +(otherwise it's autogenerated as the base color with some +transparency). The options "min"/"max" are the precise minimum/maximum value on the scale. If you don't specify either of them, a value will automatically -be chosen based on the minimum/maximum data values. +be chosen based on the minimum/maximum data values. Note that Flot +always examines all the data values you feed to it, even if a +restriction on another axis may make some of them invisible (this +makes interactive use more stable). The "autoscaleMargin" is a bit esoteric: it's the fraction of margin that the scaling algorithm will add to avoid that the outermost points -ends up on the grid border. Note that this margin is only applied -when a min or max value is not explicitly set. If a margin is -specified, the plot will furthermore extend the axis end-point to the -nearest whole tick. The default value is "null" for the x axis and -0.02 for the y axis which seems appropriate for most cases. - -"labelWidth" and "labelHeight" specifies a fixed size of the tick -labels in pixels. They're useful in case you need to align several -plots. +ends up on the grid border. Note that this margin is only applied when +a min or max value is not explicitly set. If a margin is specified, +the plot will furthermore extend the axis end-point to the nearest +whole tick. The default value is "null" for the x axes and 0.02 for y +axes which seems appropriate for most cases. "transform" and "inverseTransform" are callbacks you can put in to change the way the data is drawn. You can design a function to @@ -223,8 +250,16 @@ into a natural logarithm axis with the following code: inverseTransform: function (v) { return Math.exp(v); } } +Similarly, for reversing the y axis so the values appear in inverse +order: + + yaxis: { + transform: function (v) { return -v; }, + inverseTransform: function (v) { return -v; } + } + Note that for finding extrema, Flot assumes that the transform -function does not reorder values (monotonicity is assumed). +function does not reorder values (it should be monotone). The inverseTransform is simply the inverse of the transform function (so v == inverseTransform(transform(v)) for all relevant v). It is @@ -281,13 +316,12 @@ axis for trigonometric functions: return res; } - You can control how the ticks look like with "tickDecimals", the number of decimals to display (default is auto-detected). -Alternatively, for ultimate control over how ticks look like you can +Alternatively, for ultimate control over how ticks are formatted you can provide a function to "tickFormatter". The function is passed two -parameters, the tick value and an "axis" object with information, and +parameters, the tick value and an axis object with information, and should return a string. The default formatter looks like this: function formatter(val, axis) { @@ -309,6 +343,59 @@ an example of a custom formatter: return val.toFixed(axis.tickDecimals) + " B"; } +"labelWidth" and "labelHeight" specifies a fixed size of the tick +labels in pixels. They're useful in case you need to align several +plots. "reserveSpace" means that even if an axis isn't shown, Flot +should reserve space for it - it is useful in combination with +labelWidth and labelHeight for aligning multi-axis charts. + +"tickLength" is the length of the tick lines in pixels. By default, the +innermost axes will have ticks that extend all across the plot, while +any extra axes use small ticks. A value of null means use the default, +while a number means small ticks of that length - set it to 0 to hide +the lines completely. + +If you set "alignTicksWithAxis" to the number of another axis, e.g. +alignTicksWithAxis: 1, Flot will ensure that the autogenerated ticks +of this axis are aligned with the ticks of the other axis. This may +improve the looks, e.g. if you have one y axis to the left and one to +the right, because the grid lines will then match the ticks in both +ends. The trade-off is that the forced ticks won't necessarily be at +natural places. + + +Multiple axes +============= + +If you need more than one x axis or y axis, you need to specify for +each data series which axis they are to use, as described under the +format of the data series, e.g. { data: [...], yaxis: 2 } specifies +that a series should be plotted against the second y axis. + +To actually configure that axis, you can't use the xaxis/yaxis options +directly - instead there are two arrays in the options: + + xaxes: [] + yaxes: [] + +Here's an example of configuring a single x axis and two y axes (we +can leave options of the first y axis empty as the defaults are fine): + + { + xaxes: [ { position: "top" } ], + yaxes: [ { }, { position: "right", min: 20 } ] + } + +The arrays get their default values from the xaxis/yaxis settings, so +say you want to have all y axes start at zero, you can simply specify +yaxis: { min: 0 } instead of adding a min parameter to all the axes. + +Generally, the various interfaces in Flot dealing with data points +either accept an xaxis/yaxis parameter to specify which axis number to +use (starting from 1), or lets you specify the coordinate directly as +x2/x3/... or x2axis/x3axis/... instead of "x" or "xaxis". + + Time series data ================ @@ -396,13 +483,17 @@ specifiers are supported %H: hours (left-padded with a zero) %M: minutes (left-padded with a zero) %S: seconds (left-padded with a zero) - %d: day of month (1-31) - %m: month (1-12) + %d: day of month (1-31), use %0d for zero-padding + %m: month (1-12), use %0m for zero-padding %y: year (four digits) %b: month name (customizable) %p: am/pm, additionally switches %h/%H to 12 hour instead of 24 %P: AM/PM (uppercase version of %p) +Inserting a zero like %0m or %0d means that the specifier will be +left-padded with a zero if it's only single-digit. So %y-%0m-%0d +results in unambigious ISO timestamps like 2007-05-10 (for May 10th). + You can customize the month names with the "monthNames" option. For instance, for Danish you might specify: @@ -453,6 +544,7 @@ Customizing the data series points: { radius: number + symbol: "circle" or function } bars: { @@ -479,7 +571,7 @@ The most important options are "lines", "points" and "bars" that specify whether and how lines, points and bars should be shown for each data series. In case you don't specify anything at all, Flot will default to showing lines (you can turn this off with -lines: { show: false}). You can specify the various types +lines: { show: false }). You can specify the various types independently of each other, and Flot will happily draw each of them in turn (this is probably only useful for lines and points), e.g. @@ -519,6 +611,26 @@ connected with a straight (possibly diagonal) line or with first a horizontal and then a vertical line. Note that this transforms the data by adding extra points. +For points, you can specify the radius and the symbol. The only +built-in symbol type is circles, for other types you can use a plugin +or define them yourself by specifying a callback: + + function cross(ctx, x, y, radius, shadow) { + var size = radius * Math.sqrt(Math.PI) / 2; + ctx.moveTo(x - size, y - size); + ctx.lineTo(x + size, y + size); + ctx.moveTo(x - size, y + size); + ctx.lineTo(x + size, y - size); + } + +The parameters are the drawing context, x and y coordinates of the +center of the point, a radius which corresponds to what the circle +would have used and whether the call is to draw a shadow (due to +limited canvas support, shadows are currently faked through extra +draws). It's good practice to ensure that the area covered by the +symbol is the same as for the circle with the given radius, this +ensures that all symbols have approximately the same visual weight. + "shadowSize" is the default size of shadows in pixels. Set it to 0 to remove shadows. @@ -540,40 +652,48 @@ Customizing the grid aboveData: boolean color: color backgroundColor: color/gradient or null - tickColor: color labelMargin: number + axisMargin: number markings: array of markings or (fn: axes -> array of markings) borderWidth: number borderColor: color or null + minBorderMargin: number or null clickable: boolean hoverable: boolean autoHighlight: boolean mouseActiveRadius: number } -The grid is the thing with the axes and a number of ticks. "color" is -the color of the grid itself whereas "backgroundColor" specifies the -background color inside the grid area. The default value of null means +The grid is the thing with the axes and a number of ticks. Many of the +things in the grid are configured under the individual axes, but not +all. "color" is the color of the grid itself whereas "backgroundColor" +specifies the background color inside the grid area, here null means that the background is transparent. You can also set a gradient, see the gradient documentation below. You can turn off the whole grid including tick labels by setting -"show" to false. "aboveData" determines whether the grid is drawn on +"show" to false. "aboveData" determines whether the grid is drawn above the data or below (below is default). -"tickColor" is the color of the ticks and "labelMargin" is the spacing -between tick labels and the grid. Note that you can style the tick -labels with CSS, e.g. to change the color. They have class "tickLabel". +"labelMargin" is the space in pixels between tick labels and axis +line, and "axisMargin" is the space in pixels between axes when there +are two next to each other. Note that you can style the tick labels +with CSS, e.g. to change the color. They have class "tickLabel". + "borderWidth" is the width of the border around the plot. Set it to 0 to disable the border. You can also set "borderColor" if you want the border to have a different color than the grid lines. +"minBorderMargin" controls the default minimum margin around the +border - it's used to make sure that points aren't accidentally +clipped by the canvas edge so by default the value is computed from +the point radius. "markings" is used to draw simple lines and rectangular areas in the background of the plot. You can either specify an array of ranges on -the form { xaxis: { from, to }, yaxis: { from, to } } (secondary axis -coordinates with x2axis/y2axis) or with a function that returns such -an array given the axes for the plot in an object as the first -parameter. +the form { xaxis: { from, to }, yaxis: { from, to } } (with multiple +axes, you can specify coordinates for other axes instead, e.g. as +x2axis/x3axis/...) or with a function that returns such an array given +the axes for the plot in an object as the first parameter. You can set the color of markings by specifying "color" in the ranges object. Here's an example array: @@ -592,7 +712,7 @@ A line is drawn if from and to are the same, e.g. would draw a line parallel to the x axis at y = 1. You can control the line width with "lineWidth" in the range object. -An example function might look like this: +An example function that makes vertical stripes might look like this: markings: function (axes) { var markings = []; @@ -621,7 +741,7 @@ You can use "plotclick" and "plothover" events like this: $("#placeholder").bind("plotclick", function (event, pos, item) { alert("You clicked at " + pos.x + ", " + pos.y); - // secondary axis coordinates if present are in pos.x2, pos.y2, + // axis coordinates for other axes, if present, are in pos.x2, pos.x3, ... // if you need global screen coordinates, they are pos.pageX, pos.pageY if (item) { @@ -757,7 +877,8 @@ can call: interactive things like a selection and point highlights. This is mostly useful for writing plugins. The redraw doesn't happen immediately, instead a timer is set to catch multiple successive - redraws (e.g. from a mousemove). + redraws (e.g. from a mousemove). You can get to the overlay by + setting up a drawOverlay hook. - width()/height() @@ -775,12 +896,24 @@ can call: - pointOffset({ x: xpos, y: ypos }) Returns the calculated offset of the data point at (x, y) in data - space within the placeholder div. If you are working with dual axes, you + space within the placeholder div. If you are working with multiple axes, you can specify the x and y axis references, e.g. - o = pointOffset({ x: xpos, y: ypos, xaxis: 2, yaxis: 2 }) + o = pointOffset({ x: xpos, y: ypos, xaxis: 2, yaxis: 3 }) // o.left and o.top now contains the offset within the div - + + - resize() + + Tells Flot to resize the drawing canvas to the size of the + placeholder. You need to run setupGrid() and draw() afterwards as + canvas resizing is a destructive operation. This is used + internally by the resize plugin. + + - shutdown() + + Cleans up any event handlers Flot has currently registered. This + is used internally. + There are also some members that let you peek inside the internal workings of Flot which is useful in some cases. Note that if you change @@ -806,14 +939,22 @@ Flot to keep track of its state, so be careful. - getAxes() - Gets an object with the axes settings as { xaxis, yaxis, x2axis, - y2axis }. + Gets an object with the axes. The axes are returned as the + attributes of the object, so for instance getAxes().xaxis is the + x axis. Various things are stuffed inside an axis object, e.g. you could use getAxes().xaxis.ticks to find out what the ticks are for the xaxis. Two other useful attributes are p2c and c2p, functions for transforming from data point space to the canvas plot space and back. Both returns values that are offset with the plot offset. + Check the Flot source code for the complete set of attributes (or + output an axis with console.log() and inspect it). + + With multiple axes, the extra axes are returned as x2axis, x3axis, + etc., e.g. getAxes().y2axis is the second y axis. You can check + y2axis.used to see whether the axis is associated with any data + points and y2axis.show to see if it is currently shown. - getPlaceholder() @@ -835,8 +976,11 @@ Flot to keep track of its state, so be careful. - getOptions() - Gets the options for the plot, in a normalized format with default - values filled in. + Gets the options for the plot, normalized, with default values + filled in. You get a reference to actual values used by Flot, so + if you modify the values in here, Flot will use the new values. + If you change something, you probably have to call draw() or + setupGrid() or triggerRedrawOverlay() to see the change. Hooks @@ -866,6 +1010,8 @@ Here's an overview of the phases Flot goes through: 7. Responding to events, if any + 8. Shutdown: this mostly happens in case a plot is overwritten + Each hook is simply a function which is put in the appropriate array. You can add them through the "hooks" option, and they are also available after the plot is constructed as the "hooks" attribute on the returned @@ -945,14 +1091,23 @@ hooks in the plugins bundled with Flot. doesn't check it or do any normalization on it afterwards. + - drawSeries [phase 5] + + function(plot, canvascontext, series) + + Hook for custom drawing of a single series. Called just before the + standard drawing routine has been called in the loop that draws + each series. + + - draw [phase 5] function(plot, canvascontext) Hook for drawing on the canvas. Called after the grid is drawn - (unless it's disabled) and the series have been plotted (in case - any points, lines or bars have been turned on). For examples of how - to draw things, look at the source code. + (unless it's disabled or grid.aboveData is set) and the series have + been plotted (in case any points, lines or bars have been turned + on). For examples of how to draw things, look at the source code. - bindEvents [phase 6] @@ -981,6 +1136,12 @@ hooks in the plugins bundled with Flot. order wrong. The hook only gets one event, though (either for the overlay or for the static canvas). + Note that custom plot events generated by Flot are not generated on + eventHolder, but on the div placeholder supplied as the first + argument to the plot call. You can get that with + plot.getPlaceholder() - that's probably also the one you should use + if you need to fire a custom event. + - drawOverlay [phase 7] @@ -999,6 +1160,16 @@ hooks in the plugins bundled with Flot. crosshair plugin for an example. + - shutdown [phase 8] + + function (plot, eventHolder) + + Run when plot.shutdown() is called, which usually only happens in + case a plot is overwritten by a new plot. If you're writing a + plugin that adds extra DOM elements or event handlers, you should + add a callback to clean up after you. Take a look at the section in + PLUGINS.txt for more info. + Plugins ------- @@ -1016,9 +1187,15 @@ Here's a brief explanation of how the plugin plumbings work: Each plugin registers itself in the global array $.plot.plugins. When you make a new plot object with $.plot, Flot goes through this array calling the "init" function of each plugin and merging default options -from its "option" attribute. The init function gets a reference to the -plot object created and uses this to register hooks and add new public -methods if needed. +from the "option" attribute of the plugin. The init function gets a +reference to the plot object created and uses this to register hooks +and add new public methods if needed. See the PLUGINS.txt file for details on how to write a plugin. As the above description hints, it's actually pretty easy. + + +Version number +-------------- + +The version number of Flot is available in $.plot.version. diff --git a/FAQ.txt b/FAQ.txt index ee48124..e02b761 100644 --- a/FAQ.txt +++ b/FAQ.txt @@ -54,18 +54,23 @@ libraries, see the documentation in jQuery ("Using jQuery with other libraries") for details. -Q: Flot doesn't work with [widget framework xyz]! +Q: Flot doesn't work with [insert name of Javascript UI framework]! -A: The problem is most likely within the framework, or your use of the -framework. - -The only non-standard thing used by Flot is the canvas tag; otherwise -it is simply a series of absolute positioned divs within the +A: The only non-standard thing used by Flot is the canvas tag; +otherwise it is simply a series of absolute positioned divs within the placeholder tag you put in. If this is not working, it's probably because the framework you're using is doing something weird with the -DOM. As a last resort, you might try replotting and see if it helps. +DOM, or you're using it the wrong way. + +A common problem is that there's display:none on a container until the +user does something. Many tab widgets work this way, and there's +nothing wrong with it - you just can't call Flot inside a display:none +container as explained in the README so you need to hold off the Flot +call until the container is actually displayed (or use +visibility:hidden instead of display:none or move the container +off-screen). If you find there's a specific thing we can do to Flot to help, feel free to submit a bug report. Otherwise, you're welcome to ask for help -on the mailing list, but please don't submit a bug report to Flot - -try the framework instead. +on the forum/mailing list, but please don't submit a bug report to +Flot. diff --git a/Makefile b/Makefile index f90a969..b300f1a 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,9 @@ # Makefile for generating minified files -YUICOMPRESSOR_PATH=../yuicompressor-2.3.5.jar - -# if you need another compressor path, just copy the above line to a -# file called Makefile.local, customize it and you're good to go --include Makefile.local - .PHONY: all -# we cheat and process all .js files instead of listing them +# we cheat and process all .js files instead of an exhaustive list all: $(patsubst %.js,%.min.js,$(filter-out %.min.js,$(wildcard *.js))) %.min.js: %.js - java -jar $(YUICOMPRESSOR_PATH) $< -o $@ + yui-compressor $< -o $@ diff --git a/NEWS.txt b/NEWS.txt index 53281c5..5f8e1a0 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -1,3 +1,171 @@ +Flot 0.7 +-------- + +API changes: + +Multiple axes support. Code using dual axes should be changed from +using x2axis/y2axis in the options to using an array (although +backwards-compatibility hooks are in place). For instance, + + { + xaxis: { ... }, x2axis: { ... }, + yaxis: { ... }, y2axis: { ... } + } + +becomes + + { + xaxes: [ { ... }, { ... } ], + yaxes: [ { ... }, { ... } ] + } + +Note that if you're just using one axis, continue to use the +xaxis/yaxis directly (it now sets the default settings for the +arrays). Plugins touching the axes must be ported to take the extra +axes into account, check the source to see some examples. + +A related change is that the visibility of axes is now auto-detected. +So if you were relying on an axis to show up even without any data in +the chart, you now need to set the axis "show" option explicitly. + +"tickColor" on the grid options is now deprecated in favour of a +corresponding option on the axes, so { grid: { tickColor: "#000" }} +becomes { xaxis: { tickColor: "#000"}, yaxis: { tickColor: "#000"} }, +but if you just configure a base color Flot will now autogenerate a +tick color by adding transparency. Backwards-compatibility hooks are +in place. + +Final note: now that IE 9 is coming out with canvas support, you may +want to adapt the excanvas include to skip loading it in IE 9 (the +examples have been adapted thanks to Ryley Breiddal). An alternative +to excanvas using Flash has also surfaced, if your graphs are slow in +IE, you may want to give it a spin: + + http://code.google.com/p/flashcanvas/ + + +Changes: + +- Support for specifying a bottom for each point for line charts when + filling them, this means that an arbitrary bottom can be used + instead of just the x axis (based on patches patiently provided by + Roman V. Prikhodchenko). +- New fillbetween plugin that can compute a bottom for a series from + another series, useful for filling areas between lines (see new + example percentiles.html for a use case). +- More predictable handling of gaps for the stacking plugin, now all + undefined ranges are skipped. +- Stacking plugin can stack horizontal bar charts. +- Navigate plugin now redraws the plot while panning instead of only + after the fact (can be disabled by setting the pan.frameRate option + to null), raised by lastthemy (issue 235). +- Date formatter now accepts %0m and %0d to get a zero-padded month or + day (issue raised by Maximillian Dornseif). +- Revamped internals to support an unlimited number of axes, not just + dual (sponsored by Flight Data Services, + www.flightdataservices.com). +- New setting on axes, "tickLength", to control the size of ticks or + turn them off without turning off the labels. +- Axis labels are now put in container divs with classes, for instance + labels in the x axes can be reached via ".xAxis .tickLabel". +- Support for setting the color of an axis (sponsored by Flight Data + Services, www.flightdataservices.com). +- Tick color is now auto-generated as the base color with some + transparency (unless you override it). +- Support for aligning ticks in the axes with "alignTicksWithAxis" to + ensure that they appear next to each other rather than in between, + at the expense of possibly awkward tick steps (sponsored by Flight + Data Services, www.flightdataservices.com). +- Support for customizing the point type through a callback when + plotting points and new symbol plugin with some predefined point + types (sponsored by Utility Data Corporation). +- Resize plugin for automatically redrawing when the placeholder + changes size, e.g. on window resizes (sponsored by Novus Partners). + A resize() method has been added to plot object facilitate this. +- Support Infinity/-Infinity for plotting asymptotes by hacking it + into +/-Number.MAX_VALUE (reported by rabaea.mircea). +- Support for restricting navigate plugin to not pan/zoom an axis (based + on patch by kkaefer). +- Support for providing the drag cursor for the navigate plugin as an + option (based on patch by Kelly T. Moore). +- Options for controlling whether an axis is shown or not (suggestion + by Timo Tuominen) and whether to reserve space for it even if it + isn't shown. +- New attribute $.plot.version with the Flot version as a string. +- The version comment is now included in the minified jquery.flot.min.js. +- New options.grid.minBorderMargin for adjusting the minimum margin + provided around the border (based on patch by corani, issue 188). +- Refactor replot behaviour so Flot tries to reuse the existing + canvas, adding shutdown() methods to the plot (based on patch by + Ryley Breiddal, issue 269). This prevents a memory leak in Chrome + and hopefully makes replotting faster for those who are using $.plot + instead of .setData()/.draw(). Also update jQuery to 1.5.1 to + prevent IE leaks fixed in jQuery. +- New real-time line chart example. + +- New hooks: drawSeries, shutdown + +Bug fixes: + +- Fixed problem with findNearbyItem and bars on top of each other + (reported by ragingchikn, issue 242). +- Fixed problem with ticks and the border (based on patch from + ultimatehustler69, issue 236). +- Fixed problem with plugins adding options to the series objects. +- Fixed a problem introduced in 0.6 with specifying a gradient with { + brightness: x, opacity: y }. +- Don't use $.browser.msie, check for getContext on the created canvas + element instead and try to use excanvas if it's not found (fixes IE + 9 compatibility). +- highlight(s, index) was looking up the point in the original s.data + instead of in the computed datapoints array, which breaks with + plugins that modify the datapoints (such as the stacking plugin). + Issue 316 reported by curlypaul924. +- More robust handling of axis from data passed in from getData() + (problem reported by Morgan). +- Fixed problem with turning off bar outline (issue 253, fix by Jordi + Castells). +- Check the selection passed into setSelection in the selection + plugin, to guard against errors when synchronizing plots (fix by Lau + Bech Lauritzen). +- Fix bug in crosshair code with mouseout resetting the crosshair even + if it is locked (fix by Lau Bech Lauritzen and Banko Adam). +- Fix bug with points plotting using line width from lines rather than + points. +- Fix bug with passing non-array 0 data (for plugins that don't expect + arrays, patch by vpapp1). +- Fix errors in JSON in examples so they work with jQuery 1.4.2 + (fix reported by honestbleeps, issue 357). +- Fix bug with tooltip in interacting.html, this makes the tooltip + much smoother (fix by bdkahn). Fix related bug inside highlighting + handler in Flot. +- Use closure trick to make inline colorhelpers plugin respect + jQuery.noConflict(true), renaming the global jQuery object (reported + by Nick Stielau). +- Listen for mouseleave events and fire a plothover event with empty + item when it occurs to drop highlights when the mouse leaves the + plot (reported by by outspirit). +- Fix bug with using aboveData with a background (reported by + amitayd). +- Fix possible excanvas leak (report and suggested fix by tom9729). +- Fix bug with backwards compatibility for shadowSize = 0 (report and + suggested fix by aspinak). +- Adapt examples to skip loading excanvas (fix by Ryley Breiddal). +- Fix bug that prevent a simple f(x) = -x transform from working + correctly (fix by Mike, issue 263). +- Fix bug in restoring cursor in navigate plugin (reported by Matteo + Gattanini, issue 395). +- Fix bug in picking items when transform/inverseTransform is in use + (reported by Ofri Raviv, and patches and analysis by Jan and Tom + Paton, issue 334 and 467). +- Fix problem with unaligned ticks and hover/click events caused by + padding on the placeholder by hardcoding the placeholder padding to + 0 (reported by adityadineshsaxena, Matt Sommer, Daniel Atos and some + other people, issue 301). +- Update colorhelpers plugin to avoid dying when trying to parse an + invalid string (reported by cadavor, issue 483). + + Flot 0.6 -------- @@ -7,7 +175,7 @@ API changes: passing selection: { mode: something }, you MUST include the file jquery.flot.selection.js after jquery.flot.js. This reduces the size of base Flot and makes it easier to customize the selection as well as -improving code clarity. The change is based on patch from andershol. +improving code clarity. The change is based on a patch from andershol. 2. In the global options specified in the $.plot command, "lines", "points", "bars" and "shadowSize" have been moved to a diff --git a/PLUGINS.txt b/PLUGINS.txt index 00bf2e5..af3d90b 100644 --- a/PLUGINS.txt +++ b/PLUGINS.txt @@ -1,20 +1,22 @@ Writing plugins --------------- -To make a new plugin, create an init function and a set of options (if -needed), stuff it into an object and put it in the $.plot.plugins -array. For example: +All you need to do to make a new plugin is creating an init function +and a set of options (if needed), stuffing it into an object and +putting it in the $.plot.plugins array. For example: - function myCoolPluginInit(plot) { plot.coolstring = "Hello!" }; - var myCoolOptions = { coolstuff: { show: true } } - $.plot.plugins.push({ init: myCoolPluginInit, options: myCoolOptions }); + function myCoolPluginInit(plot) { + plot.coolstring = "Hello!"; + }; - // now when $.plot is called, the returned object will have the + $.plot.plugins.push({ init: myCoolPluginInit, options: { ... } }); + + // if $.plot is called, it will return a plot object with the // attribute "coolstring" Now, given that the plugin might run in many different places, it's -a good idea to avoid leaking names. We can avoid this by wrapping the -above lines in an anonymous function which we call immediately, like +a good idea to avoid leaking names. The usual trick here is wrap the +above lines in an anonymous function which is called immediately, like this: (function () { inner code ... })(). To make it even more robust in case $ is not bound to jQuery but some other Javascript library, we can write it as @@ -24,6 +26,13 @@ can write it as // ... })(jQuery); +There's a complete example below, but you should also check out the +plugins bundled with Flot. + + +Complete example +---------------- + Here is a simple debug plugin which alerts each of the series in the plot. It has a single option that control whether it is enabled and how much info to output: @@ -75,16 +84,41 @@ This simple plugin illustrates a couple of points: - Variables in the init function can be used to store plot-specific state between the hooks. +The two last points are important because there may be multiple plots +on the same page, and you'd want to make sure they are not mixed up. + + +Shutting down a plugin +---------------------- + +Each plot object has a shutdown hook which is run when plot.shutdown() +is called. This usually mostly happens in case another plot is made on +top of an existing one. + +The purpose of the hook is to give you a chance to unbind any event +handlers you've registered and remove any extra DOM things you've +inserted. + +The problem with event handlers is that you can have registered a +handler which is run in some point in the future, e.g. with +setTimeout(). Meanwhile, the plot may have been shutdown and removed, +but because your event handler is still referencing it, it can't be +garbage collected yet, and worse, if your handler eventually runs, it +may overwrite stuff on a completely different plot. + -Options guidelines -================== +Some hints on the options +------------------------- Plugins should always support appropriate options to enable/disable them because the plugin user may have several plots on the same page -where only one should use the plugin. +where only one should use the plugin. In most cases it's probably a +good idea if the plugin is turned off rather than on per default, just +like most of the powerful features in Flot. -If the plugin needs series-specific options, you can put them in -"series" in the options object, e.g. +If the plugin needs options that are specific to each series, like the +points or lines options in core Flot, you can put them in "series" in +the options object, e.g. var options = { series: { @@ -95,10 +129,8 @@ If the plugin needs series-specific options, you can put them in } } -Then they will be copied by Flot into each series, providing the -defaults in case the plugin user doesn't specify any. Again, in most -cases it's probably a good idea if the plugin is turned off rather -than on per default, just like most of the powerful features in Flot. +Then they will be copied by Flot into each series, providing default +values in case none are specified. Think hard and long about naming the options. These names are going to be public API, and code is going to depend on them if the plugin is diff --git a/README.txt b/README.txt index 5f962fb..1e49787 100644 --- a/README.txt +++ b/README.txt @@ -16,20 +16,29 @@ Installation Just include the Javascript file after you've included jQuery. -Note that you need to get a version of Excanvas (e.g. the one bundled -with Flot) which is canvas emulation on Internet Explorer. You can +Generally, all browsers that support the HTML5 canvas tag are +supported. + +For support for Internet Explorer < 9, you can use Excanvas, a canvas +emulator; this is used in the examples bundled with Flot. You just include the excanvas script like this: - + If it's not working on your development IE 6.0, check that it has -support for VML which excanvas is relying on. It appears that some +support for VML which Excanvas is relying on. It appears that some stripped down versions used for test environments on virtual machines lack the VML support. - -Also note that you need at least jQuery 1.2.6 (but at least jQuery -1.3.2 is recommended for interactive charts because of performance -improvements in event handling). + +You can also try using Flashcanvas (see +http://code.google.com/p/flashcanvas/), which uses Flash to do the +emulation. Although Flash can be a bit slower to load than VML, if +you've got a lot of points, the Flash version can be much faster +overall. Flot contains some wrapper code for activating Excanvas which +Flashcanvas is compatible with. + +You need at least jQuery 1.2.6, but try at least 1.3.2 for interactive +charts because of performance improvements in event handling. Basic usage diff --git a/examples/ajax.html b/examples/ajax.html index 385a834..9b5ec85 100644 --- a/examples/ajax.html +++ b/examples/ajax.html @@ -3,8 +3,8 @@ Flot Examples - - + + @@ -45,7 +45,7 @@

- @@ -19,7 +19,7 @@ manipulation, e.g. for labels. For drawing custom shapes there is also direct access to the canvas.

- @@ -19,7 +19,7 @@ plot function with the data. The axes are automatically scaled.

- - - - -

Flot Examples

- -
- -

Dual axis support showing the raw oil price in US $/barrel of - crude oil (left axis) vs. the exchange rate from US $ to € (right - axis).

- -

As illustrated, you can put in secondary y and x axes if you - need to. For each data series, simply specify the axis number.

- - - - diff --git a/examples/graph-types.html b/examples/graph-types.html index b3c3818..dd21a31 100644 --- a/examples/graph-types.html +++ b/examples/graph-types.html @@ -3,8 +3,8 @@ Flot Examples - - + + @@ -17,7 +17,7 @@ combinations of these, in the same plot and even on the same data series.

- @@ -26,7 +26,7 @@ incomplete images). The plugin comes with a couple of helpers for doing that.

- - +

Flot Examples

@@ -17,27 +14,31 @@
  • Basic example
  • Different graph types
  • Setting various options and annotating a chart
  • -
  • Updating graphs with AJAX
  • +
  • Updating graphs with AJAX and real-time updates
  • Being interactive:

    -

    Some more esoteric features:

    +

    Various features:

    diff --git a/examples/interacting-axes.html b/examples/interacting-axes.html new file mode 100644 index 0000000..5b6e3bb --- /dev/null +++ b/examples/interacting-axes.html @@ -0,0 +1,97 @@ + + + + + Flot Examples + + + + + + +

    Flot Examples

    + +
    + +

    With multiple axes, you sometimes need to interact with them. A + simple way to do this is to draw the plot, deduce the axis + placements and insert a couple of divs on top to catch events. + Try clicking an axis.

    + +

    + + + + diff --git a/examples/interacting.html b/examples/interacting.html index fbf0390..d04eedd 100644 --- a/examples/interacting.html +++ b/examples/interacting.html @@ -3,8 +3,8 @@ Flot Examples - - + + @@ -24,7 +24,7 @@

    Enable tooltip

    - + + + +

    Flot Examples

    + +
    + +

    Multiple axis support showing the raw oil price in US $/barrel of + crude oil vs. the exchange rate from US $ to €.

    + +

    As illustrated, you can put in multiple axes if you + need to. For each data series, simply specify the axis number. + In the options, you can then configure where you want the extra + axes to appear.

    + +

    Position axis or .

    + + + + diff --git a/examples/navigate.html b/examples/navigate.html index 78eff55..c916ef2 100644 --- a/examples/navigate.html +++ b/examples/navigate.html @@ -3,12 +3,12 @@ Flot Examples - - + + - + + +

    Flot Pie Examples

    + +

    Default with Legend

    +
    + + +

    Default without Legend

    +
    + + +

    Graph2

    +
    + + +

    Graph3

    +
    + + +

    Graph4

    +
    + + +

    Graph5

    +
    + + +

    Graph6

    +
    + + +

    Graph7

    +
    + + +

    Graph8

    +
    + + +

    Graph9

    +
    + + +

    Donut

    +
    + + +

    Interactive

    +
    + + +

    Pie Options

    + + +

    Changes/Features

    + + + + + + diff --git a/examples/realtime.html b/examples/realtime.html new file mode 100644 index 0000000..3b427e1 --- /dev/null +++ b/examples/realtime.html @@ -0,0 +1,83 @@ + + + + + Flot Examples + + + + + + +

    Flot Examples

    + +
    + +

    You can update a chart periodically to get a real-time effect + by using a timer to insert the new data in the plot and redraw it.

    + +

    Time between updates: milliseconds

    + + + + + diff --git a/examples/resize.html b/examples/resize.html new file mode 100644 index 0000000..d1e18c3 --- /dev/null +++ b/examples/resize.html @@ -0,0 +1,61 @@ + + + + + Flot Examples + + + + + + + + +

    Flot Examples

    + +
    + +

    + +

    Sometimes it makes more sense to just let the plot take up the + available space. In that case, we need to redraw the plot each + time the placeholder changes its size. If you include the resize + plugin, this is handled automatically.

    + +

    Try resizing the window.

    + + + + + + diff --git a/examples/selection.html b/examples/selection.html index 8b67a2b..1646f5a 100644 --- a/examples/selection.html +++ b/examples/selection.html @@ -3,8 +3,8 @@ Flot Examples - - + + @@ -35,9 +35,9 @@ in the "plotselected" event triggered. Enable the checkbox below and select a region again.

    -

    Zoom to selection.

    +

    - diff --git a/examples/setting-options.html b/examples/setting-options.html index 6eb6ee9..8d1967e 100644 --- a/examples/setting-options.html +++ b/examples/setting-options.html @@ -3,8 +3,8 @@ Flot Examples - - + + @@ -14,16 +14,12 @@

    There are plenty of options you can set to control the precise - looks of your plot. You can control the axes, the legend, the - default graph type, the look of grid, etc.

    + looks of your plot. You can control the ticks on the axes, the + legend, the graph type, etc. The idea is that Flot goes to great + lengths to provide sensible defaults so that you don't have to + customize much for a good result.

    -

    The idea is that Flot goes to great lengths to provide sensible - defaults which you can then customize as needed for your - particular application. If you've found a use case where the - defaults can be improved, please don't hesitate to give your - feedback.

    - - @@ -50,7 +50,7 @@ $(function () { $.plot($("#placeholder"), [ d1, d2, d3 ], { series: { stack: stack, - lines: { show: lines, steps: steps }, + lines: { show: lines, fill: true, steps: steps }, bars: { show: bars, barWidth: 0.6 } } }); diff --git a/examples/symbols.html b/examples/symbols.html new file mode 100644 index 0000000..e71b1aa --- /dev/null +++ b/examples/symbols.html @@ -0,0 +1,49 @@ + + + + + Flot Examples + + + + + + + +

    Flot Examples

    + +
    + +

    Various point types. Circles are built-in. For other + point types, you can define a little callback function to draw the + symbol; some common ones are available in the symbol plugin.

    + + + + + diff --git a/examples/thresholding.html b/examples/thresholding.html index 10b5b2a..f10144a 100644 --- a/examples/thresholding.html +++ b/examples/thresholding.html @@ -3,8 +3,8 @@ Flot Examples - - + + @@ -25,7 +25,7 @@

    - @@ -48,8 +48,8 @@ $(function () { $.plot($("#placeholder"), [d], { xaxis: { mode: "time", - min: (new Date("1990/01/01")).getTime(), - max: (new Date("2000/01/01")).getTime() + min: (new Date(1990, 1, 1)).getTime(), + max: (new Date(2000, 1, 1)).getTime() } }); }); @@ -59,8 +59,8 @@ $(function () { xaxis: { mode: "time", minTickSize: [1, "month"], - min: (new Date("1999/01/01")).getTime(), - max: (new Date("2000/01/01")).getTime() + min: (new Date(1999, 1, 1)).getTime(), + max: (new Date(2000, 1, 1)).getTime() } }); }); diff --git a/examples/tracking.html b/examples/tracking.html index a0ad77d..c116159 100644 --- a/examples/tracking.html +++ b/examples/tracking.html @@ -3,8 +3,8 @@ Flot Examples - - + + @@ -23,7 +23,7 @@

    - @@ -22,7 +22,7 @@

    Show:

    - @@ -50,7 +50,7 @@ $(function () { } var options = { - xaxis: { mode: "time" }, + xaxis: { mode: "time", tickLength: 5 }, selection: { mode: "x" }, grid: { markings: weekendAreas } }; diff --git a/examples/zooming.html b/examples/zooming.html index b485912..9a4ef22 100644 --- a/examples/zooming.html +++ b/examples/zooming.html @@ -3,8 +3,8 @@ Flot Examples - - + + @@ -16,16 +16,16 @@
    -
    +

    -

    The selection support makes - pretty advanced zooming schemes possible. With a few lines of code, - the small overview plot to the right has been connected to the large - plot. Try selecting a rectangle on either of them.

    +

    The selection support makes it easy to + construct flexible zooming schemes. With a few lines of code, the + small overview plot to the right has been connected to the large + plot. Try selecting a rectangle on either of them.