-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Node tooltips and URL history building for Network Viewer
- Loading branch information
1 parent
6b4af64
commit 1e921c7
Showing
8 changed files
with
296 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
from six import PY3 | ||
|
||
import dtale.global_state as global_state | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { shallow } from "enzyme"; | ||
import React from "react"; | ||
|
||
import { expect, it } from "@jest/globals"; | ||
|
||
import actions from "../../actions/dtale"; | ||
import NetworkUrlParams from "../../network/NetworkUrlParams"; | ||
|
||
describe("NetworkUrlParams", () => { | ||
const { onpopstate } = window; | ||
const { history } = global; | ||
let result, propagateState, getParamsSpy; | ||
const params = { to: "to", from: "from", group: "group", weight: "weight" }; | ||
|
||
beforeAll(() => { | ||
delete window.onpopstate; | ||
window.onpopstate = jest.fn(); | ||
}); | ||
|
||
beforeEach(() => { | ||
propagateState = jest.fn(); | ||
getParamsSpy = jest.spyOn(actions, "getParams"); | ||
result = shallow(<NetworkUrlParams params={undefined} propagateState={propagateState} />); | ||
}); | ||
|
||
afterEach(() => { | ||
getParamsSpy.mockRestore(); | ||
}); | ||
|
||
afterAll(() => { | ||
window.onpopstate = onpopstate; | ||
Object.defineProperty(global, "history", history); | ||
}); | ||
|
||
it("renders successfully", () => { | ||
expect(result.html()).toBeNull(); | ||
}); | ||
|
||
it("correctly updates history", () => { | ||
const pushState = jest.fn(); | ||
Object.defineProperty(global.history, "pushState", { | ||
value: pushState, | ||
}); | ||
getParamsSpy.mockReturnValue({}); | ||
result.setProps({ params }); | ||
expect(pushState).toHaveBeenLastCalledWith({}, "", "?to=to&from=from&group=group&weight=weight"); | ||
window.onpopstate(); | ||
expect(propagateState).toHaveBeenLastCalledWith({ | ||
to: null, | ||
from: null, | ||
group: null, | ||
weight: null, | ||
}); | ||
pushState.mockClear(); | ||
result.setProps({ params }); | ||
expect(pushState).not.toHaveBeenCalled(); | ||
getParamsSpy.mockReturnValue(params); | ||
result.setProps({ params: { ...params, test: "blah" } }); | ||
expect(pushState).not.toHaveBeenCalled(); | ||
result.unmount(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import _ from "lodash"; | ||
import vis from "vis-network/dist/vis-network"; | ||
|
||
import { expect, it } from "@jest/globals"; | ||
|
||
import * as networkUtils from "../../network/networkUtils"; | ||
|
||
describe("NetworkDisplay test", () => { | ||
it("neighborhoodHighlight", () => { | ||
const networkData = require("./data.json"); | ||
const nodesDataset = new vis.DataSet(networkData.nodes); | ||
const allNodes = nodesDataset.get({ returnType: "Object" }); | ||
const node1 = networkData.nodes[0].id; | ||
const node2 = networkData.nodes[1].id; | ||
const node3 = networkData.nodes[2].id; | ||
const network = { | ||
getConnectedNodes: nodeId => (nodeId === node1 ? [node2] : [node3]), | ||
update: () => undefined, | ||
body: { data: { nodes: nodesDataset } }, | ||
}; | ||
expect(allNodes[node3].color).toBeUndefined(); | ||
let output = networkUtils.neighborhoodHighlight({ allNodes, highlightActive: false }, network, { nodes: [node1] }); | ||
expect(_.has(allNodes[node1], "color")).toBe(true); | ||
expect(allNodes[node3].color).toBe("rgba(150,150,150,0.75)"); | ||
|
||
expect(output).toBe(true); | ||
output = networkUtils.neighborhoodHighlight({ allNodes, highlightActive: true }, network, { nodes: [] }); | ||
expect(output).toBe(false); | ||
expect(allNodes[node3].color).toBeUndefined(); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
static/__tests__/popups/analysis/filters/GeoFilters-test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { mount } from "enzyme"; | ||
import React from "react"; | ||
|
||
import { expect, it } from "@jest/globals"; | ||
|
||
import GeoFilters from "../../../../popups/analysis/filters/GeoFilters"; | ||
|
||
describe("GeoFilters tests", () => { | ||
let result, update; | ||
|
||
beforeEach(() => { | ||
update = jest.fn(); | ||
const props = { | ||
col: "lat", | ||
columns: [ | ||
{ name: "lat", coord: "lat" }, | ||
{ name: "lon", coord: "lon" }, | ||
{ name: "lat2", coord: "lat" }, | ||
{ name: "lat3", coord: "lat" }, | ||
{ name: "lon2", coord: "lon" }, | ||
], | ||
update, | ||
latCol: { value: "lat" }, | ||
lonCol: { value: "lon" }, | ||
}; | ||
result = mount(<GeoFilters {...props} />); | ||
}); | ||
|
||
it("renders longitude dropdown", () => { | ||
expect(result.find("FilterSelect").length).toBe(1); | ||
result.find("FilterSelect").prop("selectProps").onChange({ value: "lon2" }); | ||
expect(update).toHaveBeenLastCalledWith({ lonCol: { value: "lon2" } }); | ||
}); | ||
|
||
it("renders latitude dropdown", () => { | ||
result.setProps({ col: "lon" }); | ||
expect(result.find("FilterSelect").length).toBe(1); | ||
result.find("FilterSelect").prop("selectProps").onChange({ value: "lat2" }); | ||
expect(update).toHaveBeenLastCalledWith({ latCol: { value: "lat2" } }); | ||
}); | ||
|
||
it("renders text", () => { | ||
result.setProps({ | ||
columns: [ | ||
{ name: "lat", coord: "lat" }, | ||
{ name: "lon", coord: "lon" }, | ||
], | ||
}); | ||
expect(result.text()).toBe("Latitude:latLongitude:lon"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import PropTypes from "prop-types"; | ||
import React from "react"; | ||
|
||
import actions from "../actions/dtale"; | ||
import _ from "lodash"; | ||
import querystring from "querystring"; | ||
|
||
const DATA_PROPS = ["to", "from", "weight", "group"]; | ||
|
||
export default class NetworkUrlParams extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { oldOnPopState: null }; | ||
this.callOnChangeFunctions = this.callOnChangeFunctions.bind(this); | ||
} | ||
|
||
callOnChangeFunctions() { | ||
const params = actions.getParams(); | ||
const newState = {}; | ||
_.forEach(DATA_PROPS, key => { | ||
const urlValue = params[key]; | ||
newState[key] = urlValue ? { value: urlValue } : null; | ||
}); | ||
this.props.propagateState(newState); | ||
} | ||
|
||
// Once we're loaded, hook into the history API to spot any changes | ||
componentDidMount() { | ||
if (window.onpopstate) { | ||
this.setState({ oldOnPopState: window.onpopstate }); | ||
} | ||
|
||
window.onpopstate = event => { | ||
this.callOnChangeFunctions(); | ||
|
||
// Call any other onpopstate handlers. | ||
if (this.state.oldOnPopState) { | ||
this.state.oldOnPopState.call(window, event); | ||
} | ||
}; | ||
} | ||
// Cleanup window.onpopstate. | ||
componentWillUnmount() { | ||
window.onpopstate = this.state.oldOnPopState; | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
if (_.isEqual(prevProps.params, this.props.params)) { | ||
return; | ||
} | ||
const urlParams = actions.getParams(); | ||
const shouldUpdateUrl = _.find(DATA_PROPS, key => this.props.params?.[key] != urlParams[key]); | ||
|
||
if (shouldUpdateUrl) { | ||
history.pushState({}, "", `?${querystring.stringify(this.props.params)}`); | ||
} | ||
} | ||
|
||
render() { | ||
return null; | ||
} | ||
} | ||
NetworkUrlParams.propTypes = { | ||
params: PropTypes.object, | ||
propagateState: PropTypes.func, | ||
}; |
Oops, something went wrong.