Skip to content

Conversation

execjosh
Copy link
Contributor

This change adds an additional check for whether the parent element is null or undefined in $.color.extract. This can happen when working with elements that have not yet been added to the DOM under <body>.

Consider the following example pie chart.

var elm = $("<div />")
  .css({
    width: "240px"
  , height: "320px"
  })
var data = [
  {label: "One", data: "33"}
, {label: "Two", data: "33"}
, {label: "Three", data: "33"}
]
var opts = {
  legend: {
    show: true
  }
, series: {
    pie: {
      show: true
    }
  }
}
$.plot(elm, data, opts)
elm.appendTo($("body"))

When flot inserts each legend row, it tries to use the same color as the corresponding graph part, unless it was explicitly specified in the options. However, in this example, $.color.extract runs into an unexpected null reference because <body> is not an ancestor of elm. Specifically, a TypeError: Cannot read property 'nodeName' of undefined would be thrown.

@execjosh
Copy link
Contributor Author

The Travis CI build failure has nothing to do with this change. It looks like jshint is complaining about jquery.flot.js.

@ghost ghost assigned dnschnur Jun 29, 2013
This change adds an additional check for whether the parent element
is `null` or `undefined` in `$.color.extract`.  This can happen when
working with elements that have not yet been added to the DOM under
`<body>`.

Consider the following example pie chart.

    var elm = $("<div />")
      .css({
        width: "240px"
      , height: "320px"
      })
    var data = [
      {label: "One", data: "33"}
    , {label: "Two", data: "33"}
    , {label: "Three", data: "33"}
    ]
    var opts = {
      legend: {
        show: true
      }
    , series: {
        pie: {
          show: true
        }
      }
    }
    $.plot(elm, data, opts)
    elm.appendTo($("body"))

When flot inserts each legend row, it tries to use the same color as
the corresponding graph part, unless it was explicitly specified in
the options.  However, in this example, `$.color.extract` runs into
an unexpected `null` reference because `<body>` is not an ancestor
of `elm`.  Specifically, a `TypeError: Cannot read property
'nodeName' of undefined` would be thrown.
@ghost ghost assigned dnschnur Oct 14, 2013
@dnschnur
Copy link
Member

Thank you for finding, reporting, and fixing this!

dnschnur added a commit that referenced this pull request Oct 14, 2013
Also stop at root when extracting CSS color
@dnschnur dnschnur merged commit 82f28d2 into flot:master Oct 14, 2013
dnschnur added a commit that referenced this pull request Oct 14, 2013
@quentindemetz
Copy link

I was running into this issue as well, thanks!

However, I'm not seeing this fix in the main jquery.flot.js file.
In fact, It seems like this main file does not include any of the recent changes. And it seems like the build process, as defined in the Makefile, does not update the inlined version of jquery.colorhelpers.

I don't know if I'm expected to wait until a new (tagged) release of flot that would include these fixes in the jquery.flot.js file (I believe there are tens of commits not included in that file as of today).

@dnschnur can you help me on this?
Thanks

@dnschnur
Copy link
Member

@quentindemetz When you say 'main' jquery.flot.js, where are you getting that from? The zipfile linked from www.flotcharts.org is still 0.8.1; this will go out (quite soon, hopefully) with 0.8.2. To get the fix grab master.

@quentindemetz
Copy link

I am talking about https://github.com/flot/flot/blob/master/jquery.flot.js. That's the version I am using.
To my understanding, this fix did not make it into the inline dependency stated on line 8 of that file.

Can you confirm?

@dnschnur
Copy link
Member

Oh, sorry, you are correct. I've been working too much on the 0.9 branch, where this dependency is no longer inlined. Fixed.

@quentindemetz
Copy link

Awesome, thanks a million!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants