feat: Add mouse wheel zoom control and reset zoom functionality in GraphView for improved user experience and interaction
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 5m36s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 5m36s
This commit is contained in:
@@ -88,6 +88,15 @@ function GraphView({ servers, connections }) {
|
||||
});
|
||||
svg.call(zoomRef.current);
|
||||
dbg('zoom initialized', { width, height });
|
||||
|
||||
// Колёсико мыши — обычный масштаб (желательно для UX)
|
||||
svg.on('wheel.zoom', null); // убираем двойное навешивание
|
||||
svg.on('wheel', (event) => {
|
||||
event.preventDefault();
|
||||
const delta = Math.sign(event.deltaY);
|
||||
const factor = delta > 0 ? 1 / 1.2 : 1.2;
|
||||
zoomBy(factor);
|
||||
}, { passive: false });
|
||||
}, []);
|
||||
|
||||
// Контролы масштабирования
|
||||
@@ -153,6 +162,19 @@ function GraphView({ servers, connections }) {
|
||||
}
|
||||
};
|
||||
|
||||
const resetZoom = () => {
|
||||
if (!zoomRef.current || !svgRef.current) return;
|
||||
const svgEl = svgRef.current;
|
||||
d3.select(svgEl)
|
||||
.transition()
|
||||
.duration(220)
|
||||
.call(zoomRef.current.transform, d3.zoomIdentity)
|
||||
.on('end', () => {
|
||||
const nt = d3.zoomTransform(svgEl);
|
||||
dbg('resetZoom end', { k: nt.k, x: nt.x, y: nt.y });
|
||||
});
|
||||
};
|
||||
|
||||
if (servers.length === 0) {
|
||||
return (
|
||||
<div className="text-center py-5">
|
||||
@@ -524,6 +546,9 @@ function GraphView({ servers, connections }) {
|
||||
<button className="btn btn-outline-secondary" onClick={toggleFullscreen} title={isFullscreen ? 'Выйти из полноэкранного' : 'Во весь экран'}>
|
||||
{isFullscreen ? <IconMinimize size={16} /> : <IconMaximize size={16} />}
|
||||
</button>
|
||||
<button className="btn btn-outline-secondary" onClick={resetZoom} title="Сброс масштаба">
|
||||
100%
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user