@@ -206,36 +206,90 @@ describe('Axis computational utils', () => {
206206 expect ( xScale ) . toBeDefined ( ) ;
207207 } ) ;
208208
209- test ( 'should compute available ticks' , ( ) => {
210- const scale = getScaleForAxisSpec ( verticalAxisSpec , xDomain , [ yDomain ] , 0 , 0 , 100 , 0 ) ;
211- const axisPositions = getAvailableTicks ( verticalAxisSpec , scale ! , 0 , false ) ;
212- const expectedAxisPositions = [
213- { label : '0' , position : 100 , value : 0 } ,
214- { label : '0.1' , position : 90 , value : 0.1 } ,
215- { label : '0.2' , position : 80 , value : 0.2 } ,
216- { label : '0.3' , position : 70 , value : 0.3 } ,
217- { label : '0.4' , position : 60 , value : 0.4 } ,
218- { label : '0.5' , position : 50 , value : 0.5 } ,
219- { label : '0.6' , position : 40 , value : 0.6 } ,
220- { label : '0.7' , position : 30 , value : 0.7 } ,
221- { label : '0.8' , position : 20 , value : 0.8 } ,
222- { label : '0.9' , position : 10 , value : 0.9 } ,
223- { label : '1' , position : 0 , value : 1 } ,
224- ] ;
225- expect ( axisPositions ) . toEqual ( expectedAxisPositions ) ;
226-
227- // histogram mode axis ticks should add an additional tick
228- const xBandDomain : XDomain = {
229- type : 'xDomain' ,
230- scaleType : ScaleType . Linear ,
231- domain : [ 0 , 100 ] ,
232- isBandScale : true ,
233- minInterval : 10 ,
234- } ;
235- const xScale = getScaleForAxisSpec ( horizontalAxisSpec , xBandDomain , [ yDomain ] , 1 , 0 , 100 , 0 ) ;
236- const histogramAxisPositions = getAvailableTicks ( horizontalAxisSpec , xScale ! , 1 , true ) ;
237- const histogramTickLabels = histogramAxisPositions . map ( ( tick : AxisTick ) => tick . label ) ;
238- expect ( histogramTickLabels ) . toEqual ( [ '0' , '10' , '20' , '30' , '40' , '50' , '60' , '70' , '80' , '90' , '100' , '110' ] ) ;
209+ describe ( 'getAvailableTicks' , ( ) => {
210+ test ( 'should compute to end of domain when histogram mode not enabled' , ( ) => {
211+ const enableHistogramMode = false ;
212+ const scale = getScaleForAxisSpec ( verticalAxisSpec , xDomain , [ yDomain ] , 0 , 0 , 100 , 0 ) ;
213+ const axisPositions = getAvailableTicks ( verticalAxisSpec , scale ! , 0 , enableHistogramMode ) ;
214+ const expectedAxisPositions = [
215+ { label : '0' , position : 100 , value : 0 } ,
216+ { label : '0.1' , position : 90 , value : 0.1 } ,
217+ { label : '0.2' , position : 80 , value : 0.2 } ,
218+ { label : '0.3' , position : 70 , value : 0.3 } ,
219+ { label : '0.4' , position : 60 , value : 0.4 } ,
220+ { label : '0.5' , position : 50 , value : 0.5 } ,
221+ { label : '0.6' , position : 40 , value : 0.6 } ,
222+ { label : '0.7' , position : 30 , value : 0.7 } ,
223+ { label : '0.8' , position : 20 , value : 0.8 } ,
224+ { label : '0.9' , position : 10 , value : 0.9 } ,
225+ { label : '1' , position : 0 , value : 1 } ,
226+ ] ;
227+ expect ( axisPositions ) . toEqual ( expectedAxisPositions ) ;
228+ } ) ;
229+
230+ test ( 'should extend ticks to domain + minInterval in histogram mode for linear scale' , ( ) => {
231+ const enableHistogramMode = true ;
232+ const xBandDomain : XDomain = {
233+ type : 'xDomain' ,
234+ scaleType : ScaleType . Linear ,
235+ domain : [ 0 , 100 ] ,
236+ isBandScale : true ,
237+ minInterval : 10 ,
238+ } ;
239+ const xScale = getScaleForAxisSpec ( horizontalAxisSpec , xBandDomain , [ yDomain ] , 1 , 0 , 100 , 0 ) ;
240+ const histogramAxisPositions = getAvailableTicks ( horizontalAxisSpec , xScale ! , 1 , enableHistogramMode ) ;
241+ const histogramTickLabels = histogramAxisPositions . map ( ( { label } : AxisTick ) => label ) ;
242+ expect ( histogramTickLabels ) . toEqual ( [ '0' , '10' , '20' , '30' , '40' , '50' , '60' , '70' , '80' , '90' , '100' , '110' ] ) ;
243+ } ) ;
244+
245+ test ( 'should extend ticks to domain + minInterval in histogram mode for time scale' , ( ) => {
246+ const enableHistogramMode = true ;
247+ const xBandDomain : XDomain = {
248+ type : 'xDomain' ,
249+ scaleType : ScaleType . Time ,
250+ domain : [ 1560438420000 , 1560438510000 ] ,
251+ isBandScale : true ,
252+ minInterval : 90000 ,
253+ } ;
254+ const xScale = getScaleForAxisSpec ( horizontalAxisSpec , xBandDomain , [ yDomain ] , 1 , 0 , 100 , 0 ) ;
255+ const histogramAxisPositions = getAvailableTicks ( horizontalAxisSpec , xScale ! , 1 , enableHistogramMode ) ;
256+ const histogramTickValues = histogramAxisPositions . map ( ( { value } : AxisTick ) => value ) ;
257+
258+ const expectedTickValues = [
259+ 1560438420000 ,
260+ 1560438435000 ,
261+ 1560438450000 ,
262+ 1560438465000 ,
263+ 1560438480000 ,
264+ 1560438495000 ,
265+ 1560438510000 ,
266+ 1560438525000 ,
267+ 1560438540000 ,
268+ 1560438555000 ,
269+ 1560438570000 ,
270+ 1560438585000 ,
271+ 1560438600000 ,
272+ ] ;
273+
274+ expect ( histogramTickValues ) . toEqual ( expectedTickValues ) ;
275+ } ) ;
276+
277+ test ( 'should extend ticks to domain + minInterval in histogram mode for a scale with single datum' , ( ) => {
278+ const enableHistogramMode = true ;
279+ const xBandDomain : XDomain = {
280+ type : 'xDomain' ,
281+ scaleType : ScaleType . Time ,
282+ domain : [ 1560438420000 , 1560438420000 ] , // a single datum scale will have the same value for domain start & end
283+ isBandScale : true ,
284+ minInterval : 90000 ,
285+ } ;
286+ const xScale = getScaleForAxisSpec ( horizontalAxisSpec , xBandDomain , [ yDomain ] , 1 , 0 , 100 , 0 ) ;
287+ const histogramAxisPositions = getAvailableTicks ( horizontalAxisSpec , xScale ! , 1 , enableHistogramMode ) ;
288+ const histogramTickValues = histogramAxisPositions . map ( ( { value } : AxisTick ) => value ) ;
289+ const expectedTickValues = [ 1560438420000 , 1560438510000 ] ;
290+
291+ expect ( histogramTickValues ) . toEqual ( expectedTickValues ) ;
292+ } ) ;
239293 } ) ;
240294 test ( 'should compute visible ticks for a vertical axis' , ( ) => {
241295 const allTicks = [
0 commit comments