Sharkesm / flot

Automatically exported from code.google.com/p/flot
MIT License
0 stars 0 forks source link

Allow numeric tickSize for time axes #572

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Version: 0.7 (current version)

When setting tickSize in microseconds in the options array and when the mode 
for the given axis is set, to "time", just *must* supply an array, even if a 
custom format is specifed. See example code below. A diff that patches the 
issue is included.

Patch
=====
diff --git a/public/javascripts/flot/jquery.flot.js 
b/public/javascripts/flot/jquery.flot.js
index aabc544..3b6bc8b 100644
@@ -1181,6 +1181,11 @@

                     var step = tickSize * timeUnitSize[unit];

+                    if(tickSize == undefined) {
+                      step = axis.tickSize;
+                      unit = null;
+                    }
+
                     if (unit == "second")
                         d.setUTCSeconds(floorInBase(d.getUTCSeconds(), tickSize));
                     if (unit == "minute")

Example Code
============

                var data_from_analytics = {"series":[[1310664256000,2],[1310667856000,25],[1310671456000,0],[1310675056000,0],[1310678656000,3],[1310682256000,2],[1310685856000,1],[1310689456000,0],[1310693056000,0],[1310696656000,0],[1310700256000,0],[1310703856000,0],[1310707456000,0],[1310711056000,0],[1310714656000,0],[1310718256000,0],[1310721856000,0],[1310725456000,0],[1310729056000,0],[1310732656000,0],[1310736256000,0],[1310739856000,0],[1310743456000,0],[1310747056000,0]],"width":3600000};
                var data = data_from_analytics.series;
                var bar_width = data_from_analytics.width;
                var format = "%0h:00";
                var options = {
                  xaxis: {
                    mode: "time",
                    timeformat: format,
                    // this is where the bug occurs. correct behaviour is
                    // achieved when tickSize is [1, "hour"]
                    tickSize: bar_width
                  }
                };
                var datafield = {
                  data: data,
                  color: "#dd3636",
                  bars: {
                    show: true,
                    barWidth: bar_width, //in units
                    align: "center"
                  }
                };
                $.plot($("#flot-graph"), [datafield], options);

Original issue reported on code.google.com by iblue.va...@gmail.com on 15 Jul 2011 at 5:33

GoogleCodeExporter commented 8 years ago
I may be misunderstanding your description of the problem, but yes, tickSize 
and minTickSize currently require an array when using time data.

Since I can understand how you'd want to specify in milliseconds, I'll accept 
this as an enhancement, but, unless I'm missing something, this isn't a bug.

Original comment by dnsch...@gmail.com on 5 Jun 2012 at 2:23