mirror of
https://github.com/ae-utbm/sith.git
synced 2025-06-24 20:25:16 +00:00
Add zoom control of family graph
This commit is contained in:
parent
cc96c93d23
commit
10d5b9d63f
@ -16,6 +16,10 @@ type GraphData = (
|
|||||||
| { data: { source: number; target: number } }
|
| { data: { source: number; target: number } }
|
||||||
)[];
|
)[];
|
||||||
|
|
||||||
|
function isMobile() {
|
||||||
|
return window.innerWidth < 500;
|
||||||
|
}
|
||||||
|
|
||||||
async function getGraphData(
|
async function getGraphData(
|
||||||
userId: number,
|
userId: number,
|
||||||
godfathersDepth: number,
|
godfathersDepth: number,
|
||||||
@ -151,7 +155,6 @@ function createGraph(container: HTMLDivElement, data: GraphData, activeUserId: n
|
|||||||
cy.on("tap", "node", (tapped) => {
|
cy.on("tap", "node", (tapped) => {
|
||||||
onNodeTap(tapped.target);
|
onNodeTap(tapped.target);
|
||||||
});
|
});
|
||||||
cy.zoomingEnabled(false);
|
|
||||||
|
|
||||||
/* Add context menu */
|
/* Add context menu */
|
||||||
cy.cxtmenu({
|
cy.cxtmenu({
|
||||||
@ -200,6 +203,7 @@ document.addEventListener("alpine:init", () => {
|
|||||||
reverse: initialUrlParams.get("reverse")?.toLowerCase?.() === "true",
|
reverse: initialUrlParams.get("reverse")?.toLowerCase?.() === "true",
|
||||||
graph: undefined as cytoscape.Core,
|
graph: undefined as cytoscape.Core,
|
||||||
graphData: {},
|
graphData: {},
|
||||||
|
isZoomEnabled: !isMobile(),
|
||||||
|
|
||||||
getInitialDepth(prop: string) {
|
getInitialDepth(prop: string) {
|
||||||
const value = Number.parseInt(initialUrlParams.get(prop));
|
const value = Number.parseInt(initialUrlParams.get(prop));
|
||||||
@ -235,6 +239,9 @@ document.addEventListener("alpine:init", () => {
|
|||||||
await this.reverseGraph();
|
await this.reverseGraph();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.$watch("isZoomEnabled", () => {
|
||||||
|
this.graph.userZoomingEnabled(this.isZoomEnabled);
|
||||||
|
});
|
||||||
await this.fetchGraphData();
|
await this.fetchGraphData();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -279,6 +286,7 @@ document.addEventListener("alpine:init", () => {
|
|||||||
this.graphData,
|
this.graphData,
|
||||||
config.activeUser,
|
config.activeUser,
|
||||||
);
|
);
|
||||||
|
this.graph.userZoomingEnabled(this.isZoomEnabled);
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
@ -77,6 +77,7 @@
|
|||||||
></i></button>
|
></i></button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="toolbar-column">
|
<div class="toolbar-column">
|
||||||
@ -91,6 +92,31 @@
|
|||||||
<i class="fa fa-camera"></i>
|
<i class="fa fa-camera"></i>
|
||||||
{% trans %}Save{% endtrans %}
|
{% trans %}Save{% endtrans %}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<div class="toolbar-input">
|
||||||
|
<button
|
||||||
|
@click="() => graph.zoom(graph.zoom() + 1)"
|
||||||
|
>
|
||||||
|
<i class="fa-solid fa-magnifying-glass-plus"></i>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
@click="() => graph.zoom(graph.zoom() - 1)"
|
||||||
|
>
|
||||||
|
<i class="fa-solid fa-magnifying-glass-minus"></i>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
x-show="isZoomEnabled"
|
||||||
|
@click="() => isZoomEnabled = false"
|
||||||
|
>
|
||||||
|
<i class="fa-solid fa-unlock"></i>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
x-show="!isZoomEnabled"
|
||||||
|
@click="() => isZoomEnabled = true"
|
||||||
|
>
|
||||||
|
<i class="fa-solid fa-lock"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div x-ref="graph" class="graph"></div>
|
<div x-ref="graph" class="graph"></div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user