Using Flotr2 with requireJS

504 views
Skip to first unread message

KT

unread,
May 8, 2012, 1:26:58 PM5/8/12
to flo...@googlegroups.com
Hello,

Simple examples with Flotr2 work just fine for me. But as soon as I introduce requireJS and load Flotr as a module, it stops working. I'm not totally sure what I am doing wrong, but I was wondering if there are any examples of Flotr2 working along with requireJS or some other AMD loader. It seems like Flotr2 was designed to work in this fashion, but maybe not.

I am having this problem in the work I'm doing, but I also put that aside and made a test HTML file. I started with the example HTML given here: http://humblesoftware.com/flotr2/documentation . That worked 100%. Then I took out the script tags, replaced them with a call to requireJS, and added Flotr2 as a dependency in my main.js file. Granted, I could have done this incorrectly somehow, but either way, I now get a "bean is not defined" ReferenceError.

So, something has gone wrong here, but I don't have anything indicating what. Given that, I am just wondering if there are any examples using Flotr2 together with requireJS, or some similar AMD loader. If I can take a look at those, I may be able to figure out what's wrong, but I can't even find anything written about using Flotr2 with a module loader!

Thanks for any ideas,
KT

TMFReason

unread,
Jun 1, 2012, 3:29:39 PM6/1/12
to flotr2
I think the problem is that the bean dependency found at the top of
Flotr2.js has bootstrap code that will load itself as a require module
when require.js is present (if (typeof define == 'function' && typeof
define.amd == 'object')) rather than a global bean variable. The
same problem may exist if you are using bonzo.js.

Since Flotr itself is not setup as a require module, it can't find
bean as a dependency anymore. You may be able restructure Flotr as a
module with deps of ['bean"] (maybe "underscore" and "bonzo" also),
but I'm not sure how difficult it might be. A shortcut would be to
disable the require (define) check in the bean code to keep it loaded
as a global variable.

If anyone makes the conversion of Flotr to use require, hopefully they
will make it available here.

On May 8, 1:26 pm, KT <justinsip...@gmail.com> wrote:
> Hello,
>
> Simple examples with Flotr2 work just fine for me. But as soon as I
> introduce requireJS and load Flotr as a module, it stops working. I'm not
> totally sure what I am doing wrong, but I was wondering if there are any
> examples of Flotr2 working along with requireJS or some other AMD loader.
> It seems like Flotr2 was designed to work in this fashion, but maybe not.
>
> I am having this problem in the work I'm doing, but I also put that aside
> and made a test HTML file. I started with the example HTML given here:http://humblesoftware.com/flotr2/documentation. That worked 100%. Then I

David Llamazares Juarez

unread,
Jan 19, 2016, 10:58:12 AM1/19/16
to flotr2
If you want load flotr2 library with requireJS, comment red line:

!function (name, context, definition) {
if (typeof module !== 'undefined') module.exports = definition(name, context);
else if (typeof define === 'function' && typeof define.amd === 'object') define(definition);
else context[name] = definition(name, context);
}(
'bean', this, function (name, context) {
Reply all
Reply to author
Forward
0 new messages