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

Fix #315 fix selected and unselected style #333

Merged
merged 3 commits into from
Aug 19, 2024
Merged
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
55 changes: 25 additions & 30 deletions app/graph/GraphView.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import CytoscapeComponent from "react-cytoscapejs";
import cytoscape, { EdgeSingular, ElementDefinition, EventObject, NodeDataDefinition } from "cytoscape";
import cytoscape, { ElementDefinition, EventObject, NodeDataDefinition } from "cytoscape";
import { useRef, useState, useImperativeHandle, forwardRef, useEffect } from "react";
import fcose from 'cytoscape-fcose';
import Editor, { Monaco } from "@monaco-editor/react";
Expand Down Expand Up @@ -93,7 +93,6 @@ function getStyle() {
label: "data(name)",
"color": "black",
"text-valign": "center",
"text-halign": "center",
"text-wrap": "ellipsis",
"text-max-width": "10rem",
shape: "ellipse",
Expand All @@ -117,10 +116,10 @@ function getStyle() {
selector: "edge",
style: {
width: 1,
"line-color": "white",
"line-opacity": 1,
"line-color": "data(color)",
"line-opacity": 0.7,
"arrow-scale": 0.7,
"target-arrow-color": "white",
"target-arrow-color": "data(color)",
"target-arrow-shape": "triangle",
'curve-style': 'straight',
},
Expand Down Expand Up @@ -302,10 +301,7 @@ const GraphView = forwardRef(({ graph, runQuery, historyQuery, fetchCount }: {
const { target } = evt

if (target.isEdge()) {
const { color } = target.data()
target.style("line-color", color);
target.style("target-arrow-color", color);
target.style("line-opacity", 0.5);
target.style("line-opacity", 0.9);
target.style("width", 2);
target.style("arrow-scale", 1);
} else target.style("border-width", 0.7);
Expand All @@ -319,10 +315,7 @@ const GraphView = forwardRef(({ graph, runQuery, historyQuery, fetchCount }: {
const type = target.isEdge() ? "edge" : "node"

if (type === "edge") {
const { color } = target.data()
target.style("line-color", color);
target.style("target-arrow-color", color);
target.style("line-opacity", 0.5);
target.style("line-opacity", 0.9);
target.style("width", 2);
target.style("arrow-scale", 1);
} else target.style("border-width", 0.7);
Expand All @@ -336,9 +329,7 @@ const GraphView = forwardRef(({ graph, runQuery, historyQuery, fetchCount }: {
const { target } = evt

if (target.isEdge()) {
target.style("line-color", "white");
target.style("target-arrow-color", "white");
target.style("line-opacity", 1);
target.style("line-opacity", 0.7);
target.style("width", 1);
target.style("arrow-scale", 0.7);
} else target.style("border-width", 0.3);
Expand All @@ -348,22 +339,25 @@ const GraphView = forwardRef(({ graph, runQuery, historyQuery, fetchCount }: {
}

const handleMouseOver = (evt: EventObject) => {
const edge: EdgeSingular = evt.target;
const { color } = edge.data();
const { target } = evt;

edge.style("line-color", color);
edge.style("target-arrow-color", color);
edge.style("line-opacity", 0.5);
if (target.selected()) return
if (target.isEdge()) {
target.style("line-opacity", 0.9);
target.style("width", 2);
target.style("arrow-scale", 1);
} else target.style("border-width", 0.7);
};

const handleMouseOut = async (evt: EventObject) => {
const edge: EdgeSingular = evt.target;
const { target } = evt;

if (edge.selected()) return

edge.style("line-color", "white");
edge.style("target-arrow-color", "white");
edge.style("line-opacity", 1);
if (target.selected()) return
if (target.isEdge()) {
target.style("line-opacity", 0.7);
target.style("width", 1);
target.style("arrow-scale", 0.7);
} else target.style("border-width", 0.3);
};

const setProperty = async (key: string, newVal: string) => {
Expand Down Expand Up @@ -522,13 +516,14 @@ const GraphView = forwardRef(({ graph, runQuery, historyQuery, fetchCount }: {
cy.removeAllListeners()

cy.on('dbltap', 'node', handleDoubleTap)
cy.on('mouseover', 'node', handleMouseOver)
cy.on('mouseover', 'edge', handleMouseOver)
cy.on('mouseout', 'node', handleMouseOut)
cy.on('mouseout', 'edge', handleMouseOut)
cy.on('tapunselect', 'edge', handleUnselected)
cy.on('tapunselect', 'node', handleUnselected)
cy.on('tapselect', 'edge', handleSelected)
cy.on('tapselect', 'node', handleSelected)
cy.on('tapunselect', 'edge', handleUnselected)
cy.on('tapselect', 'node', handleSelected)
cy.on('tapselect', 'edge', handleSelected)
cy.on('boxselect', 'node', handleBoxSelected)
cy.on('boxselect', 'edge', handleBoxSelected)
}}
Expand Down
68 changes: 36 additions & 32 deletions app/schema/SchemaView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ function getStyle() {
label: "data(category)",
"color": "white",
"text-valign": "center",
"text-halign": "center",
"text-wrap": "ellipsis",
"text-max-width": "10rem",
shape: "ellipse",
Expand All @@ -78,10 +77,10 @@ function getStyle() {
selector: "edge",
style: {
width: 1,
"line-color": "white",
"line-color": "data(color)",
"line-opacity": 0.7,
"arrow-scale": 0.7,
"target-arrow-color": "white",
"target-arrow-color": "data(color)",
"target-arrow-shape": "triangle",
'curve-style': 'straight',
},
Expand Down Expand Up @@ -174,21 +173,19 @@ export default function SchemaView({ schema, fetchCount }: Props) {
} else dataPanel.current?.collapse()
}

const handleTap = (evt: EventObject) => {
const obj: ElementDataDefinition = evt.target.json().data;
setSelectedNodes(prev => prev.length >= 2 ? [prev[prev.length - 1], obj as NodeDataDefinition] : [...prev, obj as NodeDataDefinition])
}

const handleSelected = (evt: EventObject) => {
if (isAddRelation) return
if (isAddRelation) {
const { target } = evt;
(target as EdgeSingular).unselect()
const obj: ElementDataDefinition = evt.target.json().data;
setSelectedNodes(prev => prev.length >= 2 ? [prev[prev.length - 1], obj as NodeDataDefinition] : [...prev, obj as NodeDataDefinition])
return
}

const { target } = evt

if (target.isEdge()) {
const { color } = target.data()
target.style("line-color", color);
target.style("target-arrow-color", color);
target.style("line-opacity", 0.5);
target.style("line-opacity", 0.9);
target.style("width", 2);
target.style("arrow-scale", 1);
} else {
Expand All @@ -201,14 +198,19 @@ export default function SchemaView({ schema, fetchCount }: Props) {
}

const handleBoxSelected = (evt: EventObject) => {
if (isAddRelation) {
const { target } = evt;
(target as EdgeSingular).unselect()
const obj: ElementDataDefinition = target.json().data;
setSelectedNodes(prev => prev.length >= 2 ? [prev[prev.length - 1], obj as NodeDataDefinition] : [...prev, obj as NodeDataDefinition])
return
}

const { target } = evt
const type = target.isEdge() ? "edge" : "node"

if (type === "edge") {
const { color } = target.data()
target.style("line-color", color);
target.style("target-arrow-color", color);
target.style("line-opacity", 0.5);
target.style("line-opacity", 0.9);
target.style("width", 2);
target.style("arrow-scale", 1);
} else target.style("border-width", 0.7);
Expand All @@ -222,9 +224,7 @@ export default function SchemaView({ schema, fetchCount }: Props) {
const { target } = evt

if (target.isEdge()) {
target.style("line-color", "white");
target.style("target-arrow-color", "white");
target.style("line-opacity", 1);
target.style("line-opacity", 0.7);
target.style("width", 1);
target.style("arrow-scale", 0.7);
} else target.style("border-width", 0.3);
Expand All @@ -234,22 +234,25 @@ export default function SchemaView({ schema, fetchCount }: Props) {
}

const handleMouseOver = (evt: EventObject) => {
const edge: EdgeSingular = evt.target;
const { color } = edge.data();
const { target } = evt;

edge.style("line-color", color);
edge.style("target-arrow-color", color);
edge.style("line-opacity", 0.5);
if (target.selected()) return
if (target.isEdge()) {
target.style("line-opacity", 0.9);
target.style("width", 2);
target.style("arrow-scale", 1);
} else target.style("border-width", 0.7);
};

const handleMouseOut = async (evt: EventObject) => {
const edge: EdgeSingular = evt.target;
const { target } = evt;

if (edge.selected()) return

edge.style("line-color", "white");
edge.style("target-arrow-color", "white");
edge.style("line-opacity", 1);
if (target.selected()) return
if (target.isEdge()) {
target.style("line-opacity", 0.7);
target.style("width", 1);
target.style("arrow-scale", 0.7);
} else target.style("border-width", 0.3);
};

const onExpand = () => {
Expand Down Expand Up @@ -476,14 +479,15 @@ export default function SchemaView({ schema, fetchCount }: Props) {
cy.removeAllListeners()

cy.on('mouseover', 'edge', handleMouseOver)
cy.on('mouseover', 'node', handleMouseOver)
cy.on('mouseout', 'edge', handleMouseOut)
cy.on('mouseout', 'node', handleMouseOut)
cy.on('tapunselect', 'edge', handleUnselected)
cy.on('tapunselect', 'node', handleUnselected)
cy.on('tapselect', 'edge', handleSelected)
cy.on('tapselect', 'node', handleSelected)
cy.on('boxselect', 'node', handleBoxSelected)
cy.on('boxselect', 'edge', handleBoxSelected)
cy.on('tap', 'node', handleTap)
}}
/>
{
Expand Down
Loading