-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[layer-leaflet/maplibre] when resizing keep the same center
- Loading branch information
Showing
7 changed files
with
174 additions
and
7 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
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
56 changes: 56 additions & 0 deletions
56
packages/storybook/stories/3-additional-packages/layer-leaflet/resize.ts
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,56 @@ | ||
/** | ||
* This is a minimal example of sigma. You can use it as a base to write new | ||
* examples, or reproducible test cases for new issues, for instance. | ||
*/ | ||
import bindLeafletLayer from "@sigma/layer-leaflet"; | ||
import Graph from "graphology"; | ||
import { Attributes, SerializedGraph } from "graphology-types"; | ||
import Sigma from "sigma"; | ||
|
||
import data from "./data/airports.json"; | ||
|
||
export default () => { | ||
const container = document.getElementById("sigma-container") as HTMLElement; | ||
const graph = Graph.from(data as SerializedGraph); | ||
graph.updateEachNodeAttributes((_node, attributes) => ({ | ||
...attributes, | ||
label: attributes.fullName, | ||
x: 0, | ||
y: 0, | ||
})); | ||
|
||
// initiate sigma | ||
const renderer = new Sigma(graph, container, { | ||
labelRenderedSizeThreshold: 20, | ||
defaultNodeColor: "#e22352", | ||
defaultEdgeColor: "#ffaeaf", | ||
minEdgeThickness: 1, | ||
nodeReducer: (node, attrs) => { | ||
return { | ||
...attrs, | ||
size: Math.sqrt(graph.degree(node)) / 2, | ||
}; | ||
}, | ||
}); | ||
|
||
bindLeafletLayer(renderer, { | ||
getNodeLatLng: (attrs: Attributes) => ({ lat: attrs.latitude, lng: attrs.longitude }), | ||
}); | ||
|
||
let isSmall = false; | ||
const toggleButton = document.createElement("button"); | ||
toggleButton.innerText = "Toggle fullscreen"; | ||
toggleButton.style.position = "absolute"; | ||
toggleButton.style.zIndex = "1"; | ||
toggleButton.onclick = () => { | ||
container.style.width = isSmall ? "100%" : "50%"; | ||
container.style.height = isSmall ? "100%" : "50%"; | ||
renderer.refresh({ schedule: false }); | ||
isSmall = !isSmall; | ||
}; | ||
container.appendChild(toggleButton); | ||
|
||
return () => { | ||
renderer.kill(); | ||
}; | ||
}; |
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
56 changes: 56 additions & 0 deletions
56
packages/storybook/stories/3-additional-packages/layer-maplibre/resize.ts
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,56 @@ | ||
/** | ||
* This is a minimal example of sigma. You can use it as a base to write new | ||
* examples, or reproducible test cases for new issues, for instance. | ||
*/ | ||
import bindMapLayer from "@sigma/layer-maplibre"; | ||
import Graph from "graphology"; | ||
import { Attributes, SerializedGraph } from "graphology-types"; | ||
import Sigma from "sigma"; | ||
|
||
import data from "./data/airports.json"; | ||
|
||
export default () => { | ||
const container = document.getElementById("sigma-container") as HTMLElement; | ||
const graph = Graph.from(data as SerializedGraph); | ||
graph.updateEachNodeAttributes((_node, attributes) => ({ | ||
...attributes, | ||
label: attributes.fullName, | ||
x: 0, | ||
y: 0, | ||
})); | ||
|
||
// initiate sigma | ||
const renderer = new Sigma(graph, container, { | ||
labelRenderedSizeThreshold: 20, | ||
defaultNodeColor: "#e22352", | ||
defaultEdgeColor: "#ffaeaf", | ||
minEdgeThickness: 1, | ||
nodeReducer: (node, attrs) => { | ||
return { | ||
...attrs, | ||
size: Math.sqrt(graph.degree(node)) / 2, | ||
}; | ||
}, | ||
}); | ||
|
||
bindMapLayer(renderer, { | ||
getNodeLatLng: (attrs: Attributes) => ({ lat: attrs.latitude, lng: attrs.longitude }), | ||
}); | ||
|
||
let isSmall = false; | ||
const toggleButton = document.createElement("button"); | ||
toggleButton.innerText = "Toggle fullscreen"; | ||
toggleButton.style.position = "absolute"; | ||
toggleButton.style.zIndex = "1"; | ||
toggleButton.onclick = () => { | ||
container.style.width = isSmall ? "100%" : "50%"; | ||
container.style.height = isSmall ? "100%" : "50%"; | ||
renderer.refresh({ schedule: false }); | ||
isSmall = !isSmall; | ||
}; | ||
container.appendChild(toggleButton); | ||
|
||
return () => { | ||
renderer.kill(); | ||
}; | ||
}; |
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