66 diamondShape ,
77 addChartTitleLabel ,
88 addAxisLabel ,
9+ customTemporalAxis
910} from "../lib/helpers.js" ;
1011
1112let graphic = d3 . select ( "#graphic" ) ;
@@ -110,8 +111,8 @@ function drawGraphic() {
110111 config . dropYAxis !== true
111112 ? d3 . format ( config . yAxisTickFormat ) ( d )
112113 : chartPosition == 0
113- ? d3 . format ( config . yAxisTickFormat ) ( d )
114- : ""
114+ ? d3 . format ( config . yAxisTickFormat ) ( d )
115+ : ""
115116 ) ;
116117
117118 // Use stackColumns for the stack instead of filtering out lineSeries
@@ -126,44 +127,37 @@ function drawGraphic() {
126127
127128 let xTime = d3 . timeFormat ( config . xAxisTickFormat [ size ] ) ;
128129
129- //set up xAxis generator
130- const xAxis = d3
131- . axisBottom ( x )
132- . tickSize ( 10 )
133- . tickPadding ( 10 )
134- . tickValues (
135- xDataType == "date"
136- ? graphic_data
137- . map ( function ( d ) {
138- return d . date . getTime ( ) ;
139- } ) //just get dates as seconds past unix epoch
140- . filter ( function ( d , i , arr ) {
141- return arr . indexOf ( d ) == i ;
142- } ) //find unique
143- . map ( function ( d ) {
144- return new Date ( d ) ;
145- } ) //map back to dates
146- . sort ( function ( a , b ) {
147- return a - b ;
148- } )
149- . filter ( function ( d , i ) {
150- return (
151- ( i % config . xAxisTicksEvery [ size ] === 0 &&
152- i <= graphic_data . length - config . xAxisTicksEvery [ size ] ) ||
153- i == data . length - 1
154- ) ; //Rob's fussy comment about labelling the last date
155- } )
156- : x . domain ( ) . filter ( ( d , i ) => {
157- return (
158- ( i % config . xAxisTicksEvery [ size ] === 0 &&
159- i <= graphic_data . length - config . xAxisTicksEvery [ size ] ) ||
160- i == data . length - 1
161- ) ;
162- } )
163- )
164- . tickFormat ( ( d ) =>
165- xDataType == "date" ? xTime ( d ) : d3 . format ( config . xAxisNumberFormat ) ( d )
166- ) ;
130+ let xAxis ;
131+
132+ let tickValues = x . domain ( ) . filter ( function ( d , i ) {
133+ return ! ( i % config . xAxisTicksEvery [ size ] ) ;
134+ } ) ;
135+
136+ //Labelling the first and/or last bar if needed
137+ if ( config . addFirstDate == true ) {
138+ tickValues . push ( domain [ 0 ] ) ;
139+ }
140+
141+ if ( config . addFinalDate == true ) {
142+ tickValues . push ( domain [ domain . length - 1 ] ) ;
143+ }
144+
145+ if ( config . labelSpans . enabled === true && xDataType == "date" ) {
146+ xAxis = customTemporalAxis ( x )
147+ . timeUnit ( config . labelSpans . timeUnit )
148+ . tickSize ( 0 )
149+ . tickPadding ( 6 )
150+ . secondaryTimeUnit ( config . labelSpans . secondaryTimeUnit ) ;
151+ } else {
152+ xAxis = d3
153+ . axisBottom ( x )
154+ . tickSize ( 10 )
155+ . tickPadding ( 10 )
156+ . tickValues ( tickValues )
157+ . tickFormat ( ( d ) =>
158+ xDataType == "date" ? xTime ( d ) : d3 . format ( config . xAxisNumberFormat ) ( d )
159+ ) ;
160+ }
167161
168162 //create svg for chart
169163 const svg = addSvg ( {
@@ -405,7 +399,7 @@ d3.csv(config.graphicDataUrl).then((data) => {
405399 //load chart data
406400 graphic_data = data ;
407401
408- let parseTime = d3 . timeParse ( config . dateFormat ) ;
402+ let parseTime = d3 . utcParse ( config . dateFormat ) ;
409403
410404 data . forEach ( ( d , i ) => {
411405 //If the date column is has date data store it as dates
0 commit comments