Skip to content

Commit

Permalink
more live preview options
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Mar 25, 2020
1 parent 892e650 commit bab0805
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 35 deletions.
29 changes: 18 additions & 11 deletions src/builder/LineUpBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,24 @@ export default class LineUpBuilder {
return this;
}

livePreviews({search = false, filter = true, vis = true}) {
this.options.livePreviews = [];
if (search) {
this.options.livePreviews.push('search');
}
if (filter) {
this.options.livePreviews.push('filter');
}
if (vis) {
this.options.livePreviews.push('vis');
}
livePreviews(obj: {search?: boolean, filter?: boolean, vis?: boolean, sort?: boolean, group?: boolean, groupSort?: boolean, colorMapping?: boolean, dataMapping?: boolean}) {
const features: {[key: string]: boolean} = Object.assign({
// 'search', 'filter', 'vis', 'sort', 'group', 'sortGroup', 'colorMapping'
search: true,
filter: true,
vis: true,
group: true,
sort: true,
sortGroup: true,
colorMapping: true,
}, obj);
const options: string[] = [];
Object.keys(features).forEach((key) => {
if (features[key]) {
options.push(key);
}
});
this.options.livePreviews = options;
return this;
}

Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export interface ILineUpOptions {
* flag whether to shows filter previews as soon as the user changes the filter in the dialog
* @default ['filter', 'vis']
*/
livePreviews: ('search' | 'filter' | 'vis')[];
livePreviews: string[];

/**
* option to specify the default slope graph mode
Expand Down Expand Up @@ -209,7 +209,7 @@ export function defaultOptions(): ITaggleOptions {
defaultSlopeGraphMode: 'item',
overviewMode: false,

livePreviews: ['filter', 'vis'],
livePreviews: ['search', 'filter', 'vis', 'sort', 'group', 'sortGroup', 'colorMapping'],
onDialogBackgroundClick: 'cancel',

rowHeight: 18,
Expand Down
10 changes: 7 additions & 3 deletions src/ui/dialogs/ADialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IRankingHeaderContext} from '../interfaces';

export interface IDialogOptions {
title: string;
livePreview: boolean;
livePreview: boolean | string;
popup: boolean;
// popper options
placement?: Popper.Placement;
Expand All @@ -33,7 +33,7 @@ export function dialogContext(ctx: IRankingHeaderContext, level: number, attachm

abstract class ADialog {

protected readonly options: Readonly<IDialogOptions> = {
private readonly options: Readonly<IDialogOptions> = {
title: '',
livePreview: false,
popup: false,
Expand Down Expand Up @@ -62,8 +62,12 @@ abstract class ADialog {

protected abstract build(node: HTMLElement): boolean | void;

protected showLivePreviews() {
return this.options.livePreview === true || (typeof this.options.livePreview === 'string' && this.dialog.manager.livePreviews.includes(this.options.livePreview));
}

protected enableLivePreviews(selector: string | (HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement)[]) {
if (!this.options.livePreview) {
if (!this.showLivePreviews()) {
return;
}
const submitter = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/dialogs/BooleanFilterDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class BooleanFilterDialog extends ADialog {

constructor(private readonly column: BooleanColumn, dialog: IDialogContext) {
super(dialog, {
livePreview: dialog.manager.livePreviews.includes('filter')
livePreview: 'filter'
});
this.before = this.column.getFilter();
}
Expand Down
4 changes: 3 additions & 1 deletion src/ui/dialogs/CategoricalColorMappingDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export default class CategoricalColorMappingDialog extends ADialog {
private readonly before: ICategoricalColorMappingFunction;

constructor(private readonly column: ICategoricalColumn | CategoricalsColumn | CategoricalMapColumn, dialog: IDialogContext) {
super(dialog);
super(dialog, {
livePreview: 'colorMapping'
});

this.before = column.getColorMapping().clone();
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/dialogs/CategoricalFilterDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class CategoricalFilterDialog extends ADialog {

constructor(private readonly column: CategoricalColumn | SetColumn, dialog: IDialogContext) {
super(dialog, {
livePreview: dialog.manager.livePreviews.includes('filter')
livePreview: 'filter'
});
this.before = this.column.getFilter() || {filter: this.column.categories.map((d) => d.name), filterMissing: false};
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/dialogs/CategoricalMappingFilterDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class CategoricalMappingFilterDialog extends ADialog {

constructor(private readonly column: OrdinalColumn, dialog: IDialogContext) {
super(dialog, {
livePreview: dialog.manager.livePreviews.includes('filter')
livePreview: 'filter'
});
this.before = this.column.getFilter() || {filter: this.column.categories.map((d) => d.name), filterMissing: false};
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/dialogs/ChangeRendererDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class ChangeRendererDialog extends ADialog {

constructor(private readonly column: Column, dialog: IDialogContext, private readonly ctx: IRankingHeaderContext) {
super(dialog, {
livePreview: dialog.manager.livePreviews.includes('vis')
livePreview: 'vis'
});

this.before = {
Expand Down
6 changes: 4 additions & 2 deletions src/ui/dialogs/ColorMappingDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export default class ColorMappingDialog extends ADialog {
private readonly id = uniqueId('col');

constructor(private readonly column: IMapAbleColumn, dialog: IDialogContext) {
super(dialog);
super(dialog, {
livePreview: 'colorMapping'
});

this.before = this.column.getColorMapping();
}
Expand Down Expand Up @@ -143,7 +145,7 @@ export default class ColorMappingDialog extends ADialog {
for (const custom of customs) {
Array.from(custom.nextElementSibling!.getElementsByTagName('input')).forEach((s) => s.disabled = custom !== d);
}
if (this.options.livePreview) {
if (this.showLivePreviews()) {
this.applyColor();
}
};
Expand Down
4 changes: 3 additions & 1 deletion src/ui/dialogs/CutOffHierarchyDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export default class CutOffHierarchyDialog extends ADialog {


constructor(private readonly column: HierarchyColumn, dialog: IDialogContext, private readonly idPrefix: string) {
super(dialog);
super(dialog, {
livePreview: 'cutOff'
});

this.innerNodes = resolveInnerNodes(this.column.hierarchy);
this.innerNodePaths = this.innerNodes.map((n) => n.path);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/dialogs/DateFilterDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class DateFilterDialog extends ADialog {

constructor(private readonly column: DateColumn, dialog: IDialogContext) {
super(dialog, {
livePreview: dialog.manager.livePreviews.includes('filter')
livePreview: 'filter'
});
this.before = this.column.getFilter() || noDateFilter();
}
Expand Down
4 changes: 3 additions & 1 deletion src/ui/dialogs/GroupDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export default class GroupDialog extends ADialog {
private readonly handlers: IToolbarDialogAddonHandler[] = [];

constructor(private readonly column: Column, dialog: IDialogContext, private readonly ctx: IRankingHeaderContext) {
super(dialog);
super(dialog, {
livePreview: 'group'
});
}

protected build(node: HTMLElement) {
Expand Down
6 changes: 4 additions & 2 deletions src/ui/dialogs/MappingDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export default class MappingDialog extends ADialog {
};

constructor(private readonly column: IMapAbleColumn, dialog: IDialogContext, ctx: IRankingHeaderContext) {
super(dialog);
super(dialog, {
livePreview: 'dataMapping'
});

this.idPrefix = `me${ctx.idPrefix}`;
this.before = this.column.getMapping().clone();
Expand Down Expand Up @@ -171,7 +173,7 @@ export default class MappingDialog extends ADialog {
this.rawDomain[i] = v;
this.scale.domain = this.rawDomain.slice();
this.updateLines();
if (this.options.livePreview) {
if (this.showLivePreviews()) {
this.column.setMapping(this.scale);
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/ui/dialogs/NumberFilterDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class NumberFilterDialog extends ADialog {

constructor(private readonly column: IMapAbleColumn, dialog: IDialogContext, private readonly ctx: IRankingHeaderContext) {
super(dialog, {
livePreview: dialog.manager.livePreviews.includes('filter')
livePreview: 'filter'
});

this.before = column.getFilter();
Expand All @@ -24,7 +24,7 @@ export default class NumberFilterDialog extends ADialog {
dialogManager: this.ctx.dialogManager,
idPrefix: this.ctx.idPrefix,
tasks: this.ctx.provider.getTaskExecutor()
}, this.options.livePreview);
}, this.showLivePreviews());
}

protected reset() {
Expand Down
4 changes: 3 additions & 1 deletion src/ui/dialogs/ReduceDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export default class ReduceDialog extends ADialog {
private handler: IToolbarDialogAddonHandler | null = null;

constructor(private readonly column: ReduceColumn, dialog: IDialogContext) {
super(dialog);
super(dialog, {
livePreview: 'reduce'
})
}

protected build(node: HTMLElement) {
Expand Down
4 changes: 3 additions & 1 deletion src/ui/dialogs/RenameRankingDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export default class RenameRankingDialog extends ADialog {
private readonly before: string;

constructor(private readonly ranking: Ranking, dialog: IDialogContext) {
super(dialog);
super(dialog, {
livePreview: 'rename'
});
this.before = ranking.getLabel();
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/dialogs/SearchDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class SearchDialog extends ADialog {

constructor(private readonly column: Column, dialog: IDialogContext, private readonly provider: IDataProvider) {
super(dialog, {
livePreview: dialog.manager.livePreviews.includes('search')
livePreview: 'search'
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/ui/dialogs/SortDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export default class SortDialog extends ADialog {
private readonly handlers: IToolbarDialogAddonHandler[] = [];

constructor(private readonly column: Column, private readonly groupSortBy: boolean, dialog: IDialogContext, private readonly ctx: IRankingHeaderContext) {
super(dialog);
super(dialog, {
livePreview: groupSortBy ? 'groupSort' : 'sort'
});
}

protected build(node: HTMLElement) {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/dialogs/StringFilterDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class StringFilterDialog extends ADialog {

constructor(private readonly column: StringColumn, dialog: IDialogContext) {
super(dialog, {
livePreview: dialog.manager.livePreviews.includes('filter')
livePreview: 'filter'
});

this.before = this.column.getFilter();
Expand Down

0 comments on commit bab0805

Please sign in to comment.