11'use strict' ;
2- const Fs = require ( 'fs' ) ;
32const D3 = require ( 'd3' ) ;
43const { D3Node } = require ( 'd3-node' ) ;
54
65const styles = `
6+ svg {
7+ width: 100%;
8+ height: auto;
9+ }
710.current {
811 fill: #5fa04e;
912}
@@ -92,7 +95,7 @@ function parseInput (data, queryStart, queryEnd, excludeMain, projectName) {
9295
9396
9497function create ( options ) {
95- const { queryStart, queryEnd, html , svg : svgFile , png , animate, excludeMain, projectName, margin : marginInput , currentDateMarker } = options ;
98+ const { queryStart, queryEnd, animate, excludeMain, projectName, margin : marginInput , currentDateMarker } = options ;
9699 const data = parseInput ( options . data , queryStart , queryEnd , excludeMain , projectName ) ;
97100 const d3n = new D3Node ( { styles, d3Module : D3 } ) ;
98101 const margin = marginInput || { top : 30 , right : 30 , bottom : 30 , left : 110 } ;
@@ -113,6 +116,8 @@ function create (options) {
113116 const svg = d3n . createSVG ( )
114117 . attr ( 'width' , width + margin . left + margin . right )
115118 . attr ( 'height' , height + margin . top + margin . bottom )
119+ . attr ( 'viewBox' , `0 0 ${ width + margin . left + margin . right } ${ height + margin . top + margin . bottom } ` )
120+ . attr ( 'preserveAspectRatio' , 'xMinYMin meet' )
116121 . append ( 'g' )
117122 . attr ( 'id' , 'bar-container' )
118123 . attr ( 'transform' , `translate(${ margin . left } , ${ margin . top } )` ) ;
@@ -220,19 +225,7 @@ function create (options) {
220225 return + ( calculateWidth ( data ) >= min ) ;
221226 } ) ;
222227
223- if ( typeof html === 'string' ) {
224- Fs . writeFileSync ( html , d3n . html ( ) ) ;
225- }
226-
227- if ( typeof svgFile === 'string' ) {
228- Fs . writeFileSync ( svgFile , d3n . svgString ( ) ) ;
229- }
230-
231- if ( typeof png === 'string' ) {
232- const Svg2png = require ( 'svg2png' ) ; // Load this lazily.
233-
234- Fs . writeFileSync ( png , Svg2png . sync ( Buffer . from ( d3n . svgString ( ) ) ) ) ;
235- }
228+ return d3n ;
236229}
237230
238231module . exports . create = create ;
0 commit comments