Skip to content

Commit

Permalink
change options
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Mar 15, 2019
1 parent 57d6e55 commit bd8c814
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
42 changes: 20 additions & 22 deletions src/provider/ADataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {AEventDispatcher, debounce, ISequence, OrderedSet, IDebounceContext, IEv
import {Column, Ranking, AggregateGroupColumn, createAggregateDesc, IAggregateGroupColumnDesc, isSupportType, EDirtyReason, RankColumn, createRankDesc, createSelectionDesc, IColumnDesc, IDataRow, IGroup, IndicesArray, IOrderedGroup, ISelectionColumnDesc, EAggregationState, IColumnDump, IRankingDump, IColorMappingFunctionConstructor, IMappingFunctionConstructor, ITypeFactory} from '../model';
import {models} from '../model/models';
import {forEachIndices, everyIndices, toGroupID, unifyParents} from '../model/internal';
import {IDataProvider, IDataProviderDump, IDataProviderOptions, SCHEMA_REF, IExportOptions, IAggregationStrategy} from './interfaces';
import {IDataProvider, IDataProviderDump, IDataProviderOptions, SCHEMA_REF, IExportOptions} from './interfaces';
import {exportRanking, map2Object, object2Map} from './utils';
import {IRenderTasks} from '../renderer';
import {IColumnConstructor} from '../model/Column';
Expand Down Expand Up @@ -211,33 +211,31 @@ abstract class ADataProvider extends AEventDispatcher implements IDataProvider {
private uid = 0;
private readonly typeFactory: ITypeFactory;

private readonly options: Readonly<IDataProviderOptions> = {
columnTypes: {},
colorMappingFunctionTypes: {},
mappingFunctionTypes: {},
singleSelection: false,
showTopN: 10,
aggregationStrategy: 'item'
};

/**
* lookup map of a column type to its column implementation
*/
readonly columnTypes: {[columnType: string]: IColumnConstructor};
readonly colorMappingFunctionTypes: {[colorMappingFunctionType: string]: IColorMappingFunctionConstructor};
readonly mappingFunctionTypes: {[mappingFunctionType: string]: IMappingFunctionConstructor};

protected readonly multiSelections: boolean;
private readonly aggregationStrategy: IAggregationStrategy;
private showTopN: number;

constructor(options: Partial<IDataProviderOptions> = {}) {
super();
const o: Readonly<IDataProviderOptions> = Object.assign({
columnTypes: {},
colorMappingFunctionTypes: {},
mappingFunctionTypes: {},
singleSelection: false,
showTopN: 10,
aggregationStrategy: 'item'
}, options);
this.columnTypes = Object.assign(models(), o.columnTypes);
this.colorMappingFunctionTypes = Object.assign(colorMappingFunctions(), o.colorMappingFunctionTypes);
this.mappingFunctionTypes = Object.assign(mappingFunctions(), o.mappingFunctionTypes);
this.multiSelections = o.singleSelection !== true;
this.showTopN = o.showTopN;
this.aggregationStrategy = o.aggregationStrategy;
Object.assign(this.options, options);
this.columnTypes = Object.assign(models(), this.options.columnTypes);
this.colorMappingFunctionTypes = Object.assign(colorMappingFunctions(), this.options.colorMappingFunctionTypes);
this.mappingFunctionTypes = Object.assign(mappingFunctions(), this.options.mappingFunctionTypes);
this.showTopN = this.options.showTopN;

this.typeFactory = this.createTypeFactory();
}
Expand Down Expand Up @@ -695,7 +693,7 @@ abstract class ADataProvider extends AEventDispatcher implements IDataProvider {
if (addSupportType) {
r.push(this.create(createAggregateDesc())!);
r.push(this.create(createRankDesc())!);
if (this.multiSelections) {
if (this.options.singleSelection !== false) {
r.push(this.create(createSelectionDesc())!);
}
}
Expand Down Expand Up @@ -750,12 +748,12 @@ abstract class ADataProvider extends AEventDispatcher implements IDataProvider {
}

getAggregationStrategy() {
return this.aggregationStrategy;
return this.options.aggregationStrategy;
}

private initAggregateState(ranking: Ranking, groups: IGroup[]) {
let initial = -1;
switch(this.aggregationStrategy) {
switch(this.getAggregationStrategy()) {
case 'group':
initial = 0;
break;
Expand Down Expand Up @@ -880,7 +878,7 @@ abstract class ADataProvider extends AEventDispatcher implements IDataProvider {
if (this.selection.has(index)) {
return; //no change
}
if (!this.multiSelections && this.selection.size > 0) {
if (this.options.singleSelection === true && this.selection.size > 0) {
this.selection.clear();
}
this.selection.add(index);
Expand Down Expand Up @@ -909,7 +907,7 @@ abstract class ADataProvider extends AEventDispatcher implements IDataProvider {
if (everyIndices(indices, (i) => this.selection.has(i))) {
return; //no change
}
if (!this.multiSelections) {
if (this.options.singleSelection === true) {
this.selection.clear();
if (indices.length > 0) {
this.selection.add(indices[0]);
Expand Down
12 changes: 6 additions & 6 deletions src/provider/LocalDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface ISortHelper {
* a data provider based on an local array
*/
export default class LocalDataProvider extends ACommonDataProvider {
private readonly options: ILocalDataProviderOptions = {
private readonly ooptions: ILocalDataProviderOptions = {
/**
* whether the filter should be applied to all rankings regardless where they are
*/
Expand All @@ -56,9 +56,9 @@ export default class LocalDataProvider extends ACommonDataProvider {

constructor(private _data: any[], columns: IColumnDesc[] = [], options: Partial<ILocalDataProviderOptions & IDataProviderOptions> = {}) {
super(columns, options);
Object.assign(this.options, options);
Object.assign(this.ooptions, options);
this._dataRows = toRows(_data);
this.tasks = this.options.taskExecutor === 'direct' ? new DirectRenderTasks() : new ScheduleRenderTasks();
this.tasks = this.ooptions.taskExecutor === 'direct' ? new DirectRenderTasks() : new ScheduleRenderTasks();
this.tasks.setData(this._dataRows);

const that = this;
Expand Down Expand Up @@ -145,7 +145,7 @@ export default class LocalDataProvider extends ACommonDataProvider {
cloneRanking(existing?: Ranking) {
const ranking = super.cloneRanking(existing);

if (this.options.filterGlobally) {
if (this.ooptions.filterGlobally) {
ranking.on(`${Ranking.EVENT_FILTER_CHANGED}.reorderAll`, this.reorderAll);
}

Expand Down Expand Up @@ -207,7 +207,7 @@ export default class LocalDataProvider extends ACommonDataProvider {
}

cleanUpRanking(ranking: Ranking) {
if (this.options.filterGlobally) {
if (this.ooptions.filterGlobally) {
ranking.on(`${Ranking.EVENT_FILTER_CHANGED}.reorderAll`, null);
}

Expand All @@ -233,7 +233,7 @@ export default class LocalDataProvider extends ACommonDataProvider {
//do the optional filtering step
const filter: (Column | ((d: IDataRow) => boolean))[] = [];

if (this.options.filterGlobally) {
if (this.ooptions.filterGlobally) {
for (const r of this.getRankings()) {
if (r.isFiltered()) {
filter.push(...r.flatColumns.filter((d) => d.isFiltered()));
Expand Down
6 changes: 3 additions & 3 deletions src/provider/RemoteDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function createIndex2Pos(order: IndicesArray) {
* a remote implementation of the data provider
*/
export default class RemoteDataProvider extends ACommonDataProvider {
private readonly options: IRemoteDataProviderOptions = {
private readonly ooptions: IRemoteDataProviderOptions = {
maxCacheSize: 1000
};

Expand All @@ -62,7 +62,7 @@ export default class RemoteDataProvider extends ACommonDataProvider {

constructor(private server: IServerData, columns: IColumnDesc[] = [], options: Partial<IRemoteDataProviderOptions & IDataProviderOptions> = {}) {
super(columns, options);
Object.assign(this.options, options);
Object.assign(this.ooptions, options);
}

getTotalNumberOfRows() {
Expand Down Expand Up @@ -107,7 +107,7 @@ export default class RemoteDataProvider extends ACommonDataProvider {
// removed cached
this.cache.forEach((_v, k) => union.delete(k));

if ((this.cache.size + union.size) > this.options.maxCacheSize) {
if ((this.cache.size + union.size) > this.ooptions.maxCacheSize) {
// clean up cache
}
// const maxLength = Math.max(...orders.map((o) => o.length));
Expand Down

0 comments on commit bd8c814

Please sign in to comment.