Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 28 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { DependencyNode, NodeSelection } from '../components/types'; |
||
2 | import { ElementIds, MAXIMUM_ZOOM_SCALE, MINIMUM_ZOOM_SCALE } from '../utils/AppConsts'; |
||
3 | import { zoom } from 'd3-zoom'; |
||
4 | import { event } from 'd3-selection'; |
||
5 | import { selectById } from '../utils/helpers/Selectors'; |
||
6 | import { ZoomScaleStorage } from '../utils/helpers/UserEventHelpers'; |
||
7 | |||
8 | export const changeZoom = (zoomSelector: ElementIds.OVERVIEW_ZOOM | ElementIds.DETAILS_ZOOM) => () => { |
||
9 | const { transform } = event; |
||
10 | const zoomLayer = selectById(zoomSelector); |
||
11 | zoomLayer.attr('transform', transform); |
||
12 | ZoomScaleStorage.setScale(transform.k); |
||
13 | }; |
||
14 | |||
15 | export function createZoom(svgContainer: NodeSelection<SVGSVGElement>, selector: ElementIds.OVERVIEW_ZOOM | ElementIds.DETAILS_ZOOM) { |
||
16 | const zoomLayer = svgContainer.append('g').attr('id', selector); |
||
17 | |||
18 | svgContainer |
||
19 | .call( |
||
20 | zoom<SVGSVGElement, DependencyNode>() |
||
21 | .scaleExtent([MINIMUM_ZOOM_SCALE, MAXIMUM_ZOOM_SCALE]) |
||
22 | .on(`zoom`, changeZoom(selector)) |
||
23 | ) |
||
24 | .on('dblclick.zoom', null); |
||
25 | |||
26 | return zoomLayer; |
||
27 | } |
||
28 |