Skip to content

Commit

Permalink
small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Nov 17, 2018
1 parent 62a1f6d commit f689a5d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
15 changes: 15 additions & 0 deletions src/model/ICategoricalColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,21 @@ export function toGroupCompareCategoryValue(rows: IDataRow[], col: ICategoricalC

export const COMPARE_GROUP_CATEGORY_VALUE_TYPES = [ECompareValueType.FLOAT, ECompareValueType.STRING, ECompareValueType.UINT];

/** @internal */
function compareCategory(a: ICategory | null, b: ICategory | null) {
const aNull = a == null || isNaN(a.value);
const bNull = b == null || isNaN(b.value);
if (aNull || a == null) {
return bNull ? 0 : FIRST_IS_MISSING;
}
if (bNull || b == null) {
return -FIRST_IS_MISSING;
}
if (a.value === b.value) {
return a.label.toLowerCase().localeCompare(b.label.toLowerCase());
}
return a.value - b.value;
}

/** @internal */
export function toCategories(desc: ICategoricalDesc) {
Expand Down
12 changes: 12 additions & 0 deletions src/provider/LocalDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Ranking from '../model/Ranking';
import ACommonDataProvider from './ACommonDataProvider';
import {IDataProviderOptions, IStatsBuilder} from './interfaces';
import {sortComplex} from './sort';
import {range} from 'd3-array';


export interface ILocalDataProviderOptions {
Expand Down Expand Up @@ -162,6 +163,17 @@ export default class LocalDataProvider extends ACommonDataProvider {
filter = !filter ? this.filter : (d) => this.filter!(d) && bak!(d);
}

const isGroupedBy = ranking.getGroupCriteria().length > 0;
const isSortedBy = ranking.getSortCriteria().length > 0;

if (!isGroupedBy && isSortedBy && !filter) {
// initial no sorting required just index mapping
const order = chooseByLength(this._data.length);
order.set(range(this._data.length));
const index2pos = order.slice();
return [Object.assign({order, index2pos}, defaultGroup)];
}

const groups = new Map<string, {group: IGroup, rows: {r: IDataRow, sort: ICompareValue[]}[]}>();

for (const r of this._dataRows) {
Expand Down
8 changes: 0 additions & 8 deletions src/provider/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ function stringCompare(a: string | null, b: string | null) {
return compare.compare(av, bv);
}

export function sortNumber(arr: (number | null)[]) {
return arr.sort(floatCompare);
}

export function sortString(arr: (string | null)[]) {
return arr.sort(stringCompare);
}

function toFunction(f: {asc: boolean, v: ECompareValueType}): (a: any, b: any)=>number {
switch(f.v) {
case ECompareValueType.BINARY:
Expand Down

0 comments on commit f689a5d

Please sign in to comment.