@farm-investimentos/front-mfe-components 15.13.1 → 15.13.2

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": "@farm-investimentos/front-mfe-components",
3
- "version": "15.13.1",
3
+ "version": "15.13.2",
4
4
  "author": "farm investimentos",
5
5
  "private": false,
6
6
  "main": "./dist/front-mfe-components.common.js",
@@ -29,7 +29,10 @@
29
29
  class="farm-gantt-chart__group"
30
30
  >
31
31
  <div class="farm-gantt-chart__group-label">
32
- <farm-typography :weight="500">
32
+ <farm-typography v-if="group.subtitle" size="md" :weight="600" color="black" color-variation="50" class="mb-1">
33
+ {{ group.subtitle }}
34
+ </farm-typography>
35
+ <farm-typography size ="md" :weight="500" color="black" color-variation="50">
33
36
  {{ group.title }}
34
37
  </farm-typography>
35
38
  </div>
@@ -50,7 +53,7 @@
50
53
  </div>
51
54
  </div>
52
55
  </div>
53
-
56
+
54
57
  </div>
55
58
 
56
59
  <div class="farm-gantt-chart__legend" v-if="autoGeneratedLegend.length > 0" :style="legendStyle">
@@ -80,6 +83,7 @@
80
83
  v-if="tooltipState.visible"
81
84
  class="farm-gantt-chart__tooltip-container"
82
85
  :style="tooltipPositionStyle"
86
+ ref="tooltipElement"
83
87
  >
84
88
  <div v-if="$slots.tooltip" class="farm-gantt-chart__tooltip">
85
89
  <slot
@@ -88,7 +92,7 @@
88
92
  :tooltipData="tooltipState.barData && tooltipState.barData.tooltipData"
89
93
  />
90
94
  </div>
91
-
95
+
92
96
  <div
93
97
  v-else-if="tooltipState.barData && tooltipState.barData.tooltipData"
94
98
  class="farm-gantt-chart__tooltip farm-tooltip__popup farm-tooltip__popup--visible"
@@ -109,7 +113,7 @@
109
113
  </div>
110
114
  </div>
111
115
  </div>
112
-
116
+
113
117
  <div
114
118
  v-else
115
119
  class="farm-gantt-chart__tooltip farm-tooltip__popup farm-tooltip__popup--visible"
@@ -128,7 +132,7 @@
128
132
  </template>
129
133
 
130
134
  <script lang="ts">
131
- import { defineComponent, PropType, computed, reactive, ref } from 'vue';
135
+ import { defineComponent, PropType, computed, reactive, ref, onMounted, onUnmounted, nextTick } from 'vue';
132
136
  import type { GanttData, TooltipState, GanttBar } from './types';
133
137
  import { getMonthsBetween, formatMonth, isCurrentMonth, getColumnForDate, formatDateRange } from './utils/dateUtils';
134
138
  import { buildGanttData, buildBarPositioning } from './composition';
@@ -144,21 +148,21 @@ export default defineComponent({
144
148
  console.warn('GanttChart: prop "data" deve ser um objeto.');
145
149
  return false;
146
150
  }
147
-
151
+
148
152
  if (!Array.isArray(value.groups)) {
149
153
  console.warn('GanttChart: prop "data.groups" deve ser um array.');
150
154
  return false;
151
155
  }
152
-
156
+
153
157
  return value.groups.every((group: any) => {
154
158
  const hasValidTitle = typeof group.title === 'string';
155
159
  const hasValidBars = Array.isArray(group.bars);
156
-
160
+
157
161
  if (!hasValidTitle || !hasValidBars) {
158
162
  console.warn('GanttChart: cada grupo deve ter título (string) e barras (array).');
159
163
  return false;
160
164
  }
161
-
165
+
162
166
  return true;
163
167
  });
164
168
  }
@@ -229,11 +233,17 @@ export default defineComponent({
229
233
  };
230
234
  });
231
235
 
236
+ const tooltipElement = ref<HTMLElement>();
237
+ const lastMousePosition = ref<{ eventX: number; eventY: number } | null>(null);
238
+
232
239
  const onBarMouseEnter = (bar: GanttBar, event: MouseEvent) => {
233
240
  tooltipState.visible = true;
234
241
  tooltipState.title = bar.tooltipTitle || bar.label;
235
242
  tooltipState.barData = bar;
236
- updateTooltipPosition(event);
243
+
244
+ nextTick(() => {
245
+ updateTooltipPosition(event);
246
+ });
237
247
  };
238
248
 
239
249
  const onBarMouseMove = (bar: GanttBar, event: MouseEvent) => {
@@ -247,30 +257,50 @@ export default defineComponent({
247
257
  tooltipState.barData = null;
248
258
  };
249
259
 
250
- const updateTooltipPosition = (event: MouseEvent) => {
251
- if (!chartContainer.value) return;
260
+ const updateTooltipPosition = (event?: MouseEvent) => {
261
+ const container = chartContainer.value;
262
+ const tooltipEl = tooltipElement.value;
263
+ if (!container || !tooltipEl) return;
264
+
265
+ const { left, top } = container.getBoundingClientRect();
252
266
 
253
- const containerRect = chartContainer.value.getBoundingClientRect();
254
- const x = event.clientX - containerRect.left;
255
- const y = event.clientY - containerRect.top;
267
+ const scrollLeft = container.scrollLeft;
268
+ const scrollTop = container.scrollTop;
256
269
 
257
- const tooltipWidth = 300;
258
- const tooltipHeight = 100;
270
+ const tooltipWidth = tooltipEl.offsetWidth || 300;
271
+ const tooltipHeight = tooltipEl.offsetHeight || 100;
259
272
  const margin = 15;
260
273
 
261
- let tooltipX = x + margin;
262
- let tooltipY = y + margin;
274
+ let contentX: number;
275
+ let contentY: number;
276
+
277
+ if (event) {
278
+ lastMousePosition.value = { eventX: event.clientX, eventY: event.clientY };
279
+ contentX = event.clientX - left + scrollLeft;
280
+ contentY = event.clientY - top + scrollTop;
281
+ } else if (lastMousePosition.value) {
282
+ contentX = lastMousePosition.value.eventX - left + scrollLeft;
283
+ contentY = lastMousePosition.value.eventY - top + scrollTop;
284
+ } else {
285
+ return;
286
+ }
287
+
288
+ let tooltipX = contentX + margin;
289
+ let tooltipY = contentY + margin;
290
+
291
+ const maxVisibleX = scrollLeft + container.clientWidth - tooltipWidth - 10;
292
+ const maxVisibleY = scrollTop + container.clientHeight - tooltipHeight - 10;
263
293
 
264
- if (tooltipX + tooltipWidth > containerRect.width) {
265
- tooltipX = Math.max(10, containerRect.width - tooltipWidth - 10);
294
+ if (tooltipX > maxVisibleX) {
295
+ tooltipX = maxVisibleX;
266
296
  }
267
297
 
268
- if (tooltipY + tooltipHeight > containerRect.height) {
269
- tooltipY = Math.max(10, y - tooltipHeight - margin);
298
+ if (tooltipY > maxVisibleY) {
299
+ tooltipY = Math.max(scrollTop + 10, contentY - tooltipHeight - margin);
270
300
  }
271
301
 
272
- tooltipX = Math.max(10, tooltipX);
273
- tooltipY = Math.max(10, tooltipY);
302
+ tooltipX = Math.max(scrollLeft + 10, tooltipX);
303
+ tooltipY = Math.max(scrollTop + 10, tooltipY);
274
304
 
275
305
  tooltipState.x = tooltipX;
276
306
  tooltipState.y = tooltipY;
@@ -281,6 +311,20 @@ export default defineComponent({
281
311
  zIndex: 999
282
312
  }));
283
313
 
314
+ onMounted(() => {
315
+ if (!chartContainer.value) return;
316
+ const container = chartContainer.value;
317
+ const handleScroll = () => {
318
+ if (tooltipState.visible) {
319
+ updateTooltipPosition();
320
+ }
321
+ };
322
+ container.addEventListener('scroll', handleScroll);
323
+ onUnmounted(() => {
324
+ container.removeEventListener('scroll', handleScroll);
325
+ });
326
+ });
327
+
284
328
  return {
285
329
  monthColumns,
286
330
  timelineGridStyle,
@@ -294,6 +338,7 @@ export default defineComponent({
294
338
  tooltipState,
295
339
  tooltipPositionStyle,
296
340
  chartContainer,
341
+ tooltipElement,
297
342
  onBarMouseEnter,
298
343
  onBarMouseMove,
299
344
  onBarMouseLeave,
@@ -3,19 +3,20 @@ export interface GanttData {
3
3
  }
4
4
 
5
5
  export interface GanttGroup {
6
- title: string;
6
+ title: string;
7
+ subtitle?: string;
7
8
  bars: GanttBar[];
8
9
  }
9
10
 
10
11
  export interface GanttBar {
11
12
  id: string | number;
12
- label: string;
13
- start: Date | string;
14
- end: Date | string;
15
- color: string;
13
+ label: string;
14
+ start: Date | string;
15
+ end: Date | string;
16
+ color: string;
16
17
  rowPosition?: number;
17
18
  tooltipData?: TooltipData;
18
-
19
+
19
20
  [key: string]: any;
20
21
  }
21
22