我試圖構建一個d3 v4插件,遵循https://bost.ocks.org/mike/d3-plugin/ - 最終目標是能夠安裝插件並將其用於Angular 2/4組件。d3 v4插件 - 如何要求其他d3插件?
我的回購是在這裏:
https://github.com/denisemauldin/d3-timeline
例子:
https://denisemauldin.github.io/d3-timeline/examples/example.html
我運行到試圖包括其他D3要求的問題。以上不包括如何使用其他d3組件的示例。 我需要使用d3.timeFormat
,d3.timeHour
,d3.scaleOrdinal
,d3.schemeCategory
,d3.mouse
,d3.select
,d3.axisTop
,d3.axisBottom
和d3.scaleLinear
。
這些來自d3-axis
,d3-scale
,d3-selection
,d3-time
和d3-time-format
。我已經嘗試了幾種不同的方法:它們包括在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)把它放置在timeline.js源
1):
現在它在瀏覽器中加載並運行良好,但我無法弄清楚如何讓npm install工作,以便我可以構建一個npm包以便與我的Angular2站點一起使用。
我試過rollup-plugin-commonjs
的一些不同的rollup.config.js
選項。我不確定這是我想要去的方式,因爲它似乎會生成一個包含所有我需要的d3代碼的包文件。眼下彙總調用(這是包含在D3插件啓動包)失敗:
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')
如果我刪除我的rollup.config.js
然後它給了我同樣的錯誤,但也說:
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
那麼,如何更新src/timeline.js
文件以導出默認值,以便我可以將其與npm install d3-timeline
一起用於Angular中,並且還可以在瀏覽器中使用它?或者,如何配置彙總以使當前src/timeline.js
文件有效?
謝謝!