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

Vega Custom Toolbar #23

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
60 changes: 34 additions & 26 deletions dashi/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dashi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@
"@emotion/styled": "^11.13.0",
"@fontsource/roboto": "^5.1.0",
"@mui/material": "^6.1.5",
"@mui/icons-material": "^6.1.4",
"microdiff": "^1.4.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-vega": "^7.6.0",
"vega-lite": "^5.21.0",
"zustand": "^5.0.0"
},
"peerDependencies": {
Expand Down
14 changes: 12 additions & 2 deletions dashi/src/demo/components/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ const panelContentStyle: CSSProperties = {

interface PanelProps {
panelModel: Contribution;
panelIndex: number;
panelState: ContributionState;
onPropertyChange: PropertyChangeHandler;
}

function Panel({ panelModel, panelState, onPropertyChange }: PanelProps) {
function Panel({
panelModel,
panelIndex,
panelState,
onPropertyChange,
}: PanelProps) {
if (!panelState.visible) {
return null;
}
Expand All @@ -47,7 +53,11 @@ function Panel({ panelModel, panelState, onPropertyChange }: PanelProps) {
const componentModelResult = panelState.componentStateResult;
if (componentModelResult.data && componentState) {
panelElement = (
<DashiComponent {...componentState} onPropertyChange={onPropertyChange} />
<DashiComponent
{...componentState}
onPropertyChange={onPropertyChange}
panelIndex={panelIndex}
/>
);
} else if (componentModelResult.error) {
panelElement = (
Expand Down
1 change: 1 addition & 0 deletions dashi/src/demo/components/PanelsRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function PanelsRow() {
key={panelIndex}
panelState={panelState}
panelModel={panelModels[panelIndex]}
panelIndex={panelIndex}
onPropertyChange={(e) => handlePropertyChange(panelIndex, e)}
/>,
);
Expand Down
3 changes: 3 additions & 0 deletions dashi/src/lib/components/DashiBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import { DashiChildren } from "./DashiChildren";

export interface DashiBoxProps extends Omit<BoxState, "type"> {
onPropertyChange: PropertyChangeHandler;
panelIndex: number;
}

export function DashiBox({
id,
style,
components,
panelIndex,
onPropertyChange,
}: DashiBoxProps) {
return (
<Box id={id} style={style}>
<DashiChildren
panelIndex={panelIndex}
components={components}
onPropertyChange={onPropertyChange}
/>
Expand Down
1 change: 1 addition & 0 deletions dashi/src/lib/components/DashiButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { type PropertyChangeHandler } from "@/lib/types/model/event";

export interface DashiButtonProps extends Omit<ButtonState, "type"> {
onPropertyChange: PropertyChangeHandler;
panelIndex: number;
}

export function DashiButton({
Expand Down
5 changes: 4 additions & 1 deletion dashi/src/lib/components/DashiChildren.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { type PropertyChangeHandler } from "@/lib/types/model/event";
import { type ComponentState } from "@/lib/types/state/component";
import { DashiComponent } from "./DashiComponent";
import { DashiComponent } from "@/lib";

export interface DashiChildrenProps {
components?: ComponentState[];
onPropertyChange: PropertyChangeHandler;
panelIndex: number;
}

export function DashiChildren({
components,
panelIndex,
onPropertyChange,
}: DashiChildrenProps) {
if (!components || components.length === 0) {
Expand All @@ -22,6 +24,7 @@ export function DashiChildren({
<DashiComponent
key={key}
{...component}
panelIndex={panelIndex}
onPropertyChange={onPropertyChange}
/>
);
Expand Down
1 change: 1 addition & 0 deletions dashi/src/lib/components/DashiComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DashiDropdown, type DashiDropdownProps } from "./DashiDropdown";

export interface DashiComponentProps extends ComponentState {
onPropertyChange: PropertyChangeHandler;
panelIndex: number;
}

export function DashiComponent({ type, ...props }: DashiComponentProps) {
Expand Down
2 changes: 2 additions & 0 deletions dashi/src/lib/components/DashiDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { type PropertyChangeHandler } from "@/lib/types/model/event";

export interface DashiDropdownProps extends Omit<DropdownState, "type"> {
onPropertyChange: PropertyChangeHandler;
panelIndex: number;
Copy link
Member

Choose a reason for hiding this comment

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

The term panel does not exist is the API, the lib part. This is relevant fort the demo only.

Also, I don't see why this is needed in every component now.

}

export function DashiDropdown({
Expand Down Expand Up @@ -46,6 +47,7 @@ export function DashiDropdown({
value={`${value}`}
disabled={disabled}
onChange={handleChange}
variant={"standard"}
>
{options.map(([text, value], index) => (
<MenuItem key={index} value={value}>
Expand Down
29 changes: 20 additions & 9 deletions dashi/src/lib/components/DashiPlot.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { VegaLite } from "react-vega";
import { type PropertyChangeHandler } from "@/lib/types/model/event";

import { type PlotState } from "@/lib/types/state/component";
import { type PropertyChangeHandler } from "@/lib/types/model/event";
import { DashiPlotToolbar } from "@/lib/components/DashiPlotToolbar";

export interface DashiPlotProps extends Omit<PlotState, "type"> {
onPropertyChange: PropertyChangeHandler;
panelIndex: number;
}

export function DashiPlot({
id,
style,
chart,
panelIndex,
onPropertyChange,
}: DashiPlotProps) {
if (!chart) {
return <div id={id} style={style} />;
}
const { datasets, ...spec } = chart;
const { datasets, ...specification } = chart;

const handleSignal = (_signalName: string, value: unknown) => {
if (id) {
return onPropertyChange({
Expand All @@ -28,12 +32,19 @@ export function DashiPlot({
}
};
return (
<VegaLite
spec={spec}
data={datasets}
style={style}
signalListeners={{ onClick: handleSignal }}
actions={false}
/>
<DashiPlotToolbar
style={{ position: "relative", display: "inline-block" }}
onPropertyChange={onPropertyChange}
panelIndex={panelIndex}
>
<VegaLite
spec={specification}
data={datasets}
style={style}
signalListeners={{ onClick: handleSignal }}
actions={false}
renderer={"svg"}
/>
</DashiPlotToolbar>
);
}
Loading