add toggle to show/hide edges
This commit is contained in:
parent
de6d997976
commit
2c036a9cf1
|
@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
bengali, brazilian, bulgarian, catalan, cjk (i.e. chinese, japanese, korean), czech, danish, dutch, english, finnish,
|
bengali, brazilian, bulgarian, catalan, cjk (i.e. chinese, japanese, korean), czech, danish, dutch, english, finnish,
|
||||||
french, galician, german, greek, hindi, hungarian, indonesian, irish, italian, latvian, lithuanian, norwegian,
|
french, galician, german, greek, hindi, hungarian, indonesian, irish, italian, latvian, lithuanian, norwegian,
|
||||||
persian, romanian, russian, sorani, spanish, swedish, turkish, thai.
|
persian, romanian, russian, sorani, spanish, swedish, turkish, thai.
|
||||||
|
- Added toggle to show/hide edges on graph.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
19
frontend/src/components/atoms/GraphHideEdgesButton.tsx
Normal file
19
frontend/src/components/atoms/GraphHideEdgesButton.tsx
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import { Switch } from "@blueprintjs/core";
|
||||||
|
import * as React from "react";
|
||||||
|
import styled from "styled-components";
|
||||||
|
import FloatingCard from "./FloatingCard";
|
||||||
|
|
||||||
|
const StyledSwitch = styled(Switch)`
|
||||||
|
margin: 0;
|
||||||
|
`;
|
||||||
|
|
||||||
|
interface IGraphHideEdgesButtonProps {
|
||||||
|
isShowingEdges: boolean;
|
||||||
|
toggleEdges: () => void;
|
||||||
|
}
|
||||||
|
const GraphHideEdgesButton: React.FC<IGraphHideEdgesButtonProps> = ({ isShowingEdges, toggleEdges }) => (
|
||||||
|
<FloatingCard>
|
||||||
|
<StyledSwitch checked={isShowingEdges} label="Show connections" onChange={toggleEdges} />
|
||||||
|
</FloatingCard>
|
||||||
|
);
|
||||||
|
export default GraphHideEdgesButton;
|
|
@ -2,4 +2,5 @@ export { default as Page } from "./Page";
|
||||||
export { default as FloatingCard } from "./FloatingCard";
|
export { default as FloatingCard } from "./FloatingCard";
|
||||||
export { default as GraphKey } from "./GraphKey";
|
export { default as GraphKey } from "./GraphKey";
|
||||||
export { default as GraphResetButton } from "./GraphResetButton";
|
export { default as GraphResetButton } from "./GraphResetButton";
|
||||||
|
export { default as GraphHideEdgesButton } from "./GraphHideEdgesButton";
|
||||||
export { default as InstanceType } from "./InstanceType";
|
export { default as InstanceType } from "./InstanceType";
|
||||||
|
|
|
@ -28,6 +28,7 @@ interface ICytoscapeProps {
|
||||||
hoveringOver?: string;
|
hoveringOver?: string;
|
||||||
ranges?: { [key: string]: [number, number] };
|
ranges?: { [key: string]: [number, number] };
|
||||||
searchResultIds?: string[];
|
searchResultIds?: string[];
|
||||||
|
showEdges: boolean;
|
||||||
navigateToInstancePath?: (domain: string) => void;
|
navigateToInstancePath?: (domain: string) => void;
|
||||||
navigateToRoot?: () => void;
|
navigateToRoot?: () => void;
|
||||||
}
|
}
|
||||||
|
@ -85,7 +86,7 @@ class Cytoscape extends React.PureComponent<ICytoscapeProps> {
|
||||||
"font-size": "mapData(size, 1, 6, 10, 100)",
|
"font-size": "mapData(size, 1, 6, 10, 100)",
|
||||||
"min-zoomed-font-size": 16
|
"min-zoomed-font-size": 16
|
||||||
})
|
})
|
||||||
.selector(".hidden") // used to hide nodes not in the neighborhood of the selected
|
.selector(".hidden") // used to hide nodes not in the neighborhood of the selected, or to hide edges
|
||||||
.style({
|
.style({
|
||||||
display: "none"
|
display: "none"
|
||||||
})
|
})
|
||||||
|
@ -146,6 +147,13 @@ class Cytoscape extends React.PureComponent<ICytoscapeProps> {
|
||||||
if (!isEqual(prevProps.searchResultIds, this.props.searchResultIds)) {
|
if (!isEqual(prevProps.searchResultIds, this.props.searchResultIds)) {
|
||||||
this.updateSearchResultNodeClass();
|
this.updateSearchResultNodeClass();
|
||||||
}
|
}
|
||||||
|
if (prevProps.showEdges !== this.props.showEdges) {
|
||||||
|
if (this.props.showEdges) {
|
||||||
|
this.showEdges();
|
||||||
|
} else {
|
||||||
|
this.hideEdges();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentWillUnmount() {
|
public componentWillUnmount() {
|
||||||
|
@ -319,6 +327,20 @@ class Cytoscape extends React.PureComponent<ICytoscapeProps> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private showEdges = () => {
|
||||||
|
if (!this.cy) {
|
||||||
|
throw new Error("Expected cytoscape, but there wasn't one!");
|
||||||
|
}
|
||||||
|
this.cy.edges().removeClass("hidden");
|
||||||
|
};
|
||||||
|
|
||||||
|
private hideEdges = () => {
|
||||||
|
if (!this.cy) {
|
||||||
|
throw new Error("Expected cytoscape, but there wasn't one!");
|
||||||
|
}
|
||||||
|
this.cy.edges().addClass("hidden");
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Cytoscape;
|
export default Cytoscape;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import { IColorScheme } from "../../types";
|
import { IColorScheme } from "../../types";
|
||||||
import { GraphKey, GraphResetButton } from "../atoms";
|
import { GraphHideEdgesButton, GraphKey, GraphResetButton } from "../atoms";
|
||||||
|
|
||||||
const GraphToolsContainer = styled.div`
|
const GraphToolsContainer = styled.div`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
@ -14,20 +14,25 @@ const GraphToolsContainer = styled.div`
|
||||||
interface IGraphToolsProps {
|
interface IGraphToolsProps {
|
||||||
currentColorScheme?: IColorScheme;
|
currentColorScheme?: IColorScheme;
|
||||||
colorSchemes: IColorScheme[];
|
colorSchemes: IColorScheme[];
|
||||||
|
isShowingEdges: boolean;
|
||||||
ranges?: { [key: string]: [number, number] };
|
ranges?: { [key: string]: [number, number] };
|
||||||
onColorSchemeSelect: (colorScheme?: IColorScheme) => void;
|
onColorSchemeSelect: (colorScheme?: IColorScheme) => void;
|
||||||
onResetButtonClick: () => void;
|
onResetButtonClick: () => void;
|
||||||
|
toggleEdges: () => void;
|
||||||
}
|
}
|
||||||
const GraphTools: React.FC<IGraphToolsProps> = ({
|
const GraphTools: React.FC<IGraphToolsProps> = ({
|
||||||
currentColorScheme,
|
currentColorScheme,
|
||||||
colorSchemes,
|
colorSchemes,
|
||||||
|
isShowingEdges,
|
||||||
ranges,
|
ranges,
|
||||||
onColorSchemeSelect,
|
onColorSchemeSelect,
|
||||||
onResetButtonClick
|
onResetButtonClick,
|
||||||
|
toggleEdges
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<GraphToolsContainer>
|
<GraphToolsContainer>
|
||||||
<GraphResetButton onClick={onResetButtonClick} />
|
<GraphResetButton onClick={onResetButtonClick} />
|
||||||
|
<GraphHideEdgesButton isShowingEdges={isShowingEdges} toggleEdges={toggleEdges} />
|
||||||
<GraphKey
|
<GraphKey
|
||||||
current={currentColorScheme}
|
current={currentColorScheme}
|
||||||
colorSchemes={colorSchemes}
|
colorSchemes={colorSchemes}
|
||||||
|
|
|
@ -27,6 +27,7 @@ interface IGraphProps {
|
||||||
}
|
}
|
||||||
interface IGraphState {
|
interface IGraphState {
|
||||||
colorScheme?: IColorScheme;
|
colorScheme?: IColorScheme;
|
||||||
|
isShowingEdges: boolean;
|
||||||
}
|
}
|
||||||
class GraphImpl extends React.PureComponent<IGraphProps, IGraphState> {
|
class GraphImpl extends React.PureComponent<IGraphProps, IGraphState> {
|
||||||
private cytoscapeComponent: React.RefObject<Cytoscape>;
|
private cytoscapeComponent: React.RefObject<Cytoscape>;
|
||||||
|
@ -34,7 +35,7 @@ class GraphImpl extends React.PureComponent<IGraphProps, IGraphState> {
|
||||||
public constructor(props: IGraphProps) {
|
public constructor(props: IGraphProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.cytoscapeComponent = React.createRef();
|
this.cytoscapeComponent = React.createRef();
|
||||||
this.state = { colorScheme: undefined };
|
this.state = { colorScheme: undefined, isShowingEdges: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentDidMount() {
|
public componentDidMount() {
|
||||||
|
@ -59,14 +60,17 @@ class GraphImpl extends React.PureComponent<IGraphProps, IGraphState> {
|
||||||
navigateToInstancePath={this.navigateToInstancePath}
|
navigateToInstancePath={this.navigateToInstancePath}
|
||||||
navigateToRoot={this.navigateToRoot}
|
navigateToRoot={this.navigateToRoot}
|
||||||
searchResultIds={this.props.searchResultDomains}
|
searchResultIds={this.props.searchResultDomains}
|
||||||
|
showEdges={this.state.isShowingEdges}
|
||||||
ref={this.cytoscapeComponent}
|
ref={this.cytoscapeComponent}
|
||||||
/>
|
/>
|
||||||
<GraphTools
|
<GraphTools
|
||||||
onResetButtonClick={this.resetGraphPosition}
|
onResetButtonClick={this.resetGraphPosition}
|
||||||
currentColorScheme={this.state.colorScheme}
|
currentColorScheme={this.state.colorScheme}
|
||||||
colorSchemes={colorSchemes}
|
colorSchemes={colorSchemes}
|
||||||
|
isShowingEdges={this.state.isShowingEdges}
|
||||||
onColorSchemeSelect={this.setColorScheme}
|
onColorSchemeSelect={this.setColorScheme}
|
||||||
ranges={this.props.graphResponse.metadata.ranges}
|
ranges={this.props.graphResponse.metadata.ranges}
|
||||||
|
toggleEdges={this.toggleEdges}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@ -87,6 +91,10 @@ class GraphImpl extends React.PureComponent<IGraphProps, IGraphState> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private toggleEdges = () => {
|
||||||
|
this.setState({ isShowingEdges: !this.state.isShowingEdges });
|
||||||
|
};
|
||||||
|
|
||||||
private setColorScheme = (colorScheme?: IColorScheme) => {
|
private setColorScheme = (colorScheme?: IColorScheme) => {
|
||||||
this.setState({ colorScheme });
|
this.setState({ colorScheme });
|
||||||
};
|
};
|
||||||
|
|
|
@ -236,6 +236,7 @@ class InstanceScreenImpl extends React.PureComponent<IInstanceScreenProps, IInst
|
||||||
elements={localGraph!}
|
elements={localGraph!}
|
||||||
currentNodeId={this.props.instanceName}
|
currentNodeId={this.props.instanceName}
|
||||||
navigateToInstancePath={this.props.navigateToInstance}
|
navigateToInstancePath={this.props.navigateToInstance}
|
||||||
|
showEdges={true}
|
||||||
/>
|
/>
|
||||||
<Divider />
|
<Divider />
|
||||||
</StyledGraphContainer>
|
</StyledGraphContainer>
|
||||||
|
|
Loading…
Reference in a new issue