Skip to content

Commit

Permalink
Merge pull request #299 from visdesignlab/default-grammar-config
Browse files Browse the repository at this point in the history
Add Horziontal grammar flag, refactor defaultConfig
  • Loading branch information
JakeWags authored Feb 29, 2024
2 parents ad191bf + 7a018f1 commit 9bca4a5
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 79 deletions.
36 changes: 4 additions & 32 deletions packages/app/src/atoms/config/upsetConfigAtoms.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,10 @@
import { UpsetConfig } from '@visdesignlab/upset2-core';
import { UpsetConfig, DefaultConfig } from '@visdesignlab/upset2-core';
import { atom } from 'recoil';

export const defaultConfig: UpsetConfig = {
plotInformation: {
description: '',
sets: '',
items: '',
},
firstAggregateBy: 'None',
firstOverlapDegree: 2,
secondAggregateBy: 'None',
secondOverlapDegree: 2,
sortVisibleBy: 'Alphabetical',
sortBy: 'Size',
sortByOrder: 'Descending',
filters: {
maxVisible: 3,
minVisible: 0,
hideEmpty: true,
hideNoSet: false,
},
visibleSets: [],
visibleAttributes: [],
bookmarkedIntersections: [],
collapsed: [],
plots: {
scatterplots: [],
histograms: [],
wordClouds: [],
},
allSets: [],
};
// fields can be edited here to stray from default config
const config = { ...DefaultConfig };

export const upsetConfigAtom = atom<UpsetConfig>({
key: 'app-config',
default: defaultConfig,
default: config,
});
33 changes: 33 additions & 0 deletions packages/core/src/defaultConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { UpsetConfig } from './types';

export const DefaultConfig: UpsetConfig = {
plotInformation: {
description: '',
sets: '',
items: '',
},
horizontal: false,
firstAggregateBy: 'None',
firstOverlapDegree: 2,
secondAggregateBy: 'None',
secondOverlapDegree: 2,
sortVisibleBy: 'Alphabetical',
sortBy: 'Size',
sortByOrder: 'Descending',
filters: {
maxVisible: 6,
minVisible: 0,
hideEmpty: true,
hideNoSet: false,
},
visibleSets: [],
visibleAttributes: [],
bookmarkedIntersections: [],
collapsed: [],
plots: {
scatterplots: [],
histograms: [],
wordClouds: [],
},
allSets: [],
};
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from './aggregate';
export * from './sort';
export * from './filter';
export * from './render';
export * from './defaultConfig';
9 changes: 7 additions & 2 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
export type ColumnName = string;

export type Column = {
name: string,
size: number
name: string;
size: number;
};

export type ColumnDefs = {
[columnName: string]: 'number' | 'boolean' | 'string' | 'label';
};

export type Meta = {
columns: ColumnDefs;
};

export type PlotInformation = {
description: string;
sets: string;
Expand Down Expand Up @@ -161,6 +165,7 @@ export type Bookmark = { id: string; label: string; size: number }

export type UpsetConfig = {
plotInformation: PlotInformation;
horizontal: boolean;
firstAggregateBy: AggregateBy;
firstOverlapDegree: number;
secondAggregateBy: AggregateBy;
Expand Down
35 changes: 2 additions & 33 deletions packages/upset/src/atoms/config/upsetConfigAtoms.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,8 @@
import { UpsetConfig } from '@visdesignlab/upset2-core';
import { UpsetConfig, DefaultConfig } from '@visdesignlab/upset2-core';
import { atom } from 'recoil';

// This config is overruled by any config provided by an external source
export const defaultConfig: UpsetConfig = {
plotInformation: {
description: '',
sets: '',
items: '',
},
firstAggregateBy: 'None',
firstOverlapDegree: 2,
secondAggregateBy: 'None',
secondOverlapDegree: 2,
sortVisibleBy: 'Alphabetical',
sortBy: 'Size',
sortByOrder: 'Descending',
filters: {
maxVisible: 3,
minVisible: 0,
hideEmpty: true,
hideNoSet: false,
},
visibleSets: [],
visibleAttributes: [],
bookmarkedIntersections: [],
collapsed: [],
plots: {
scatterplots: [],
histograms: [],
wordClouds: [],
},
allSets: [],
};

export const upsetConfigAtom = atom<UpsetConfig>({
key: 'upset-config',
default: defaultConfig,
default: DefaultConfig,
});
6 changes: 2 additions & 4 deletions packages/upset/src/atoms/provenanceAtom.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { UpsetConfig } from '@visdesignlab/upset2-core';
import { UpsetConfig, DefaultConfig } from '@visdesignlab/upset2-core';
import { atom } from 'recoil';

import { defaultConfig } from './config/upsetConfigAtoms';

export const stateAtom = atom<UpsetConfig>({
key: 'upset-state',
default: defaultConfig,
default: DefaultConfig,
});
5 changes: 2 additions & 3 deletions packages/upset/src/components/Upset.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Box, ThemeProvider } from '@mui/material';
import { CoreUpsetData, UpsetConfig } from '@visdesignlab/upset2-core';
import { CoreUpsetData, UpsetConfig, DefaultConfig } from '@visdesignlab/upset2-core';
import { FC, useMemo } from 'react';
import { RecoilRoot } from 'recoil';

import { defaultConfig } from '../atoms/config/upsetConfigAtoms';
import { UpsetActions, UpsetProvenance } from '../provenance';
import defaultTheme from '../utils/theme';
import { Root } from './Root';
Expand Down Expand Up @@ -50,7 +49,7 @@ export const Upset: FC<UpsetProps> = ({
// Combine the partial config and add visible sets if empty
// Also add missing attributes if specified
const combinedConfig = useMemo(() => {
const conf: UpsetConfig = { ...defaultConfig, ...config };
const conf: UpsetConfig = { ...DefaultConfig, ...config };

if (conf.visibleSets.length === 0) {
const setList = Object.entries(data.sets);
Expand Down
1 change: 0 additions & 1 deletion packages/upset/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export {

export {
upsetConfigAtom,
defaultConfig,
} from './atoms/config/upsetConfigAtoms';

export * from './utils/downloads';
Expand Down
7 changes: 3 additions & 4 deletions packages/upset/src/provenance/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import {
AggregateBy, Plot, PlotInformation, SortBy, SortByOrder, SortVisibleBy, UpsetConfig,
AggregateBy, Plot, PlotInformation, SortBy, SortByOrder, SortVisibleBy, UpsetConfig, DefaultConfig,
} from '@visdesignlab/upset2-core';

import { Registry, initializeTrrack } from '@trrack/core';
import { defaultConfig } from '../atoms/config/upsetConfigAtoms';

export type Metadata = {
[key: string]: unknown;
Expand Down Expand Up @@ -302,7 +301,7 @@ export function initializeProvenanceTracking(
config: Partial<UpsetConfig> = {},
setter?: (state: UpsetConfig) => void,
) {
const finalConfig: UpsetConfig = { ...defaultConfig, ...config };
const finalConfig: UpsetConfig = { ...DefaultConfig, ...config };

const provenance = initializeTrrack(
{ initialState: finalConfig, registry },
Expand All @@ -326,7 +325,7 @@ export function getActions(provenance: UpsetProvenance) {
secondAggregateBy: (aggBy: AggregateBy) => provenance.apply(`Second aggregate by ${aggBy}`, secondAggAction(aggBy)),
secondOverlapBy: (overlap: number) => provenance.apply(`Second overlap by ${overlap}`, secondOverlapAction(overlap)),
sortVisibleBy: (sort: SortVisibleBy) => provenance.apply(`Sort Visible Sets by ${sort}`, sortVisibleSetsAction(sort)),
sortBy: (sort: SortBy, sortByOrder: SortByOrder) => provenance.apply(`Sort by ${sort}, ${sortByOrder}`, sortByAction({sort, sortByOrder})),
sortBy: (sort: SortBy, sortByOrder: SortByOrder) => provenance.apply(`Sort by ${sort}, ${sortByOrder}`, sortByAction({ sort, sortByOrder })),
setMaxVisible: (val: number) => provenance.apply(`Hide intersections above ${val}`, maxVisibleAction(val)),
setMinVisible: (val: number) => provenance.apply(`Hide intersections below ${val}`, minVisibleAction(val)),
setHideEmpty: (val: boolean) => provenance.apply(val ? 'Hide empty intersections' : 'Show empty intersections', hideEmptyAction(val)),
Expand Down

0 comments on commit 9bca4a5

Please sign in to comment.