Skip to content

Commit 89bbfef

Browse files
committed
Switch to using canvas text to draw the axis labels, fix a problem with axis box calculations
1 parent 36df8f0 commit 89bbfef

File tree

5 files changed

+242
-188
lines changed

5 files changed

+242
-188
lines changed

API.txt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ Customizing the axes
178178

179179
color: null or color spec
180180
tickColor: null or color spec
181-
181+
font: null or font spec object
182+
182183
min: null or number
183184
max: null or number
184185
autoscaleMargin: null or number
@@ -222,6 +223,20 @@ you can also set the color of the ticks separately with "tickColor"
222223
(otherwise it's autogenerated as the base color with some
223224
transparency).
224225

226+
You can customize the font used to draw the labels with CSS or
227+
directly with "font". The default value of null means that the font is
228+
read from the font style on the placeholder element (80% the size of
229+
that to be precise). If you set it directly with "font: { ... }", the
230+
format is like this:
231+
232+
{
233+
size: 11,
234+
style: "italic",
235+
weight: "bold",
236+
family: "sans-serif",
237+
variant: "small-caps"
238+
}
239+
225240
The options "min"/"max" are the precise minimum/maximum value on the
226241
scale. If you don't specify either of them, a value will automatically
227242
be chosen based on the minimum/maximum data values. Note that Flot
@@ -677,8 +692,7 @@ above the data or below (below is default).
677692

678693
"labelMargin" is the space in pixels between tick labels and axis
679694
line, and "axisMargin" is the space in pixels between axes when there
680-
are two next to each other. Note that you can style the tick labels
681-
with CSS, e.g. to change the color. They have class "tickLabel".
695+
are two next to each other.
682696

683697
"borderWidth" is the width of the border around the plot. Set it to 0
684698
to disable the border. You can also set "borderColor" if you want the

FAQ.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Q: How much data can Flot cope with?
66
A: Flot will happily draw everything you send to it so the answer
77
depends on the browser. The excanvas emulation used for IE (built with
88
VML) makes IE by far the slowest browser so be sure to test with that
9-
if IE users are in your target group.
9+
if IE users are in your target group (for large plots in IE, you can
10+
also check out Flashcanvas which may be faster).
1011

1112
1000 points is not a problem, but as soon as you start having more
1213
points than the pixel width, you should probably start thinking about
@@ -25,10 +26,11 @@ conversion automatically.
2526

2627
Q: Can I export the graph?
2728

28-
A: This is a limitation of the canvas technology. There's a hook in
29-
the canvas object for getting an image out, but you won't get the tick
30-
labels. And it's not likely to be supported by IE. At this point, your
31-
best bet is probably taking a screenshot, e.g. with PrtScn.
29+
A: You can grab the image rendered by the canvas element used by Flot
30+
as a PNG or JPEG (remember to set a background). Note that it won't
31+
include anything not drawn in the canvas (such as the legend). And it
32+
doesn't work with excanvas which uses VML, but you could try
33+
Flashcanvas.
3234

3335

3436
Q: The bars are all tiny in time mode?
@@ -56,11 +58,9 @@ libraries") for details.
5658

5759
Q: Flot doesn't work with [insert name of Javascript UI framework]!
5860

59-
A: The only non-standard thing used by Flot is the canvas tag;
60-
otherwise it is simply a series of absolute positioned divs within the
61-
placeholder tag you put in. If this is not working, it's probably
62-
because the framework you're using is doing something weird with the
63-
DOM, or you're using it the wrong way.
61+
A: Flot is using standard HTML to make charts. If this is not working,
62+
it's probably because the framework you're using is doing something
63+
weird with the DOM or with the CSS that is interfering with Flot.
6464

6565
A common problem is that there's display:none on a container until the
6666
user does something. Many tab widgets work this way, and there's

NEWS.txt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
Flot x.x
22
--------
33

4+
API changes:
5+
6+
Axis labels are now drawn with canvas text with some parsing to
7+
support newlines. This solves various issues but also means that they
8+
no longer support HTML markup, can be accessed as DOM elements or
9+
styled directly with CSS. Some older browsers lack this function of
10+
the canvas API (this doesn't affect IE); if this is a problem, either
11+
continue using an older version of Flot or try an emulation helper
12+
such as canvas-text or Flashcanvas.
13+
14+
15+
16+
Changes:
17+
18+
- Canvas text support for labels (sponsored by YCharts.com).
419

520
Bug fixes
621

722
- Fix problem with null values and pie plugin (patch by gcruxifix,
823
issue 500).
9-
- Fix problem with threshold plugin and bars (based on patch by kaarlenkaski)
10-
24+
- Fix problem with threshold plugin and bars (based on patch by
25+
kaarlenkaski, issue 348).
26+
- Fix axis box calculations so the boxes include the outermost part of
27+
the labels too.
28+
1129

1230
Flot 0.7
1331
--------

examples/interacting-axes.html

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ <h1>Flot Examples</h1>
3232
}
3333

3434
var data = [
35-
{ data: generate(0, 10, function (x) { return Math.sqrt(x)}), xaxis: 1, yaxis:1 },
36-
{ data: generate(0, 10, function (x) { return Math.sin(x)}), xaxis: 1, yaxis:2 },
37-
{ data: generate(0, 10, function (x) { return Math.cos(x)}), xaxis: 1, yaxis:3 },
38-
{ data: generate(2, 10, function (x) { return Math.tan(x)}), xaxis: 2, yaxis: 4 }
35+
{ data: generate(0, 10, function (x) { return Math.sqrt(x);}), xaxis: 1, yaxis:1 },
36+
{ data: generate(0, 10, function (x) { return Math.sin(x);}), xaxis: 1, yaxis:2 },
37+
{ data: generate(0, 10, function (x) { return Math.cos(x);}), xaxis: 1, yaxis:3 },
38+
{ data: generate(2, 10, function (x) { return Math.tan(x);}), xaxis: 2, yaxis: 4 }
3939
];
4040

4141
var plot = $.plot($("#placeholder"),
@@ -54,29 +54,11 @@ <h1>Flot Examples</h1>
5454
});
5555

5656
// now for each axis, create a div
57-
58-
function getBoundingBoxForAxis(plot, axis) {
59-
var left = axis.box.left, top = axis.box.top,
60-
right = left + axis.box.width, bottom = top + axis.box.height;
61-
62-
// some ticks may stick out, enlarge the box to encompass all ticks
63-
var cls = axis.direction + axis.n + 'Axis';
64-
plot.getPlaceholder().find('.' + cls + ' .tickLabel').each(function () {
65-
var pos = $(this).position();
66-
left = Math.min(pos.left, left);
67-
top = Math.min(pos.top, top);
68-
right = Math.max(Math.round(pos.left) + $(this).outerWidth(), right);
69-
bottom = Math.max(Math.round(pos.top) + $(this).outerHeight(), bottom);
70-
});
71-
72-
return { left: left, top: top, width: right - left, height: bottom - top };
73-
}
74-
7557
$.each(plot.getAxes(), function (i, axis) {
7658
if (!axis.show)
7759
return;
7860

79-
var box = getBoundingBoxForAxis(plot, axis);
61+
var box = axis.box;
8062

8163
$('<div class="axisTarget" style="position:absolute;left:' + box.left + 'px;top:' + box.top + 'px;width:' + box.width + 'px;height:' + box.height + 'px"></div>')
8264
.data('axis.direction', axis.direction)

0 commit comments

Comments
 (0)