@centreon/ui 24.4.1-MON-34377-implement-tree-chart-on-centreon-ui.7 → 24.4.1-MON-34377-implement-tree-chart-on-centreon-ui.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centreon/ui",
3
- "version": "24.4.1-MON-34377-implement-tree-chart-on-centreon-ui.7",
3
+ "version": "24.4.1-MON-34377-implement-tree-chart-on-centreon-ui.8",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -287,7 +287,12 @@ export const moreComplexData: Node<ComplexData> = {
287
287
  { data: { id: 30, name: 'Indicator 30', status: 'ok' } },
288
288
  { data: { id: 31, name: 'Indicator 31', status: 'ok' } },
289
289
  { data: { id: 32, name: 'Indicator 32', status: 'ok' } },
290
- { data: { id: 33, name: 'Indicator 33', status: 'ok' } }
290
+ { data: { id: 33, name: 'Indicator 33', status: 'ok' } },
291
+ { data: { id: 34, name: 'Indicator 34', status: 'ok' } },
292
+ { data: { id: 35, name: 'Indicator 35', status: 'ok' } },
293
+ { data: { id: 36, name: 'Indicator 36', status: 'ok' } },
294
+ { data: { id: 37, name: 'Indicator 37', status: 'ok' } },
295
+ { data: { id: 38, name: 'Indicator 38', status: 'ok' } }
291
296
  ],
292
297
  data: { count: 2, id: 0, name: 'ok', status: 'ok' }
293
298
  }
@@ -42,7 +42,7 @@ const Minimap = ({
42
42
  height,
43
43
  isDraggingFromContainer,
44
44
  minimapScale,
45
- scale: (1 / scale > 1 ? 1 : scale) || 1,
45
+ scale: (invertedScale > 1 ? 1 : scale) || 1,
46
46
  width,
47
47
  zoom
48
48
  });
@@ -50,12 +50,40 @@ const Minimap = ({
50
50
  const finalHeight = height;
51
51
  const finalWidth = width;
52
52
 
53
- const additionalScale = scaleLinear({
53
+ const additionalScaleScale = scaleLinear({
54
54
  clamp: true,
55
55
  domain: [contentClientRect.height, 0],
56
56
  range: [0, 0.05]
57
57
  });
58
58
 
59
+ const additionalScale =
60
+ additionalScaleScale(contentClientRect.height - height) /
61
+ 2 /
62
+ zoom.transformMatrix.scaleY;
63
+
64
+ const getAdditionalPadding = (): number => {
65
+ if (additionalScale > 0.05) {
66
+ return 0;
67
+ }
68
+
69
+ const padding =
70
+ additionalScale > 0.012
71
+ ? (1 / additionalScale) * (1 / zoom.transformMatrix.scaleY)
72
+ : 1 / additionalScale / zoom.transformMatrix.scaleY;
73
+
74
+ if (additionalScale < 0.009) {
75
+ const test = scaleLinear({
76
+ clamp: true,
77
+ domain: [0.005, 0.002],
78
+ range: [1, 5]
79
+ });
80
+
81
+ return padding - padding / test(additionalScale);
82
+ }
83
+
84
+ return padding;
85
+ };
86
+
59
87
  return (
60
88
  <g className={classes.minimap} clipPath="url(#zoom-clip)">
61
89
  <rect
@@ -66,7 +94,7 @@ const Minimap = ({
66
94
  />
67
95
  <g
68
96
  style={{
69
- transform: `scale(${scaleToUse - additionalScale(contentClientRect.height - height) / 2})`
97
+ transform: `scale(${scaleToUse - additionalScale}) translate(0px, ${getAdditionalPadding()}px)`
70
98
  }}
71
99
  >
72
100
  {children}
@@ -92,6 +120,8 @@ const Minimap = ({
92
120
  rx={radius}
93
121
  width={finalWidth}
94
122
  onMouseDown={dragStart}
123
+ onMouseEnter={dragStart}
124
+ onMouseLeave={dragEnd}
95
125
  onMouseMove={move}
96
126
  onMouseUp={dragEnd}
97
127
  onWheel={zoomInOut}
@@ -7,7 +7,7 @@ const content = (
7
7
  );
8
8
 
9
9
  const contentWithMultipleShapes = (
10
- <g style={{ transform: 'translate(0px, -200px)' }}>
10
+ <g style={{ transform: 'translate(0px, -300px)' }}>
11
11
  <g style={{ transform: 'translate(300px, 150px)' }}>
12
12
  <circle fill="blue" r={50} stroke="black" />
13
13
  </g>
@@ -203,7 +203,11 @@ describe('Zoom', () => {
203
203
  cy.findByTestId('minimap-interaction')
204
204
  .parent()
205
205
  .find('g')
206
- .should('have.attr', 'style', 'transform: scale(0.684211);');
206
+ .should(
207
+ 'have.attr',
208
+ 'style',
209
+ 'transform: scale(0.684211) translate(0px, 57px);'
210
+ );
207
211
 
208
212
  cy.makeSnapshot();
209
213
  });
@@ -73,6 +73,8 @@ const ZoomContent = ({
73
73
  height={height}
74
74
  width={width}
75
75
  onMouseDown={dragStart(zoom)}
76
+ onMouseEnter={dragStart(zoom)}
77
+ onMouseLeave={dragEnd}
76
78
  onMouseMove={move(zoom)}
77
79
  onMouseUp={dragEnd}
78
80
  onWheel={zoom.handleWheel}
@@ -37,15 +37,21 @@ export const useMinimap = ({
37
37
  const [startTranslate, setStartTranslate] = useState<Translate | null>(null);
38
38
 
39
39
  const getMatrixPoint = useCallback(
40
- (event): { x: number; y: number } => {
40
+ (event, newScale?: number): { x: number; y: number } => {
41
41
  const hasScale = scale > 1;
42
42
  const point = {
43
43
  x: event.nativeEvent.offsetX * (1 / minimapScale),
44
44
  y: event.nativeEvent.offsetY * (1 / minimapScale)
45
45
  };
46
46
 
47
- const dx = -(point.x * zoom.transformMatrix.scaleX - width / 2);
48
- const dy = -(point.y * zoom.transformMatrix.scaleY - height / 2);
47
+ const dx = -(
48
+ point.x * (newScale || zoom.transformMatrix.scaleX) -
49
+ width / 2
50
+ );
51
+ const dy = -(
52
+ point.y * (newScale || zoom.transformMatrix.scaleY) -
53
+ height / 2
54
+ );
49
55
 
50
56
  return {
51
57
  x: !hasScale ? dx : dx * scale - width / 2,
@@ -72,7 +78,7 @@ export const useMinimap = ({
72
78
 
73
79
  const dragStart = (e): void => {
74
80
  if (
75
- (!equals(e.buttons, 0) && !equals(e.nativeEvent.which, 1)) ||
81
+ (!isNil(e.nativeEvent.which) && !equals(e.nativeEvent.which, 1)) ||
76
82
  isDraggingFromContainer
77
83
  ) {
78
84
  return;
@@ -109,21 +115,35 @@ export const useMinimap = ({
109
115
  const zoomInOut = useCallback(
110
116
  (e): void => {
111
117
  const isZoomIn = gt(0, e.deltaY);
112
- const { x, y } = getMatrixPoint(e);
118
+
119
+ const newScaleX = isZoomIn
120
+ ? zoom.transformMatrix.scaleX + 0.1
121
+ : zoom.transformMatrix.scaleX - 0.1;
122
+
123
+ const newScaleY = isZoomIn
124
+ ? zoom.transformMatrix.scaleX + 0.1
125
+ : zoom.transformMatrix.scaleX - 0.1;
126
+ const { x, y } = getMatrixPoint(e, newScaleX);
127
+
128
+ const diffX = x - zoom.transformMatrix.translateX;
129
+ const diffY = y - zoom.transformMatrix.translateY;
113
130
 
114
131
  zoom.setTransformMatrix({
115
132
  ...zoom.transformMatrix,
116
- scaleX: isZoomIn
117
- ? zoom.transformMatrix.scaleX + 0.1
118
- : zoom.transformMatrix.scaleX - 0.1,
119
- scaleY: isZoomIn
120
- ? zoom.transformMatrix.scaleY + 0.1
121
- : zoom.transformMatrix.scaleY - 0.1,
122
- translateX: x,
123
- translateY: y
133
+ scaleX: newScaleX,
134
+ scaleY: newScaleY,
135
+ translateX: zoom.transformMatrix.translateX + diffX / 4,
136
+ translateY: zoom.transformMatrix.translateY + diffY / 4
124
137
  });
125
138
  },
126
- [zoom.transformMatrix]
139
+ [
140
+ zoom.transformMatrix,
141
+ width,
142
+ height,
143
+ isDraggingFromContainer,
144
+ scale,
145
+ startPoint
146
+ ]
127
147
  );
128
148
 
129
149
  return {