File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change 1- import { identity } from '../../utils/commons' ;
1+ import { compareByValueAsc , identity } from '../../utils/commons' ;
22import { computeContinuousDataDomain , computeOrdinalDataDomain } from '../../utils/domain' ;
33import { ScaleType } from '../../utils/scales/scales' ;
44import { BasicSeriesSpec } from '../specs' ;
@@ -49,14 +49,17 @@ export function mergeXDomain(
4949 * to display a bar chart in a linear scale.
5050 */
5151export function findMinInterval ( xValues : number [ ] ) : number | null {
52- const sortedValues = xValues . slice ( ) . sort ( ) ;
52+ if ( xValues . length === 1 ) {
53+ return 1 ;
54+ }
55+ const sortedValues = xValues . slice ( ) . sort ( compareByValueAsc ) ;
5356 const sortedValuesLength = sortedValues . length - 1 ;
5457 let i ;
5558 let minInterval = null ;
5659 for ( i = 0 ; i < sortedValuesLength ; i ++ ) {
5760 const current = sortedValues [ i ] ;
5861 const next = sortedValues [ i + 1 ] ;
59- const interval = next - current ;
62+ const interval = Math . abs ( next - current ) ;
6063 if ( minInterval === null ) {
6164 minInterval = interval ;
6265 } else {
Original file line number Diff line number Diff line change 11export function identity < T > ( value : T ) : T {
22 return value ;
33}
4+
5+ export function compareByValueAsc ( firstEl : number , secondEl : number ) : number {
6+ return firstEl - secondEl ;
7+ }
You can’t perform that action at this time.
0 commit comments