Patch for timeplot

43 views
Skip to first unread message

ruffm...@googlemail.com

unread,
Aug 15, 2009, 5:48:43 PM8/15/09
to simile-...@googlegroups.com
Hi,

i have changed three things in the current timeplot code from svn:

o Changed global 'unit' variable to be of local scope

o Added support for entity of a value to be displayed in tooltip, see
example:
http://gpsvision.biz/timeplot.png

o Workaround for stale mouseevents
Note: this is no fix but a workaround only, I have reported the bug
in a previous mail

Is it possible to apply this to the current svn?

Thank you for all

Marcel

********* timeplot-svn-2009-08-15.patch ***********

Index: scripts/geometry.js
===================================================================
--- scripts/geometry.js (Revision 2043)
+++ scripts/geometry.js (Arbeitskopie)
@@ -589,11 +589,10 @@

if (p == 0) return grid;

+ var unit = time.MILLENNIUM;
// find the time units nearest to the time period
- if (p > time.gregorianUnitLengths[time.MILLENNIUM]) {
- unit = time.MILLENNIUM;
- } else {
- for (var unit = time.MILLENNIUM; unit > 0; unit--) {
+ if (p <= time.gregorianUnitLengths[time.MILLENNIUM]) {
+ for (; unit > 0; unit--) {
if (time.gregorianUnitLengths[unit-1] <= p && p <
time.gregorianUnitLengths[unit]) {
unit--;
break;
Index: scripts/timeplot.js
===================================================================
--- scripts/timeplot.js (Revision 2043)
+++ scripts/timeplot.js (Arbeitskopie)
@@ -51,7 +51,8 @@
roundValues: ("roundValues" in params) ?
params.roundValues : true,
valuesOpacity: ("valuesOpacity" in params) ?
params.valuesOpacity : 75,
bubbleWidth: ("bubbleWidth" in params) ?
params.bubbleWidth : 300,
- bubbleHeight: ("bubbleHeight" in params) ?
params.bubbleHeight : 200
+ bubbleHeight: ("bubbleHeight" in params) ?
params.bubbleHeight : 200,
+ valueEntity: ("valueEntity" in params) ?
params.valueEntity : ""
};
};

Index: scripts/plot.js
===================================================================
--- scripts/plot.js (Revision 2043)
+++ scripts/plot.js (Arbeitskopie)
@@ -66,7 +66,8 @@
var month = 30 * day;

var mouseMoveHandler = function(elmt, evt, target) {
- if (typeof SimileAjax != "undefined" &&
plot._plotInfo.showValues) {
+ if (typeof SimileAjax != "undefined" &&
plot._plotInfo.showValues
+ && plot._dataSource != null) {
var c = plot._canvas;
var x =
Math.round(SimileAjax.DOM.getEventRelativeCoordinates(evt,plot._canvas).x);
if (x > c.width) x = c.width;
@@ -78,10 +79,12 @@
}

var validTime =
plot._dataSource.getClosestValidTime(t);
+ if (validTime == 0) // event from removed DataSource?!
+ return;
x = plot._timeGeometry.toScreen(validTime);
var v = plot._dataSource.getValue(validTime);
if (plot._plotInfo.roundValues) v = Math.round(v);
- plot._valueFlag.innerHTML = new String(v);
+ plot._valueFlag.innerHTML = new String(v +
plot._plotInfo.valueEntity); // 80 km/h
var d = new Date(validTime);
var p = plot._timeGeometry.getPeriod();
if (p < day) {

ruffm...@googlemail.com

unread,
Sep 1, 2009, 7:05:36 AM9/1/09
to simile-...@googlegroups.com
Hi again,

what is the correct way to send patches?
Who shall I contact best?

Thank you
Marcel

Stefano Mazzocchi

unread,
Sep 1, 2009, 11:24:28 AM9/1/09
to simile-...@googlegroups.com
ruffm...@gmail.com wrote:
> Hi again,
>
> what is the correct way to send patches?
> Who shall I contact best?

It's probably best to attach the patches to an issue on google code than
sending them via email. Things tend to get lost more here.

Also, I'm still the timeplot maintainer but I'm terribly swamped at the
moment, so I don't know when I'll be able to get to it, sorry.

--
Stefano Mazzocchi Application Catalyst
Metaweb Technologies, Inc. ste...@metaweb.com
-------------------------------------------------------------------

Marcel Ruff

unread,
Sep 2, 2009, 4:56:43 AM9/2/09
to simile-...@googlegroups.com
Dear Stefano,

thank you for all your excellent work.

If you give me write permissions I can commit it myself,
else I do as suggested,

regards
Marcel


Stefano Mazzocchi schrieb:


> ruffm...@gmail.com wrote:
>
>> Hi again,
>>
>> what is the correct way to send patches?
>> Who shall I contact best?
>>
>
> It's probably best to attach the patches to an issue on google code than
> sending them via email. Things tend to get lost more here.
>
> Also, I'm still the timeplot maintainer but I'm terribly swamped at the
> moment, so I don't know when I'll be able to get to it, sorry.
>
>


--
Marcel Ruff
http://www.xmlBlaster.org
http://watchee.net
Phone: +49 7551 309371

Marcel Ruff

unread,
Sep 3, 2009, 8:38:09 AM9/3/09
to simile-...@googlegroups.com
Stefano Mazzocchi schrieb:

> ruffm...@gmail.com wrote:
>
>> Hi again,
>>
>> what is the correct way to send patches?
>> Who shall I contact best?
>>
>
> It's probably best to attach the patches to an issue on google code than
> sending them via email. Things tend to get lost more here.
>
> Also, I'm still the timeplot maintainer but I'm terribly swamped at the
> moment, so I don't know when I'll be able to get to it, sorry.
>
>
See

http://code.google.com/p/simile-widgets/issues/detail?id=311
http://code.google.com/p/simile-widgets/issues/detail?id=312 <http://code.google.com/p/simile-widgets/issues/detail?id=311>

thanks
Marcel

Niels Mayer

unread,
Sep 8, 2009, 9:09:25 PM9/8/09
to simile-...@googlegroups.com, ruffm...@googlemail.com
I've had to override some methods in Timeplot to get it to prevent them from looking all wrong, e.g.

 /*
  * NPM BUGFIX Timeplot.DefaultTimeGeometry.prototype._calculateGrid originally from
  * This particular change comes from a patch supplied on Timeplot: 
  * "Changed global 'unit' variable to be of local scope" 
  * (which also corrects a programming issue)
  * -------------
  * This function calculates the grid spacing that it will be used 
  * by this geometry to draw the grid in order to reduce clutter.
  */
 Timeplot.DefaultTimeGeometry.prototype._calculateGrid = function() {
        var grid = [];
        
        var time = SimileAjax.DateTime;
        var u = this._unit;
        var p = this._period;
        
        if (p == 0) return grid;
        
        var unit = time.MILLENNIUM;; /*was:(missing)*/
        // find the time units nearest to the time period
/*was:
        if (p > time.gregorianUnitLengths[time.MILLENNIUM]) {
           unit = time.MILLENNIUM;
        } else {
*/
        if (p <= time.gregorianUnitLengths[time.MILLENNIUM]) {
            for ( /*was:var unit = time.MILLENNIUM*/ ; unit > 0; unit--) {
                if (time.gregorianUnitLengths[unit-1] <= p && p < time.gregorianUnitLengths[unit]) {
                    unit--;
                    break;
                }
            }
        }

        var t = u.cloneValue(this._earliestDate);

        do {
            time.roundDownToInterval(t, unit, this._timeZone, 1, 0);
            var x = this.toScreen(u.toNumber(t));
         /* 
          * NPM: changed switch() cases below to work in UTC correctly when using timeplot's
          * ex:timeGeometry="timeplotGeometer" == new Timeplot.DefaultTimeGeometry({ timeZone: 0 })
          * Prior code incorrectly used t.toLocaleTimeString() & t.toLocaleDateString() which caused
          * data to be printed in local timezone rather than the data's UTC/GMT timezone. Also,
          * original code printed labels that overlapped due to varying length and long sizes.
          */
            switch (unit) {
                case time.SECOND:
                  var s = t.getUTCSeconds();
                  var l = ((s < 10) ? "0" : "") + s;
                  break;
                case time.MINUTE:
                  var m = t.getUTCMinutes();
                  var l = ((m < 10) ? "0" : "") + m;
                  break;
                case time.HOUR:
                  var h = t.getUTCHours();
                  var l = ((h < 10) ? "0" : "") + h + ":00";
                  break;
                case time.DAY:
                case time.WEEK:
                case time.MONTH:
                  var l = t.toUTCString();
                  break;  
                case time.YEAR:
                case time.DECADE:
                case time.CENTURY:
                case time.MILLENNIUM:
                  var l = t.getUTCFullYear();
                  break;
            }
            if (x > 0) { 
                grid.push({ x: x, label: l });
            }
            time.incrementByInterval(t, unit, this._timeZone);
        } while (t.getTime() < this._latestDate.getTime());
        
        return grid;
  };

  /**
   * NPM BUGFIX Timeplot.Plot.prototype.initialize() originally from
   * --------------
   * Initialize the plot layer
   */
  Timeplot.Plot.prototype.initialize = function() {
        if (this._dataSource && this._dataSource.getValue) {
            this._timeFlag = this._timeplot.putDiv("timeflag","timeplot-timeflag");
            this._valueFlag = this._timeplot.putDiv(this._id + "valueflag","timeplot-valueflag");
            this._valueFlagLineLeft = this._timeplot.putDiv(this._id + "valueflagLineLeft","timeplot-valueflag-line");
            this._valueFlagLineRight = this._timeplot.putDiv(this._id + "valueflagLineRight","timeplot-valueflag-line");
            if (!this._valueFlagLineLeft.firstChild) {
                this._valueFlagLineLeft.appendChild(SimileAjax.Graphics.createTranslucentImage(Timeplot.urlPrefix + "images/line_left.png"));
                this._valueFlagLineRight.appendChild(SimileAjax.Graphics.createTranslucentImage(Timeplot.urlPrefix + "images/line_right.png"));
            }
            this._valueFlagPole = this._timeplot.putDiv(this._id + "valuepole","timeplot-valueflag-pole");

            var opacity = this._plotInfo.valuesOpacity;
            
            SimileAjax.Graphics.setOpacity(this._timeFlag, opacity);
            SimileAjax.Graphics.setOpacity(this._valueFlag, opacity);
            SimileAjax.Graphics.setOpacity(this._valueFlagLineLeft, opacity);
            SimileAjax.Graphics.setOpacity(this._valueFlagLineRight, opacity);
            SimileAjax.Graphics.setOpacity(this._valueFlagPole, opacity);

            var plot = this;
            
            var mouseOverHandler = function(elmt, evt, target) {
                if (plot._plotInfo.showValues) { 
                        plot._valueFlag.style.display = "block";
                        mouseMoveHandler(elmt, evt, target);
                    }
            }
        
            var day = 24 * 60 * 60 * 1000;
            var month = 30 * day;
            
            var mouseMoveHandler = function(elmt, evt, target) {
                if (typeof SimileAjax != "undefined" && plot._plotInfo.showValues) {
                    var c = plot._canvas;
                    var x = Math.round(SimileAjax.DOM.getEventRelativeCoordinates(evt,plot._canvas).x);
                    if (x > c.width) x = c.width;
                    if (isNaN(x) || x < 0) x = 0;
                    var t = plot._timeGeometry.fromScreen(x);
                    if (t == 0) { // something is wrong
                        plot._valueFlag.style.display = "none";
                        return;
                    }
                    
                    var validTime = plot._dataSource.getClosestValidTime(t);
                    x = plot._timeGeometry.toScreen(validTime);
                    var v = plot._dataSource.getValue(validTime);
                    if (plot._plotInfo.roundValues) v = Math.round(v);
                    plot._valueFlag.innerHTML = new String(v);
                    var d = new Date(validTime);
                    var p = plot._timeGeometry.getPeriod(); 
                    if (p < day) {
                        plot._timeFlag.innerHTML = /*d.getUTCHours()+':'+*/ d.getUTCMinutes()+':'+d.getUTCSeconds()+'.'+d.getUTCMilliseconds() /*was:d.toLocaleTimeString()*/ ;
                    } else if (p > month) {
                        plot._timeFlag.innerHTML = d.toLocaleDateString(); /*NPM: leave in local TZ since returns date w/o time; there's no equiv UTC fn */
                    } else {
                        plot._timeFlag.innerHTML = d.toUTCString() /*was:d.toLocaleString()*/ ;
                    }

                    var tw = plot._timeFlag.clientWidth;
                    var th = plot._timeFlag.clientHeight;
                    var tdw = Math.round(tw / 2);
                    var vw = plot._valueFlag.clientWidth;
                    var vh = plot._valueFlag.clientHeight;
                    var y = plot._valueGeometry.toScreen(v);

                    if (x + tdw > c.width) {
                        var tx = c.width - tdw;
                    } else if (x - tdw < 0) {
                        var tx = tdw;
                    } else {
                        var tx = x;
                    }

                    if (plot._timeGeometry._timeValuePosition == "top") {
                        plot._timeplot.placeDiv(plot._valueFlagPole, {
                            left: x,
                            top: th - 5,
                            height: c.height - y - th + 6,
                            display: "block"
                        });
                        plot._timeplot.placeDiv(plot._timeFlag,{
                            left: tx - tdw,
                            top: -6,
                            display: "block"
                        });
                    } else {
                        plot._timeplot.placeDiv(plot._valueFlagPole, {
                            left: x,
                            bottom: th - 5,
                            height: y - th + 6,
                            display: "block"
                        });
                        plot._timeplot.placeDiv(plot._timeFlag,{
                            left: tx - tdw,
                            bottom: -6,
                            display: "block"
                        });
                    }

                    if (x + vw + 14 > c.width && y + vh + 4 > c.height) {
                        plot._valueFlagLineLeft.style.display = "none";
                        plot._timeplot.placeDiv(plot._valueFlagLineRight,{
                            left: x - 14,
                            bottom: y - 14,
                            display: "block"
                        });
                        plot._timeplot.placeDiv(plot._valueFlag,{
                            left: x - vw - 13,
                            bottom: y - vh - 13,
                            display: "block"
                        });
                    } else if (x + vw + 14 > c.width && y + vh + 4 < c.height) {
                        plot._valueFlagLineRight.style.display = "none";
                        plot._timeplot.placeDiv(plot._valueFlagLineLeft,{
                            left: x - 14,
                            bottom: y,
                            display: "block"
                        });
                        plot._timeplot.placeDiv(plot._valueFlag,{
                            left: x - vw - 13,
                            bottom: y + 13,
                            display: "block"
                        });
                    } else if (x + vw + 14 < c.width && y + vh + 4 > c.height) {
                        plot._valueFlagLineRight.style.display = "none";
                        plot._timeplot.placeDiv(plot._valueFlagLineLeft,{
                            left: x,
                            bottom: y - 13,
                            display: "block"
                        });
                        plot._timeplot.placeDiv(plot._valueFlag,{
                            left: x + 13,
                            bottom: y - 13,
                            display: "block"
                        });
                    } else {
                        plot._valueFlagLineLeft.style.display = "none";
                        plot._timeplot.placeDiv(plot._valueFlagLineRight,{
                            left: x,
                            bottom: y,
                            display: "block"
                        });
                        plot._timeplot.placeDiv(plot._valueFlag,{
                            left: x + 13,
                            bottom: y + 13,
                            display: "block"
                        });
                    }
                }
            }

            var timeplotElement = this._timeplot.getElement();
            SimileAjax.DOM.registerEvent(timeplotElement, "mouseover", mouseOverHandler);
            SimileAjax.DOM.registerEvent(timeplotElement, "mousemove", mouseMoveHandler);
        }
  };


Niels Mayer

unread,
Sep 9, 2009, 6:07:17 PM9/9/09
to simile-...@googlegroups.com, ruffm...@googlemail.com
Another bug related to timeplot. It seems like there's some unexpected CSS overriding that cause some of the layout and overlaps 


.timeplot-container {
    overflow: hidden;
    position: relative;
    height: 200px;
    border: 1px solid #ccc;
    padding: 12px 14px;
}


.exhibit-ui-protection div {
    margin:0;
    padding:0;
}

As workaround, I added a specific override to the override:

#timeindex-viewpanel .timeplot-container {
                        conflict setting ".exhibit-ui-protection div { margin:0; padding:0; }"
                        back to original value from 
}

After JS code overrides from previous message, and this CSS override,  now things look like this: 

Marcel Ruff

unread,
Nov 24, 2009, 3:02:03 AM11/24/09
to simile-...@googlegroups.com
Hi Stefano,

I'm coming back to my patches, and I have one more bugfix.
As I believe you are still swamped, could you please
consider to give me write access to commit them myself?

It is just that it makes my work complicated to always
convey the patches on our developer PCs manually.
Having them applied would simplify the task a bit and
also others would benefit (this is probably one of
the ideas of open source and svn).

What do you think?

Thanks
Marcel


Stefano Mazzocchi schrieb:
> ruffm...@gmail.com wrote:
>
>> Hi again,
>>
>> what is the correct way to send patches?
>> Who shall I contact best?
>>
>
> It's probably best to attach the patches to an issue on google code than
> sending them via email. Things tend to get lost more here.
>
> Also, I'm still the timeplot maintainer but I'm terribly swamped at the
> moment, so I don't know when I'll be able to get to it, sorry.
>
>

--
http://gpsvision.biz


Reply all
Reply to author
Forward
0 new messages