I am currently working on developing a d3 v4 plugin by following the guidelines provided at . My main objective is to be able to npm install the plugin and seamlessly use it within an Angular 2/4 component.
The repository for my project can be found here:
https://github.com/denisemauldin/d3-timeline
Check out some examples:
One of the challenges I'm facing is integrating other necessary d3 components. The current setup does not provide guidance on utilizing other d3 elements.
I specifically require d3.timeFormat
, d3.timeHour
, d3.scaleOrdinal
, d3.schemeCategory
, d3.mouse
, d3.select
, d3.axisTop
, d3.axisBottom
, and d3.scaleLinear
.
These functionalities are part of d3-axis
, d3-scale
, d3-selection
, d3-time
, and d3-time-format
. I have attempted a couple of approaches:
1) Including them as imports in index.js
import "d3-axis";
import "d3-scale";
import "d3-selection";
import "d3-time";
import "d3-time-format";
export {default as timeline} from "./src/timeline";
2) Integrating them directly in the timeline.js source:
var d3 = Object.assign({}, require("d3-axis"), require("d3-scale"), require("d3-selection"), require("d3-time"), require("d3-time-format"));
(function() {
d3.timeline = function() {
//variable definitions
function timeline (gParent) {};
//method definitions
return timeline;
};
})();
export default d3.timeline;
Currently, the plugin loads successfully in the browser and functions properly, but I am struggling to get the npm install to work in order to create a npm package for usage with my Angular 2 site.
I have experimented with various options in the rollup.config.js
file using rollup-plugin-commonjs
. I am unsure if this is the correct path as it seems to generate a bundled file containing all the required d3 code. The rollup call (included in the d3 plugin starter bundle) is failing:
rm -rf build && mkdir build && rollup -c -f umd -n d3 -o build/d3-timeline.js -- index.js
'default' is not exported by 'd3-timeline/src/timeline.js' (imported by 'd3-timeline/index.js')
If I remove the rollup.config.js
, the same error persists, along with the message:
Treating 'd3-axis' as external dependency
Treating 'd3-scale' as external dependency
Treating 'd3-selection' as external dependency
Treating 'd3-time' as external dependency
Treating 'd3-time-format' as external dependency
So, how can I update the src/timeline.js
file to correctly export as default for use with npm install d3-timeline
in Angular and also ensure compatibility for browser usage? Alternatively, how should I configure rollup to enable the current src/timeline.js
functionality?
Your help is greatly appreciated!