@performant-software/visualize 0.6.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,139 @@
1
+ // @flow
2
+
3
+ import React, { useCallback, type ComponentType, type Element } from 'react';
4
+ import { localPoint } from '@visx/event';
5
+ import { Zoom } from '@visx/zoom';
6
+ import i18n from '../i18n/i18n';
7
+ import './Zoom.css';
8
+
9
+ type Props = {
10
+ initialTransform?: {
11
+ skewX: number,
12
+ skewY: number,
13
+ scaleX: number,
14
+ scaleY: number,
15
+ translateX: number,
16
+ translateY: number
17
+ },
18
+ parentHeight: number,
19
+ parentWidth: number,
20
+ scaleXMax?: number,
21
+ scaleXMin?: number,
22
+ scaleYMax?: number,
23
+ scaleYMin?: number
24
+ };
25
+
26
+ type WithZoomType = (WrappedComponent: ComponentType<any>) => (props: Props) => Element<any>;
27
+
28
+ const DEFAULT_INITIAL_TRANSFORM = {
29
+ scaleX: 1,
30
+ scaleY: 1,
31
+ translateX: 0,
32
+ translateY: 0,
33
+ skewX: 0,
34
+ skewY: 0,
35
+ };
36
+
37
+ const withZoom: WithZoomType = (WrappedComponent: ComponentType<any>) => (props: Props) => {
38
+ const { parentWidth: width, parentHeight: height } = props;
39
+ const { scaleXMin = 1 / 2, scaleXMax = 4 } = props;
40
+ const { scaleYMin = 1 / 2, scaleYMax = 4 } = props;
41
+ const { initialTransform = DEFAULT_INITIAL_TRANSFORM } = props;
42
+
43
+ /**
44
+ * Renders the container with zoom controls.
45
+ *
46
+ * @type {unknown}
47
+ */
48
+ const renderZoomContainer = useCallback((zoom) => (
49
+ <rect
50
+ width={width}
51
+ height={height}
52
+ rx={14}
53
+ fill='transparent'
54
+ onTouchStart={zoom.dragStart}
55
+ onTouchMove={zoom.dragMove}
56
+ onTouchEnd={zoom.dragEnd}
57
+ onMouseDown={zoom.dragStart}
58
+ onMouseMove={zoom.dragMove}
59
+ onMouseUp={zoom.dragEnd}
60
+ onMouseLeave={() => {
61
+ if (zoom.isDragging) zoom.dragEnd();
62
+ }}
63
+ onDoubleClick={(event) => {
64
+ const point = localPoint(event) || { x: 0, y: 0 };
65
+ zoom.scale({ scaleX: 1.1, scaleY: 1.1, point });
66
+ }}
67
+ />
68
+ ), [width, height]);
69
+
70
+ return (
71
+ <Zoom
72
+ width={width}
73
+ height={height}
74
+ scaleXMin={scaleXMin}
75
+ scaleXMax={scaleXMax}
76
+ scaleYMin={scaleYMin}
77
+ scaleYMax={scaleYMax}
78
+ initialTransformMatrix={initialTransform}
79
+ >
80
+ { (zoom) => (
81
+ <div
82
+ className='zoom'
83
+ >
84
+ <WrappedComponent
85
+ {...props}
86
+ renderZoomContainer={renderZoomContainer.bind(this, zoom)}
87
+ zoom={zoom}
88
+ />
89
+ <div
90
+ className='controls'
91
+ >
92
+ <button
93
+ type='button'
94
+ className='btn btn-zoom'
95
+ onClick={() => zoom.scale({ scaleX: 1.2, scaleY: 1.2 })}
96
+ >
97
+ { i18n.t('Zoom.buttons.zoomIn') }
98
+ </button>
99
+ <button
100
+ type='button'
101
+ className='btn btn-zoom btn-bottom'
102
+ onClick={() => zoom.scale({ scaleX: 0.8, scaleY: 0.8 })}
103
+ >
104
+ { i18n.t('Zoom.buttons.zoomOut') }
105
+ </button>
106
+ <button
107
+ type='button'
108
+ className='btn btn-lg'
109
+ onClick={zoom.center}
110
+ >
111
+ { i18n.t('Zoom.buttons.center') }
112
+ </button>
113
+ <button
114
+ type='button'
115
+ className='btn btn-lg'
116
+ onClick={zoom.reset}
117
+ >
118
+ { i18n.t('Zoom.buttons.reset') }
119
+ </button>
120
+ <button
121
+ type='button'
122
+ className='btn btn-lg'
123
+ onClick={zoom.clear}
124
+ >
125
+ { i18n.t('Zoom.buttons.clear') }
126
+ </button>
127
+ </div>
128
+ </div>
129
+ )}
130
+ </Zoom>
131
+ );
132
+ };
133
+
134
+ export default withZoom;
135
+
136
+ export type ZoomProps = {
137
+ renderZoomContainer: () => Element<any>,
138
+ zoom: typeof Zoom
139
+ };
@@ -0,0 +1,24 @@
1
+ import i18next from 'i18next';
2
+
3
+ import en from './en.json';
4
+
5
+ const resources = {
6
+ en: {
7
+ translation: en
8
+ }
9
+ };
10
+
11
+ const i18n = i18next.createInstance();
12
+
13
+ i18n
14
+ .init({
15
+ debug: true,
16
+ fallbackLng: 'en',
17
+ lng: 'en',
18
+ interpolation: {
19
+ escapeValue: false,
20
+ },
21
+ resources
22
+ });
23
+
24
+ export default i18n;
@@ -0,0 +1,7 @@
1
+ // @flow
2
+
3
+ // Components
4
+ export { default as TreeGraph } from './components/TreeGraph';
5
+
6
+ // Hooks
7
+ export { default as withZoom } from './hooks/Zoom';
@@ -0,0 +1,3 @@
1
+ const { configure } = require('@performant-software/webpack-config');
2
+
3
+ module.exports = configure(__dirname);