Passed
Pull Request — master (#37)
by
unknown
03:48
created

src/zoom/zoom.ts   A

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 28
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 22
mnd 0
bc 0
fnc 1
dl 0
loc 28
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A zoom.ts ➔ createZoom 0 13 1
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