Skip to content

Commit

Permalink
Use data lib's comparator
Browse files Browse the repository at this point in the history
(This way  the returned domain is consistent with order in axis in visualizations)

cc: @RileyChang
  • Loading branch information
kanitw committed Sep 1, 2016
1 parent d10607d commit 41e4735
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as dlBin from 'datalib/src/bins/bins';

import {BinQuery, EncodingQuery} from './query/encoding';
import {QueryConfig, DEFAULT_QUERY_CONFIG} from './config';
import {contains, extend, keys} from './util';
import {cmp, contains, extend, keys} from './util';

export class Schema {
private _fieldSchemas: FieldSchema[];
Expand Down Expand Up @@ -255,11 +255,14 @@ export class Schema {
fieldSchema.primitiveType === PrimitiveType.NUMBER) {
// coerce non-quantitative numerical data into number type
domain = domain.map(x => +x);
return domain.sort(function(a, b) {
return a - b;
});
return domain.sort(cmp);
}
return domain.sort();

return domain.map((x) => {
// Convert 'null' to null as it is encoded similarly in datalib.
// This is wrong when it is a string 'null' but that rarely happens.
return x==='null' ? null : x;
}).sort(cmp);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {isArray} from 'datalib/src/util';
export {keys, duplicate, extend, isObject, isArray} from 'datalib/src/util';
export {cmp, keys, duplicate, extend, isObject, isArray} from 'datalib/src/util';

export interface Dict<T> {
[key: string]: T;
Expand Down
1 change: 1 addition & 0 deletions typings/datalib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ declare module 'datalib/src/import/load' {
}

declare module 'datalib/src/util' {
export function cmp(a, b): number;
export function keys(a): Array<string>;
export function extend(a, b, ...rest);
export function duplicate<T>(a: T): T;
Expand Down

0 comments on commit 41e4735

Please sign in to comment.