mathisonian / d3-multiaxis-zoom

d3 plugin to zoom along multiple axes independently
MIT License
15 stars 1 forks source link

'd3_multiaxis_zoom' is undefined #2

Closed marfoldi closed 8 years ago

marfoldi commented 8 years ago

Hi,

I'm trying to load the plugin as it described in the readme without success. I get "Uncaught ReferenceError: d3_multiaxis_zoom is not defined" runtime error.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="d3-multiaxis-zoom.js"></script>
<script type="text/javascript">

    // Apply to plugin
    d3_multiaxis_zoom(d3);

    // now all d3.behavior.zoom instances will be modified with this plugin

</script>
</body>
</html>
marfoldi commented 8 years ago

Directory structure:

capture

mathisonian commented 8 years ago

Are you using any sort of javascript bundler? The logic to decide whether or not to attach the plugin to the window as a global is as follows (to make it work with browserify, require.js, and vanilla script tags):

// export as a Node module, an AMD module or a global browser variable
if (typeof module !== 'undefined') {
    module.exports = d3_multiaxis_zoom;

} else if (typeof define === 'function' && define.amd) {
    define(function() {
        return d3_multiaxis_zoom;
    });

} else {
    window.d3_multiaxis_zoom = d3_multiaxis_zoom;
}
marfoldi commented 8 years ago

I've just cloned your repo and added a html file (code above). So is it necessary to use a bundler e.g. require.js to make it work?

mathisonian commented 8 years ago

@marfoldi it looks like the standalone d3-multiaxis-zoom.js file was incorrectly bundled last time. I've updated it and tested with the above html file

marfoldi commented 8 years ago

Thank you!