columbus3 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.textile +62 -0
- data/bower_components/flot/.bower.json +19 -0
- data/bower_components/flot/.gitignore +3 -0
- data/bower_components/flot/.travis.yml +3 -0
- data/bower_components/flot/API.md +1498 -0
- data/bower_components/flot/CONTRIBUTING.md +98 -0
- data/bower_components/flot/FAQ.md +75 -0
- data/bower_components/flot/LICENSE.txt +22 -0
- data/bower_components/flot/Makefile +12 -0
- data/bower_components/flot/NEWS.md +1026 -0
- data/bower_components/flot/PLUGINS.md +143 -0
- data/bower_components/flot/README.md +110 -0
- data/bower_components/flot/component.json +8 -0
- data/bower_components/flot/examples/ajax/data-eu-gdp-growth-1.json +4 -0
- data/bower_components/flot/examples/ajax/data-eu-gdp-growth-2.json +4 -0
- data/bower_components/flot/examples/ajax/data-eu-gdp-growth-3.json +4 -0
- data/bower_components/flot/examples/ajax/data-eu-gdp-growth-4.json +4 -0
- data/bower_components/flot/examples/ajax/data-eu-gdp-growth-5.json +4 -0
- data/bower_components/flot/examples/ajax/data-eu-gdp-growth.json +4 -0
- data/bower_components/flot/examples/ajax/data-japan-gdp-growth.json +4 -0
- data/bower_components/flot/examples/ajax/data-usa-gdp-growth.json +4 -0
- data/bower_components/flot/examples/ajax/index.html +173 -0
- data/bower_components/flot/examples/annotating/index.html +87 -0
- data/bower_components/flot/examples/axes-interacting/index.html +97 -0
- data/bower_components/flot/examples/axes-multiple/index.html +77 -0
- data/bower_components/flot/examples/axes-time-zones/date.js +893 -0
- data/bower_components/flot/examples/axes-time-zones/index.html +114 -0
- data/bower_components/flot/examples/axes-time-zones/tz/africa +1181 -0
- data/bower_components/flot/examples/axes-time-zones/tz/antarctica +413 -0
- data/bower_components/flot/examples/axes-time-zones/tz/asia +2717 -0
- data/bower_components/flot/examples/axes-time-zones/tz/australasia +1719 -0
- data/bower_components/flot/examples/axes-time-zones/tz/backward +117 -0
- data/bower_components/flot/examples/axes-time-zones/tz/etcetera +81 -0
- data/bower_components/flot/examples/axes-time-zones/tz/europe +2856 -0
- data/bower_components/flot/examples/axes-time-zones/tz/factory +10 -0
- data/bower_components/flot/examples/axes-time-zones/tz/iso3166.tab +276 -0
- data/bower_components/flot/examples/axes-time-zones/tz/leapseconds +100 -0
- data/bower_components/flot/examples/axes-time-zones/tz/northamerica +3235 -0
- data/bower_components/flot/examples/axes-time-zones/tz/pacificnew +28 -0
- data/bower_components/flot/examples/axes-time-zones/tz/solar87 +390 -0
- data/bower_components/flot/examples/axes-time-zones/tz/solar88 +390 -0
- data/bower_components/flot/examples/axes-time-zones/tz/solar89 +395 -0
- data/bower_components/flot/examples/axes-time-zones/tz/southamerica +1711 -0
- data/bower_components/flot/examples/axes-time-zones/tz/systemv +38 -0
- data/bower_components/flot/examples/axes-time-zones/tz/yearistype.sh +38 -0
- data/bower_components/flot/examples/axes-time-zones/tz/zone.tab +441 -0
- data/bower_components/flot/examples/axes-time/index.html +137 -0
- data/bower_components/flot/examples/background.png +0 -0
- data/bower_components/flot/examples/basic-options/index.html +91 -0
- data/bower_components/flot/examples/basic-usage/index.html +57 -0
- data/bower_components/flot/examples/canvas/index.html +75 -0
- data/bower_components/flot/examples/categories/index.html +64 -0
- data/bower_components/flot/examples/examples.css +97 -0
- data/bower_components/flot/examples/image/hs-2004-27-a-large-web.jpg +0 -0
- data/bower_components/flot/examples/image/index.html +69 -0
- data/bower_components/flot/examples/index.html +80 -0
- data/bower_components/flot/examples/interacting/index.html +118 -0
- data/bower_components/flot/examples/navigate/arrow-down.gif +0 -0
- data/bower_components/flot/examples/navigate/arrow-left.gif +0 -0
- data/bower_components/flot/examples/navigate/arrow-right.gif +0 -0
- data/bower_components/flot/examples/navigate/arrow-up.gif +0 -0
- data/bower_components/flot/examples/navigate/index.html +153 -0
- data/bower_components/flot/examples/percentiles/index.html +79 -0
- data/bower_components/flot/examples/realtime/index.html +122 -0
- data/bower_components/flot/examples/resize/index.html +76 -0
- data/bower_components/flot/examples/selection/index.html +152 -0
- data/bower_components/flot/examples/series-errorbars/index.html +150 -0
- data/bower_components/flot/examples/series-pie/index.html +818 -0
- data/bower_components/flot/examples/series-toggle/index.html +121 -0
- data/bower_components/flot/examples/series-types/index.html +90 -0
- data/bower_components/flot/examples/shared/jquery-ui/jquery-ui.min.css +6 -0
- data/bower_components/flot/examples/stacking/index.html +107 -0
- data/bower_components/flot/examples/symbols/index.html +76 -0
- data/bower_components/flot/examples/threshold/index.html +76 -0
- data/bower_components/flot/examples/tracking/index.html +135 -0
- data/bower_components/flot/examples/visitors/index.html +147 -0
- data/bower_components/flot/examples/zooming/index.html +144 -0
- data/bower_components/flot/excanvas.js +1428 -0
- data/bower_components/flot/excanvas.min.js +1 -0
- data/bower_components/flot/flot.jquery.json +27 -0
- data/bower_components/flot/jquery.colorhelpers.js +180 -0
- data/bower_components/flot/jquery.flot.canvas.js +345 -0
- data/bower_components/flot/jquery.flot.categories.js +190 -0
- data/bower_components/flot/jquery.flot.crosshair.js +176 -0
- data/bower_components/flot/jquery.flot.errorbars.js +353 -0
- data/bower_components/flot/jquery.flot.fillbetween.js +226 -0
- data/bower_components/flot/jquery.flot.image.js +241 -0
- data/bower_components/flot/jquery.flot.js +3168 -0
- data/bower_components/flot/jquery.flot.navigate.js +346 -0
- data/bower_components/flot/jquery.flot.pie.js +820 -0
- data/bower_components/flot/jquery.flot.resize.js +59 -0
- data/bower_components/flot/jquery.flot.selection.js +360 -0
- data/bower_components/flot/jquery.flot.stack.js +188 -0
- data/bower_components/flot/jquery.flot.symbol.js +71 -0
- data/bower_components/flot/jquery.flot.threshold.js +142 -0
- data/bower_components/flot/jquery.flot.time.js +432 -0
- data/bower_components/flot/jquery.js +9472 -0
- data/bower_components/flot/package.json +11 -0
- data/bower_components/jquery/.bower.json +38 -0
- data/bower_components/jquery/MIT-LICENSE.txt +21 -0
- data/bower_components/jquery/bower.json +28 -0
- data/bower_components/jquery/dist/jquery.js +9210 -0
- data/bower_components/jquery/dist/jquery.min.js +5 -0
- data/bower_components/jquery/dist/jquery.min.map +1 -0
- data/bower_components/jquery/src/ajax.js +786 -0
- data/bower_components/jquery/src/ajax/jsonp.js +89 -0
- data/bower_components/jquery/src/ajax/load.js +75 -0
- data/bower_components/jquery/src/ajax/parseJSON.js +13 -0
- data/bower_components/jquery/src/ajax/parseXML.js +28 -0
- data/bower_components/jquery/src/ajax/script.js +64 -0
- data/bower_components/jquery/src/ajax/var/nonce.js +5 -0
- data/bower_components/jquery/src/ajax/var/rquery.js +3 -0
- data/bower_components/jquery/src/ajax/xhr.js +136 -0
- data/bower_components/jquery/src/attributes.js +11 -0
- data/bower_components/jquery/src/attributes/attr.js +141 -0
- data/bower_components/jquery/src/attributes/classes.js +158 -0
- data/bower_components/jquery/src/attributes/prop.js +94 -0
- data/bower_components/jquery/src/attributes/support.js +35 -0
- data/bower_components/jquery/src/attributes/val.js +161 -0
- data/bower_components/jquery/src/callbacks.js +205 -0
- data/bower_components/jquery/src/core.js +502 -0
- data/bower_components/jquery/src/core/access.js +60 -0
- data/bower_components/jquery/src/core/init.js +123 -0
- data/bower_components/jquery/src/core/parseHTML.js +39 -0
- data/bower_components/jquery/src/core/ready.js +97 -0
- data/bower_components/jquery/src/core/var/rsingleTag.js +4 -0
- data/bower_components/jquery/src/css.js +450 -0
- data/bower_components/jquery/src/css/addGetHookIf.js +22 -0
- data/bower_components/jquery/src/css/curCSS.js +57 -0
- data/bower_components/jquery/src/css/defaultDisplay.js +70 -0
- data/bower_components/jquery/src/css/hiddenVisibleSelectors.js +15 -0
- data/bower_components/jquery/src/css/support.js +96 -0
- data/bower_components/jquery/src/css/swap.js +28 -0
- data/bower_components/jquery/src/css/var/cssExpand.js +3 -0
- data/bower_components/jquery/src/css/var/getStyles.js +12 -0
- data/bower_components/jquery/src/css/var/isHidden.js +13 -0
- data/bower_components/jquery/src/css/var/rmargin.js +3 -0
- data/bower_components/jquery/src/css/var/rnumnonpx.js +5 -0
- data/bower_components/jquery/src/data.js +178 -0
- data/bower_components/jquery/src/data/Data.js +181 -0
- data/bower_components/jquery/src/data/accepts.js +20 -0
- data/bower_components/jquery/src/data/var/data_priv.js +5 -0
- data/bower_components/jquery/src/data/var/data_user.js +5 -0
- data/bower_components/jquery/src/deferred.js +149 -0
- data/bower_components/jquery/src/deprecated.js +13 -0
- data/bower_components/jquery/src/dimensions.js +50 -0
- data/bower_components/jquery/src/effects.js +648 -0
- data/bower_components/jquery/src/effects/Tween.js +114 -0
- data/bower_components/jquery/src/effects/animatedSelector.js +13 -0
- data/bower_components/jquery/src/event.js +868 -0
- data/bower_components/jquery/src/event/ajax.js +13 -0
- data/bower_components/jquery/src/event/alias.js +39 -0
- data/bower_components/jquery/src/event/support.js +9 -0
- data/bower_components/jquery/src/exports/amd.js +24 -0
- data/bower_components/jquery/src/exports/global.js +32 -0
- data/bower_components/jquery/src/intro.js +44 -0
- data/bower_components/jquery/src/jquery.js +37 -0
- data/bower_components/jquery/src/manipulation.js +580 -0
- data/bower_components/jquery/src/manipulation/_evalUrl.js +18 -0
- data/bower_components/jquery/src/manipulation/support.js +32 -0
- data/bower_components/jquery/src/manipulation/var/rcheckableType.js +3 -0
- data/bower_components/jquery/src/offset.js +207 -0
- data/bower_components/jquery/src/outro.js +1 -0
- data/bower_components/jquery/src/queue.js +142 -0
- data/bower_components/jquery/src/queue/delay.js +22 -0
- data/bower_components/jquery/src/selector-native.js +172 -0
- data/bower_components/jquery/src/selector-sizzle.js +14 -0
- data/bower_components/jquery/src/selector.js +1 -0
- data/bower_components/jquery/src/serialize.js +111 -0
- data/bower_components/jquery/src/sizzle/dist/sizzle.js +2067 -0
- data/bower_components/jquery/src/sizzle/dist/sizzle.min.js +3 -0
- data/bower_components/jquery/src/sizzle/dist/sizzle.min.map +1 -0
- data/bower_components/jquery/src/traversing.js +199 -0
- data/bower_components/jquery/src/traversing/findFilter.js +100 -0
- data/bower_components/jquery/src/traversing/var/rneedsContext.js +6 -0
- data/bower_components/jquery/src/var/arr.js +3 -0
- data/bower_components/jquery/src/var/class2type.js +4 -0
- data/bower_components/jquery/src/var/concat.js +5 -0
- data/bower_components/jquery/src/var/hasOwn.js +5 -0
- data/bower_components/jquery/src/var/indexOf.js +5 -0
- data/bower_components/jquery/src/var/pnum.js +3 -0
- data/bower_components/jquery/src/var/push.js +5 -0
- data/bower_components/jquery/src/var/rnotwhite.js +3 -0
- data/bower_components/jquery/src/var/slice.js +5 -0
- data/bower_components/jquery/src/var/strundefined.js +3 -0
- data/bower_components/jquery/src/var/support.js +4 -0
- data/bower_components/jquery/src/var/toString.js +5 -0
- data/bower_components/jquery/src/wrap.js +79 -0
- data/columbus3.gemspec +1 -1
- data/exe/columbus3 +72 -7
- data/lib/columbus3.rb +2 -1
- data/lib/columbus3/metadata/sidecar.rb +10 -1
- data/lib/columbus3/renderer/flot_renderer.rb +66 -0
- data/lib/columbus3/renderer/{renderer.rb → leaflet_renderer.rb} +0 -0
- data/lib/columbus3/version.rb +1 -1
- data/lib/html/flot.html.erb +106 -0
- metadata +194 -5
- data/README.md +0 -41
@@ -0,0 +1,71 @@
|
|
1
|
+
/* Flot plugin that adds some extra symbols for plotting points.
|
2
|
+
|
3
|
+
Copyright (c) 2007-2014 IOLA and Ole Laursen.
|
4
|
+
Licensed under the MIT license.
|
5
|
+
|
6
|
+
The symbols are accessed as strings through the standard symbol options:
|
7
|
+
|
8
|
+
series: {
|
9
|
+
points: {
|
10
|
+
symbol: "square" // or "diamond", "triangle", "cross"
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
*/
|
15
|
+
|
16
|
+
(function ($) {
|
17
|
+
function processRawData(plot, series, datapoints) {
|
18
|
+
// we normalize the area of each symbol so it is approximately the
|
19
|
+
// same as a circle of the given radius
|
20
|
+
|
21
|
+
var handlers = {
|
22
|
+
square: function (ctx, x, y, radius, shadow) {
|
23
|
+
// pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2
|
24
|
+
var size = radius * Math.sqrt(Math.PI) / 2;
|
25
|
+
ctx.rect(x - size, y - size, size + size, size + size);
|
26
|
+
},
|
27
|
+
diamond: function (ctx, x, y, radius, shadow) {
|
28
|
+
// pi * r^2 = 2s^2 => s = r * sqrt(pi/2)
|
29
|
+
var size = radius * Math.sqrt(Math.PI / 2);
|
30
|
+
ctx.moveTo(x - size, y);
|
31
|
+
ctx.lineTo(x, y - size);
|
32
|
+
ctx.lineTo(x + size, y);
|
33
|
+
ctx.lineTo(x, y + size);
|
34
|
+
ctx.lineTo(x - size, y);
|
35
|
+
},
|
36
|
+
triangle: function (ctx, x, y, radius, shadow) {
|
37
|
+
// pi * r^2 = 1/2 * s^2 * sin (pi / 3) => s = r * sqrt(2 * pi / sin(pi / 3))
|
38
|
+
var size = radius * Math.sqrt(2 * Math.PI / Math.sin(Math.PI / 3));
|
39
|
+
var height = size * Math.sin(Math.PI / 3);
|
40
|
+
ctx.moveTo(x - size/2, y + height/2);
|
41
|
+
ctx.lineTo(x + size/2, y + height/2);
|
42
|
+
if (!shadow) {
|
43
|
+
ctx.lineTo(x, y - height/2);
|
44
|
+
ctx.lineTo(x - size/2, y + height/2);
|
45
|
+
}
|
46
|
+
},
|
47
|
+
cross: function (ctx, x, y, radius, shadow) {
|
48
|
+
// pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2
|
49
|
+
var size = radius * Math.sqrt(Math.PI) / 2;
|
50
|
+
ctx.moveTo(x - size, y - size);
|
51
|
+
ctx.lineTo(x + size, y + size);
|
52
|
+
ctx.moveTo(x - size, y + size);
|
53
|
+
ctx.lineTo(x + size, y - size);
|
54
|
+
}
|
55
|
+
};
|
56
|
+
|
57
|
+
var s = series.points.symbol;
|
58
|
+
if (handlers[s])
|
59
|
+
series.points.symbol = handlers[s];
|
60
|
+
}
|
61
|
+
|
62
|
+
function init(plot) {
|
63
|
+
plot.hooks.processDatapoints.push(processRawData);
|
64
|
+
}
|
65
|
+
|
66
|
+
$.plot.plugins.push({
|
67
|
+
init: init,
|
68
|
+
name: 'symbols',
|
69
|
+
version: '1.0'
|
70
|
+
});
|
71
|
+
})(jQuery);
|
@@ -0,0 +1,142 @@
|
|
1
|
+
/* Flot plugin for thresholding data.
|
2
|
+
|
3
|
+
Copyright (c) 2007-2014 IOLA and Ole Laursen.
|
4
|
+
Licensed under the MIT license.
|
5
|
+
|
6
|
+
The plugin supports these options:
|
7
|
+
|
8
|
+
series: {
|
9
|
+
threshold: {
|
10
|
+
below: number
|
11
|
+
color: colorspec
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
It can also be applied to a single series, like this:
|
16
|
+
|
17
|
+
$.plot( $("#placeholder"), [{
|
18
|
+
data: [ ... ],
|
19
|
+
threshold: { ... }
|
20
|
+
}])
|
21
|
+
|
22
|
+
An array can be passed for multiple thresholding, like this:
|
23
|
+
|
24
|
+
threshold: [{
|
25
|
+
below: number1
|
26
|
+
color: color1
|
27
|
+
},{
|
28
|
+
below: number2
|
29
|
+
color: color2
|
30
|
+
}]
|
31
|
+
|
32
|
+
These multiple threshold objects can be passed in any order since they are
|
33
|
+
sorted by the processing function.
|
34
|
+
|
35
|
+
The data points below "below" are drawn with the specified color. This makes
|
36
|
+
it easy to mark points below 0, e.g. for budget data.
|
37
|
+
|
38
|
+
Internally, the plugin works by splitting the data into two series, above and
|
39
|
+
below the threshold. The extra series below the threshold will have its label
|
40
|
+
cleared and the special "originSeries" attribute set to the original series.
|
41
|
+
You may need to check for this in hover events.
|
42
|
+
|
43
|
+
*/
|
44
|
+
|
45
|
+
(function ($) {
|
46
|
+
var options = {
|
47
|
+
series: { threshold: null } // or { below: number, color: color spec}
|
48
|
+
};
|
49
|
+
|
50
|
+
function init(plot) {
|
51
|
+
function thresholdData(plot, s, datapoints, below, color) {
|
52
|
+
var ps = datapoints.pointsize, i, x, y, p, prevp,
|
53
|
+
thresholded = $.extend({}, s); // note: shallow copy
|
54
|
+
|
55
|
+
thresholded.datapoints = { points: [], pointsize: ps, format: datapoints.format };
|
56
|
+
thresholded.label = null;
|
57
|
+
thresholded.color = color;
|
58
|
+
thresholded.threshold = null;
|
59
|
+
thresholded.originSeries = s;
|
60
|
+
thresholded.data = [];
|
61
|
+
|
62
|
+
var origpoints = datapoints.points,
|
63
|
+
addCrossingPoints = s.lines.show;
|
64
|
+
|
65
|
+
var threspoints = [];
|
66
|
+
var newpoints = [];
|
67
|
+
var m;
|
68
|
+
|
69
|
+
for (i = 0; i < origpoints.length; i += ps) {
|
70
|
+
x = origpoints[i];
|
71
|
+
y = origpoints[i + 1];
|
72
|
+
|
73
|
+
prevp = p;
|
74
|
+
if (y < below)
|
75
|
+
p = threspoints;
|
76
|
+
else
|
77
|
+
p = newpoints;
|
78
|
+
|
79
|
+
if (addCrossingPoints && prevp != p && x != null
|
80
|
+
&& i > 0 && origpoints[i - ps] != null) {
|
81
|
+
var interx = x + (below - y) * (x - origpoints[i - ps]) / (y - origpoints[i - ps + 1]);
|
82
|
+
prevp.push(interx);
|
83
|
+
prevp.push(below);
|
84
|
+
for (m = 2; m < ps; ++m)
|
85
|
+
prevp.push(origpoints[i + m]);
|
86
|
+
|
87
|
+
p.push(null); // start new segment
|
88
|
+
p.push(null);
|
89
|
+
for (m = 2; m < ps; ++m)
|
90
|
+
p.push(origpoints[i + m]);
|
91
|
+
p.push(interx);
|
92
|
+
p.push(below);
|
93
|
+
for (m = 2; m < ps; ++m)
|
94
|
+
p.push(origpoints[i + m]);
|
95
|
+
}
|
96
|
+
|
97
|
+
p.push(x);
|
98
|
+
p.push(y);
|
99
|
+
for (m = 2; m < ps; ++m)
|
100
|
+
p.push(origpoints[i + m]);
|
101
|
+
}
|
102
|
+
|
103
|
+
datapoints.points = newpoints;
|
104
|
+
thresholded.datapoints.points = threspoints;
|
105
|
+
|
106
|
+
if (thresholded.datapoints.points.length > 0) {
|
107
|
+
var origIndex = $.inArray(s, plot.getData());
|
108
|
+
// Insert newly-generated series right after original one (to prevent it from becoming top-most)
|
109
|
+
plot.getData().splice(origIndex + 1, 0, thresholded);
|
110
|
+
}
|
111
|
+
|
112
|
+
// FIXME: there are probably some edge cases left in bars
|
113
|
+
}
|
114
|
+
|
115
|
+
function processThresholds(plot, s, datapoints) {
|
116
|
+
if (!s.threshold)
|
117
|
+
return;
|
118
|
+
|
119
|
+
if (s.threshold instanceof Array) {
|
120
|
+
s.threshold.sort(function(a, b) {
|
121
|
+
return a.below - b.below;
|
122
|
+
});
|
123
|
+
|
124
|
+
$(s.threshold).each(function(i, th) {
|
125
|
+
thresholdData(plot, s, datapoints, th.below, th.color);
|
126
|
+
});
|
127
|
+
}
|
128
|
+
else {
|
129
|
+
thresholdData(plot, s, datapoints, s.threshold.below, s.threshold.color);
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
plot.hooks.processDatapoints.push(processThresholds);
|
134
|
+
}
|
135
|
+
|
136
|
+
$.plot.plugins.push({
|
137
|
+
init: init,
|
138
|
+
options: options,
|
139
|
+
name: 'threshold',
|
140
|
+
version: '1.2'
|
141
|
+
});
|
142
|
+
})(jQuery);
|
@@ -0,0 +1,432 @@
|
|
1
|
+
/* Pretty handling of time axes.
|
2
|
+
|
3
|
+
Copyright (c) 2007-2014 IOLA and Ole Laursen.
|
4
|
+
Licensed under the MIT license.
|
5
|
+
|
6
|
+
Set axis.mode to "time" to enable. See the section "Time series data" in
|
7
|
+
API.txt for details.
|
8
|
+
|
9
|
+
*/
|
10
|
+
|
11
|
+
(function($) {
|
12
|
+
|
13
|
+
var options = {
|
14
|
+
xaxis: {
|
15
|
+
timezone: null, // "browser" for local to the client or timezone for timezone-js
|
16
|
+
timeformat: null, // format string to use
|
17
|
+
twelveHourClock: false, // 12 or 24 time in time mode
|
18
|
+
monthNames: null // list of names of months
|
19
|
+
}
|
20
|
+
};
|
21
|
+
|
22
|
+
// round to nearby lower multiple of base
|
23
|
+
|
24
|
+
function floorInBase(n, base) {
|
25
|
+
return base * Math.floor(n / base);
|
26
|
+
}
|
27
|
+
|
28
|
+
// Returns a string with the date d formatted according to fmt.
|
29
|
+
// A subset of the Open Group's strftime format is supported.
|
30
|
+
|
31
|
+
function formatDate(d, fmt, monthNames, dayNames) {
|
32
|
+
|
33
|
+
if (typeof d.strftime == "function") {
|
34
|
+
return d.strftime(fmt);
|
35
|
+
}
|
36
|
+
|
37
|
+
var leftPad = function(n, pad) {
|
38
|
+
n = "" + n;
|
39
|
+
pad = "" + (pad == null ? "0" : pad);
|
40
|
+
return n.length == 1 ? pad + n : n;
|
41
|
+
};
|
42
|
+
|
43
|
+
var r = [];
|
44
|
+
var escape = false;
|
45
|
+
var hours = d.getHours();
|
46
|
+
var isAM = hours < 12;
|
47
|
+
|
48
|
+
if (monthNames == null) {
|
49
|
+
monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
50
|
+
}
|
51
|
+
|
52
|
+
if (dayNames == null) {
|
53
|
+
dayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
54
|
+
}
|
55
|
+
|
56
|
+
var hours12;
|
57
|
+
|
58
|
+
if (hours > 12) {
|
59
|
+
hours12 = hours - 12;
|
60
|
+
} else if (hours == 0) {
|
61
|
+
hours12 = 12;
|
62
|
+
} else {
|
63
|
+
hours12 = hours;
|
64
|
+
}
|
65
|
+
|
66
|
+
for (var i = 0; i < fmt.length; ++i) {
|
67
|
+
|
68
|
+
var c = fmt.charAt(i);
|
69
|
+
|
70
|
+
if (escape) {
|
71
|
+
switch (c) {
|
72
|
+
case 'a': c = "" + dayNames[d.getDay()]; break;
|
73
|
+
case 'b': c = "" + monthNames[d.getMonth()]; break;
|
74
|
+
case 'd': c = leftPad(d.getDate()); break;
|
75
|
+
case 'e': c = leftPad(d.getDate(), " "); break;
|
76
|
+
case 'h': // For back-compat with 0.7; remove in 1.0
|
77
|
+
case 'H': c = leftPad(hours); break;
|
78
|
+
case 'I': c = leftPad(hours12); break;
|
79
|
+
case 'l': c = leftPad(hours12, " "); break;
|
80
|
+
case 'm': c = leftPad(d.getMonth() + 1); break;
|
81
|
+
case 'M': c = leftPad(d.getMinutes()); break;
|
82
|
+
// quarters not in Open Group's strftime specification
|
83
|
+
case 'q':
|
84
|
+
c = "" + (Math.floor(d.getMonth() / 3) + 1); break;
|
85
|
+
case 'S': c = leftPad(d.getSeconds()); break;
|
86
|
+
case 'y': c = leftPad(d.getFullYear() % 100); break;
|
87
|
+
case 'Y': c = "" + d.getFullYear(); break;
|
88
|
+
case 'p': c = (isAM) ? ("" + "am") : ("" + "pm"); break;
|
89
|
+
case 'P': c = (isAM) ? ("" + "AM") : ("" + "PM"); break;
|
90
|
+
case 'w': c = "" + d.getDay(); break;
|
91
|
+
}
|
92
|
+
r.push(c);
|
93
|
+
escape = false;
|
94
|
+
} else {
|
95
|
+
if (c == "%") {
|
96
|
+
escape = true;
|
97
|
+
} else {
|
98
|
+
r.push(c);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
return r.join("");
|
104
|
+
}
|
105
|
+
|
106
|
+
// To have a consistent view of time-based data independent of which time
|
107
|
+
// zone the client happens to be in we need a date-like object independent
|
108
|
+
// of time zones. This is done through a wrapper that only calls the UTC
|
109
|
+
// versions of the accessor methods.
|
110
|
+
|
111
|
+
function makeUtcWrapper(d) {
|
112
|
+
|
113
|
+
function addProxyMethod(sourceObj, sourceMethod, targetObj, targetMethod) {
|
114
|
+
sourceObj[sourceMethod] = function() {
|
115
|
+
return targetObj[targetMethod].apply(targetObj, arguments);
|
116
|
+
};
|
117
|
+
};
|
118
|
+
|
119
|
+
var utc = {
|
120
|
+
date: d
|
121
|
+
};
|
122
|
+
|
123
|
+
// support strftime, if found
|
124
|
+
|
125
|
+
if (d.strftime != undefined) {
|
126
|
+
addProxyMethod(utc, "strftime", d, "strftime");
|
127
|
+
}
|
128
|
+
|
129
|
+
addProxyMethod(utc, "getTime", d, "getTime");
|
130
|
+
addProxyMethod(utc, "setTime", d, "setTime");
|
131
|
+
|
132
|
+
var props = ["Date", "Day", "FullYear", "Hours", "Milliseconds", "Minutes", "Month", "Seconds"];
|
133
|
+
|
134
|
+
for (var p = 0; p < props.length; p++) {
|
135
|
+
addProxyMethod(utc, "get" + props[p], d, "getUTC" + props[p]);
|
136
|
+
addProxyMethod(utc, "set" + props[p], d, "setUTC" + props[p]);
|
137
|
+
}
|
138
|
+
|
139
|
+
return utc;
|
140
|
+
};
|
141
|
+
|
142
|
+
// select time zone strategy. This returns a date-like object tied to the
|
143
|
+
// desired timezone
|
144
|
+
|
145
|
+
function dateGenerator(ts, opts) {
|
146
|
+
if (opts.timezone == "browser") {
|
147
|
+
return new Date(ts);
|
148
|
+
} else if (!opts.timezone || opts.timezone == "utc") {
|
149
|
+
return makeUtcWrapper(new Date(ts));
|
150
|
+
} else if (typeof timezoneJS != "undefined" && typeof timezoneJS.Date != "undefined") {
|
151
|
+
var d = new timezoneJS.Date();
|
152
|
+
// timezone-js is fickle, so be sure to set the time zone before
|
153
|
+
// setting the time.
|
154
|
+
d.setTimezone(opts.timezone);
|
155
|
+
d.setTime(ts);
|
156
|
+
return d;
|
157
|
+
} else {
|
158
|
+
return makeUtcWrapper(new Date(ts));
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
// map of app. size of time units in milliseconds
|
163
|
+
|
164
|
+
var timeUnitSize = {
|
165
|
+
"second": 1000,
|
166
|
+
"minute": 60 * 1000,
|
167
|
+
"hour": 60 * 60 * 1000,
|
168
|
+
"day": 24 * 60 * 60 * 1000,
|
169
|
+
"month": 30 * 24 * 60 * 60 * 1000,
|
170
|
+
"quarter": 3 * 30 * 24 * 60 * 60 * 1000,
|
171
|
+
"year": 365.2425 * 24 * 60 * 60 * 1000
|
172
|
+
};
|
173
|
+
|
174
|
+
// the allowed tick sizes, after 1 year we use
|
175
|
+
// an integer algorithm
|
176
|
+
|
177
|
+
var baseSpec = [
|
178
|
+
[1, "second"], [2, "second"], [5, "second"], [10, "second"],
|
179
|
+
[30, "second"],
|
180
|
+
[1, "minute"], [2, "minute"], [5, "minute"], [10, "minute"],
|
181
|
+
[30, "minute"],
|
182
|
+
[1, "hour"], [2, "hour"], [4, "hour"],
|
183
|
+
[8, "hour"], [12, "hour"],
|
184
|
+
[1, "day"], [2, "day"], [3, "day"],
|
185
|
+
[0.25, "month"], [0.5, "month"], [1, "month"],
|
186
|
+
[2, "month"]
|
187
|
+
];
|
188
|
+
|
189
|
+
// we don't know which variant(s) we'll need yet, but generating both is
|
190
|
+
// cheap
|
191
|
+
|
192
|
+
var specMonths = baseSpec.concat([[3, "month"], [6, "month"],
|
193
|
+
[1, "year"]]);
|
194
|
+
var specQuarters = baseSpec.concat([[1, "quarter"], [2, "quarter"],
|
195
|
+
[1, "year"]]);
|
196
|
+
|
197
|
+
function init(plot) {
|
198
|
+
plot.hooks.processOptions.push(function (plot, options) {
|
199
|
+
$.each(plot.getAxes(), function(axisName, axis) {
|
200
|
+
|
201
|
+
var opts = axis.options;
|
202
|
+
|
203
|
+
if (opts.mode == "time") {
|
204
|
+
axis.tickGenerator = function(axis) {
|
205
|
+
|
206
|
+
var ticks = [];
|
207
|
+
var d = dateGenerator(axis.min, opts);
|
208
|
+
var minSize = 0;
|
209
|
+
|
210
|
+
// make quarter use a possibility if quarters are
|
211
|
+
// mentioned in either of these options
|
212
|
+
|
213
|
+
var spec = (opts.tickSize && opts.tickSize[1] ===
|
214
|
+
"quarter") ||
|
215
|
+
(opts.minTickSize && opts.minTickSize[1] ===
|
216
|
+
"quarter") ? specQuarters : specMonths;
|
217
|
+
|
218
|
+
if (opts.minTickSize != null) {
|
219
|
+
if (typeof opts.tickSize == "number") {
|
220
|
+
minSize = opts.tickSize;
|
221
|
+
} else {
|
222
|
+
minSize = opts.minTickSize[0] * timeUnitSize[opts.minTickSize[1]];
|
223
|
+
}
|
224
|
+
}
|
225
|
+
|
226
|
+
for (var i = 0; i < spec.length - 1; ++i) {
|
227
|
+
if (axis.delta < (spec[i][0] * timeUnitSize[spec[i][1]]
|
228
|
+
+ spec[i + 1][0] * timeUnitSize[spec[i + 1][1]]) / 2
|
229
|
+
&& spec[i][0] * timeUnitSize[spec[i][1]] >= minSize) {
|
230
|
+
break;
|
231
|
+
}
|
232
|
+
}
|
233
|
+
|
234
|
+
var size = spec[i][0];
|
235
|
+
var unit = spec[i][1];
|
236
|
+
|
237
|
+
// special-case the possibility of several years
|
238
|
+
|
239
|
+
if (unit == "year") {
|
240
|
+
|
241
|
+
// if given a minTickSize in years, just use it,
|
242
|
+
// ensuring that it's an integer
|
243
|
+
|
244
|
+
if (opts.minTickSize != null && opts.minTickSize[1] == "year") {
|
245
|
+
size = Math.floor(opts.minTickSize[0]);
|
246
|
+
} else {
|
247
|
+
|
248
|
+
var magn = Math.pow(10, Math.floor(Math.log(axis.delta / timeUnitSize.year) / Math.LN10));
|
249
|
+
var norm = (axis.delta / timeUnitSize.year) / magn;
|
250
|
+
|
251
|
+
if (norm < 1.5) {
|
252
|
+
size = 1;
|
253
|
+
} else if (norm < 3) {
|
254
|
+
size = 2;
|
255
|
+
} else if (norm < 7.5) {
|
256
|
+
size = 5;
|
257
|
+
} else {
|
258
|
+
size = 10;
|
259
|
+
}
|
260
|
+
|
261
|
+
size *= magn;
|
262
|
+
}
|
263
|
+
|
264
|
+
// minimum size for years is 1
|
265
|
+
|
266
|
+
if (size < 1) {
|
267
|
+
size = 1;
|
268
|
+
}
|
269
|
+
}
|
270
|
+
|
271
|
+
axis.tickSize = opts.tickSize || [size, unit];
|
272
|
+
var tickSize = axis.tickSize[0];
|
273
|
+
unit = axis.tickSize[1];
|
274
|
+
|
275
|
+
var step = tickSize * timeUnitSize[unit];
|
276
|
+
|
277
|
+
if (unit == "second") {
|
278
|
+
d.setSeconds(floorInBase(d.getSeconds(), tickSize));
|
279
|
+
} else if (unit == "minute") {
|
280
|
+
d.setMinutes(floorInBase(d.getMinutes(), tickSize));
|
281
|
+
} else if (unit == "hour") {
|
282
|
+
d.setHours(floorInBase(d.getHours(), tickSize));
|
283
|
+
} else if (unit == "month") {
|
284
|
+
d.setMonth(floorInBase(d.getMonth(), tickSize));
|
285
|
+
} else if (unit == "quarter") {
|
286
|
+
d.setMonth(3 * floorInBase(d.getMonth() / 3,
|
287
|
+
tickSize));
|
288
|
+
} else if (unit == "year") {
|
289
|
+
d.setFullYear(floorInBase(d.getFullYear(), tickSize));
|
290
|
+
}
|
291
|
+
|
292
|
+
// reset smaller components
|
293
|
+
|
294
|
+
d.setMilliseconds(0);
|
295
|
+
|
296
|
+
if (step >= timeUnitSize.minute) {
|
297
|
+
d.setSeconds(0);
|
298
|
+
}
|
299
|
+
if (step >= timeUnitSize.hour) {
|
300
|
+
d.setMinutes(0);
|
301
|
+
}
|
302
|
+
if (step >= timeUnitSize.day) {
|
303
|
+
d.setHours(0);
|
304
|
+
}
|
305
|
+
if (step >= timeUnitSize.day * 4) {
|
306
|
+
d.setDate(1);
|
307
|
+
}
|
308
|
+
if (step >= timeUnitSize.month * 2) {
|
309
|
+
d.setMonth(floorInBase(d.getMonth(), 3));
|
310
|
+
}
|
311
|
+
if (step >= timeUnitSize.quarter * 2) {
|
312
|
+
d.setMonth(floorInBase(d.getMonth(), 6));
|
313
|
+
}
|
314
|
+
if (step >= timeUnitSize.year) {
|
315
|
+
d.setMonth(0);
|
316
|
+
}
|
317
|
+
|
318
|
+
var carry = 0;
|
319
|
+
var v = Number.NaN;
|
320
|
+
var prev;
|
321
|
+
|
322
|
+
do {
|
323
|
+
|
324
|
+
prev = v;
|
325
|
+
v = d.getTime();
|
326
|
+
ticks.push(v);
|
327
|
+
|
328
|
+
if (unit == "month" || unit == "quarter") {
|
329
|
+
if (tickSize < 1) {
|
330
|
+
|
331
|
+
// a bit complicated - we'll divide the
|
332
|
+
// month/quarter up but we need to take
|
333
|
+
// care of fractions so we don't end up in
|
334
|
+
// the middle of a day
|
335
|
+
|
336
|
+
d.setDate(1);
|
337
|
+
var start = d.getTime();
|
338
|
+
d.setMonth(d.getMonth() +
|
339
|
+
(unit == "quarter" ? 3 : 1));
|
340
|
+
var end = d.getTime();
|
341
|
+
d.setTime(v + carry * timeUnitSize.hour + (end - start) * tickSize);
|
342
|
+
carry = d.getHours();
|
343
|
+
d.setHours(0);
|
344
|
+
} else {
|
345
|
+
d.setMonth(d.getMonth() +
|
346
|
+
tickSize * (unit == "quarter" ? 3 : 1));
|
347
|
+
}
|
348
|
+
} else if (unit == "year") {
|
349
|
+
d.setFullYear(d.getFullYear() + tickSize);
|
350
|
+
} else {
|
351
|
+
d.setTime(v + step);
|
352
|
+
}
|
353
|
+
} while (v < axis.max && v != prev);
|
354
|
+
|
355
|
+
return ticks;
|
356
|
+
};
|
357
|
+
|
358
|
+
axis.tickFormatter = function (v, axis) {
|
359
|
+
|
360
|
+
var d = dateGenerator(v, axis.options);
|
361
|
+
|
362
|
+
// first check global format
|
363
|
+
|
364
|
+
if (opts.timeformat != null) {
|
365
|
+
return formatDate(d, opts.timeformat, opts.monthNames, opts.dayNames);
|
366
|
+
}
|
367
|
+
|
368
|
+
// possibly use quarters if quarters are mentioned in
|
369
|
+
// any of these places
|
370
|
+
|
371
|
+
var useQuarters = (axis.options.tickSize &&
|
372
|
+
axis.options.tickSize[1] == "quarter") ||
|
373
|
+
(axis.options.minTickSize &&
|
374
|
+
axis.options.minTickSize[1] == "quarter");
|
375
|
+
|
376
|
+
var t = axis.tickSize[0] * timeUnitSize[axis.tickSize[1]];
|
377
|
+
var span = axis.max - axis.min;
|
378
|
+
var suffix = (opts.twelveHourClock) ? " %p" : "";
|
379
|
+
var hourCode = (opts.twelveHourClock) ? "%I" : "%H";
|
380
|
+
var fmt;
|
381
|
+
|
382
|
+
if (t < timeUnitSize.minute) {
|
383
|
+
fmt = hourCode + ":%M:%S" + suffix;
|
384
|
+
} else if (t < timeUnitSize.day) {
|
385
|
+
if (span < 2 * timeUnitSize.day) {
|
386
|
+
fmt = hourCode + ":%M" + suffix;
|
387
|
+
} else {
|
388
|
+
fmt = "%b %d " + hourCode + ":%M" + suffix;
|
389
|
+
}
|
390
|
+
} else if (t < timeUnitSize.month) {
|
391
|
+
fmt = "%b %d";
|
392
|
+
} else if ((useQuarters && t < timeUnitSize.quarter) ||
|
393
|
+
(!useQuarters && t < timeUnitSize.year)) {
|
394
|
+
if (span < timeUnitSize.year) {
|
395
|
+
fmt = "%b";
|
396
|
+
} else {
|
397
|
+
fmt = "%b %Y";
|
398
|
+
}
|
399
|
+
} else if (useQuarters && t < timeUnitSize.year) {
|
400
|
+
if (span < timeUnitSize.year) {
|
401
|
+
fmt = "Q%q";
|
402
|
+
} else {
|
403
|
+
fmt = "Q%q %Y";
|
404
|
+
}
|
405
|
+
} else {
|
406
|
+
fmt = "%Y";
|
407
|
+
}
|
408
|
+
|
409
|
+
var rt = formatDate(d, fmt, opts.monthNames, opts.dayNames);
|
410
|
+
|
411
|
+
return rt;
|
412
|
+
};
|
413
|
+
}
|
414
|
+
});
|
415
|
+
});
|
416
|
+
}
|
417
|
+
|
418
|
+
$.plot.plugins.push({
|
419
|
+
init: init,
|
420
|
+
options: options,
|
421
|
+
name: 'time',
|
422
|
+
version: '1.0'
|
423
|
+
});
|
424
|
+
|
425
|
+
// Time-axis support used to be in Flot core, which exposed the
|
426
|
+
// formatDate function on the plot object. Various plugins depend
|
427
|
+
// on the function, so we need to re-expose it here.
|
428
|
+
|
429
|
+
$.plot.formatDate = formatDate;
|
430
|
+
$.plot.dateGenerator = dateGenerator;
|
431
|
+
|
432
|
+
})(jQuery);
|