Menu

populateGraphOptions(me, other)

Help
Anonymous
2013-02-26
2013-11-01
  • Anonymous

    Anonymous - 2013-02-26

    What happens when populateGraphOptions(me, other) in rrdFlot.js gets an array?  Is it processed correctly?  I have an yaxes argument (as an array) that I want it to parse and this is the only value not handled correctly.

     
  • Igor Sfiligoi

    Igor Sfiligoi - 2013-03-23

    Not sure I understand the question.

    Can you give me a concrete example?

    Thanks,
      Igor

     
  • Sean Whitney

    Sean Whitney - 2013-05-20

    I have an object graph_options that contains
    Object {tooltip: true, yaxes: Array[2], xaxis: Object, tooltipOpts: Object, legend: Object…}
    yaxes is an Array, flot is expecting to receive an array for yaxes/xaxes.

    From what I can tell populateGraphOptions(me, other) can handle a object or a string, but not an array.

     
  • Robert Grimm

    Robert Grimm - 2013-10-02

    I just noticed the same problem. populateGraphOptions doesn't properly handle array options. If "option" has an array option and "me" does not have that option at all, it will convert that array option into a JavaScript object instead of keeping it an array.

    For example:

    populateGraphOptions({}, {arrayOption: [1,2,3]});
    

    will result in:

    { arrayOption: { 0: 1, 1: 2, 2: 3 } }
    

    instead of:

    { arrayOption: [1,2,3] }
    

    This breaks flot options such as xaxes and yaxes.

    Here's a simple patch (a hack really) that will handle the case I just gave but still won't properly merge array options when both "me" and "other" have the same array option defined but with different values (it will ignore the option defined in "me"). This patch is, however, enough to get Flot's xaxes and yaxes options working since javascriptRRD doesn't seem to use those.

    --- rrdFlot.js  2013-10-02 17:47:10.301371527 -0600
    +++ rrdFlot.js.fixed   2013-10-02 17:33:20.780369745 -0600
    @@ -665,7 +665,7 @@
           }
         } else {
           /// create a new one
    -      if (typeof(other[e])=="object") {
    +      if (typeof(other[e])=="object" && !$.isArray(other[e])) {
             // This will do a deep copy
             me[e]=populateGraphOptions({},other[e]);
           } else {
    

    A proper fix would merge an array option when it is defined in both "me" and "other". It's quite a bit more complicated but definitely doable. Maybe there's a simpler "correct" answer that I'm not thinking of.

     

    Last edit: Robert Grimm 2013-10-03
  • Igor Sfiligoi

    Igor Sfiligoi - 2013-11-01

    First off... sorry for the long abense.

    Now, I think I have found the answer to the problem here:
    http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/

    One has to use Object.prototype.toString.call instead of typeof to distinguish an array from a regular object.

    Applying the fixes to the code now.

    Thanks for pointing it out.

    Igor

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.