bubble-chart-js 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +171 -123
- package/assets/bubble-chart.png +0 -0
- package/dist/bubbleChart.cjs.js +1 -1
- package/dist/bubbleChart.esm.js +1 -1
- package/dist/bubbleChart.umd.js +1 -1
- package/dist/features/text-wrapper.d.ts +2 -3
- package/dist/utils/helper.d.ts +2 -1
- package/index.html +66 -105
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,123 +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
|
-

|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
{
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
+

|
|
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
|
package/assets/bubble-chart.png
CHANGED
|
Binary file
|
package/dist/bubbleChart.cjs.js
CHANGED
|
@@ -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,{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!=u&&((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
|
+
(()=>{"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.querySelector("#bubbleChartTooltip")||e.prepend(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 a(t,e,n){return n.find((n=>Math.hypot(t-n.x,e-n.y)<n.radius))||null}class r{}r.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,o=6){const i=n>=700?1.25:n>=500?1.1:1,a=Math.min(t/o,t/1.2);let r=Math.min(e*i,a,.8*t);return r=Math.max(r,Math.max(8,t/6)),Math.round(r)}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;if(o.querySelector("canvas"))return console.error("A canvas already exists inside the container."),null;const i=document.createElement("canvas");return i.width=o.offsetWidth,i.height=o.offsetHeight,Object.assign(i.style,{border:(null===(e=t.canvasBorderColor)||void 0===e?void 0:e.trim())?`1px solid #${t.canvasBorderColor}`:r.TRANSPARENT,background:(null===(n=t.canvasBackgroundColor)||void 0===n?void 0:n.trim())?`#${t.canvasBackgroundColor}`:r.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,a=e.getBoundingClientRect();e.width=a.width*i,e.height=a.height*i,e.style.width=a.width+"px",e.style.height=a.height+"px",n.scale(i,i);const r=a.width/2,s=a.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,.2*Math.min(e.width,e.height)),h=Math.max(.3*c,.05*Math.min(e.width,e.height));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=r,t.y=s,t.fixed=!0;else{const o=d[0].radius+t.radius+3,i=Math.PI*(3-Math.sqrt(5)),a=e.width-5-t.radius,l=e.height-5-t.radius;t.x=Math.min(a,Math.max(5+t.radius,r+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=r-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 a=t.radius+5;t.x<a?o+=(a-t.x)*l.boundaryForce:t.x>e.width-a&&(o+=(e.width-a-t.x)*l.boundaryForce),d.forEach((e=>{if(t===e)return;const n=t.x-e.x,a=t.y-e.y,d=Math.hypot(n,a),c=t.radius+e.radius;if(d<1.5*c){const t=l.forceStrength*(c/Math.max(d,.1));o+=n/d*t,i+=a/d*t}const h=r-t.x,f=s-t.y,m=Math.hypot(h,f),v=t.value/u*.02;t.x+=h/m*v,t.y+=f/m*v}));const c=r-t.x,h=s-t.y,f=Math.hypot(c,h),m=d[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)})),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,a=i.x-o.x,r=i.y-o.y,l=Math.hypot(a,r),s=o.radius+i.radius+2;if(l<s){const t=s-l,e=Math.atan2(r,a);i.x+=Math.cos(e)*t*.7,i.y+=Math.sin(e)*t*.7}return}const i=t.x-n.x,a=t.y-n.y,r=Math.hypot(i,a),s=t.radius+n.radius-5;if(r<s){const e=(s-r)*(.3+5*l.forceStrength),o=Math.atan2(a,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:a,borderColor:r,borderThickness:l,opacity:u,fontColor:c,fontFamily:h,fontSize:f,fontStyle:m,fontWeight:v,textAlign:g,textTransform:y,textBaseline:p}=function(t,e){var n,o,i,a,r,l,d,u,c,h,f,m;return{x:t.x,y:t.y,radius:Math.max(t.radius||0,e.minRadius||10),bubbleColor:null!==(o=null!==(n=t.bubbleColor)&&void 0!==n?n:e.defaultBubbleColor)&&void 0!==o?o:"#3498db",borderColor:null!==(i=t.borderColor)&&void 0!==i?i:"black",borderThickness:Math.max(null!==(a=t.borderThickness)&&void 0!==a?a:.25,0),opacity:void 0!==t.opacity?Math.max(0,Math.min(1,t.opacity)):1,fontStyle:t.fontStyle||"normal",fontWeight:"number"==typeof t.fontWeight&&t.fontWeight>=100&&t.fontWeight<=900?t.fontWeight:400,textAlign:null!==(r=t.textAlign)&&void 0!==r?r:"center",textTransform:null!==(l=t.textTransform)&&void 0!==l?l:"none",fontColor:null!==(u=null!==(d=t.fontColor)&&void 0!==d?d:e.defaultFontColor)&&void 0!==u?u:"#000",textBaseline:null!==(c=t.textBaseline)&&void 0!==c?c:"middle",fontSize:Math.max(s(t.radius||e.minRadius||10,null!==(h=e.fontSize)&&void 0!==h?h:14,null!==(f=t.fontWeight)&&void 0!==f?f:400),8),fontFamily:t.fontFamily&&"string"==typeof t.fontFamily&&"Arial"!==t.fontFamily?`${t.fontFamily}, Arial, sans-serif`:`${null!==(m=e.defaultFontFamily)&&void 0!==m?m:"Arial"}, sans-serif`}}(e,t);d.beginPath(),d.arc(n,o,i,0,2*Math.PI),d.fillStyle=a,d.fill(),d.strokeStyle=r,d.lineWidth=l,d.stroke();const x=`${m} ${v} ${f}px ${h}`;d.fillStyle=c,d.font=x,d.textAlign=g,d.textBaseline=p;let b=e.label||"";if("uppercase"===y?b=b.toUpperCase():"lowercase"===y?b=b.toLowerCase():"capitalize"===y&&(b=b.replace(/\b\w/g,(t=>t.toUpperCase()))),t.textWrap){const a=1.5*i-10,r=1.2*f,l=function(t,e,n,o,i,a=14,r=400,l="normal",s="Arial",d=2,u=5,c=1.2){const h=1.5*(i-u),f=a*c,m=Math.max(1,Math.floor(h/f)),v="auto"===o||void 0===o?m:Math.min(o,m);n=Math.max(0,n-d);const g=e.split(" ");let y="";const p=[];let x=!1,b=!1;for(const e of g){const o=y?`${y} ${e}`:e;if(t.font=`${r||""} ${l||""} ${a}px ${s}`,t.measureText(o).width<=n)y=o;else if(y.trim()&&p.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);p.push(e+"..."),b=!0;break}if(p.length>=v){x=!0;break}}if(y&&p.length<v&&!b&&p.push(y),x&&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}(d,e.label,a,t.maxLines,i,f,v,m,h),s=o-(l.length-1)*r/2;l.forEach(((t,e)=>d.fillText(t,n,s+e*r)))}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,a,r,l,s,d,u,c,h,f,m,v,g,y,p,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 M=document.createElement("div");M.id="bubbleChartTooltip",M.style.display="none";const C=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(M.style,{position:"absolute",padding:w(C.padding,"8px"),margin:w(C.margin,"0"),background:null!==(a=C.backgroundColor)&&void 0!==a?a:"rgba(0, 0, 0, 0.85)",color:null!==(r=C.fontColor)&&void 0!==r?r:"white",borderRadius:"4px",pointerEvents:null!==(l=C.pointerEvents)&&void 0!==l?l:"none",fontFamily:null!==(s=C.fontFamily)&&void 0!==s?s:"Arial, sans-serif",fontSize:w(C.fontSize,"14px"),fontWeight:String(null!==(d=C.fontWeight)&&void 0!==d?d:"400"),fontStyle:null!==(u=C.fontStyle)&&void 0!==u?u:"normal",textAlign:null!==(c=C.textAlign)&&void 0!==c?c:"left",textDecoration:null!==(h=C.textDecoration)&&void 0!==h?h:"none",textTransform:null!==(f=C.textTransform)&&void 0!==f?f:"none",letterSpacing:w(C.letterSpacing,"normal"),border:(()=>{var t;if(!C.borderStyle)return"none";const e=w(C.borderWidth,"1px"),n=null!==(t=C.borderColor)&&void 0!==t?t:"transparent";return`${e} ${C.borderStyle} ${n}`})(),boxShadow:null!==(m=C.boxShadow)&&void 0!==m?m:"none",opacity:String(null!==(v=C.opacity)&&void 0!==v?v:1),maxWidth:w(C.maxWidth,"200px"),minWidth:w(C.minWidth,"auto"),maxHeight:w(C.maxHeight,"none"),minHeight:w(C.minHeight,"auto"),zIndex:String(null!==(g=C.zIndex)&&void 0!==g?g:1e3),transition:null!==(y=C.transition)&&void 0!==y?y:"opacity 0.2s",transform:null!==(p=C.transform)&&void 0!==p?p:"none",backdropFilter:null!==(x=C.backdropFilter)&&void 0!==x?x:"none"}),o(M),M}(t));let m=null;if(e.addEventListener("mousemove",(o=>{m||(m=requestAnimationFrame((()=>{(function(t,e,o,r,l){const{mouseX:s,mouseY:d}=i(t,o),u=a(s,d,e);(null==l?void 0:l.cursorType)&&(n=null==l?void 0:l.cursorType),r&&(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 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,u,o,r):(o.style.cursor="default",r.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:r,mouseY:l}=i(t,n),s=a(r,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,module.exports=e})();
|
package/dist/bubbleChart.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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!=u&&((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
|
+
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.querySelector("#bubbleChartTooltip")||e.prepend(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 a(t,e,n){return n.find((n=>Math.hypot(t-n.x,e-n.y)<n.radius))||null}class r{}r.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,o=6){const i=n>=700?1.25:n>=500?1.1:1,a=Math.min(t/o,t/1.2);let r=Math.min(e*i,a,.8*t);return r=Math.max(r,Math.max(8,t/6)),Math.round(r)}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;if(o.querySelector("canvas"))return console.error("A canvas already exists inside the container."),null;const i=document.createElement("canvas");return i.width=o.offsetWidth,i.height=o.offsetHeight,Object.assign(i.style,{border:(null===(e=t.canvasBorderColor)||void 0===e?void 0:e.trim())?`1px solid #${t.canvasBorderColor}`:r.TRANSPARENT,background:(null===(n=t.canvasBackgroundColor)||void 0===n?void 0:n.trim())?`#${t.canvasBackgroundColor}`:r.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,a=e.getBoundingClientRect();e.width=a.width*i,e.height=a.height*i,e.style.width=a.width+"px",e.style.height=a.height+"px",n.scale(i,i);const r=a.width/2,s=a.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,.2*Math.min(e.width,e.height)),h=Math.max(.3*c,.05*Math.min(e.width,e.height));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=r,t.y=s,t.fixed=!0;else{const o=d[0].radius+t.radius+3,i=Math.PI*(3-Math.sqrt(5)),a=e.width-5-t.radius,l=e.height-5-t.radius;t.x=Math.min(a,Math.max(5+t.radius,r+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=r-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 a=t.radius+5;t.x<a?o+=(a-t.x)*l.boundaryForce:t.x>e.width-a&&(o+=(e.width-a-t.x)*l.boundaryForce),d.forEach((e=>{if(t===e)return;const n=t.x-e.x,a=t.y-e.y,d=Math.hypot(n,a),c=t.radius+e.radius;if(d<1.5*c){const t=l.forceStrength*(c/Math.max(d,.1));o+=n/d*t,i+=a/d*t}const h=r-t.x,f=s-t.y,m=Math.hypot(h,f),v=t.value/u*.02;t.x+=h/m*v,t.y+=f/m*v}));const c=r-t.x,h=s-t.y,f=Math.hypot(c,h),m=d[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)})),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,a=i.x-o.x,r=i.y-o.y,l=Math.hypot(a,r),s=o.radius+i.radius+2;if(l<s){const t=s-l,e=Math.atan2(r,a);i.x+=Math.cos(e)*t*.7,i.y+=Math.sin(e)*t*.7}return}const i=t.x-n.x,a=t.y-n.y,r=Math.hypot(i,a),s=t.radius+n.radius-5;if(r<s){const e=(s-r)*(.3+5*l.forceStrength),o=Math.atan2(a,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:a,borderColor:r,borderThickness:l,opacity:u,fontColor:c,fontFamily:h,fontSize:f,fontStyle:m,fontWeight:v,textAlign:g,textTransform:x,textBaseline:y}=function(t,e){var n,o,i,a,r,l,d,u,c,h,f,m;return{x:t.x,y:t.y,radius:Math.max(t.radius||0,e.minRadius||10),bubbleColor:null!==(o=null!==(n=t.bubbleColor)&&void 0!==n?n:e.defaultBubbleColor)&&void 0!==o?o:"#3498db",borderColor:null!==(i=t.borderColor)&&void 0!==i?i:"black",borderThickness:Math.max(null!==(a=t.borderThickness)&&void 0!==a?a:.25,0),opacity:void 0!==t.opacity?Math.max(0,Math.min(1,t.opacity)):1,fontStyle:t.fontStyle||"normal",fontWeight:"number"==typeof t.fontWeight&&t.fontWeight>=100&&t.fontWeight<=900?t.fontWeight:400,textAlign:null!==(r=t.textAlign)&&void 0!==r?r:"center",textTransform:null!==(l=t.textTransform)&&void 0!==l?l:"none",fontColor:null!==(u=null!==(d=t.fontColor)&&void 0!==d?d:e.defaultFontColor)&&void 0!==u?u:"#000",textBaseline:null!==(c=t.textBaseline)&&void 0!==c?c:"middle",fontSize:Math.max(s(t.radius||e.minRadius||10,null!==(h=e.fontSize)&&void 0!==h?h:14,null!==(f=t.fontWeight)&&void 0!==f?f:400),8),fontFamily:t.fontFamily&&"string"==typeof t.fontFamily&&"Arial"!==t.fontFamily?`${t.fontFamily}, Arial, sans-serif`:`${null!==(m=e.defaultFontFamily)&&void 0!==m?m:"Arial"}, sans-serif`}}(e,t);d.beginPath(),d.arc(n,o,i,0,2*Math.PI),d.fillStyle=a,d.fill(),d.strokeStyle=r,d.lineWidth=l,d.stroke();const p=`${m} ${v} ${f}px ${h}`;d.fillStyle=c,d.font=p,d.textAlign=g,d.textBaseline=y;let b=e.label||"";if("uppercase"===x?b=b.toUpperCase():"lowercase"===x?b=b.toLowerCase():"capitalize"===x&&(b=b.replace(/\b\w/g,(t=>t.toUpperCase()))),t.textWrap){const a=1.5*i-10,r=1.2*f,l=function(t,e,n,o,i,a=14,r=400,l="normal",s="Arial",d=2,u=5,c=1.2){const h=1.5*(i-u),f=a*c,m=Math.max(1,Math.floor(h/f)),v="auto"===o||void 0===o?m:Math.min(o,m);n=Math.max(0,n-d);const g=e.split(" ");let x="";const y=[];let p=!1,b=!1;for(const e of g){const o=x?`${x} ${e}`:e;if(t.font=`${r||""} ${l||""} ${a}px ${s}`,t.measureText(o).width<=n)x=o;else if(x.trim()&&y.push(x),x=e,t.measureText(x).width>n){let e=x;for(;t.measureText(e+"...").width>n&&e.length>0;)e=e.slice(0,-1);y.push(e+"..."),b=!0;break}if(y.length>=v){p=!0;break}}if(x&&y.length<v&&!b&&y.push(x),p&&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,a,t.maxLines,i,f,v,m,h),s=o-(l.length-1)*r/2;l.forEach(((t,e)=>d.fillText(t,n,s+e*r)))}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,a,r,l,s,d,u,c,h,f,m,v,g,x,y,p;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 M=document.createElement("div");M.id="bubbleChartTooltip",M.style.display="none";const C=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(M.style,{position:"absolute",padding:w(C.padding,"8px"),margin:w(C.margin,"0"),background:null!==(a=C.backgroundColor)&&void 0!==a?a:"rgba(0, 0, 0, 0.85)",color:null!==(r=C.fontColor)&&void 0!==r?r:"white",borderRadius:"4px",pointerEvents:null!==(l=C.pointerEvents)&&void 0!==l?l:"none",fontFamily:null!==(s=C.fontFamily)&&void 0!==s?s:"Arial, sans-serif",fontSize:w(C.fontSize,"14px"),fontWeight:String(null!==(d=C.fontWeight)&&void 0!==d?d:"400"),fontStyle:null!==(u=C.fontStyle)&&void 0!==u?u:"normal",textAlign:null!==(c=C.textAlign)&&void 0!==c?c:"left",textDecoration:null!==(h=C.textDecoration)&&void 0!==h?h:"none",textTransform:null!==(f=C.textTransform)&&void 0!==f?f:"none",letterSpacing:w(C.letterSpacing,"normal"),border:(()=>{var t;if(!C.borderStyle)return"none";const e=w(C.borderWidth,"1px"),n=null!==(t=C.borderColor)&&void 0!==t?t:"transparent";return`${e} ${C.borderStyle} ${n}`})(),boxShadow:null!==(m=C.boxShadow)&&void 0!==m?m:"none",opacity:String(null!==(v=C.opacity)&&void 0!==v?v:1),maxWidth:w(C.maxWidth,"200px"),minWidth:w(C.minWidth,"auto"),maxHeight:w(C.maxHeight,"none"),minHeight:w(C.minHeight,"auto"),zIndex:String(null!==(g=C.zIndex)&&void 0!==g?g:1e3),transition:null!==(x=C.transition)&&void 0!==x?x:"opacity 0.2s",transform:null!==(y=C.transform)&&void 0!==y?y:"none",backdropFilter:null!==(p=C.backdropFilter)&&void 0!==p?p:"none"}),o(M),M}(t));let m=null;if(e.addEventListener("mousemove",(o=>{m||(m=requestAnimationFrame((()=>{(function(t,e,o,r,l){const{mouseX:s,mouseY:d}=i(t,o),u=a(s,d,e);(null==l?void 0:l.cursorType)&&(n=null==l?void 0:l.cursorType),r&&(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 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,u,o,r):(o.style.cursor="default",r.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:r,mouseY:l}=i(t,n),s=a(r,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.$,m=e.s;export{f as BubbleChart,m as initializeChart};
|
package/dist/bubbleChart.umd.js
CHANGED
|
@@ -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,{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!=u&&((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
|
+
!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.querySelector("#bubbleChartTooltip")||e.prepend(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,o=6){const i=n>=700?1.25:n>=500?1.1:1,r=Math.min(t/o,t/1.2);let a=Math.min(e*i,r,.8*t);return a=Math.max(a,Math.max(8,t/6)),Math.round(a)}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;if(o.querySelector("canvas"))return console.error("A canvas already exists inside the container."),null;const i=document.createElement("canvas");return i.width=o.offsetWidth,i.height=o.offsetHeight,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,.2*Math.min(e.width,e.height)),h=Math.max(.3*c,.05*Math.min(e.width,e.height));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,m=Math.hypot(h,f),y=t.value/u*.02;t.x+=h/m*y,t.y+=f/m*y}));const c=a-t.x,h=s-t.y,f=Math.hypot(c,h),m=d[0].radius+t.radius+l.centerRadiusBuffer,y=(l.centerForce,Math.pow(t.value/u,.3),l.centerAttraction*(1-t.value/u)*(1-Math.min(1,f/m)));t.x+=c*y,t.y+=h*y,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:m,fontWeight:y,textAlign:p,textTransform:v,textBaseline:g}=function(t,e){var n,o,i,r,a,l,d,u,c,h,f,m;return{x:t.x,y:t.y,radius:Math.max(t.radius||0,e.minRadius||10),bubbleColor:null!==(o=null!==(n=t.bubbleColor)&&void 0!==n?n:e.defaultBubbleColor)&&void 0!==o?o:"#3498db",borderColor:null!==(i=t.borderColor)&&void 0!==i?i:"black",borderThickness:Math.max(null!==(r=t.borderThickness)&&void 0!==r?r:.25,0),opacity:void 0!==t.opacity?Math.max(0,Math.min(1,t.opacity)):1,fontStyle:t.fontStyle||"normal",fontWeight:"number"==typeof t.fontWeight&&t.fontWeight>=100&&t.fontWeight<=900?t.fontWeight:400,textAlign:null!==(a=t.textAlign)&&void 0!==a?a:"center",textTransform:null!==(l=t.textTransform)&&void 0!==l?l:"none",fontColor:null!==(u=null!==(d=t.fontColor)&&void 0!==d?d:e.defaultFontColor)&&void 0!==u?u:"#000",textBaseline:null!==(c=t.textBaseline)&&void 0!==c?c:"middle",fontSize:Math.max(s(t.radius||e.minRadius||10,null!==(h=e.fontSize)&&void 0!==h?h:14,null!==(f=t.fontWeight)&&void 0!==f?f:400),8),fontFamily:t.fontFamily&&"string"==typeof t.fontFamily&&"Arial"!==t.fontFamily?`${t.fontFamily}, Arial, sans-serif`:`${null!==(m=e.defaultFontFamily)&&void 0!==m?m:"Arial"}, sans-serif`}}(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();const x=`${m} ${y} ${f}px ${h}`;d.fillStyle=c,d.font=x,d.textAlign=p,d.textBaseline=g;let b=e.label||"";if("uppercase"===v?b=b.toUpperCase():"lowercase"===v?b=b.toLowerCase():"capitalize"===v&&(b=b.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=14,a=400,l="normal",s="Arial",d=2,u=5,c=1.2){const h=1.5*(i-u),f=r*c,m=Math.max(1,Math.floor(h/f)),y="auto"===o||void 0===o?m:Math.min(o,m);n=Math.max(0,n-d);const p=e.split(" ");let v="";const g=[];let x=!1,b=!1;for(const e of p){const o=v?`${v} ${e}`:e;if(t.font=`${a||""} ${l||""} ${r}px ${s}`,t.measureText(o).width<=n)v=o;else if(v.trim()&&g.push(v),v=e,t.measureText(v).width>n){let e=v;for(;t.measureText(e+"...").width>n&&e.length>0;)e=e.slice(0,-1);g.push(e+"..."),b=!0;break}if(g.length>=y){x=!0;break}}if(v&&g.length<y&&!b&&g.push(v),x&&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}(d,e.label,r,t.maxLines,i,f,y,m,h),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,m,y,p,v,g,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 M=document.createElement("div");M.id="bubbleChartTooltip",M.style.display="none";const C=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(M.style,{position:"absolute",padding:w(C.padding,"8px"),margin:w(C.margin,"0"),background:null!==(r=C.backgroundColor)&&void 0!==r?r:"rgba(0, 0, 0, 0.85)",color:null!==(a=C.fontColor)&&void 0!==a?a:"white",borderRadius:"4px",pointerEvents:null!==(l=C.pointerEvents)&&void 0!==l?l:"none",fontFamily:null!==(s=C.fontFamily)&&void 0!==s?s:"Arial, sans-serif",fontSize:w(C.fontSize,"14px"),fontWeight:String(null!==(d=C.fontWeight)&&void 0!==d?d:"400"),fontStyle:null!==(u=C.fontStyle)&&void 0!==u?u:"normal",textAlign:null!==(c=C.textAlign)&&void 0!==c?c:"left",textDecoration:null!==(h=C.textDecoration)&&void 0!==h?h:"none",textTransform:null!==(f=C.textTransform)&&void 0!==f?f:"none",letterSpacing:w(C.letterSpacing,"normal"),border:(()=>{var t;if(!C.borderStyle)return"none";const e=w(C.borderWidth,"1px"),n=null!==(t=C.borderColor)&&void 0!==t?t:"transparent";return`${e} ${C.borderStyle} ${n}`})(),boxShadow:null!==(m=C.boxShadow)&&void 0!==m?m:"none",opacity:String(null!==(y=C.opacity)&&void 0!==y?y:1),maxWidth:w(C.maxWidth,"200px"),minWidth:w(C.minWidth,"auto"),maxHeight:w(C.maxHeight,"none"),minHeight:w(C.minHeight,"auto"),zIndex:String(null!==(p=C.zIndex)&&void 0!==p?p:1e3),transition:null!==(v=C.transition)&&void 0!==v?v:"opacity 0.2s",transform:null!==(g=C.transform)&&void 0!==g?g:"none",backdropFilter:null!==(x=C.backdropFilter)&&void 0!==x?x:"none"}),o(M),M}(t));let m=null;if(e.addEventListener("mousemove",(o=>{m||(m=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),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),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)}}return window.initializeChart=c,e})()));
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export declare function getWrappedLines(ctx: CanvasRenderingContext2D, text: string, maxLineWidth: number, maxAllowedLines: number | "auto" | undefined, radius: number,
|
|
2
|
-
|
|
3
|
-
horizontalPadding?: number, verticalPadding?: number, lineHeightFactor?: number, fontWeight?: number, fontStyle?: "normal" | "italic" | "oblique", fontFamily?: string): string[];
|
|
1
|
+
export declare function getWrappedLines(ctx: CanvasRenderingContext2D, text: string, maxLineWidth: number, maxAllowedLines: number | "auto" | undefined, radius: number, fontSize?: number, // TODO : take all default values from constants
|
|
2
|
+
fontWeight?: number, fontStyle?: "normal" | "italic" | "oblique", fontFamily?: string, horizontalPadding?: number, verticalPadding?: number, lineHeightFactor?: number, maxCharsPerWord?: number | undefined): string[];
|
package/dist/utils/helper.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare function getFontSize(radius: number, fontSize?: number, fontWeight?: number): number;
|
|
1
|
+
export declare function getFontSize(radius: number, fontSize?: number, fontWeight?: number, avgCharsPerLine?: number): number;
|
|
2
|
+
export declare function isFontAvailable(font: string, fontSize?: string): boolean;
|
package/index.html
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
<meta charset="UTF-8">
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
7
|
<title>Bubble JS</title>
|
|
8
|
+
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
|
|
8
9
|
|
|
9
10
|
<!-- <script type="module" src="./dist/index.js"></script> -->
|
|
10
11
|
<script src="./dist/bubbleChart.umd.js" defer></script>
|
|
@@ -12,117 +13,76 @@
|
|
|
12
13
|
</head>
|
|
13
14
|
|
|
14
15
|
<body>
|
|
15
|
-
<div id="bubbleChart" style="width:
|
|
16
|
+
<div id="bubbleChart" style="width: 290px; height: 250px;border: 1px solid red;"></div>
|
|
16
17
|
<script>
|
|
18
|
+
const data = [
|
|
19
|
+
{
|
|
20
|
+
label: 'Rocket Fuel Orders',
|
|
21
|
+
value: 207,
|
|
22
|
+
bubbleColor: '#ff5733',
|
|
23
|
+
fontColor: '#FFFFFF',
|
|
24
|
+
fontWeight: 600,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
label: 'Time Machine Repairs',
|
|
28
|
+
value: 154,
|
|
29
|
+
bubbleColor: '#c70039',
|
|
30
|
+
fontColor: '#FFF',
|
|
31
|
+
fontWeight: 600,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
label: 'AI Overlord Complaints',
|
|
35
|
+
value: 192,
|
|
36
|
+
bubbleColor: '#900c3f',
|
|
37
|
+
fontColor: '#000',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
label: 'Quantum Internet Activation',
|
|
41
|
+
value: 73,
|
|
42
|
+
bubbleColor: '#ffc300',
|
|
43
|
+
fontColor: '#000',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
label: 'Zero-Gravity Plumbing Issues',
|
|
47
|
+
value: 96,
|
|
48
|
+
bubbleColor: '#4caf50',
|
|
49
|
+
fontColor: '#000',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
label: 'Hologram Tech Support',
|
|
53
|
+
value: 119,
|
|
54
|
+
bubbleColor: '#ff8c00',
|
|
55
|
+
fontColor: '#000',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
label: 'Teleportation Delay Reports',
|
|
59
|
+
value: 87,
|
|
60
|
+
bubbleColor: '#03875c',
|
|
61
|
+
fontColor: '#000',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
label: 'Neural Chip Upgrades',
|
|
65
|
+
value: 163,
|
|
66
|
+
bubbleColor: '#3f51b5',
|
|
67
|
+
fontColor: '#000',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
label: 'Intergalactic Toll Fees',
|
|
71
|
+
value: 132,
|
|
72
|
+
bubbleColor: '#795548',
|
|
73
|
+
fontColor: '#000',
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
|
|
17
77
|
document.addEventListener("DOMContentLoaded", function () {
|
|
18
78
|
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
|
-
// }
|
|
26
|
-
|
|
27
|
-
// const tooltipOptions = {
|
|
28
|
-
// fontStyle: 'italic',
|
|
29
|
-
// fontWeight: 800,
|
|
30
|
-
// textAlign: 'center',
|
|
31
|
-
// textDecoration: 'underline',
|
|
32
|
-
// textTransform: "uppercase",
|
|
33
|
-
// fontColor: '#FFF'
|
|
34
|
-
// }
|
|
35
|
-
|
|
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
|
-
// ];
|
|
48
|
-
|
|
49
|
-
// const chartoptions = {
|
|
50
|
-
// canvasContainerId: 'bubbleChart',
|
|
51
|
-
// data: data,
|
|
52
|
-
// fontSize: 14,
|
|
53
|
-
// maxLines: 2,
|
|
54
|
-
// tooltipOptions: tooltipOptions,
|
|
55
|
-
// }
|
|
56
|
-
|
|
57
|
-
const handleBubbleClick = (bubbleData, event) => {
|
|
58
|
-
console.log("Bubble clicked:", bubbleData);
|
|
59
|
-
alert(`You clicked on: ${bubbleData.label}`);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// Initialize chart
|
|
63
79
|
const chartOptions = {
|
|
64
80
|
canvasContainerId: 'bubbleChart',
|
|
65
|
-
data:
|
|
66
|
-
{
|
|
67
|
-
label: 'Activation of supply for Electricity and Water',
|
|
68
|
-
value: 307,
|
|
69
|
-
bubbleColor: '#024831',
|
|
70
|
-
fontColor: '#FFFFFF',
|
|
71
|
-
fontWeight: 600,
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
label: 'Reconnection',
|
|
75
|
-
value: 114,
|
|
76
|
-
bubbleColor: '#03714d',
|
|
77
|
-
fontColor: '#FFF',
|
|
78
|
-
fontWeight: 600,
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
label: 'Refund Request',
|
|
82
|
-
value: 92,
|
|
83
|
-
bubbleColor: '#03714d',
|
|
84
|
-
fontColor: '#000',
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
label: 'Request for Information Update',
|
|
88
|
-
value: 73,
|
|
89
|
-
bubbleColor: '#049e6b',
|
|
90
|
-
fontColor: '#000',
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
label: 'Supply Issues',
|
|
94
|
-
value: 96,
|
|
95
|
-
bubbleColor: '#31b086',
|
|
96
|
-
fontColor: '#000',
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
label: 'Smart Services',
|
|
100
|
-
value: 119,
|
|
101
|
-
bubbleColor: '#03875c',
|
|
102
|
-
fontColor: '#000',
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
label: 'High Consumption',
|
|
106
|
-
value: 87,
|
|
107
|
-
bubbleColor: '#03875c',
|
|
108
|
-
fontColor: '#000',
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
label: 'Billing Consumption',
|
|
112
|
-
value: 103,
|
|
113
|
-
bubbleColor: '#03875c',
|
|
114
|
-
fontColor: '#000',
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
label: 'Wrong Bill',
|
|
118
|
-
value: 92,
|
|
119
|
-
bubbleColor: '#03875c',
|
|
120
|
-
fontColor: '#000',
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
fontSize: 10,
|
|
81
|
+
data: data,
|
|
124
82
|
defaultFontFamily: 'Roboto',
|
|
125
|
-
onBubbleClick:
|
|
83
|
+
onBubbleClick: (bubbleData, event) => {
|
|
84
|
+
alert(`You clicked on: ${bubbleData.label}`);
|
|
85
|
+
},
|
|
126
86
|
tooltipOptions: {
|
|
127
87
|
// fontStyle: 'italic',
|
|
128
88
|
// fontWeight: 800,
|
|
@@ -134,6 +94,7 @@
|
|
|
134
94
|
}
|
|
135
95
|
|
|
136
96
|
|
|
97
|
+
initializeChart(chartOptions);
|
|
137
98
|
initializeChart(chartOptions);
|
|
138
99
|
} else {
|
|
139
100
|
console.error("initializeChart is not defined");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bubble-chart-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
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",
|