diff --git a/Changelog.md b/Changelog.md index f70a966d2..46977bfb9 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,6 @@ ## 5.0.0-alpha2 -* Change minimum chart size from 200x200to 25x25 +* Change minimum chart size from 200x200to 25x25. +* Use dimName instead of chartID for FilterStorage. ## 5.0.0-alpha1 * Port to typescript. diff --git a/src/core/filter-storage.ts b/src/core/filter-storage.ts index 878267489..1b564b44b 100644 --- a/src/core/filter-storage.ts +++ b/src/core/filter-storage.ts @@ -55,7 +55,7 @@ export class FilterStorage implements IFilterStorage { l.onFiltersChanged(filters); }); - const chartIds = listenerChain.map(lsnr => lsnr.chartId); + const chartIds = listenerChain.map(lsnr => lsnr.dimName); this._filterChangeListener.call('filter-changed', this, { chartIds, filters: this._filters.get(storageKey), @@ -108,7 +108,7 @@ export class FilterStorage implements IFilterStorage { if (listener) { const filters = this._filters.get(listener.storageKey); if (filters && filters.length > 0) { - const entry = this._serializeFilters(listener.chartId, filters); + const entry = this._serializeFilters(listener.dimName, filters); if (includeStorageKey) { entry.storageKey = listener.storageKey; } @@ -127,7 +127,7 @@ export class FilterStorage implements IFilterStorage { entries.map(entry => { // Find a listenerChain that has same chartId registered const listenerChain = listenerChains.find((lsnrsChain: IFilterListenerParams[]) => - lsnrsChain.find(listener => listener.chartId === entry.chartId) + lsnrsChain.find(listener => listener.dimName === entry.dimName) ); // convert to appropriate dc IFilter objects @@ -150,10 +150,10 @@ export class FilterStorage implements IFilterStorage { } } - private _serializeFilters(chartId: string, filters: any[]): ISerializedFilters { + private _serializeFilters(dimName: string, filters: any[]): ISerializedFilters { if (typeof filters[0].isFiltered !== 'function') { return { - chartId, + dimName, filterType: 'Simple', values: [...filters], // defensively clone }; @@ -161,7 +161,7 @@ export class FilterStorage implements IFilterStorage { const filtersWithType: IFilter[] = filters; return { - chartId, + dimName, filterType: filtersWithType[0].filterType, values: filtersWithType.map(f => f.serialize()), }; diff --git a/src/core/i-filter-storage.ts b/src/core/i-filter-storage.ts index a2a7d4e08..ceb5053c9 100644 --- a/src/core/i-filter-storage.ts +++ b/src/core/i-filter-storage.ts @@ -3,7 +3,7 @@ import { ISerializedFilters } from './i-serialized-filters.js'; export interface IFilterListenerParams { storageKey: any; onFiltersChanged: (filters) => void; - chartId: string; + dimName: string; primaryChart: boolean; applyFilters: (filters) => void; } diff --git a/src/core/i-serialized-filters.ts b/src/core/i-serialized-filters.ts index 7a6ca5051..257e9a77d 100644 --- a/src/core/i-serialized-filters.ts +++ b/src/core/i-serialized-filters.ts @@ -1,5 +1,5 @@ export interface ISerializedFilters { - chartId: string; + dimName: string; filterType: string; values: any[]; storageKey?: any; diff --git a/src/core/types.ts b/src/core/types.ts index 3c84da481..6d48056ed 100644 --- a/src/core/types.ts +++ b/src/core/types.ts @@ -18,6 +18,7 @@ export interface MinimalCFDimension { // filterAll(): this; // unused top(k: number): any[]; bottom(k: number): any[]; + name?: string; } export interface CFGrouping { diff --git a/src/data/filter-storage-helper.ts b/src/data/filter-storage-helper.ts index a96d6b106..d6d4758ae 100644 --- a/src/data/filter-storage-helper.ts +++ b/src/data/filter-storage-helper.ts @@ -4,6 +4,7 @@ import { IFilterStorage } from '../core/i-filter-storage.js'; export interface IFilterStorageConf extends ICFFilterHandlerConf { readonly filterStorage?: IFilterStorage; readonly chartId?: string; + readonly dimName?: string; readonly primaryChart?: boolean; readonly shareFilters?: boolean; readonly onFiltersChanged?: (filters) => void; @@ -27,10 +28,19 @@ export class FilterStorageHelper extends CFFilterHandler { public configure(conf: IFilterStorageConf): this { super.configure(conf); + if ('dimName' in conf) { + if (typeof this._conf.dimension === 'object') { + this._conf.dimension.name = conf.dimName; + } + } this._ensureListenerRegistered(); return this; } + get dimName(): string { + return this._conf.dimension?.name || this._conf.chartId; + } + private _ensureListenerRegistered() { if (!this._conf.filterStorage) { return; @@ -53,7 +63,7 @@ export class FilterStorageHelper extends CFFilterHandler { this._listenerRegToken = this._conf.filterStorage.registerFilterListener({ storageKey, onFiltersChanged: this._conf.onFiltersChanged, - chartId: this._conf.chartId, + dimName: this.dimName, primaryChart: this._conf.primaryChart, applyFilters: filters => this.applyFilters(), });