Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to specify which vis types to show in the sidebar #129

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/vis/EagerVis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import { IViolinConfig } from './violin/interfaces';

const DEFAULT_SHAPES = ['circle', 'square', 'triangle-up', 'star'];

function registerAllVis() {
function registerAllVis(visTypes?: string[]) {
return [
createVis({
type: ESupportedPlotlyVis.SCATTER,
Expand Down Expand Up @@ -113,15 +113,15 @@ function registerAllVis() {
mergeConfig: correlationMergeDefaultConfig,
description: 'Visualizes statistical relationships between pairs of numerical variables',
}),
];
].filter((v) => !visTypes || visTypes.includes(v.type));
}

export function useRegisterDefaultVis() {
export function useRegisterDefaultVis(visTypes?: string[]) {
const { registerVisType } = useVisProvider();

React.useEffect(() => {
registerVisType(...registerAllVis());
}, [registerVisType]);
registerVisType(...registerAllVis(visTypes));
}, [registerVisType, visTypes]);
}
Copy link
Contributor

@dvmoritzschoefl dvmoritzschoefl Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will kill performance of the app if visTypes is not memoized, since its wrapped in a context
should we do a shallow compare here? or alternatively we could call it initialVisTypes to make it clear that it will only affect the vis types at the first render, similiar to mantine-react-table (initialState) and other libraries

EDIT: the visprovider can handle this already by checking which vis are already in the provider


export function EagerVis({
Expand All @@ -141,6 +141,7 @@ export function EagerVis({
setShowSidebar: internalSetShowSidebar,
showSidebarDefault = false,
scrollZoom = true,
visTypes,
}: {
/**
* Required data columns which are displayed.
Expand Down Expand Up @@ -185,6 +186,10 @@ export function EagerVis({
setShowSidebar?(show: boolean): void;
showSidebarDefault?: boolean;
scrollZoom?: boolean;
/**
* Optional property which enables the user to specify which vis types to show as options in the sidebar. If not specified, all vis types will be used.
*/
visTypes?: string[];
}) {
const [showSidebar, setShowSidebar] = useUncontrolled<boolean>({
value: internalShowSidebar,
Expand All @@ -195,7 +200,7 @@ export function EagerVis({

const [ref, dimensions] = useResizeObserver();

useRegisterDefaultVis();
useRegisterDefaultVis(visTypes);

const { getVisByType } = useVisProvider();

Expand Down
Loading