@stfrigerio/sito-template 0.1.34 → 0.1.35
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoodChart.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/charts/MoodChart/MoodChart.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAA;AAInE,UAAU,YAAY;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;CACnB;AAMD,UAAU,cAAc;IACpB,QAAQ,EAAE,YAAY,EAAE,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAClB;AAID,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,
|
|
1
|
+
{"version":3,"file":"MoodChart.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/charts/MoodChart/MoodChart.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAA;AAInE,UAAU,YAAY;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;CACnB;AAMD,UAAU,cAAc;IACpB,QAAQ,EAAE,YAAY,EAAE,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAClB;AAID,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAoN9C,CAAA"}
|
package/dist/index.esm.js
CHANGED
|
@@ -3036,8 +3036,10 @@ var styles$7 = {"container":"MoodChart-module_container__MB1Vr","chart":"MoodCha
|
|
|
3036
3036
|
const MoodChart = ({ moodData, width = 800, height = 400 }) => {
|
|
3037
3037
|
const svgRef = useRef(null);
|
|
3038
3038
|
const containerRef = useRef(null);
|
|
3039
|
+
const tooltipRef = useRef(null);
|
|
3039
3040
|
const [selectedMood, setSelectedMood] = useState(null);
|
|
3040
3041
|
const [tooltipPosition, setTooltipPosition] = useState({ x: 0, y: 0 });
|
|
3042
|
+
const [isHoveringTooltip, setIsHoveringTooltip] = useState(false);
|
|
3041
3043
|
const margin = { top: 20, right: 20, bottom: 50, left: 40 };
|
|
3042
3044
|
const chartWidth = width - margin.left - margin.right;
|
|
3043
3045
|
const chartHeight = height - margin.top - margin.bottom;
|
|
@@ -3115,11 +3117,26 @@ const MoodChart = ({ moodData, width = 800, height = 400 }) => {
|
|
|
3115
3117
|
.style('cursor', 'pointer')
|
|
3116
3118
|
.on('mouseenter', (event, d) => {
|
|
3117
3119
|
const rect = svgRef.current?.getBoundingClientRect();
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3120
|
+
const containerRect = containerRef.current?.getBoundingClientRect();
|
|
3121
|
+
if (rect && containerRect) {
|
|
3122
|
+
let x = event.clientX - rect.left + 10;
|
|
3123
|
+
let y = event.clientY - rect.top - 10;
|
|
3124
|
+
// Check if tooltip would overflow on the right
|
|
3125
|
+
const estimatedTooltipWidth = 250; // Approximate tooltip width
|
|
3126
|
+
const rightEdgeBuffer = 20; // Buffer from the right edge
|
|
3127
|
+
if (x + estimatedTooltipWidth > chartWidth + margin.left - rightEdgeBuffer) {
|
|
3128
|
+
// Position tooltip to the left of the cursor, but keep it close
|
|
3129
|
+
x = event.clientX - rect.left - estimatedTooltipWidth - 10;
|
|
3130
|
+
// Ensure it doesn't go off the left edge
|
|
3131
|
+
if (x < 0) {
|
|
3132
|
+
x = 10;
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
// Ensure tooltip doesn't go above the container
|
|
3136
|
+
if (y < 0) {
|
|
3137
|
+
y = 10;
|
|
3138
|
+
}
|
|
3139
|
+
setTooltipPosition({ x, y });
|
|
3123
3140
|
}
|
|
3124
3141
|
setSelectedMood(d);
|
|
3125
3142
|
d3.select(event.currentTarget)
|
|
@@ -3128,28 +3145,33 @@ const MoodChart = ({ moodData, width = 800, height = 400 }) => {
|
|
|
3128
3145
|
.attr('r', 8);
|
|
3129
3146
|
})
|
|
3130
3147
|
.on('mouseleave', (event) => {
|
|
3131
|
-
//
|
|
3148
|
+
// Add delay to allow mouse to move to tooltip
|
|
3132
3149
|
setTimeout(() => {
|
|
3133
|
-
|
|
3134
|
-
|
|
3150
|
+
if (!isHoveringTooltip) {
|
|
3151
|
+
setSelectedMood(null);
|
|
3152
|
+
}
|
|
3153
|
+
}, 250);
|
|
3135
3154
|
d3.select(event.currentTarget)
|
|
3136
3155
|
.transition()
|
|
3137
3156
|
.duration(200)
|
|
3138
3157
|
.attr('r', 5);
|
|
3139
3158
|
});
|
|
3140
|
-
}, [processedData, chartWidth, chartHeight, colorScale, margin]);
|
|
3159
|
+
}, [processedData, chartWidth, chartHeight, colorScale, margin, isHoveringTooltip]);
|
|
3141
3160
|
// Clean up tooltip on unmount
|
|
3142
3161
|
useEffect(() => {
|
|
3143
3162
|
return () => {
|
|
3144
3163
|
setSelectedMood(null);
|
|
3145
3164
|
};
|
|
3146
3165
|
}, []);
|
|
3147
|
-
return (jsxs("div", { className: styles$7.container, ref: containerRef,
|
|
3166
|
+
return (jsxs("div", { className: styles$7.container, ref: containerRef, children: [jsx("svg", { ref: svgRef, width: width, height: height, className: styles$7.chart }), selectedMood && (jsxs("div", { ref: tooltipRef, className: styles$7.tooltip, style: {
|
|
3148
3167
|
position: 'absolute',
|
|
3149
|
-
pointerEvents: '
|
|
3168
|
+
pointerEvents: 'auto',
|
|
3150
3169
|
left: tooltipPosition.x,
|
|
3151
3170
|
top: tooltipPosition.y,
|
|
3152
3171
|
zIndex: 1000
|
|
3172
|
+
}, onMouseEnter: () => setIsHoveringTooltip(true), onMouseLeave: () => {
|
|
3173
|
+
setIsHoveringTooltip(false);
|
|
3174
|
+
setSelectedMood(null);
|
|
3153
3175
|
}, children: [jsxs("div", { className: styles$7.tooltipHeader, children: [jsx("div", { className: styles$7.tooltipDate, children: selectedMood.date.toLocaleDateString() }), jsxs("div", { className: styles$7.tooltipRating, children: [jsx("span", { className: styles$7.ratingValue, children: selectedMood.rating }), jsx("span", { className: styles$7.ratingMax, children: "/10" })] })] }), selectedMood.tags.length > 0 && (jsx("div", { className: styles$7.tooltipTags, children: selectedMood.tags.map((tag, index) => (jsx("span", { className: styles$7.tag, children: tag }, index))) })), selectedMood.comment && (jsx("div", { className: styles$7.tooltipComment, children: selectedMood.comment }))] }))] }));
|
|
3154
3176
|
};
|
|
3155
3177
|
|