Skip to content

Commit

Permalink
fix scatter plot events
Browse files Browse the repository at this point in the history
  • Loading branch information
ritch committed Aug 1, 2024
1 parent 830c789 commit e22eb80
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions app/packages/core/src/plugins/SchemaIO/components/PlotlyView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export default function PlotlyView(props) {
let range = [0, 0];
const triggerPanelEvent = usePanelEvent();
const handleEvent = (event?: string) => (e) => {
// TODO: add more interesting/useful event data
const data = EventDataMappers[event]?.(e) || {};
const x_data_source = view.x_data_source;
let xValue = null;
let yValue = null;
if (event === "onClick") {
Expand All @@ -37,9 +35,12 @@ export default function PlotlyView(props) {
range = [xValue - xBinsSize / 2, xValue + xBinsSize / 2];
} else if (type === "scatter") {
selected.push(p.pointIndex);
xValue = p.x;
yValue = p.y;
} else if (type === "bar") {
xValue = p.x;
yValue = p.y;
range = [p.x, p.x + p.width];
} else if (type === "heatmap") {
xValue = p.x;
yValue = p.y;
Expand All @@ -52,25 +53,30 @@ export default function PlotlyView(props) {

const eventHandlerOperator = view[snakeCase(event)];

const defaultParams = {
path: props.path,
relative_path: props.relativePath,
schema: props.schema,
view,
event,
};

if (eventHandlerOperator) {
let params = {};
if (event === "onClick") {
params = {
event,
data,
x_data_source,
...defaultParams,
range,
type: view.type,
x: xValue,
y: yValue,
};
} else if (event === "onSelected") {
params = {
event,
...defaultParams,
data,
type: view.type,
};
}

triggerPanelEvent(panelId, {
operator: eventHandlerOperator,
params,
Expand Down

0 comments on commit e22eb80

Please sign in to comment.