bubble-chart-js 1.0.5 → 1.0.7

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/README.md CHANGED
@@ -1,124 +1,171 @@
1
- # bubbleChartJs
2
-
3
- bubbleChartJs is a lightweight and customizable JavaScript library for creating stacked bubble charts, arranging bubbles by size with the largest at the top.
4
-
5
- ### ✨ Why Use a Stacked Bubble Chart?
6
-
7
- Multi-Dimensional Data Representation – Visualizes multiple datasets at once.
8
-
9
- Better Group Comparisons – Highlights relationships between different categories.
10
-
11
- Enhanced Readability – Shows data trends with layered or clustered bubbles.
12
-
13
- Customizable & Interactive – Allows tooltips.
14
-
15
- ### 🔧 Features
16
-
17
- ✔️ Supports stacked or grouped bubble layouts
18
-
19
- ✔️ Customizable bubble color
20
-
21
- ✔️ Fully compatible with JavaScript & Typescript
22
-
23
- ✔️ Interactive tooltips and hover effects
24
-
25
- ### 📌 Use Cases
26
-
27
- Financial Analysis – Display investment risks vs. returns for multiple assets.
28
-
29
- Social Media Metrics – Visualize engagement levels across platforms.
30
-
31
- Scientific Research – Show relationships in grouped experimental data.
32
-
33
- ### 🎨 Example Output
34
-
35
- Here’s an example of the bubble chart generated using this package:
36
-
37
- ![Stacked Bubble Chart Example](https://github.com/Praga-Dev/bubbleChartJS/blob/HEAD/assets/bubble-chart.png)
38
-
39
- ## Installation
40
-
41
- You can install `bubbleChartJs` via npm:
42
-
43
- ```sh
44
- npm install bubble-chart-js
45
- ```
46
-
47
- ## Usage
48
-
49
- ### Basic Example
50
-
51
- ```js
52
- import BubbleChart from "bubblechartjs";
53
-
54
- const tooltipOptions = {
55
- fontStyle: "italic",
56
- fontWeight: 800,
57
- textAlign: "center",
58
- textDecoration: "underline",
59
- textTransform: "uppercase",
60
- fontColor: "#FFF",
61
- };
62
-
63
- const data = [
64
- { label: "Biryani Battles", value: 89, bubbleColor: "#ff5733" },
65
- { label: "Chai vs. Coffee", value: 70, bubbleColor: "#c70039" },
66
- { label: "Bollywood Blockbusters", value: 90, bubbleColor: "#900c3f" },
67
- { label: "IPL Fever", value: 85, bubbleColor: "#ffc300" },
68
- { label: "Himalayan Treks", value: 65, bubbleColor: "#4caf50" },
69
- { label: "Diwali Firecrackers", value: 95, bubbleColor: "#ff8c00" },
70
- { label: "Street Food Craze", value: 75, bubbleColor: "#e91e63" },
71
- { label: "Fastest Century Records", value: 88, bubbleColor: "#3f51b5" },
72
- { label: "Royal Enfield Craze", value: 60, bubbleColor: "#795548" },
73
- { label: "Digital Payment Boom", value: 93, bubbleColor: "#00bcd4" },
74
- ];
75
-
76
- const chartoptions = {
77
- canvasContainerId: "bubbleChart",
78
- data: data,
79
- fontSize: 14,
80
- maxLines: 2,
81
- tooltipOptions: tooltipOptions,
82
- };
83
-
84
- // Initialize chart
85
- initializeChart(chartoptions);
86
- ```
87
-
88
- ## Configuration Options
89
-
90
- The `BubbleChart` class accepts a configuration object with the following properties:
91
-
92
- ## Configuration Options
93
-
94
- The `BubbleChart` class accepts a configuration object with the following properties:
95
-
96
- | Property | Type | Required | Optional | Description | Default |
97
- | ---------------------------------- | ------------------------ | -------- | -------- | ------------------------------------------------------------------- | ----------- |
98
- | `canvasContainerId` | `string` | ✔️ Yes | ❌ No | The ID of the container where the chart will be rendered. | `-` |
99
- | `data` | `DataItem[]` | ✔️ Yes | ❌ No | An array of objects containing `label` and `value` for each bubble. | `-` |
100
- | `colorMap` | `Record<string, string>` | ❌ No | ✔️ Yes | A mapping of labels to specific bubble colors. | `{}` |
101
- | `defaultBubbleColor` | `string` | ❌ No | ✔️ Yes | Default color for bubbles if not specified in `colorMap`. | `"#3498db"` |
102
- | `fontSize` | `number` | ❌ No | ✔️ Yes | Font size for bubble labels. | `14` |
103
- | `fontFamily` | `string` | ❌ No | ✔️ Yes | Font family for text rendering. | `"Arial"` |
104
- | `fontColor` | `string` | ❌ No | ✔️ Yes | Color of the text inside bubbles. | `"#ffffff"` |
105
- | `minRadius` | `number` | ❌ No | ✔️ Yes | Minimum radius for the bubbles. | `10` |
106
- | `maxLines` | `number` | ❌ No | ✔️ Yes | Maximum number of lines allowed for text wrapping. | `3` |
107
- | `textWrap` | `boolean` | ❌ No | ✔️ Yes | Enables or disables text wrapping inside bubbles. | `true` |
108
- | `isResizeCanvasOnWindowSizeChange` | `boolean` | ❌ No | ✔️ Yes | Whether the chart should resize when the window size changes. | `true` |
109
- | `showToolTip` | `boolean` | ❌ No | ✔️ Yes | Whether the chart should display the tooltip or not. | `true` |
110
-
111
- ✔️ **Required**: These properties must be provided.
112
- ✔️ **Optional**: If not provided, the default value will be used.
113
-
114
- ## License
115
-
116
- This project is licensed under the MIT License.
117
-
118
- ## Contributions
119
-
120
- Contributions, issues, and feature requests are welcome!
121
-
122
- ---
123
-
124
- Made with ❤️ by Pragadeesh
1
+ # bubbleChartJs
2
+
3
+ bubbleChartJs is a lightweight and customizable JavaScript library for creating stacked bubble charts, arranging bubbles by size with the largest at the top.
4
+
5
+ ### ✨ Why Use a Stacked Bubble Chart?
6
+
7
+ Multi-Dimensional Data Representation – Visualizes multiple datasets at once.
8
+
9
+ Better Group Comparisons – Highlights relationships between different categories.
10
+
11
+ Enhanced Readability – Shows data trends with layered or clustered bubbles.
12
+
13
+ Customizable & Interactive – Allows tooltips.
14
+
15
+ ### 🔧 Features
16
+
17
+ ✔️ Supports stacked or grouped bubble layouts
18
+
19
+ ✔️ Customizable bubble color
20
+
21
+ ✔️ Fully compatible with JavaScript & Typescript
22
+
23
+ ✔️ Interactive tooltips and hover effects
24
+
25
+ ### 📌 Use Cases
26
+
27
+ Financial Analysis – Display investment risks vs. returns for multiple assets.
28
+
29
+ Social Media Metrics – Visualize engagement levels across platforms.
30
+
31
+ Scientific Research – Show relationships in grouped experimental data.
32
+
33
+ ### 🎨 Example Output
34
+
35
+ Here’s an example of the bubble chart generated using this package:
36
+
37
+ ![Stacked Bubble Chart Example](https://github.com/Praga-Dev/bubbleChartJS/blob/HEAD/assets/bubble-chart.png)
38
+
39
+ ## Installation
40
+
41
+ You can install `bubbleChartJs` via npm:
42
+
43
+ ```sh
44
+ npm install bubble-chart-js
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ ### Basic Example
50
+
51
+ ```js
52
+ import BubbleChart from "bubblechartjs";
53
+
54
+ const tooltipOptions = {
55
+ fontStyle: "italic",
56
+ fontWeight: 800,
57
+ textAlign: "center",
58
+ textDecoration: "underline",
59
+ textTransform: "uppercase",
60
+ fontColor: "#FFF",
61
+ };
62
+
63
+ const data = [
64
+ {
65
+ label: "Rocket Fuel Orders",
66
+ value: 207,
67
+ bubbleColor: "#ff5733",
68
+ fontColor: "#FFFFFF",
69
+ fontWeight: 600,
70
+ },
71
+ {
72
+ label: "Time Machine Repairs",
73
+ value: 154,
74
+ bubbleColor: "#c70039",
75
+ fontColor: "#FFF",
76
+ fontWeight: 600,
77
+ },
78
+ {
79
+ label: "AI Overlord Complaints",
80
+ value: 192,
81
+ bubbleColor: "#900c3f",
82
+ fontColor: "#000",
83
+ },
84
+ {
85
+ label: "Quantum Internet Activation",
86
+ value: 73,
87
+ bubbleColor: "#ffc300",
88
+ fontColor: "#000",
89
+ },
90
+ {
91
+ label: "Zero-Gravity Plumbing Issues",
92
+ value: 96,
93
+ bubbleColor: "#4caf50",
94
+ fontColor: "#000",
95
+ },
96
+ {
97
+ label: "Hologram Tech Support",
98
+ value: 119,
99
+ bubbleColor: "#ff8c00",
100
+ fontColor: "#000",
101
+ },
102
+ {
103
+ label: "Teleportation Delay Reports",
104
+ value: 87,
105
+ bubbleColor: "#03875c",
106
+ fontColor: "#000",
107
+ },
108
+ {
109
+ label: "Neural Chip Upgrades",
110
+ value: 163,
111
+ bubbleColor: "#3f51b5",
112
+ fontColor: "#000",
113
+ },
114
+ {
115
+ label: "Intergalactic Toll Fees",
116
+ value: 132,
117
+ bubbleColor: "#795548",
118
+ fontColor: "#000",
119
+ },
120
+ ];
121
+
122
+ const chartOptions = {
123
+ canvasContainerId: "bubbleChart",
124
+ data: data,
125
+ fontSize: 10,
126
+ onBubbleClick: (bubbleData, event) => {
127
+ alert(`You clicked on: ${bubbleData.label}`);
128
+ },
129
+ };
130
+
131
+ // Initialize chart
132
+ initializeChart(chartoptions);
133
+ ```
134
+
135
+ ## Configuration Options
136
+
137
+ The `BubbleChart` class accepts a configuration object with the following properties:
138
+
139
+ ## Configuration Options
140
+
141
+ The `BubbleChart` class accepts a configuration object with the following properties:
142
+
143
+ | Property | Type | Required | Optional | Description | Default |
144
+ | ---------------------------------- | ------------ | -------- | -------- | ------------------------------------------------------------------------------------------------- | ----------- |
145
+ | `canvasContainerId` | `string` | ✔️ Yes | ❌ No | The ID of the container where the chart will be rendered. | `-` |
146
+ | `data` | `DataItem[]` | ✔️ Yes | ❌ No | An array of objects containing `label` and `value` for each bubble. | `-` |
147
+ | `defaultBubbleColor` | `string` | ❌ No | ✔️ Yes | Default color for bubbles if not specified in `colorMap`. | `"#3498db"` |
148
+ | `fontSize` | `number` | ❌ No | ✔️ Yes | Font size for bubble labels. | `14` |
149
+ | `fontFamily` | `string` | ❌ No | ✔️ Yes | Font family for text rendering. | `"Arial"` |
150
+ | `fontColor` | `string` | ❌ No | ✔️ Yes | Color of the text inside bubbles. | `"#ffffff"` |
151
+ | `minRadius` | `number` | ❌ No | ✔️ Yes | Minimum radius for the bubbles. | `10` |
152
+ | `maxLines` | `number` | ❌ No | ✔️ Yes | Maximum number of lines allowed for text wrapping. | `3` |
153
+ | `textWrap` | `boolean` | ❌ No | ✔️ Yes | Enables or disables text wrapping inside bubbles. | `true` |
154
+ | `isResizeCanvasOnWindowSizeChange` | `boolean` | ❌ No | ✔️ Yes | Whether the chart should resize when the window size changes. | `true` |
155
+ | `showToolTip` | `boolean` | ❌ No | ✔️ Yes | Whether the chart should display the tooltip or not. | `true` |
156
+ | `onBubbleClick` | `method` | ❌ No | ✔️ Yes | Callback function triggered when a bubble is clicked. Provides the clicked bubble data and event. | `true` |
157
+
158
+ ✔️ **Required**: These properties must be provided.
159
+ ✔️ **Optional**: If not provided, the default value will be used.
160
+
161
+ ## License
162
+
163
+ This project is licensed under the MIT License.
164
+
165
+ ## Contributions
166
+
167
+ Contributions, issues, and feature requests are welcome!
168
+
169
+ ---
170
+
171
+ Made with ❤️ by Pragadeesh
Binary file
@@ -1 +1 @@
1
- (()=>{"use strict";var t={d:(e,n)=>{for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{initializeChart:()=>d});let n="default";class o{}o.TRANSPARENT="transparent";const i={forceStrength:.008,iterations:1e3,damping:.65,boundaryForce:.02,centerForce:.12,centerAttraction:.8,centerDamping:.3,centerRadiusBuffer:35};function a(t,e=14,n=400){const o=n>=700?1.25:n>=500?1.1:1;return Math.min(e*o,t/2)}function r(t){if(!function(t){return t?!(!Array.isArray(t.data)||0===t.data.length)||(console.error("Invalid or empty data array"),!1):(console.error("Invalid config object"),!1)}(t))return;let e=function(t){var e,n;const i=document.getElementById(t.canvasContainerId);if(!i)return console.error(`Canvas container with ID '${t.canvasContainerId}' not found.`),null;const a=document.createElement("canvas");return a.width=i.offsetWidth,a.height=i.offsetHeight,console.log(t.canvasBackgroundColor),Object.assign(a.style,{border:(null===(e=t.canvasBorderColor)||void 0===e?void 0:e.trim())?`1px solid #${t.canvasBorderColor}`:o.TRANSPARENT,background:(null===(n=t.canvasBackgroundColor)||void 0===n?void 0:n.trim())?`#${t.canvasBackgroundColor}`:o.TRANSPARENT,width:"100%",height:"100%",display:"block",imageRendering:"crisp-edges",aspectRatio:"1 / 1"}),a.style.setProperty("image-rendering","-moz-crisp-edges"),a.style.setProperty("image-rendering","-webkit-optimize-contrast"),a.style.setProperty("-ms-interpolation-mode","nearest-neighbor"),i.appendChild(a),a}(t);if(!e)return;const r=e.getContext("2d");if(!r)return void console.error("Invalid context");const l=function(t,e,n){const o=Math.min((e.width-10)/2,(e.height-10)/2),a=window.devicePixelRatio||1,r=e.getBoundingClientRect();e.width=r.width*a,e.height=r.height*a,e.style.width=r.width+"px",e.style.height=r.height+"px",n.scale(a,a);const l=r.width/2,d=r.height/2,s=[...t.data].sort(((t,e)=>e.value-t.value)).map((t=>Object.assign(Object.assign({},t),{radius:0,x:0,y:0,fixed:!1}))),u=s[0].value,c=Math.min(1*o,100),h=Math.max(.3*c,30);s.forEach((t=>{const n=t.value/u;t.radius=h+n*(c-h),t.radius=Math.min(t.radius,(e.width-10)/2,(e.height-10)/2)})),s.forEach(((t,n)=>{if(0===n)t.x=l,t.y=d,t.fixed=!0;else{const o=s[0].radius+t.radius+3,i=Math.PI*(3-Math.sqrt(5)),a=e.width-5-t.radius,r=e.height-5-t.radius;t.x=Math.min(a,Math.max(5+t.radius,l+Math.cos(i*n)*o)),t.y=Math.min(r,Math.max(5+t.radius,d+Math.sin(i*n)*o)),t.fixed=!1}}));for(let t=0;t<i.iterations;t++)s.forEach(((t,n)=>{if(0===n){const e=l-t.x,n=d-t.y;return void(Math.hypot(e,n)>2&&(t.x+=e*i.centerDamping,t.y+=n*i.centerDamping))}let o=0,a=0;const r=t.radius+5;t.x<r?o+=(r-t.x)*i.boundaryForce:t.x>e.width-r&&(o+=(e.width-r-t.x)*i.boundaryForce),s.forEach((e=>{if(t===e)return;const n=t.x-e.x,r=t.y-e.y,s=Math.hypot(n,r),c=t.radius+e.radius;if(s<1.5*c){const t=i.forceStrength*(c/Math.max(s,.1));o+=n/s*t,a+=r/s*t}const h=l-t.x,f=d-t.y,v=Math.hypot(h,f),m=t.value/u*.02;t.x+=h/v*m,t.y+=f/v*m}));const c=l-t.x,h=d-t.y,f=Math.hypot(c,h),v=s[0].radius+t.radius+i.centerRadiusBuffer,m=(i.centerForce,Math.pow(t.value/u,.3),i.centerAttraction*(1-t.value/u)*(1-Math.min(1,f/v)));t.x+=c*m,t.y+=h*m,t.x+=o*(1-i.damping),t.y+=a*(1-i.damping)})),s.forEach(((t,e)=>{s.forEach(((n,o)=>{if(e>=o)return;if(0===e||0===o){const o=0===e?t:n,i=0===e?n:t,a=i.x-o.x,r=i.y-o.y,l=Math.hypot(a,r),d=o.radius+i.radius+2;if(l<d){const t=d-l,e=Math.atan2(r,a);i.x+=Math.cos(e)*t*.7,i.y+=Math.sin(e)*t*.7}return}const a=t.x-n.x,r=t.y-n.y,l=Math.hypot(a,r),d=t.radius+n.radius-5;if(l<d){const e=(d-l)*(.3+5*i.forceStrength),o=Math.atan2(r,a),s=n.radius/(t.radius+n.radius);t.fixed||(t.x+=Math.cos(o)*e*s,t.y+=Math.sin(o)*e*s),n.fixed||(n.x-=Math.cos(o)*e*(1-s),n.y-=Math.sin(o)*e*(1-s))}}))}));return s.forEach((t=>{const n=Math.max(5+t.radius,Math.min(e.width-5-t.radius,t.x)),o=Math.max(5+t.radius,Math.min(e.height-5-t.radius,t.y));(!t.fixed||Math.hypot(t.x-n,t.y-o)>2)&&(t.x=n,t.y=o)})),s}(t,e,r);function d(){e&&r?(r.clearRect(0,0,e.width,e.height),l.forEach((e=>{const{x:n,y:o,radius:i,bubbleColor:l,borderColor:d,borderThickness:s,opacity:u,fontColor:c,fontFamily:h,fontSize:f,fontStyle:v,fontWeight:m,textAlign:g,textTransform:y,textBaseline:p}=function(t,e){var n,o,i,r,l,d,s,u,c,h,f;return{x:t.x,y:t.y,radius:Math.max(t.radius,e.minRadius),bubbleColor:null!==(n=t.bubbleColor)&&void 0!==n?n:e.defaultBubbleColor,borderColor:null!==(o=t.borderColor)&&void 0!==o?o:"black",borderThickness:null!==(i=t.borderThickness)&&void 0!==i?i:.25,opacity:null!==(r=t.opacity)&&void 0!==r?r:1,fontFamily:null!==(l=t.fontFamily)&&void 0!==l?l:e.defaultFontFamily,fontStyle:null!==(d=t.fontStyle)&&void 0!==d?d:"normal",fontWeight:null!==(s=t.fontWeight)&&void 0!==s?s:400,textAlign:null!==(u=t.textAlign)&&void 0!==u?u:"center",textTransform:null!==(c=t.textTransform)&&void 0!==c?c:"none",fontColor:null!==(h=t.fontColor)&&void 0!==h?h:e.defaultFontColor,textBaseline:null!==(f=t.textBaseline)&&void 0!==f?f:"middle",fontSize:a(t.radius,e.fontSize,t.fontWeight)}}(e,t);r.beginPath(),r.arc(n,o,i,0,2*Math.PI),r.fillStyle=l,r.fill(),r.strokeStyle=d,r.lineWidth=s,r.stroke(),r.fillStyle=c,r.font=`${v} ${m} ${f}px ${h}`,r.textAlign=g,r.textBaseline=p;let x=e.label||"";if("uppercase"===y?x=x.toUpperCase():"lowercase"===y?x=x.toLowerCase():"capitalize"===y&&(x=x.replace(/\b\w/g,(t=>t.toUpperCase()))),t.textWrap){const a=1.5*i-10,l=1.2*f,d=function(t,e,n,o,i,a,r=14,l=5,d=5,s=1.2){const u=1.5*(i-d),c=r*s,h=Math.max(1,Math.floor(u/c)),f="auto"===o||void 0===o?h:Math.min(o,h);n=Math.max(0,n-l);const v=e.split(" ");let m="";const g=[];let y=!1;for(const e of v){const o=m?`${m} ${e}`:e;if(t.measureText(o).width<=n?m=o:(m.trim()&&g.push(m),m=e),g.length>=f){y=!0;break}}if(m&&g.length<f&&g.push(m),y&&g.length>0){let e=g[g.length-1];for(;t.measureText(e+"...").width>n&&e.length>0;)e=e.slice(0,-1);g[g.length-1]=e+"..."}return g}(r,e.label,a,t.maxLines,i),s=o-(d.length-1)*l/2;d.forEach(((t,e)=>r.fillText(t,n,s+e*l)))}else r.fillText(e.label,n,o)}))):console.warn("canvas or ctx is not valid")}function s(){const n=document.getElementById(t.canvasContainerId);n&&e&&(e.width=n.offsetWidth,e.height=n.offsetHeight,d())}if(t.isResizeCanvasOnWindowSizeChange&&(s(),window.addEventListener("resize",s)),d(),t.showToolTip){const o=function(t){var e,n,o,i,a,r,l,d,s,u,c,h,f,v,m,g,y,p;const x=null===(n=null===(e=t.data[0].toolTipConfig)||void 0===e?void 0:e.tooltipFormattedData)||void 0===n?void 0:n.trim();if(x){const e=document.createElement("div");e.innerHTML=x.trim();const n=t.canvasContainerId?document.getElementById(t.canvasContainerId):null,o=e.firstElementChild;return(n||document.body).appendChild(o),o}const b=document.createElement("div");b.id="tooltip",b.style.display="none";const C=null!==(o=null==t?void 0:t.tooltipOptions)&&void 0!==o?o:{},M=(t,e)=>"number"==typeof t?`${t}px`:null!=t?t:e;return Object.assign(b.style,{position:"absolute",padding:M(C.padding,"8px"),margin:M(C.margin,"0"),background:null!==(i=C.backgroundColor)&&void 0!==i?i:"rgba(0, 0, 0, 0.85)",color:null!==(a=C.fontColor)&&void 0!==a?a:"white",borderRadius:"4px",pointerEvents:null!==(r=C.pointerEvents)&&void 0!==r?r:"none",fontFamily:null!==(l=C.fontFamily)&&void 0!==l?l:"Arial, sans-serif",fontSize:M(C.fontSize,"14px"),fontWeight:String(null!==(d=C.fontWeight)&&void 0!==d?d:"400"),fontStyle:null!==(s=C.fontStyle)&&void 0!==s?s:"normal",textAlign:null!==(u=C.textAlign)&&void 0!==u?u:"left",textDecoration:null!==(c=C.textDecoration)&&void 0!==c?c:"none",textTransform:null!==(h=C.textTransform)&&void 0!==h?h:"none",letterSpacing:M(C.letterSpacing,"normal"),border:(()=>{var t;if(!C.borderStyle)return"none";const e=M(C.borderWidth,"1px"),n=null!==(t=C.borderColor)&&void 0!==t?t:"transparent";return`${e} ${C.borderStyle} ${n}`})(),boxShadow:null!==(f=C.boxShadow)&&void 0!==f?f:"none",opacity:String(null!==(v=C.opacity)&&void 0!==v?v:1),maxWidth:M(C.maxWidth,"200px"),minWidth:M(C.minWidth,"auto"),maxHeight:M(C.maxHeight,"none"),minHeight:M(C.minHeight,"auto"),zIndex:String(null!==(m=C.zIndex)&&void 0!==m?m:1e3),transition:null!==(g=C.transition)&&void 0!==g?g:"opacity 0.2s",transform:null!==(y=C.transform)&&void 0!==y?y:"none",backdropFilter:null!==(p=C.backdropFilter)&&void 0!==p?p:"none"}),((t.canvasContainerId?document.getElementById(t.canvasContainerId):null)||document.body).appendChild(b),b}(t);let i=null;e.addEventListener("mousemove",(a=>{i||(i=requestAnimationFrame((()=>{(function(t,e,o,i,a){const{mouseX:r,mouseY:l}=function(t,e){const n=e.getBoundingClientRect();return{mouseX:t.clientX-n.left,mouseY:t.clientY-n.top}}(t,o),d=function(t,e,n){return n.find((n=>Math.hypot(t-n.x,e-n.y)<n.radius))||null}(r,l,e);(null==a?void 0:a.cursorType)&&(n=null==a?void 0:a.cursorType),d?function(t,e,o,i){e&&e.value&&o&&i&&(o.style.cursor=n,i.style.display="block",i.innerHTML=function(t){var e,n,o;if(!t)return"";const i=null===(n=null===(e=t.toolTipConfig)||void 0===e?void 0:e.tooltipText)||void 0===n?void 0:n.trim();if(i)return`<div>${i}</div>`;const a=null===(o=t.label)||void 0===o?void 0:o.trim();return a?`<div>${a}<br>Value: ${t.value}</div>`:`<div>${t.value}</div>`}(e),i.style.left=`${t.pageX+15}px`,i.style.top=t.pageY-30+"px",i.style.zIndex="9999")}(t,d,o,i):(o.style.cursor="default",i.style.display="none")})(a,l,e,o,t),i=null})))}))}}const l={defaultBubbleColor:"#3498DB",defaultFontColor:"#ffffff",minRadius:10,maxLines:"auto",textWrap:!0,isResizeCanvasOnWindowSizeChange:!0,fontSize:14,defaultFontFamily:"Arial",showToolTip:!0};function d(t={}){var e,n;if(!t.data||0===t.data.length)return void console.warn("initializeChart: No valid data provided. Chart initialization aborted.");var o;r((o=Object.assign({canvasContainerId:null!==(e=t.canvasContainerId)&&void 0!==e?e:"chart-container",data:null!==(n=t.data)&&void 0!==n?n:[]},t),Object.assign(Object.assign({},l),o)))}window.initializeChart=d,module.exports=e})();
1
+ (()=>{"use strict";var t={d:(e,n)=>{for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{BubbleChart:()=>h,initializeChart:()=>c});let n="default";function o(t){const e=document.body;e?e.firstChild?e.insertBefore(t,e.firstChild):e.appendChild(t):console.error("Body element not found.")}function i(t,e){const n=e.getBoundingClientRect();return{mouseX:t.clientX-n.left,mouseY:t.clientY-n.top}}function r(t,e,n){return n.find((n=>Math.hypot(t-n.x,e-n.y)<n.radius))||null}class a{}a.TRANSPARENT="transparent";const l={forceStrength:.008,iterations:1e3,damping:.65,boundaryForce:.02,centerForce:.12,centerAttraction:.8,centerDamping:.3,centerRadiusBuffer:35};function d(t,e=14,n=400){const o=n>=700?1.25:n>=500?1.1:1;return Math.min(e*o,t/2)}function s(t){if(!function(t){return t?!(!Array.isArray(t.data)||0===t.data.length)||(console.error("Invalid or empty data array"),!1):(console.error("Invalid config object"),!1)}(t))return;let e=function(t){var e,n;const o=document.getElementById(t.canvasContainerId);if(!o)return console.error(`Canvas container with ID '${t.canvasContainerId}' not found.`),null;const i=document.createElement("canvas");return i.width=o.offsetWidth,i.height=o.offsetHeight,console.log(t.canvasBackgroundColor),Object.assign(i.style,{border:(null===(e=t.canvasBorderColor)||void 0===e?void 0:e.trim())?`1px solid #${t.canvasBorderColor}`:a.TRANSPARENT,background:(null===(n=t.canvasBackgroundColor)||void 0===n?void 0:n.trim())?`#${t.canvasBackgroundColor}`:a.TRANSPARENT,width:"100%",height:"100%",display:"block",imageRendering:"crisp-edges",aspectRatio:"1 / 1"}),i.style.setProperty("image-rendering","-moz-crisp-edges"),i.style.setProperty("image-rendering","-webkit-optimize-contrast"),i.style.setProperty("-ms-interpolation-mode","nearest-neighbor"),o.appendChild(i),i}(t);if(!e)return;const s=e.getContext("2d");if(!s)return void console.error("Invalid context");const u=function(t,e,n){const o=Math.min((e.width-10)/2,(e.height-10)/2),i=window.devicePixelRatio||1,r=e.getBoundingClientRect();e.width=r.width*i,e.height=r.height*i,e.style.width=r.width+"px",e.style.height=r.height+"px",n.scale(i,i);const a=r.width/2,d=r.height/2,s=[...t.data].sort(((t,e)=>e.value-t.value)).map((t=>Object.assign(Object.assign({},t),{radius:0,x:0,y:0,fixed:!1}))),u=s[0].value,c=Math.min(.5*o,70),h=Math.max(.3*c,25);s.forEach((t=>{const n=t.value/u;t.radius=h+n*(c-h),t.radius=Math.min(t.radius,(e.width-10)/2,(e.height-10)/2)})),s.forEach(((t,n)=>{if(0===n)t.x=a,t.y=d,t.fixed=!0;else{const o=s[0].radius+t.radius+3,i=Math.PI*(3-Math.sqrt(5)),r=e.width-5-t.radius,l=e.height-5-t.radius;t.x=Math.min(r,Math.max(5+t.radius,a+Math.cos(i*n)*o)),t.y=Math.min(l,Math.max(5+t.radius,d+Math.sin(i*n)*o)),t.fixed=!1}}));for(let t=0;t<l.iterations;t++)s.forEach(((t,n)=>{if(0===n){const e=a-t.x,n=d-t.y;return void(Math.hypot(e,n)>2&&(t.x+=e*l.centerDamping,t.y+=n*l.centerDamping))}let o=0,i=0;const r=t.radius+5;t.x<r?o+=(r-t.x)*l.boundaryForce:t.x>e.width-r&&(o+=(e.width-r-t.x)*l.boundaryForce),s.forEach((e=>{if(t===e)return;const n=t.x-e.x,r=t.y-e.y,s=Math.hypot(n,r),c=t.radius+e.radius;if(s<1.5*c){const t=l.forceStrength*(c/Math.max(s,.1));o+=n/s*t,i+=r/s*t}const h=a-t.x,f=d-t.y,m=Math.hypot(h,f),v=t.value/u*.02;t.x+=h/m*v,t.y+=f/m*v}));const c=a-t.x,h=d-t.y,f=Math.hypot(c,h),m=s[0].radius+t.radius+l.centerRadiusBuffer,v=(l.centerForce,Math.pow(t.value/u,.3),l.centerAttraction*(1-t.value/u)*(1-Math.min(1,f/m)));t.x+=c*v,t.y+=h*v,t.x+=o*(1-l.damping),t.y+=i*(1-l.damping)})),s.forEach(((t,e)=>{s.forEach(((n,o)=>{if(e>=o)return;if(0===e||0===o){const o=0===e?t:n,i=0===e?n:t,r=i.x-o.x,a=i.y-o.y,l=Math.hypot(r,a),d=o.radius+i.radius+2;if(l<d){const t=d-l,e=Math.atan2(a,r);i.x+=Math.cos(e)*t*.7,i.y+=Math.sin(e)*t*.7}return}const i=t.x-n.x,r=t.y-n.y,a=Math.hypot(i,r),d=t.radius+n.radius-5;if(a<d){const e=(d-a)*(.3+5*l.forceStrength),o=Math.atan2(r,i),s=n.radius/(t.radius+n.radius);t.fixed||(t.x+=Math.cos(o)*e*s,t.y+=Math.sin(o)*e*s),n.fixed||(n.x-=Math.cos(o)*e*(1-s),n.y-=Math.sin(o)*e*(1-s))}}))}));return s.forEach((t=>{const n=Math.max(5+t.radius,Math.min(e.width-5-t.radius,t.x)),o=Math.max(5+t.radius,Math.min(e.height-5-t.radius,t.y));(!t.fixed||Math.hypot(t.x-n,t.y-o)>2)&&(t.x=n,t.y=o)})),s}(t,e,s);function c(){e&&s?(s.clearRect(0,0,e.width,e.height),u.forEach((e=>{const{x:n,y:o,radius:i,bubbleColor:r,borderColor:a,borderThickness:l,opacity:u,fontColor:c,fontFamily:h,fontSize:f,fontStyle:m,fontWeight:v,textAlign:g,textTransform:p,textBaseline:y}=function(t,e){var n,o,i,r,a,l,s,u,c,h,f;return{x:t.x,y:t.y,radius:Math.max(t.radius,e.minRadius),bubbleColor:null!==(n=t.bubbleColor)&&void 0!==n?n:e.defaultBubbleColor,borderColor:null!==(o=t.borderColor)&&void 0!==o?o:"black",borderThickness:null!==(i=t.borderThickness)&&void 0!==i?i:.25,opacity:null!==(r=t.opacity)&&void 0!==r?r:1,fontFamily:null!==(a=t.fontFamily)&&void 0!==a?a:e.defaultFontFamily,fontStyle:null!==(l=t.fontStyle)&&void 0!==l?l:"normal",fontWeight:null!==(s=t.fontWeight)&&void 0!==s?s:400,textAlign:null!==(u=t.textAlign)&&void 0!==u?u:"center",textTransform:null!==(c=t.textTransform)&&void 0!==c?c:"none",fontColor:null!==(h=t.fontColor)&&void 0!==h?h:e.defaultFontColor,textBaseline:null!==(f=t.textBaseline)&&void 0!==f?f:"middle",fontSize:d(t.radius,e.fontSize,t.fontWeight)}}(e,t);s.beginPath(),s.arc(n,o,i,0,2*Math.PI),s.fillStyle=r,s.fill(),s.strokeStyle=a,s.lineWidth=l,s.stroke(),s.fillStyle=c,s.font=`${m} ${v} ${f}px ${h}`,s.textAlign=g,s.textBaseline=y;let x=e.label||"";if("uppercase"===p?x=x.toUpperCase():"lowercase"===p?x=x.toLowerCase():"capitalize"===p&&(x=x.replace(/\b\w/g,(t=>t.toUpperCase()))),t.textWrap){const r=1.5*i-10,a=1.2*f,l=function(t,e,n,o,i,r,a=14,l=2,d=5,s=1.2,u=400,c="normal",h="Arial"){const f=1.5*(i-d),m=a*s,v=Math.max(1,Math.floor(f/m)),g="auto"===o||void 0===o?v:Math.min(o,v);n=Math.max(0,n-l);const p=e.split(" ");let y="";const x=[];let b=!1,C=!1;for(const e of p){const o=y?`${y} ${e}`:e;if(t.font=`${u||""} ${c||""} ${a}px ${h}`,t.measureText(o).width<=n)y=o;else if(y.trim()&&x.push(y),y=e,t.measureText(y).width>n){let e=y;for(;t.measureText(e+"...").width>n&&e.length>0;)e=e.slice(0,-1);x.push(e+"..."),C=!0;break}if(x.length>=g){b=!0;break}}if(y&&x.length<g&&!C&&x.push(y),b&&x.length>0){let e=x[x.length-1];for(;t.measureText(e+"...").width>n&&e.length>0;)e=e.slice(0,-1);x[x.length-1]=e+"..."}return x}(s,e.label,r,t.maxLines,i),d=o-(l.length-1)*a/2;l.forEach(((t,e)=>s.fillText(t,n,d+e*a)))}else s.fillText(e.label,n,o)}))):console.warn("canvas or ctx is not valid")}function h(){const n=document.getElementById(t.canvasContainerId);n&&e&&(e.width=n.offsetWidth,e.height=n.offsetHeight,c())}let f;t.isResizeCanvasOnWindowSizeChange&&(h(),window.addEventListener("resize",h)),c(),t.showToolTip&&(f=function(t){var e,n,i,r,a,l,d,s,u,c,h,f,m,v,g,p,y,x;const b=null===(n=null===(e=t.data[0].toolTipConfig)||void 0===e?void 0:e.tooltipFormattedData)||void 0===n?void 0:n.trim();if(b){const t=document.createElement("div");t.innerHTML=b.trim();const e=t.firstElementChild;return o(e),e}const C=document.createElement("div");C.id="bubbleChartTooltip",C.style.display="none";const M=null!==(i=null==t?void 0:t.tooltipOptions)&&void 0!==i?i:{},w=(t,e)=>"number"==typeof t?`${t}px`:null!=t?t:e;return Object.assign(C.style,{position:"absolute",padding:w(M.padding,"8px"),margin:w(M.margin,"0"),background:null!==(r=M.backgroundColor)&&void 0!==r?r:"rgba(0, 0, 0, 0.85)",color:null!==(a=M.fontColor)&&void 0!==a?a:"white",borderRadius:"4px",pointerEvents:null!==(l=M.pointerEvents)&&void 0!==l?l:"none",fontFamily:null!==(d=M.fontFamily)&&void 0!==d?d:"Arial, sans-serif",fontSize:w(M.fontSize,"14px"),fontWeight:String(null!==(s=M.fontWeight)&&void 0!==s?s:"400"),fontStyle:null!==(u=M.fontStyle)&&void 0!==u?u:"normal",textAlign:null!==(c=M.textAlign)&&void 0!==c?c:"left",textDecoration:null!==(h=M.textDecoration)&&void 0!==h?h:"none",textTransform:null!==(f=M.textTransform)&&void 0!==f?f:"none",letterSpacing:w(M.letterSpacing,"normal"),border:(()=>{var t;if(!M.borderStyle)return"none";const e=w(M.borderWidth,"1px"),n=null!==(t=M.borderColor)&&void 0!==t?t:"transparent";return`${e} ${M.borderStyle} ${n}`})(),boxShadow:null!==(m=M.boxShadow)&&void 0!==m?m:"none",opacity:String(null!==(v=M.opacity)&&void 0!==v?v:1),maxWidth:w(M.maxWidth,"200px"),minWidth:w(M.minWidth,"auto"),maxHeight:w(M.maxHeight,"none"),minHeight:w(M.minHeight,"auto"),zIndex:String(null!==(g=M.zIndex)&&void 0!==g?g:1e3),transition:null!==(p=M.transition)&&void 0!==p?p:"opacity 0.2s",transform:null!==(y=M.transform)&&void 0!==y?y:"none",backdropFilter:null!==(x=M.backdropFilter)&&void 0!==x?x:"none"}),o(C),C}(t));let m=null;if(e.addEventListener("mousemove",(o=>{m||(m=requestAnimationFrame((()=>{(function(t,e,o,a,l){const{mouseX:d,mouseY:s}=i(t,o),u=r(d,s,e);(null==l?void 0:l.cursorType)&&(n=null==l?void 0:l.cursorType),a&&(u?function(t,e,o,i){e&&e.value&&o&&i&&(o.style.cursor=n,i.style.display="block",i.innerHTML=function(t){var e,n,o;if(!t)return"";const i=null===(n=null===(e=t.toolTipConfig)||void 0===e?void 0:e.tooltipText)||void 0===n?void 0:n.trim();if(i)return`<div>${i}</div>`;const r=null===(o=t.label)||void 0===o?void 0:o.trim();return r?`<div>${r}<br>Value: ${t.value}</div>`:`<div>${t.value}</div>`}(e),i.style.left=`${t.pageX+15}px`,i.style.top=t.pageY-30+"px",i.style.zIndex="9999")}(t,u,o,a):(o.style.cursor="default",a.style.display="none"))})(o,u,e,f,t),m=null})))})),t.onBubbleClick){let n=null;e.addEventListener("click",(o=>{n||(n=requestAnimationFrame((()=>{!function(t,e,n,o){const{mouseX:a,mouseY:l}=i(t,n),d=r(a,l,e);null!=d&&o.onBubbleClick&&o.onBubbleClick(d,t)}(o,u,e,t),n=null})))}))}}const u={defaultBubbleColor:"#3498DB",defaultFontColor:"#ffffff",minRadius:10,maxLines:"auto",textWrap:!0,isResizeCanvasOnWindowSizeChange:!0,fontSize:14,defaultFontFamily:"Arial",showToolTip:!0};function c(t={}){var e,n;if(!t)return void console.error("Configuration is not valid. Chart initialization aborted.");if(!t.data||0===t.data.length)return void console.error("No valid data provided. Chart initialization aborted.");const o=(i=Object.assign({canvasContainerId:null!==(e=t.canvasContainerId)&&void 0!==e?e:"chart-container",data:null!==(n=t.data)&&void 0!==n?n:[]},t),Object.assign(Object.assign({},u),i));var i;return s(o),o}class h{constructor(t){const e=c(t);e&&(this.configuration=e)}render(){this.configuration&&s(this.configuration)}}window.initializeChart=c,module.exports=e})();
@@ -1 +1 @@
1
- var t={d:(n,e)=>{for(var o in e)t.o(e,o)&&!t.o(n,o)&&Object.defineProperty(n,o,{enumerable:!0,get:e[o]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n)},n={};t.d(n,{$:()=>d});let e="default";class o{}o.TRANSPARENT="transparent";const i={forceStrength:.008,iterations:1e3,damping:.65,boundaryForce:.02,centerForce:.12,centerAttraction:.8,centerDamping:.3,centerRadiusBuffer:35};function a(t,n=14,e=400){const o=e>=700?1.25:e>=500?1.1:1;return Math.min(n*o,t/2)}function r(t){if(!function(t){return t?!(!Array.isArray(t.data)||0===t.data.length)||(console.error("Invalid or empty data array"),!1):(console.error("Invalid config object"),!1)}(t))return;let n=function(t){var n,e;const i=document.getElementById(t.canvasContainerId);if(!i)return console.error(`Canvas container with ID '${t.canvasContainerId}' not found.`),null;const a=document.createElement("canvas");return a.width=i.offsetWidth,a.height=i.offsetHeight,console.log(t.canvasBackgroundColor),Object.assign(a.style,{border:(null===(n=t.canvasBorderColor)||void 0===n?void 0:n.trim())?`1px solid #${t.canvasBorderColor}`:o.TRANSPARENT,background:(null===(e=t.canvasBackgroundColor)||void 0===e?void 0:e.trim())?`#${t.canvasBackgroundColor}`:o.TRANSPARENT,width:"100%",height:"100%",display:"block",imageRendering:"crisp-edges",aspectRatio:"1 / 1"}),a.style.setProperty("image-rendering","-moz-crisp-edges"),a.style.setProperty("image-rendering","-webkit-optimize-contrast"),a.style.setProperty("-ms-interpolation-mode","nearest-neighbor"),i.appendChild(a),a}(t);if(!n)return;const r=n.getContext("2d");if(!r)return void console.error("Invalid context");const l=function(t,n,e){const o=Math.min((n.width-10)/2,(n.height-10)/2),a=window.devicePixelRatio||1,r=n.getBoundingClientRect();n.width=r.width*a,n.height=r.height*a,n.style.width=r.width+"px",n.style.height=r.height+"px",e.scale(a,a);const l=r.width/2,d=r.height/2,s=[...t.data].sort(((t,n)=>n.value-t.value)).map((t=>Object.assign(Object.assign({},t),{radius:0,x:0,y:0,fixed:!1}))),u=s[0].value,c=Math.min(1*o,100),h=Math.max(.3*c,30);s.forEach((t=>{const e=t.value/u;t.radius=h+e*(c-h),t.radius=Math.min(t.radius,(n.width-10)/2,(n.height-10)/2)})),s.forEach(((t,e)=>{if(0===e)t.x=l,t.y=d,t.fixed=!0;else{const o=s[0].radius+t.radius+3,i=Math.PI*(3-Math.sqrt(5)),a=n.width-5-t.radius,r=n.height-5-t.radius;t.x=Math.min(a,Math.max(5+t.radius,l+Math.cos(i*e)*o)),t.y=Math.min(r,Math.max(5+t.radius,d+Math.sin(i*e)*o)),t.fixed=!1}}));for(let t=0;t<i.iterations;t++)s.forEach(((t,e)=>{if(0===e){const n=l-t.x,e=d-t.y;return void(Math.hypot(n,e)>2&&(t.x+=n*i.centerDamping,t.y+=e*i.centerDamping))}let o=0,a=0;const r=t.radius+5;t.x<r?o+=(r-t.x)*i.boundaryForce:t.x>n.width-r&&(o+=(n.width-r-t.x)*i.boundaryForce),s.forEach((n=>{if(t===n)return;const e=t.x-n.x,r=t.y-n.y,s=Math.hypot(e,r),c=t.radius+n.radius;if(s<1.5*c){const t=i.forceStrength*(c/Math.max(s,.1));o+=e/s*t,a+=r/s*t}const h=l-t.x,f=d-t.y,v=Math.hypot(h,f),m=t.value/u*.02;t.x+=h/v*m,t.y+=f/v*m}));const c=l-t.x,h=d-t.y,f=Math.hypot(c,h),v=s[0].radius+t.radius+i.centerRadiusBuffer,m=(i.centerForce,Math.pow(t.value/u,.3),i.centerAttraction*(1-t.value/u)*(1-Math.min(1,f/v)));t.x+=c*m,t.y+=h*m,t.x+=o*(1-i.damping),t.y+=a*(1-i.damping)})),s.forEach(((t,n)=>{s.forEach(((e,o)=>{if(n>=o)return;if(0===n||0===o){const o=0===n?t:e,i=0===n?e:t,a=i.x-o.x,r=i.y-o.y,l=Math.hypot(a,r),d=o.radius+i.radius+2;if(l<d){const t=d-l,n=Math.atan2(r,a);i.x+=Math.cos(n)*t*.7,i.y+=Math.sin(n)*t*.7}return}const a=t.x-e.x,r=t.y-e.y,l=Math.hypot(a,r),d=t.radius+e.radius-5;if(l<d){const n=(d-l)*(.3+5*i.forceStrength),o=Math.atan2(r,a),s=e.radius/(t.radius+e.radius);t.fixed||(t.x+=Math.cos(o)*n*s,t.y+=Math.sin(o)*n*s),e.fixed||(e.x-=Math.cos(o)*n*(1-s),e.y-=Math.sin(o)*n*(1-s))}}))}));return s.forEach((t=>{const e=Math.max(5+t.radius,Math.min(n.width-5-t.radius,t.x)),o=Math.max(5+t.radius,Math.min(n.height-5-t.radius,t.y));(!t.fixed||Math.hypot(t.x-e,t.y-o)>2)&&(t.x=e,t.y=o)})),s}(t,n,r);function d(){n&&r?(r.clearRect(0,0,n.width,n.height),l.forEach((n=>{const{x:e,y:o,radius:i,bubbleColor:l,borderColor:d,borderThickness:s,opacity:u,fontColor:c,fontFamily:h,fontSize:f,fontStyle:v,fontWeight:m,textAlign:g,textTransform:p,textBaseline:y}=function(t,n){var e,o,i,r,l,d,s,u,c,h,f;return{x:t.x,y:t.y,radius:Math.max(t.radius,n.minRadius),bubbleColor:null!==(e=t.bubbleColor)&&void 0!==e?e:n.defaultBubbleColor,borderColor:null!==(o=t.borderColor)&&void 0!==o?o:"black",borderThickness:null!==(i=t.borderThickness)&&void 0!==i?i:.25,opacity:null!==(r=t.opacity)&&void 0!==r?r:1,fontFamily:null!==(l=t.fontFamily)&&void 0!==l?l:n.defaultFontFamily,fontStyle:null!==(d=t.fontStyle)&&void 0!==d?d:"normal",fontWeight:null!==(s=t.fontWeight)&&void 0!==s?s:400,textAlign:null!==(u=t.textAlign)&&void 0!==u?u:"center",textTransform:null!==(c=t.textTransform)&&void 0!==c?c:"none",fontColor:null!==(h=t.fontColor)&&void 0!==h?h:n.defaultFontColor,textBaseline:null!==(f=t.textBaseline)&&void 0!==f?f:"middle",fontSize:a(t.radius,n.fontSize,t.fontWeight)}}(n,t);r.beginPath(),r.arc(e,o,i,0,2*Math.PI),r.fillStyle=l,r.fill(),r.strokeStyle=d,r.lineWidth=s,r.stroke(),r.fillStyle=c,r.font=`${v} ${m} ${f}px ${h}`,r.textAlign=g,r.textBaseline=y;let x=n.label||"";if("uppercase"===p?x=x.toUpperCase():"lowercase"===p?x=x.toLowerCase():"capitalize"===p&&(x=x.replace(/\b\w/g,(t=>t.toUpperCase()))),t.textWrap){const a=1.5*i-10,l=1.2*f,d=function(t,n,e,o,i,a,r=14,l=5,d=5,s=1.2){const u=1.5*(i-d),c=r*s,h=Math.max(1,Math.floor(u/c)),f="auto"===o||void 0===o?h:Math.min(o,h);e=Math.max(0,e-l);const v=n.split(" ");let m="";const g=[];let p=!1;for(const n of v){const o=m?`${m} ${n}`:n;if(t.measureText(o).width<=e?m=o:(m.trim()&&g.push(m),m=n),g.length>=f){p=!0;break}}if(m&&g.length<f&&g.push(m),p&&g.length>0){let n=g[g.length-1];for(;t.measureText(n+"...").width>e&&n.length>0;)n=n.slice(0,-1);g[g.length-1]=n+"..."}return g}(r,n.label,a,t.maxLines,i),s=o-(d.length-1)*l/2;d.forEach(((t,n)=>r.fillText(t,e,s+n*l)))}else r.fillText(n.label,e,o)}))):console.warn("canvas or ctx is not valid")}function s(){const e=document.getElementById(t.canvasContainerId);e&&n&&(n.width=e.offsetWidth,n.height=e.offsetHeight,d())}if(t.isResizeCanvasOnWindowSizeChange&&(s(),window.addEventListener("resize",s)),d(),t.showToolTip){const o=function(t){var n,e,o,i,a,r,l,d,s,u,c,h,f,v,m,g,p,y;const x=null===(e=null===(n=t.data[0].toolTipConfig)||void 0===n?void 0:n.tooltipFormattedData)||void 0===e?void 0:e.trim();if(x){const n=document.createElement("div");n.innerHTML=x.trim();const e=t.canvasContainerId?document.getElementById(t.canvasContainerId):null,o=n.firstElementChild;return(e||document.body).appendChild(o),o}const b=document.createElement("div");b.id="tooltip",b.style.display="none";const C=null!==(o=null==t?void 0:t.tooltipOptions)&&void 0!==o?o:{},M=(t,n)=>"number"==typeof t?`${t}px`:null!=t?t:n;return Object.assign(b.style,{position:"absolute",padding:M(C.padding,"8px"),margin:M(C.margin,"0"),background:null!==(i=C.backgroundColor)&&void 0!==i?i:"rgba(0, 0, 0, 0.85)",color:null!==(a=C.fontColor)&&void 0!==a?a:"white",borderRadius:"4px",pointerEvents:null!==(r=C.pointerEvents)&&void 0!==r?r:"none",fontFamily:null!==(l=C.fontFamily)&&void 0!==l?l:"Arial, sans-serif",fontSize:M(C.fontSize,"14px"),fontWeight:String(null!==(d=C.fontWeight)&&void 0!==d?d:"400"),fontStyle:null!==(s=C.fontStyle)&&void 0!==s?s:"normal",textAlign:null!==(u=C.textAlign)&&void 0!==u?u:"left",textDecoration:null!==(c=C.textDecoration)&&void 0!==c?c:"none",textTransform:null!==(h=C.textTransform)&&void 0!==h?h:"none",letterSpacing:M(C.letterSpacing,"normal"),border:(()=>{var t;if(!C.borderStyle)return"none";const n=M(C.borderWidth,"1px"),e=null!==(t=C.borderColor)&&void 0!==t?t:"transparent";return`${n} ${C.borderStyle} ${e}`})(),boxShadow:null!==(f=C.boxShadow)&&void 0!==f?f:"none",opacity:String(null!==(v=C.opacity)&&void 0!==v?v:1),maxWidth:M(C.maxWidth,"200px"),minWidth:M(C.minWidth,"auto"),maxHeight:M(C.maxHeight,"none"),minHeight:M(C.minHeight,"auto"),zIndex:String(null!==(m=C.zIndex)&&void 0!==m?m:1e3),transition:null!==(g=C.transition)&&void 0!==g?g:"opacity 0.2s",transform:null!==(p=C.transform)&&void 0!==p?p:"none",backdropFilter:null!==(y=C.backdropFilter)&&void 0!==y?y:"none"}),((t.canvasContainerId?document.getElementById(t.canvasContainerId):null)||document.body).appendChild(b),b}(t);let i=null;n.addEventListener("mousemove",(a=>{i||(i=requestAnimationFrame((()=>{(function(t,n,o,i,a){const{mouseX:r,mouseY:l}=function(t,n){const e=n.getBoundingClientRect();return{mouseX:t.clientX-e.left,mouseY:t.clientY-e.top}}(t,o),d=function(t,n,e){return e.find((e=>Math.hypot(t-e.x,n-e.y)<e.radius))||null}(r,l,n);(null==a?void 0:a.cursorType)&&(e=null==a?void 0:a.cursorType),d?function(t,n,o,i){n&&n.value&&o&&i&&(o.style.cursor=e,i.style.display="block",i.innerHTML=function(t){var n,e,o;if(!t)return"";const i=null===(e=null===(n=t.toolTipConfig)||void 0===n?void 0:n.tooltipText)||void 0===e?void 0:e.trim();if(i)return`<div>${i}</div>`;const a=null===(o=t.label)||void 0===o?void 0:o.trim();return a?`<div>${a}<br>Value: ${t.value}</div>`:`<div>${t.value}</div>`}(n),i.style.left=`${t.pageX+15}px`,i.style.top=t.pageY-30+"px",i.style.zIndex="9999")}(t,d,o,i):(o.style.cursor="default",i.style.display="none")})(a,l,n,o,t),i=null})))}))}}const l={defaultBubbleColor:"#3498DB",defaultFontColor:"#ffffff",minRadius:10,maxLines:"auto",textWrap:!0,isResizeCanvasOnWindowSizeChange:!0,fontSize:14,defaultFontFamily:"Arial",showToolTip:!0};function d(t={}){var n,e;if(!t.data||0===t.data.length)return void console.warn("initializeChart: No valid data provided. Chart initialization aborted.");var o;r((o=Object.assign({canvasContainerId:null!==(n=t.canvasContainerId)&&void 0!==n?n:"chart-container",data:null!==(e=t.data)&&void 0!==e?e:[]},t),Object.assign(Object.assign({},l),o)))}window.initializeChart=d;var s=n.$;export{s as initializeChart};
1
+ var t={d:(e,n)=>{for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{$:()=>h,s:()=>c});let n="default";function o(t){const e=document.body;e?e.firstChild?e.insertBefore(t,e.firstChild):e.appendChild(t):console.error("Body element not found.")}function i(t,e){const n=e.getBoundingClientRect();return{mouseX:t.clientX-n.left,mouseY:t.clientY-n.top}}function r(t,e,n){return n.find((n=>Math.hypot(t-n.x,e-n.y)<n.radius))||null}class a{}a.TRANSPARENT="transparent";const l={forceStrength:.008,iterations:1e3,damping:.65,boundaryForce:.02,centerForce:.12,centerAttraction:.8,centerDamping:.3,centerRadiusBuffer:35};function s(t,e=14,n=400){const o=n>=700?1.25:n>=500?1.1:1;return Math.min(e*o,t/2)}function d(t){if(!function(t){return t?!(!Array.isArray(t.data)||0===t.data.length)||(console.error("Invalid or empty data array"),!1):(console.error("Invalid config object"),!1)}(t))return;let e=function(t){var e,n;const o=document.getElementById(t.canvasContainerId);if(!o)return console.error(`Canvas container with ID '${t.canvasContainerId}' not found.`),null;const i=document.createElement("canvas");return i.width=o.offsetWidth,i.height=o.offsetHeight,console.log(t.canvasBackgroundColor),Object.assign(i.style,{border:(null===(e=t.canvasBorderColor)||void 0===e?void 0:e.trim())?`1px solid #${t.canvasBorderColor}`:a.TRANSPARENT,background:(null===(n=t.canvasBackgroundColor)||void 0===n?void 0:n.trim())?`#${t.canvasBackgroundColor}`:a.TRANSPARENT,width:"100%",height:"100%",display:"block",imageRendering:"crisp-edges",aspectRatio:"1 / 1"}),i.style.setProperty("image-rendering","-moz-crisp-edges"),i.style.setProperty("image-rendering","-webkit-optimize-contrast"),i.style.setProperty("-ms-interpolation-mode","nearest-neighbor"),o.appendChild(i),i}(t);if(!e)return;const d=e.getContext("2d");if(!d)return void console.error("Invalid context");const u=function(t,e,n){const o=Math.min((e.width-10)/2,(e.height-10)/2),i=window.devicePixelRatio||1,r=e.getBoundingClientRect();e.width=r.width*i,e.height=r.height*i,e.style.width=r.width+"px",e.style.height=r.height+"px",n.scale(i,i);const a=r.width/2,s=r.height/2,d=[...t.data].sort(((t,e)=>e.value-t.value)).map((t=>Object.assign(Object.assign({},t),{radius:0,x:0,y:0,fixed:!1}))),u=d[0].value,c=Math.min(.5*o,70),h=Math.max(.3*c,25);d.forEach((t=>{const n=t.value/u;t.radius=h+n*(c-h),t.radius=Math.min(t.radius,(e.width-10)/2,(e.height-10)/2)})),d.forEach(((t,n)=>{if(0===n)t.x=a,t.y=s,t.fixed=!0;else{const o=d[0].radius+t.radius+3,i=Math.PI*(3-Math.sqrt(5)),r=e.width-5-t.radius,l=e.height-5-t.radius;t.x=Math.min(r,Math.max(5+t.radius,a+Math.cos(i*n)*o)),t.y=Math.min(l,Math.max(5+t.radius,s+Math.sin(i*n)*o)),t.fixed=!1}}));for(let t=0;t<l.iterations;t++)d.forEach(((t,n)=>{if(0===n){const e=a-t.x,n=s-t.y;return void(Math.hypot(e,n)>2&&(t.x+=e*l.centerDamping,t.y+=n*l.centerDamping))}let o=0,i=0;const r=t.radius+5;t.x<r?o+=(r-t.x)*l.boundaryForce:t.x>e.width-r&&(o+=(e.width-r-t.x)*l.boundaryForce),d.forEach((e=>{if(t===e)return;const n=t.x-e.x,r=t.y-e.y,d=Math.hypot(n,r),c=t.radius+e.radius;if(d<1.5*c){const t=l.forceStrength*(c/Math.max(d,.1));o+=n/d*t,i+=r/d*t}const h=a-t.x,f=s-t.y,v=Math.hypot(h,f),m=t.value/u*.02;t.x+=h/v*m,t.y+=f/v*m}));const c=a-t.x,h=s-t.y,f=Math.hypot(c,h),v=d[0].radius+t.radius+l.centerRadiusBuffer,m=(l.centerForce,Math.pow(t.value/u,.3),l.centerAttraction*(1-t.value/u)*(1-Math.min(1,f/v)));t.x+=c*m,t.y+=h*m,t.x+=o*(1-l.damping),t.y+=i*(1-l.damping)})),d.forEach(((t,e)=>{d.forEach(((n,o)=>{if(e>=o)return;if(0===e||0===o){const o=0===e?t:n,i=0===e?n:t,r=i.x-o.x,a=i.y-o.y,l=Math.hypot(r,a),s=o.radius+i.radius+2;if(l<s){const t=s-l,e=Math.atan2(a,r);i.x+=Math.cos(e)*t*.7,i.y+=Math.sin(e)*t*.7}return}const i=t.x-n.x,r=t.y-n.y,a=Math.hypot(i,r),s=t.radius+n.radius-5;if(a<s){const e=(s-a)*(.3+5*l.forceStrength),o=Math.atan2(r,i),d=n.radius/(t.radius+n.radius);t.fixed||(t.x+=Math.cos(o)*e*d,t.y+=Math.sin(o)*e*d),n.fixed||(n.x-=Math.cos(o)*e*(1-d),n.y-=Math.sin(o)*e*(1-d))}}))}));return d.forEach((t=>{const n=Math.max(5+t.radius,Math.min(e.width-5-t.radius,t.x)),o=Math.max(5+t.radius,Math.min(e.height-5-t.radius,t.y));(!t.fixed||Math.hypot(t.x-n,t.y-o)>2)&&(t.x=n,t.y=o)})),d}(t,e,d);function c(){e&&d?(d.clearRect(0,0,e.width,e.height),u.forEach((e=>{const{x:n,y:o,radius:i,bubbleColor:r,borderColor:a,borderThickness:l,opacity:u,fontColor:c,fontFamily:h,fontSize:f,fontStyle:v,fontWeight:m,textAlign:g,textTransform:x,textBaseline:p}=function(t,e){var n,o,i,r,a,l,d,u,c,h,f;return{x:t.x,y:t.y,radius:Math.max(t.radius,e.minRadius),bubbleColor:null!==(n=t.bubbleColor)&&void 0!==n?n:e.defaultBubbleColor,borderColor:null!==(o=t.borderColor)&&void 0!==o?o:"black",borderThickness:null!==(i=t.borderThickness)&&void 0!==i?i:.25,opacity:null!==(r=t.opacity)&&void 0!==r?r:1,fontFamily:null!==(a=t.fontFamily)&&void 0!==a?a:e.defaultFontFamily,fontStyle:null!==(l=t.fontStyle)&&void 0!==l?l:"normal",fontWeight:null!==(d=t.fontWeight)&&void 0!==d?d:400,textAlign:null!==(u=t.textAlign)&&void 0!==u?u:"center",textTransform:null!==(c=t.textTransform)&&void 0!==c?c:"none",fontColor:null!==(h=t.fontColor)&&void 0!==h?h:e.defaultFontColor,textBaseline:null!==(f=t.textBaseline)&&void 0!==f?f:"middle",fontSize:s(t.radius,e.fontSize,t.fontWeight)}}(e,t);d.beginPath(),d.arc(n,o,i,0,2*Math.PI),d.fillStyle=r,d.fill(),d.strokeStyle=a,d.lineWidth=l,d.stroke(),d.fillStyle=c,d.font=`${v} ${m} ${f}px ${h}`,d.textAlign=g,d.textBaseline=p;let y=e.label||"";if("uppercase"===x?y=y.toUpperCase():"lowercase"===x?y=y.toLowerCase():"capitalize"===x&&(y=y.replace(/\b\w/g,(t=>t.toUpperCase()))),t.textWrap){const r=1.5*i-10,a=1.2*f,l=function(t,e,n,o,i,r,a=14,l=2,s=5,d=1.2,u=400,c="normal",h="Arial"){const f=1.5*(i-s),v=a*d,m=Math.max(1,Math.floor(f/v)),g="auto"===o||void 0===o?m:Math.min(o,m);n=Math.max(0,n-l);const x=e.split(" ");let p="";const y=[];let b=!1,C=!1;for(const e of x){const o=p?`${p} ${e}`:e;if(t.font=`${u||""} ${c||""} ${a}px ${h}`,t.measureText(o).width<=n)p=o;else if(p.trim()&&y.push(p),p=e,t.measureText(p).width>n){let e=p;for(;t.measureText(e+"...").width>n&&e.length>0;)e=e.slice(0,-1);y.push(e+"..."),C=!0;break}if(y.length>=g){b=!0;break}}if(p&&y.length<g&&!C&&y.push(p),b&&y.length>0){let e=y[y.length-1];for(;t.measureText(e+"...").width>n&&e.length>0;)e=e.slice(0,-1);y[y.length-1]=e+"..."}return y}(d,e.label,r,t.maxLines,i),s=o-(l.length-1)*a/2;l.forEach(((t,e)=>d.fillText(t,n,s+e*a)))}else d.fillText(e.label,n,o)}))):console.warn("canvas or ctx is not valid")}function h(){const n=document.getElementById(t.canvasContainerId);n&&e&&(e.width=n.offsetWidth,e.height=n.offsetHeight,c())}let f;t.isResizeCanvasOnWindowSizeChange&&(h(),window.addEventListener("resize",h)),c(),t.showToolTip&&(f=function(t){var e,n,i,r,a,l,s,d,u,c,h,f,v,m,g,x,p,y;const b=null===(n=null===(e=t.data[0].toolTipConfig)||void 0===e?void 0:e.tooltipFormattedData)||void 0===n?void 0:n.trim();if(b){const t=document.createElement("div");t.innerHTML=b.trim();const e=t.firstElementChild;return o(e),e}const C=document.createElement("div");C.id="bubbleChartTooltip",C.style.display="none";const M=null!==(i=null==t?void 0:t.tooltipOptions)&&void 0!==i?i:{},w=(t,e)=>"number"==typeof t?`${t}px`:null!=t?t:e;return Object.assign(C.style,{position:"absolute",padding:w(M.padding,"8px"),margin:w(M.margin,"0"),background:null!==(r=M.backgroundColor)&&void 0!==r?r:"rgba(0, 0, 0, 0.85)",color:null!==(a=M.fontColor)&&void 0!==a?a:"white",borderRadius:"4px",pointerEvents:null!==(l=M.pointerEvents)&&void 0!==l?l:"none",fontFamily:null!==(s=M.fontFamily)&&void 0!==s?s:"Arial, sans-serif",fontSize:w(M.fontSize,"14px"),fontWeight:String(null!==(d=M.fontWeight)&&void 0!==d?d:"400"),fontStyle:null!==(u=M.fontStyle)&&void 0!==u?u:"normal",textAlign:null!==(c=M.textAlign)&&void 0!==c?c:"left",textDecoration:null!==(h=M.textDecoration)&&void 0!==h?h:"none",textTransform:null!==(f=M.textTransform)&&void 0!==f?f:"none",letterSpacing:w(M.letterSpacing,"normal"),border:(()=>{var t;if(!M.borderStyle)return"none";const e=w(M.borderWidth,"1px"),n=null!==(t=M.borderColor)&&void 0!==t?t:"transparent";return`${e} ${M.borderStyle} ${n}`})(),boxShadow:null!==(v=M.boxShadow)&&void 0!==v?v:"none",opacity:String(null!==(m=M.opacity)&&void 0!==m?m:1),maxWidth:w(M.maxWidth,"200px"),minWidth:w(M.minWidth,"auto"),maxHeight:w(M.maxHeight,"none"),minHeight:w(M.minHeight,"auto"),zIndex:String(null!==(g=M.zIndex)&&void 0!==g?g:1e3),transition:null!==(x=M.transition)&&void 0!==x?x:"opacity 0.2s",transform:null!==(p=M.transform)&&void 0!==p?p:"none",backdropFilter:null!==(y=M.backdropFilter)&&void 0!==y?y:"none"}),o(C),C}(t));let v=null;if(e.addEventListener("mousemove",(o=>{v||(v=requestAnimationFrame((()=>{(function(t,e,o,a,l){const{mouseX:s,mouseY:d}=i(t,o),u=r(s,d,e);(null==l?void 0:l.cursorType)&&(n=null==l?void 0:l.cursorType),a&&(u?function(t,e,o,i){e&&e.value&&o&&i&&(o.style.cursor=n,i.style.display="block",i.innerHTML=function(t){var e,n,o;if(!t)return"";const i=null===(n=null===(e=t.toolTipConfig)||void 0===e?void 0:e.tooltipText)||void 0===n?void 0:n.trim();if(i)return`<div>${i}</div>`;const r=null===(o=t.label)||void 0===o?void 0:o.trim();return r?`<div>${r}<br>Value: ${t.value}</div>`:`<div>${t.value}</div>`}(e),i.style.left=`${t.pageX+15}px`,i.style.top=t.pageY-30+"px",i.style.zIndex="9999")}(t,u,o,a):(o.style.cursor="default",a.style.display="none"))})(o,u,e,f,t),v=null})))})),t.onBubbleClick){let n=null;e.addEventListener("click",(o=>{n||(n=requestAnimationFrame((()=>{!function(t,e,n,o){const{mouseX:a,mouseY:l}=i(t,n),s=r(a,l,e);null!=s&&o.onBubbleClick&&o.onBubbleClick(s,t)}(o,u,e,t),n=null})))}))}}const u={defaultBubbleColor:"#3498DB",defaultFontColor:"#ffffff",minRadius:10,maxLines:"auto",textWrap:!0,isResizeCanvasOnWindowSizeChange:!0,fontSize:14,defaultFontFamily:"Arial",showToolTip:!0};function c(t={}){var e,n;if(!t)return void console.error("Configuration is not valid. Chart initialization aborted.");if(!t.data||0===t.data.length)return void console.error("No valid data provided. Chart initialization aborted.");const o=(i=Object.assign({canvasContainerId:null!==(e=t.canvasContainerId)&&void 0!==e?e:"chart-container",data:null!==(n=t.data)&&void 0!==n?n:[]},t),Object.assign(Object.assign({},u),i));var i;return d(o),o}class h{constructor(t){const e=c(t);e&&(this.configuration=e)}render(){this.configuration&&d(this.configuration)}}window.initializeChart=c;var f=e.$,v=e.s;export{f as BubbleChart,v as initializeChart};
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("BubbleChart",[],e):"object"==typeof exports?exports.BubbleChart=e():t.BubbleChart=e()}(this,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{initializeChart:()=>d});let n="default";class o{}o.TRANSPARENT="transparent";const i={forceStrength:.008,iterations:1e3,damping:.65,boundaryForce:.02,centerForce:.12,centerAttraction:.8,centerDamping:.3,centerRadiusBuffer:35};function a(t,e=14,n=400){const o=n>=700?1.25:n>=500?1.1:1;return Math.min(e*o,t/2)}function r(t){if(!function(t){return t?!(!Array.isArray(t.data)||0===t.data.length)||(console.error("Invalid or empty data array"),!1):(console.error("Invalid config object"),!1)}(t))return;let e=function(t){var e,n;const i=document.getElementById(t.canvasContainerId);if(!i)return console.error(`Canvas container with ID '${t.canvasContainerId}' not found.`),null;const a=document.createElement("canvas");return a.width=i.offsetWidth,a.height=i.offsetHeight,console.log(t.canvasBackgroundColor),Object.assign(a.style,{border:(null===(e=t.canvasBorderColor)||void 0===e?void 0:e.trim())?`1px solid #${t.canvasBorderColor}`:o.TRANSPARENT,background:(null===(n=t.canvasBackgroundColor)||void 0===n?void 0:n.trim())?`#${t.canvasBackgroundColor}`:o.TRANSPARENT,width:"100%",height:"100%",display:"block",imageRendering:"crisp-edges",aspectRatio:"1 / 1"}),a.style.setProperty("image-rendering","-moz-crisp-edges"),a.style.setProperty("image-rendering","-webkit-optimize-contrast"),a.style.setProperty("-ms-interpolation-mode","nearest-neighbor"),i.appendChild(a),a}(t);if(!e)return;const r=e.getContext("2d");if(!r)return void console.error("Invalid context");const l=function(t,e,n){const o=Math.min((e.width-10)/2,(e.height-10)/2),a=window.devicePixelRatio||1,r=e.getBoundingClientRect();e.width=r.width*a,e.height=r.height*a,e.style.width=r.width+"px",e.style.height=r.height+"px",n.scale(a,a);const l=r.width/2,d=r.height/2,s=[...t.data].sort(((t,e)=>e.value-t.value)).map((t=>Object.assign(Object.assign({},t),{radius:0,x:0,y:0,fixed:!1}))),u=s[0].value,c=Math.min(1*o,100),h=Math.max(.3*c,30);s.forEach((t=>{const n=t.value/u;t.radius=h+n*(c-h),t.radius=Math.min(t.radius,(e.width-10)/2,(e.height-10)/2)})),s.forEach(((t,n)=>{if(0===n)t.x=l,t.y=d,t.fixed=!0;else{const o=s[0].radius+t.radius+3,i=Math.PI*(3-Math.sqrt(5)),a=e.width-5-t.radius,r=e.height-5-t.radius;t.x=Math.min(a,Math.max(5+t.radius,l+Math.cos(i*n)*o)),t.y=Math.min(r,Math.max(5+t.radius,d+Math.sin(i*n)*o)),t.fixed=!1}}));for(let t=0;t<i.iterations;t++)s.forEach(((t,n)=>{if(0===n){const e=l-t.x,n=d-t.y;return void(Math.hypot(e,n)>2&&(t.x+=e*i.centerDamping,t.y+=n*i.centerDamping))}let o=0,a=0;const r=t.radius+5;t.x<r?o+=(r-t.x)*i.boundaryForce:t.x>e.width-r&&(o+=(e.width-r-t.x)*i.boundaryForce),s.forEach((e=>{if(t===e)return;const n=t.x-e.x,r=t.y-e.y,s=Math.hypot(n,r),c=t.radius+e.radius;if(s<1.5*c){const t=i.forceStrength*(c/Math.max(s,.1));o+=n/s*t,a+=r/s*t}const h=l-t.x,f=d-t.y,v=Math.hypot(h,f),m=t.value/u*.02;t.x+=h/v*m,t.y+=f/v*m}));const c=l-t.x,h=d-t.y,f=Math.hypot(c,h),v=s[0].radius+t.radius+i.centerRadiusBuffer,m=(i.centerForce,Math.pow(t.value/u,.3),i.centerAttraction*(1-t.value/u)*(1-Math.min(1,f/v)));t.x+=c*m,t.y+=h*m,t.x+=o*(1-i.damping),t.y+=a*(1-i.damping)})),s.forEach(((t,e)=>{s.forEach(((n,o)=>{if(e>=o)return;if(0===e||0===o){const o=0===e?t:n,i=0===e?n:t,a=i.x-o.x,r=i.y-o.y,l=Math.hypot(a,r),d=o.radius+i.radius+2;if(l<d){const t=d-l,e=Math.atan2(r,a);i.x+=Math.cos(e)*t*.7,i.y+=Math.sin(e)*t*.7}return}const a=t.x-n.x,r=t.y-n.y,l=Math.hypot(a,r),d=t.radius+n.radius-5;if(l<d){const e=(d-l)*(.3+5*i.forceStrength),o=Math.atan2(r,a),s=n.radius/(t.radius+n.radius);t.fixed||(t.x+=Math.cos(o)*e*s,t.y+=Math.sin(o)*e*s),n.fixed||(n.x-=Math.cos(o)*e*(1-s),n.y-=Math.sin(o)*e*(1-s))}}))}));return s.forEach((t=>{const n=Math.max(5+t.radius,Math.min(e.width-5-t.radius,t.x)),o=Math.max(5+t.radius,Math.min(e.height-5-t.radius,t.y));(!t.fixed||Math.hypot(t.x-n,t.y-o)>2)&&(t.x=n,t.y=o)})),s}(t,e,r);function d(){e&&r?(r.clearRect(0,0,e.width,e.height),l.forEach((e=>{const{x:n,y:o,radius:i,bubbleColor:l,borderColor:d,borderThickness:s,opacity:u,fontColor:c,fontFamily:h,fontSize:f,fontStyle:v,fontWeight:m,textAlign:p,textTransform:y,textBaseline:g}=function(t,e){var n,o,i,r,l,d,s,u,c,h,f;return{x:t.x,y:t.y,radius:Math.max(t.radius,e.minRadius),bubbleColor:null!==(n=t.bubbleColor)&&void 0!==n?n:e.defaultBubbleColor,borderColor:null!==(o=t.borderColor)&&void 0!==o?o:"black",borderThickness:null!==(i=t.borderThickness)&&void 0!==i?i:.25,opacity:null!==(r=t.opacity)&&void 0!==r?r:1,fontFamily:null!==(l=t.fontFamily)&&void 0!==l?l:e.defaultFontFamily,fontStyle:null!==(d=t.fontStyle)&&void 0!==d?d:"normal",fontWeight:null!==(s=t.fontWeight)&&void 0!==s?s:400,textAlign:null!==(u=t.textAlign)&&void 0!==u?u:"center",textTransform:null!==(c=t.textTransform)&&void 0!==c?c:"none",fontColor:null!==(h=t.fontColor)&&void 0!==h?h:e.defaultFontColor,textBaseline:null!==(f=t.textBaseline)&&void 0!==f?f:"middle",fontSize:a(t.radius,e.fontSize,t.fontWeight)}}(e,t);r.beginPath(),r.arc(n,o,i,0,2*Math.PI),r.fillStyle=l,r.fill(),r.strokeStyle=d,r.lineWidth=s,r.stroke(),r.fillStyle=c,r.font=`${v} ${m} ${f}px ${h}`,r.textAlign=p,r.textBaseline=g;let x=e.label||"";if("uppercase"===y?x=x.toUpperCase():"lowercase"===y?x=x.toLowerCase():"capitalize"===y&&(x=x.replace(/\b\w/g,(t=>t.toUpperCase()))),t.textWrap){const a=1.5*i-10,l=1.2*f,d=function(t,e,n,o,i,a,r=14,l=5,d=5,s=1.2){const u=1.5*(i-d),c=r*s,h=Math.max(1,Math.floor(u/c)),f="auto"===o||void 0===o?h:Math.min(o,h);n=Math.max(0,n-l);const v=e.split(" ");let m="";const p=[];let y=!1;for(const e of v){const o=m?`${m} ${e}`:e;if(t.measureText(o).width<=n?m=o:(m.trim()&&p.push(m),m=e),p.length>=f){y=!0;break}}if(m&&p.length<f&&p.push(m),y&&p.length>0){let e=p[p.length-1];for(;t.measureText(e+"...").width>n&&e.length>0;)e=e.slice(0,-1);p[p.length-1]=e+"..."}return p}(r,e.label,a,t.maxLines,i),s=o-(d.length-1)*l/2;d.forEach(((t,e)=>r.fillText(t,n,s+e*l)))}else r.fillText(e.label,n,o)}))):console.warn("canvas or ctx is not valid")}function s(){const n=document.getElementById(t.canvasContainerId);n&&e&&(e.width=n.offsetWidth,e.height=n.offsetHeight,d())}if(t.isResizeCanvasOnWindowSizeChange&&(s(),window.addEventListener("resize",s)),d(),t.showToolTip){const o=function(t){var e,n,o,i,a,r,l,d,s,u,c,h,f,v,m,p,y,g;const x=null===(n=null===(e=t.data[0].toolTipConfig)||void 0===e?void 0:e.tooltipFormattedData)||void 0===n?void 0:n.trim();if(x){const e=document.createElement("div");e.innerHTML=x.trim();const n=t.canvasContainerId?document.getElementById(t.canvasContainerId):null,o=e.firstElementChild;return(n||document.body).appendChild(o),o}const b=document.createElement("div");b.id="tooltip",b.style.display="none";const C=null!==(o=null==t?void 0:t.tooltipOptions)&&void 0!==o?o:{},M=(t,e)=>"number"==typeof t?`${t}px`:null!=t?t:e;return Object.assign(b.style,{position:"absolute",padding:M(C.padding,"8px"),margin:M(C.margin,"0"),background:null!==(i=C.backgroundColor)&&void 0!==i?i:"rgba(0, 0, 0, 0.85)",color:null!==(a=C.fontColor)&&void 0!==a?a:"white",borderRadius:"4px",pointerEvents:null!==(r=C.pointerEvents)&&void 0!==r?r:"none",fontFamily:null!==(l=C.fontFamily)&&void 0!==l?l:"Arial, sans-serif",fontSize:M(C.fontSize,"14px"),fontWeight:String(null!==(d=C.fontWeight)&&void 0!==d?d:"400"),fontStyle:null!==(s=C.fontStyle)&&void 0!==s?s:"normal",textAlign:null!==(u=C.textAlign)&&void 0!==u?u:"left",textDecoration:null!==(c=C.textDecoration)&&void 0!==c?c:"none",textTransform:null!==(h=C.textTransform)&&void 0!==h?h:"none",letterSpacing:M(C.letterSpacing,"normal"),border:(()=>{var t;if(!C.borderStyle)return"none";const e=M(C.borderWidth,"1px"),n=null!==(t=C.borderColor)&&void 0!==t?t:"transparent";return`${e} ${C.borderStyle} ${n}`})(),boxShadow:null!==(f=C.boxShadow)&&void 0!==f?f:"none",opacity:String(null!==(v=C.opacity)&&void 0!==v?v:1),maxWidth:M(C.maxWidth,"200px"),minWidth:M(C.minWidth,"auto"),maxHeight:M(C.maxHeight,"none"),minHeight:M(C.minHeight,"auto"),zIndex:String(null!==(m=C.zIndex)&&void 0!==m?m:1e3),transition:null!==(p=C.transition)&&void 0!==p?p:"opacity 0.2s",transform:null!==(y=C.transform)&&void 0!==y?y:"none",backdropFilter:null!==(g=C.backdropFilter)&&void 0!==g?g:"none"}),((t.canvasContainerId?document.getElementById(t.canvasContainerId):null)||document.body).appendChild(b),b}(t);let i=null;e.addEventListener("mousemove",(a=>{i||(i=requestAnimationFrame((()=>{(function(t,e,o,i,a){const{mouseX:r,mouseY:l}=function(t,e){const n=e.getBoundingClientRect();return{mouseX:t.clientX-n.left,mouseY:t.clientY-n.top}}(t,o),d=function(t,e,n){return n.find((n=>Math.hypot(t-n.x,e-n.y)<n.radius))||null}(r,l,e);(null==a?void 0:a.cursorType)&&(n=null==a?void 0:a.cursorType),d?function(t,e,o,i){e&&e.value&&o&&i&&(o.style.cursor=n,i.style.display="block",i.innerHTML=function(t){var e,n,o;if(!t)return"";const i=null===(n=null===(e=t.toolTipConfig)||void 0===e?void 0:e.tooltipText)||void 0===n?void 0:n.trim();if(i)return`<div>${i}</div>`;const a=null===(o=t.label)||void 0===o?void 0:o.trim();return a?`<div>${a}<br>Value: ${t.value}</div>`:`<div>${t.value}</div>`}(e),i.style.left=`${t.pageX+15}px`,i.style.top=t.pageY-30+"px",i.style.zIndex="9999")}(t,d,o,i):(o.style.cursor="default",i.style.display="none")})(a,l,e,o,t),i=null})))}))}}const l={defaultBubbleColor:"#3498DB",defaultFontColor:"#ffffff",minRadius:10,maxLines:"auto",textWrap:!0,isResizeCanvasOnWindowSizeChange:!0,fontSize:14,defaultFontFamily:"Arial",showToolTip:!0};function d(t={}){var e,n;if(!t.data||0===t.data.length)return void console.warn("initializeChart: No valid data provided. Chart initialization aborted.");var o;r((o=Object.assign({canvasContainerId:null!==(e=t.canvasContainerId)&&void 0!==e?e:"chart-container",data:null!==(n=t.data)&&void 0!==n?n:[]},t),Object.assign(Object.assign({},l),o)))}return window.initializeChart=d,e})()));
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("BubbleChart",[],e):"object"==typeof exports?exports.BubbleChart=e():t.BubbleChart=e()}(this,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{BubbleChart:()=>h,initializeChart:()=>c});let n="default";function o(t){const e=document.body;e?e.firstChild?e.insertBefore(t,e.firstChild):e.appendChild(t):console.error("Body element not found.")}function i(t,e){const n=e.getBoundingClientRect();return{mouseX:t.clientX-n.left,mouseY:t.clientY-n.top}}function r(t,e,n){return n.find((n=>Math.hypot(t-n.x,e-n.y)<n.radius))||null}class a{}a.TRANSPARENT="transparent";const l={forceStrength:.008,iterations:1e3,damping:.65,boundaryForce:.02,centerForce:.12,centerAttraction:.8,centerDamping:.3,centerRadiusBuffer:35};function d(t,e=14,n=400){const o=n>=700?1.25:n>=500?1.1:1;return Math.min(e*o,t/2)}function s(t){if(!function(t){return t?!(!Array.isArray(t.data)||0===t.data.length)||(console.error("Invalid or empty data array"),!1):(console.error("Invalid config object"),!1)}(t))return;let e=function(t){var e,n;const o=document.getElementById(t.canvasContainerId);if(!o)return console.error(`Canvas container with ID '${t.canvasContainerId}' not found.`),null;const i=document.createElement("canvas");return i.width=o.offsetWidth,i.height=o.offsetHeight,console.log(t.canvasBackgroundColor),Object.assign(i.style,{border:(null===(e=t.canvasBorderColor)||void 0===e?void 0:e.trim())?`1px solid #${t.canvasBorderColor}`:a.TRANSPARENT,background:(null===(n=t.canvasBackgroundColor)||void 0===n?void 0:n.trim())?`#${t.canvasBackgroundColor}`:a.TRANSPARENT,width:"100%",height:"100%",display:"block",imageRendering:"crisp-edges",aspectRatio:"1 / 1"}),i.style.setProperty("image-rendering","-moz-crisp-edges"),i.style.setProperty("image-rendering","-webkit-optimize-contrast"),i.style.setProperty("-ms-interpolation-mode","nearest-neighbor"),o.appendChild(i),i}(t);if(!e)return;const s=e.getContext("2d");if(!s)return void console.error("Invalid context");const u=function(t,e,n){const o=Math.min((e.width-10)/2,(e.height-10)/2),i=window.devicePixelRatio||1,r=e.getBoundingClientRect();e.width=r.width*i,e.height=r.height*i,e.style.width=r.width+"px",e.style.height=r.height+"px",n.scale(i,i);const a=r.width/2,d=r.height/2,s=[...t.data].sort(((t,e)=>e.value-t.value)).map((t=>Object.assign(Object.assign({},t),{radius:0,x:0,y:0,fixed:!1}))),u=s[0].value,c=Math.min(.5*o,70),h=Math.max(.3*c,25);s.forEach((t=>{const n=t.value/u;t.radius=h+n*(c-h),t.radius=Math.min(t.radius,(e.width-10)/2,(e.height-10)/2)})),s.forEach(((t,n)=>{if(0===n)t.x=a,t.y=d,t.fixed=!0;else{const o=s[0].radius+t.radius+3,i=Math.PI*(3-Math.sqrt(5)),r=e.width-5-t.radius,l=e.height-5-t.radius;t.x=Math.min(r,Math.max(5+t.radius,a+Math.cos(i*n)*o)),t.y=Math.min(l,Math.max(5+t.radius,d+Math.sin(i*n)*o)),t.fixed=!1}}));for(let t=0;t<l.iterations;t++)s.forEach(((t,n)=>{if(0===n){const e=a-t.x,n=d-t.y;return void(Math.hypot(e,n)>2&&(t.x+=e*l.centerDamping,t.y+=n*l.centerDamping))}let o=0,i=0;const r=t.radius+5;t.x<r?o+=(r-t.x)*l.boundaryForce:t.x>e.width-r&&(o+=(e.width-r-t.x)*l.boundaryForce),s.forEach((e=>{if(t===e)return;const n=t.x-e.x,r=t.y-e.y,s=Math.hypot(n,r),c=t.radius+e.radius;if(s<1.5*c){const t=l.forceStrength*(c/Math.max(s,.1));o+=n/s*t,i+=r/s*t}const h=a-t.x,f=d-t.y,m=Math.hypot(h,f),v=t.value/u*.02;t.x+=h/m*v,t.y+=f/m*v}));const c=a-t.x,h=d-t.y,f=Math.hypot(c,h),m=s[0].radius+t.radius+l.centerRadiusBuffer,v=(l.centerForce,Math.pow(t.value/u,.3),l.centerAttraction*(1-t.value/u)*(1-Math.min(1,f/m)));t.x+=c*v,t.y+=h*v,t.x+=o*(1-l.damping),t.y+=i*(1-l.damping)})),s.forEach(((t,e)=>{s.forEach(((n,o)=>{if(e>=o)return;if(0===e||0===o){const o=0===e?t:n,i=0===e?n:t,r=i.x-o.x,a=i.y-o.y,l=Math.hypot(r,a),d=o.radius+i.radius+2;if(l<d){const t=d-l,e=Math.atan2(a,r);i.x+=Math.cos(e)*t*.7,i.y+=Math.sin(e)*t*.7}return}const i=t.x-n.x,r=t.y-n.y,a=Math.hypot(i,r),d=t.radius+n.radius-5;if(a<d){const e=(d-a)*(.3+5*l.forceStrength),o=Math.atan2(r,i),s=n.radius/(t.radius+n.radius);t.fixed||(t.x+=Math.cos(o)*e*s,t.y+=Math.sin(o)*e*s),n.fixed||(n.x-=Math.cos(o)*e*(1-s),n.y-=Math.sin(o)*e*(1-s))}}))}));return s.forEach((t=>{const n=Math.max(5+t.radius,Math.min(e.width-5-t.radius,t.x)),o=Math.max(5+t.radius,Math.min(e.height-5-t.radius,t.y));(!t.fixed||Math.hypot(t.x-n,t.y-o)>2)&&(t.x=n,t.y=o)})),s}(t,e,s);function c(){e&&s?(s.clearRect(0,0,e.width,e.height),u.forEach((e=>{const{x:n,y:o,radius:i,bubbleColor:r,borderColor:a,borderThickness:l,opacity:u,fontColor:c,fontFamily:h,fontSize:f,fontStyle:m,fontWeight:v,textAlign:p,textTransform:g,textBaseline:y}=function(t,e){var n,o,i,r,a,l,s,u,c,h,f;return{x:t.x,y:t.y,radius:Math.max(t.radius,e.minRadius),bubbleColor:null!==(n=t.bubbleColor)&&void 0!==n?n:e.defaultBubbleColor,borderColor:null!==(o=t.borderColor)&&void 0!==o?o:"black",borderThickness:null!==(i=t.borderThickness)&&void 0!==i?i:.25,opacity:null!==(r=t.opacity)&&void 0!==r?r:1,fontFamily:null!==(a=t.fontFamily)&&void 0!==a?a:e.defaultFontFamily,fontStyle:null!==(l=t.fontStyle)&&void 0!==l?l:"normal",fontWeight:null!==(s=t.fontWeight)&&void 0!==s?s:400,textAlign:null!==(u=t.textAlign)&&void 0!==u?u:"center",textTransform:null!==(c=t.textTransform)&&void 0!==c?c:"none",fontColor:null!==(h=t.fontColor)&&void 0!==h?h:e.defaultFontColor,textBaseline:null!==(f=t.textBaseline)&&void 0!==f?f:"middle",fontSize:d(t.radius,e.fontSize,t.fontWeight)}}(e,t);s.beginPath(),s.arc(n,o,i,0,2*Math.PI),s.fillStyle=r,s.fill(),s.strokeStyle=a,s.lineWidth=l,s.stroke(),s.fillStyle=c,s.font=`${m} ${v} ${f}px ${h}`,s.textAlign=p,s.textBaseline=y;let x=e.label||"";if("uppercase"===g?x=x.toUpperCase():"lowercase"===g?x=x.toLowerCase():"capitalize"===g&&(x=x.replace(/\b\w/g,(t=>t.toUpperCase()))),t.textWrap){const r=1.5*i-10,a=1.2*f,l=function(t,e,n,o,i,r,a=14,l=2,d=5,s=1.2,u=400,c="normal",h="Arial"){const f=1.5*(i-d),m=a*s,v=Math.max(1,Math.floor(f/m)),p="auto"===o||void 0===o?v:Math.min(o,v);n=Math.max(0,n-l);const g=e.split(" ");let y="";const x=[];let b=!1,C=!1;for(const e of g){const o=y?`${y} ${e}`:e;if(t.font=`${u||""} ${c||""} ${a}px ${h}`,t.measureText(o).width<=n)y=o;else if(y.trim()&&x.push(y),y=e,t.measureText(y).width>n){let e=y;for(;t.measureText(e+"...").width>n&&e.length>0;)e=e.slice(0,-1);x.push(e+"..."),C=!0;break}if(x.length>=p){b=!0;break}}if(y&&x.length<p&&!C&&x.push(y),b&&x.length>0){let e=x[x.length-1];for(;t.measureText(e+"...").width>n&&e.length>0;)e=e.slice(0,-1);x[x.length-1]=e+"..."}return x}(s,e.label,r,t.maxLines,i),d=o-(l.length-1)*a/2;l.forEach(((t,e)=>s.fillText(t,n,d+e*a)))}else s.fillText(e.label,n,o)}))):console.warn("canvas or ctx is not valid")}function h(){const n=document.getElementById(t.canvasContainerId);n&&e&&(e.width=n.offsetWidth,e.height=n.offsetHeight,c())}let f;t.isResizeCanvasOnWindowSizeChange&&(h(),window.addEventListener("resize",h)),c(),t.showToolTip&&(f=function(t){var e,n,i,r,a,l,d,s,u,c,h,f,m,v,p,g,y,x;const b=null===(n=null===(e=t.data[0].toolTipConfig)||void 0===e?void 0:e.tooltipFormattedData)||void 0===n?void 0:n.trim();if(b){const t=document.createElement("div");t.innerHTML=b.trim();const e=t.firstElementChild;return o(e),e}const C=document.createElement("div");C.id="bubbleChartTooltip",C.style.display="none";const M=null!==(i=null==t?void 0:t.tooltipOptions)&&void 0!==i?i:{},w=(t,e)=>"number"==typeof t?`${t}px`:null!=t?t:e;return Object.assign(C.style,{position:"absolute",padding:w(M.padding,"8px"),margin:w(M.margin,"0"),background:null!==(r=M.backgroundColor)&&void 0!==r?r:"rgba(0, 0, 0, 0.85)",color:null!==(a=M.fontColor)&&void 0!==a?a:"white",borderRadius:"4px",pointerEvents:null!==(l=M.pointerEvents)&&void 0!==l?l:"none",fontFamily:null!==(d=M.fontFamily)&&void 0!==d?d:"Arial, sans-serif",fontSize:w(M.fontSize,"14px"),fontWeight:String(null!==(s=M.fontWeight)&&void 0!==s?s:"400"),fontStyle:null!==(u=M.fontStyle)&&void 0!==u?u:"normal",textAlign:null!==(c=M.textAlign)&&void 0!==c?c:"left",textDecoration:null!==(h=M.textDecoration)&&void 0!==h?h:"none",textTransform:null!==(f=M.textTransform)&&void 0!==f?f:"none",letterSpacing:w(M.letterSpacing,"normal"),border:(()=>{var t;if(!M.borderStyle)return"none";const e=w(M.borderWidth,"1px"),n=null!==(t=M.borderColor)&&void 0!==t?t:"transparent";return`${e} ${M.borderStyle} ${n}`})(),boxShadow:null!==(m=M.boxShadow)&&void 0!==m?m:"none",opacity:String(null!==(v=M.opacity)&&void 0!==v?v:1),maxWidth:w(M.maxWidth,"200px"),minWidth:w(M.minWidth,"auto"),maxHeight:w(M.maxHeight,"none"),minHeight:w(M.minHeight,"auto"),zIndex:String(null!==(p=M.zIndex)&&void 0!==p?p:1e3),transition:null!==(g=M.transition)&&void 0!==g?g:"opacity 0.2s",transform:null!==(y=M.transform)&&void 0!==y?y:"none",backdropFilter:null!==(x=M.backdropFilter)&&void 0!==x?x:"none"}),o(C),C}(t));let m=null;if(e.addEventListener("mousemove",(o=>{m||(m=requestAnimationFrame((()=>{(function(t,e,o,a,l){const{mouseX:d,mouseY:s}=i(t,o),u=r(d,s,e);(null==l?void 0:l.cursorType)&&(n=null==l?void 0:l.cursorType),a&&(u?function(t,e,o,i){e&&e.value&&o&&i&&(o.style.cursor=n,i.style.display="block",i.innerHTML=function(t){var e,n,o;if(!t)return"";const i=null===(n=null===(e=t.toolTipConfig)||void 0===e?void 0:e.tooltipText)||void 0===n?void 0:n.trim();if(i)return`<div>${i}</div>`;const r=null===(o=t.label)||void 0===o?void 0:o.trim();return r?`<div>${r}<br>Value: ${t.value}</div>`:`<div>${t.value}</div>`}(e),i.style.left=`${t.pageX+15}px`,i.style.top=t.pageY-30+"px",i.style.zIndex="9999")}(t,u,o,a):(o.style.cursor="default",a.style.display="none"))})(o,u,e,f,t),m=null})))})),t.onBubbleClick){let n=null;e.addEventListener("click",(o=>{n||(n=requestAnimationFrame((()=>{!function(t,e,n,o){const{mouseX:a,mouseY:l}=i(t,n),d=r(a,l,e);null!=d&&o.onBubbleClick&&o.onBubbleClick(d,t)}(o,u,e,t),n=null})))}))}}const u={defaultBubbleColor:"#3498DB",defaultFontColor:"#ffffff",minRadius:10,maxLines:"auto",textWrap:!0,isResizeCanvasOnWindowSizeChange:!0,fontSize:14,defaultFontFamily:"Arial",showToolTip:!0};function c(t={}){var e,n;if(!t)return void console.error("Configuration is not valid. Chart initialization aborted.");if(!t.data||0===t.data.length)return void console.error("No valid data provided. Chart initialization aborted.");const o=(i=Object.assign({canvasContainerId:null!==(e=t.canvasContainerId)&&void 0!==e?e:"chart-container",data:null!==(n=t.data)&&void 0!==n?n:[]},t),Object.assign(Object.assign({},u),i));var i;return s(o),o}class h{constructor(t){const e=c(t);e&&(this.configuration=e)}render(){this.configuration&&s(this.configuration)}}return window.initializeChart=c,e})()));
@@ -1 +1,3 @@
1
- export declare function getWrappedLines(ctx: CanvasRenderingContext2D, text: string, maxLineWidth: number, maxAllowedLines: number | "auto" | undefined, radius: number, maxCharsPerWord?: number | undefined, fontSize?: number, horizontalPadding?: number, verticalPadding?: number, lineHeightFactor?: number): string[];
1
+ export declare function getWrappedLines(ctx: CanvasRenderingContext2D, text: string, maxLineWidth: number, maxAllowedLines: number | "auto" | undefined, radius: number, maxCharsPerWord?: number | undefined, // TODO : need support
2
+ fontSize?: number, // TODO : take all default values from constants
3
+ horizontalPadding?: number, verticalPadding?: number, lineHeightFactor?: number, fontWeight?: number, fontStyle?: "normal" | "italic" | "oblique", fontFamily?: string): string[];
@@ -1,4 +1,6 @@
1
1
  import { DataItemInfo } from "../models/internal/data-item-info";
2
2
  import { Configuration } from "../models/public/configuration";
3
3
  export declare function createTooltipElement(config: Configuration): HTMLDivElement;
4
+ export declare function onBubbleClickEventHandler(// TODO : move to interactions.ts
5
+ event: MouseEvent, data: DataItemInfo[], canvas: HTMLCanvasElement, config: Configuration): void;
4
6
  export declare function handleMouseMove(event: MouseEvent, data: DataItemInfo[], canvas: HTMLCanvasElement, tooltip: HTMLDivElement, config: Configuration): void;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import { BubbleChart } from "./models/public/bubble-chart";
1
2
  import { initializeChart } from "./services/chart-service";
2
- export { initializeChart };
3
+ export { initializeChart, BubbleChart };
3
4
  declare global {
4
5
  interface Window {
5
6
  initializeChart: typeof initializeChart;
@@ -0,0 +1,6 @@
1
+ import { Configuration } from "./configuration";
2
+ export declare class BubbleChart {
3
+ configuration: Configuration;
4
+ constructor(config: Configuration);
5
+ render(): void;
6
+ }
@@ -1,9 +1,3 @@
1
- export interface BubbleAppearance {
2
- bubbleColor?: string;
3
- borderThickness?: number;
4
- borderColor?: string;
5
- opacity?: number;
6
- }
7
1
  /**
8
2
  * Defines the appearance properties for a bubble.
9
3
  */
@@ -2,4 +2,5 @@ export interface InteractionOptions {
2
2
  showToolTip?: boolean;
3
3
  isResizeCanvasOnWindowSizeChange?: boolean;
4
4
  cursorType?: "default" | "pointer" | "grab" | "crosshair" | "move" | "not-allowed" | "help";
5
+ onBubbleClick?: (bubbleData: any, event: MouseEvent) => void;
5
6
  }
@@ -2,4 +2,4 @@ import { Configuration } from "../models/public/configuration";
2
2
  /**
3
3
  * Initializes the chart, but stops execution if no valid data is provided.
4
4
  */
5
- export declare function initializeChart(config?: Partial<Configuration>): void;
5
+ export declare function initializeChart(config?: Partial<Configuration>): Configuration | undefined;
package/index.html CHANGED
@@ -12,61 +12,126 @@
12
12
  </head>
13
13
 
14
14
  <body>
15
- <div id="bubbleChart" style="width: 667px; height: 632px;"></div>
15
+ <div id="bubbleChart" style="width: 470px; height: 350px;border: 1px solid red;"></div>
16
16
  <script>
17
17
  document.addEventListener("DOMContentLoaded", function () {
18
18
  if (typeof initializeChart === "function") {
19
+ // const toolTipConfig = {
20
+ // tooltipText: 'Sample Tooltip',
21
+ // tooltipFormattedData: `<div style="position: absolute; display: block; border-style: solid; z-index: 99999999; will-change: transform; transition: opacity 0.2s cubic-bezier(0.23, 1, 0.32, 1), visibility 0.2s cubic-bezier(0.23, 1, 0.32, 1), transform 0.4s cubic-bezier(0.23, 1, 0.32, 1); background-color: rgb(30, 30, 47); border-width: 1px; border-radius: 8px; color: rgb(237, 237, 237); font: 12px / 18px Arial, sans-serif; padding: 10px 12px; top: 0px; left: 0px; transform: translate3d(4px, 4px, 0px); border-color: transparent; overflow: visible; white-space: normal; box-shadow: rgba(0, 0, 0, 0.25) 0px 4px 10px; pointer-events: none;">
22
+ // Sample Tooltip
23
+ // </div>
24
+ // `
25
+ // }
19
26
 
20
- // Sample data
21
- // const data = [
22
- // { label: 'Activation of supply for Electricity and Water', value: 45000, bubbleColor: "#024831", fontColor: '#FFFFFF', fontWeight: 600 },
23
- // { label: 'Reconnection', value: 28500, bubbleColor: "#03714d", fontColor: '#FFF', fontWeight: 600 },
24
- // { label: 'Refund Request', value: 22500, bubbleColor: "#03714d", fontColor: '#000', fontWeight: 400 },
25
- // { label: 'Request for Information Update', value: 28500, bubbleColor: "#049e6b", fontColor: '#000', fontWeight: 400 },
26
- // { label: 'Supply Issues', value: 25500, bubbleColor: "#31b086", fontColor: '#000', fontWeight: 400 },
27
- // { label: 'Smart Services', value: 26500, bubbleColor: "#03875c", fontColor: '#000', fontWeight: 400 },
28
- // ];
27
+ // const tooltipOptions = {
28
+ // fontStyle: 'italic',
29
+ // fontWeight: 800,
30
+ // textAlign: 'center',
31
+ // textDecoration: 'underline',
32
+ // textTransform: "uppercase",
33
+ // fontColor: '#FFF'
34
+ // }
29
35
 
30
- const toolTipConfig = {
31
- tooltipText: 'Sample Tooltip',
32
- tooltipFormattedData: `<div style="position: absolute; display: block; border-style: solid; z-index: 99999999; will-change: transform; transition: opacity 0.2s cubic-bezier(0.23, 1, 0.32, 1), visibility 0.2s cubic-bezier(0.23, 1, 0.32, 1), transform 0.4s cubic-bezier(0.23, 1, 0.32, 1); background-color: rgb(30, 30, 47); border-width: 1px; border-radius: 8px; color: rgb(237, 237, 237); font: 12px / 18px Arial, sans-serif; padding: 10px 12px; top: 0px; left: 0px; transform: translate3d(4px, 4px, 0px); border-color: transparent; overflow: visible; white-space: normal; box-shadow: rgba(0, 0, 0, 0.25) 0px 4px 10px; pointer-events: none;">
33
- Sample Tooltip
34
- </div>
35
- `
36
- }
37
-
38
- const tooltipOptions = {
39
- fontStyle: 'italic',
40
- fontWeight: 800,
41
- textAlign: 'center',
42
- textDecoration: 'underline',
43
- textTransform: "uppercase",
44
- fontColor: '#FFF'
45
- }
36
+ // const data = [
37
+ // { label: "Biryani Battles", "value": 89, bubbleColor: "#ff5733" },
38
+ // { label: "Chai vs. Coffee", "value": 70, bubbleColor: "#c70039" },
39
+ // { label: "Bollywood Blockbusters", "value": 90, bubbleColor: "#900c3f" },
40
+ // { label: "IPL Fever", "value": 85, bubbleColor: "#ffc300" },
41
+ // { label: "Himalayan Treks", "value": 65, bubbleColor: "#4caf50" },
42
+ // { label: "Diwali Firecrackers", "value": 95, bubbleColor: "#ff8c00" },
43
+ // { label: "Street Food Craze", "value": 75, bubbleColor: "#e91e63" },
44
+ // { label: "Fastest Century Records", "value": 88, bubbleColor: "#3f51b5" },
45
+ // { label: "Royal Enfield Craze", "value": 60, bubbleColor: "#795548" },
46
+ // { label: "Digital Payment Boom", "value": 93, bubbleColor: "#00bcd4" }
47
+ // ];
46
48
 
47
- const data = [
48
- { label: "Biryani Battles", "value": 89, bubbleColor: "#ff5733" },
49
- { label: "Chai vs. Coffee", "value": 70, bubbleColor: "#c70039" },
50
- { label: "Bollywood Blockbusters", "value": 90, bubbleColor: "#900c3f" },
51
- { label: "IPL Fever", "value": 85, bubbleColor: "#ffc300" },
52
- { label: "Himalayan Treks", "value": 65, bubbleColor: "#4caf50" },
53
- { label: "Diwali Firecrackers", "value": 95, bubbleColor: "#ff8c00" },
54
- { label: "Street Food Craze", "value": 75, bubbleColor: "#e91e63" },
55
- { label: "Fastest Century Records", "value": 88, bubbleColor: "#3f51b5" },
56
- { label: "Royal Enfield Craze", "value": 60, bubbleColor: "#795548" },
57
- { label: "Digital Payment Boom", "value": 93, bubbleColor: "#00bcd4" }
58
- ];
49
+ // const chartoptions = {
50
+ // canvasContainerId: 'bubbleChart',
51
+ // data: data,
52
+ // fontSize: 14,
53
+ // maxLines: 2,
54
+ // tooltipOptions: tooltipOptions,
55
+ // }
59
56
 
60
- const chartoptions = {
57
+ // Initialize chart
58
+ const chartOptions = {
61
59
  canvasContainerId: 'bubbleChart',
62
- data: data,
63
- fontSize: 14,
64
- maxLines: 2,
65
- tooltipOptions: tooltipOptions,
60
+ data: [
61
+ {
62
+ label: 'Rocket Fuel Orders',
63
+ value: 207,
64
+ bubbleColor: '#ff5733',
65
+ fontColor: '#FFFFFF',
66
+ fontWeight: 600,
67
+ },
68
+ {
69
+ label: 'Time Machine Repairs',
70
+ value: 154,
71
+ bubbleColor: '#c70039',
72
+ fontColor: '#FFF',
73
+ fontWeight: 600,
74
+ },
75
+ {
76
+ label: 'AI Overlord Complaints',
77
+ value: 192,
78
+ bubbleColor: '#900c3f',
79
+ fontColor: '#000',
80
+ },
81
+ {
82
+ label: 'Quantum Internet Activation',
83
+ value: 73,
84
+ bubbleColor: '#ffc300',
85
+ fontColor: '#000',
86
+ },
87
+ {
88
+ label: 'Zero-Gravity Plumbing Issues',
89
+ value: 96,
90
+ bubbleColor: '#4caf50',
91
+ fontColor: '#000',
92
+ },
93
+ {
94
+ label: 'Hologram Tech Support',
95
+ value: 119,
96
+ bubbleColor: '#ff8c00',
97
+ fontColor: '#000',
98
+ },
99
+ {
100
+ label: 'Teleportation Delay Reports',
101
+ value: 87,
102
+ bubbleColor: '#03875c',
103
+ fontColor: '#000',
104
+ },
105
+ {
106
+ label: 'Neural Chip Upgrades',
107
+ value: 163,
108
+ bubbleColor: '#3f51b5',
109
+ fontColor: '#000',
110
+ },
111
+ {
112
+ label: 'Intergalactic Toll Fees',
113
+ value: 132,
114
+ bubbleColor: '#795548',
115
+ fontColor: '#000',
116
+ },
117
+ ],
118
+ fontSize: 10,
119
+ defaultFontFamily: 'Roboto',
120
+ onBubbleClick: (bubbleData, event) => {
121
+ alert(`You clicked on: ${bubbleData.label}`);
122
+ },
123
+ tooltipOptions: {
124
+ // fontStyle: 'italic',
125
+ // fontWeight: 800,
126
+ // textAlign: 'center',
127
+ // textDecoration: 'underline',
128
+ // textTransform: 'uppercase',
129
+ // fontColor: '#FFF',
130
+ },
66
131
  }
67
132
 
68
- // Initialize chart
69
- initializeChart(chartoptions);
133
+
134
+ initializeChart(chartOptions);
70
135
  } else {
71
136
  console.error("initializeChart is not defined");
72
137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bubble-chart-js",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "bubbleChartJs is a lightweight, customizable JavaScript library for creating stacked bubble charts. It arranges bubbles based on their values, with the largest bubble positioned at the top and surrounding bubbles decreasing in size accordingly.",
5
5
  "main": "dist/bubbleChart.cjs.js",
6
6
  "module": "dist/bubbleChart.esm.js",
package/tsconfig.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES6",
4
- "module": "ESNext",
5
- "declaration": true,
6
- "declarationDir": "./dist",
7
- "outDir": "./dist",
8
- "rootDir": "./src",
9
- "strict": true,
10
- "esModuleInterop": true,
11
- "skipLibCheck": true,
12
- "forceConsistentCasingInFileNames": true,
13
- "allowSyntheticDefaultImports": true
14
- },
15
- "include": ["src/**/*"],
16
- "exclude": ["node_modules", "**/*.test.ts"]
17
- }
package/webpack.config.js DELETED
@@ -1,64 +0,0 @@
1
- const path = require("path");
2
-
3
- /** @type {import('webpack').Configuration} */
4
- const commonConfig = {
5
- entry: "./src/index.ts",
6
- target: "web",
7
- resolve: {
8
- extensions: [".ts", ".js"],
9
- },
10
- module: {
11
- rules: [
12
- {
13
- test: /\.ts$/,
14
- use: "ts-loader",
15
- exclude: /node_modules/,
16
- },
17
- ],
18
- },
19
- optimization: {
20
- minimize: true,
21
- },
22
- };
23
-
24
- /** UMD Build (Browser + Node.js) */
25
- const umdConfig = {
26
- ...commonConfig,
27
- output: {
28
- path: path.resolve(__dirname, "dist"),
29
- filename: "bubbleChart.umd.js",
30
- library: "BubbleChart",
31
- libraryTarget: "umd",
32
- globalObject: "this",
33
- umdNamedDefine: true,
34
- },
35
- };
36
-
37
- /** ESM Build (Modern JavaScript) */
38
- const esmConfig = {
39
- ...commonConfig,
40
- output: {
41
- path: path.resolve(__dirname, "dist"),
42
- filename: "bubbleChart.esm.js",
43
- library: {
44
- type: "module",
45
- },
46
- },
47
- experiments: {
48
- outputModule: true, // Required for ESM builds
49
- },
50
- };
51
-
52
- /** CommonJS Build (Node.js) */
53
- const cjsConfig = {
54
- ...commonConfig,
55
- output: {
56
- path: path.resolve(__dirname, "dist"),
57
- filename: "bubbleChart.cjs.js",
58
- library: {
59
- type: "commonjs2",
60
- },
61
- },
62
- };
63
-
64
- module.exports = [umdConfig, esmConfig, cjsConfig];