c3 icon indicating copy to clipboard operation
c3 copied to clipboard

Using $$ conflicts with phantomJS

Open danielgrippi opened this issue 12 years ago • 12 comments

I'm using c3 in a Rails / AngularJS project where we use PhantomJS drivers to run capybara feature tests. PhantomJS uses a global $$ while evaluating, which causes conflicts and cryptic failures whenever a c3 object is included on a page. Also worth noting: Chrome's dev tools use $$ as well for quick object inspection in their JS console.

Here's an example of the error messages I'm getting. It's failing due to undefined functions on $$:

TypeError: 'undefined' is not a function (evaluating '$$.getXAxisClipX.bind($$)')
    at http://127.0.0.1:59858/assets/application.js:61586
    at http://127.0.0.1:59858/assets/application.js:61051
    at http://127.0.0.1:59858/assets/application.js:60917
    at Chart (http://127.0.0.1:59858/assets/application.js:60865)
    at http://127.0.0.1:59858/assets/application.js:60889
    at http://127.0.0.1:59858/assets/application.js:72238
    at TimeseriesCtrl (http://127.0.0.1:59858/assets/application.js:72209)
    at invoke (http://127.0.0.1:59858/assets/application.js:23530)
    at instantiate (http://127.0.0.1:59858/assets/application.js:23541)
    at http://127.0.0.1:59858/assets/application.js:69133
    at http://127.0.0.1:59858/assets/application.js:26034
    at forEach (http://127.0.0.1:59858/assets/application.js:20055)
    at nodeLinkFn (http://127.0.0.1:59858/assets/application.js:26048)
    at compositeLinkFn (http://127.0.0.1:59858/assets/application.js:25486)
    at compositeLinkFn (http://127.0.0.1:59858/assets/application.js:25489)
    at compositeLinkFn (http://127.0.0.1:59858/assets/application.js:25489)
    at compositeLinkFn (http://127.0.0.1:59858/assets/application.js:25489)
    at compositeLinkFn (http://127.0.0.1:59858/assets/application.js:25489)
    at compositeLinkFn (http://127.0.0.1:59858/assets/application.js:25489)
    at compositeLinkFn (http://127.0.0.1:59858/assets/application.js:25489)
    at publicLinkFn (http://127.0.0.1:59858/assets/application.js:25391)
    at boundTranscludeFn (http://127.0.0.1:59858/assets/application.js:25505)
    at controllersBoundTransclude (http://127.0.0.1:59858/assets/application.js:26096)
    at ngIfWatchAction (http://127.0.0.1:59858/assets/application.js:38558)
    at http://127.0.0.1:59858/assets/application.js:31756
    at http://127.0.0.1:59858/assets/application.js:32004
    at done (http://127.0.0.1:59858/assets/application.js:27716)
    at completeRequest (http://127.0.0.1:59858/assets/application.js:27921)
    at http://127.0.0.1:59858/assets/application.js:27865 undefined

A quick fix for this is to use the c3.min.js file in my rails asset pipeline instead; however, this makes development a bit tricky since I'm not loading the un-minified / uglified c3 source in an environment where I'd need it.

If c3 switches to use something other than $$ for variable naming, these issues issues should go away!

danielgrippi avatar Sep 23 '14 14:09 danielgrippi

I was running into the same error and tried to your solution but it is not having any impact. I get the same error, just the $$ or a or whatever I call that variable referenced within the error. Could something else be the cause?

dannybrowne86 avatar Oct 05 '14 20:10 dannybrowne86

I have a similar error. Using c3.min.js does not solve the issue for me either.

I'm using PhantomJS to save PNG versions of charts. My current results show no chart at all.

I'm afraid this stack trace isn't very useful since it's in a concatenated & minified JS file, but I will include it in case it's helpful.

TypeError: 'undefined' is not a function (evaluating 't.getXAxisClipX.bind(t)')
TypeError: 'undefined' is not a function (evaluating 't.getXAxisClipX.bind(t)')
    at http://localhost/assets/application-63837eb5339894f9a7730a7c560be59f.js:9
    at http://localhost/assets/application-63837eb5339894f9a7730a7c560be59f.js:9
    at http://localhost/assets/application-63837eb5339894f9a7730a7c560be59f.js:9
    at http://localhost/assets/application-63837eb5339894f9a7730a7c560be59f.js:8 in e
    at http://localhost/assets/application-63837eb5339894f9a7730a7c560be59f.js:8
    at http://localhost/burnup/roadrunner/milestone/89.html:11
    at http://localhost/assets/application-63837eb5339894f9a7730a7c560be59f.js:2
    at http://localhost/assets/application-63837eb5339894f9a7730a7c560be59f.js:2
    at http://localhost/assets/application-63837eb5339894f9a7730a7c560be59f.js:2
    at http://localhost/assets/application-63837eb5339894f9a7730a7c560be59f.js:1

alexdean avatar Nov 21 '14 17:11 alexdean

Yeah, it turns out I'm using a minified version of c3 that I thought was v0.2.5, but it appears to be an earlier version. Finding out what exact version it is, though, would take some time to figure out. My hunch is that it's v0.2.4.

Still investigating this issue...

danielgrippi avatar Nov 23 '14 23:11 danielgrippi

@danielgrippi are you sure PhantomJS isn't doing something suspect? $$ isn't a global in the c3js library, it's internal.

what-is-a-crow avatar Nov 28 '14 17:11 what-is-a-crow

@egoodberry PhantomJS is definitely doing something suspect, but I'm not sure what exactly; because, you're right, $$ isn't global, and everything is internal. A vexing situation, indeed.

danielgrippi avatar Nov 30 '14 21:11 danielgrippi

@danielgrippi If it helps, C3's version is stored in the global c3.version.

aendra-rininsland avatar Dec 01 '14 18:12 aendra-rininsland

@danielgrippi I haven't had time to dig into it further, but take a look at this comment which suggests adding a JS polyfill for Function.prototype.bind.

alexdean avatar Dec 01 '14 19:12 alexdean

:+1: @alexdean I had a similar problem running my unit test through PhantomJS. Adding the above polyfill solved that problem.

TypeError: 'undefined' is not a function (evaluating 'a.getXAxisClipX.bind(a)')
          at /path/to/c3/c3.min.js:1
          at /path/to/c3/c3.min.js:1
          at /path/to/c3/c3.min.js:1
          at b (/path/to/c3/c3.min.js:1)
          at /path/to/c3/c3.min.js:1

kennykaye avatar Dec 18 '14 19:12 kennykaye

@alexdean solved my issue, too.

I'd like to close this out, but it seems useful to have around. Is there somewhere else more appropriate to mention this phantomJS gotcha?

danielgrippi avatar Dec 18 '14 19:12 danielgrippi

@danielgrippi @kennykaye I added some phantom-compatibility notes to the main c3 README. Not sure if that's the right place for it, but let's continue discussion in the PR.

alexdean avatar Dec 18 '14 20:12 alexdean

Thank you for your investigation. I added the polyfill in c3 as default. I think it will work and now we don't need mention about this issue in README. And I'll release this commit in the next version v0.4.9. Thanks.

masayuki0812 avatar Dec 25 '14 07:12 masayuki0812

@masayuki0812 great news! with that patch, i'd say this is resolved.

danielgrippi avatar Dec 29 '14 18:12 danielgrippi