1+ /**
2+ * Creates the Reporting instance and returns it
3+ * @param dotNetObject The calling dotnet object
4+ * @returns {InputCode } the Reporting instance
5+ */
6+ export function createReporting ( dotNetObject )
7+ {
8+ return new Reporting ( dotNetObject ) ;
9+ }
10+
11+ export class Reporting {
12+
13+ initCharts ( ) {
14+ console . log ( 'init charts!' ) ;
15+ let pieCharts = document . querySelectorAll ( '.report-output svg.pie-chart' ) ;
16+
17+ for ( let pie of pieCharts ) {
18+ console . log ( 'pie' , pie ) ;
19+ let slices = pie . querySelectorAll ( '.slice' ) ;
20+
21+ for ( let slice of slices ) {
22+ slice . addEventListener ( 'mouseover' , ( ) => {
23+ // Get tooltip content from data-tooltip attribute
24+ let tooltipText = slice . getAttribute ( 'data-title' ) ;
25+
26+ // Create a tooltip element
27+ let tooltip = document . createElement ( 'div' ) ;
28+ tooltip . classList . add ( 'svg-tooltip' ) ;
29+ tooltip . textContent = tooltipText ;
30+
31+ // Position the tooltip relative to the slice
32+ let rect = slice . getBoundingClientRect ( ) ;
33+ tooltip . style . left = rect . left + rect . width / 2 + 'px' ;
34+ tooltip . style . top = rect . top + rect . height / 2 + 'px' ;
35+
36+ // Append tooltip to the body or another container
37+ document . body . appendChild ( tooltip ) ;
38+ } ) ;
39+
40+ slice . addEventListener ( 'mouseout' , ( ) => {
41+ // Remove tooltip on mouse out
42+ let tooltip = document . querySelector ( '.svg-tooltip' ) ;
43+ if ( tooltip ) {
44+ tooltip . parentNode . removeChild ( tooltip ) ;
45+ }
46+ } ) ;
47+ }
48+ }
49+ }
50+ }
0 commit comments