bubble-chart-js 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  import { DataItemInfo } from "../models/internal/dataItemInfo";
2
- export declare function createTooltipElement(): HTMLDivElement;
2
+ export declare function createTooltipElement(canvasContainerId: string): HTMLDivElement;
3
3
  export declare function handleMouseMove(event: MouseEvent, data: DataItemInfo[], canvas: HTMLCanvasElement, tooltip: HTMLDivElement): void;
@@ -0,0 +1,7 @@
1
+ import { initializeChart } from "./services/chartService";
2
+ export { initializeChart };
3
+ declare global {
4
+ interface Window {
5
+ initializeChart: typeof initializeChart;
6
+ }
7
+ }
@@ -16,7 +16,7 @@
16
16
  \***********************/
17
17
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
18
18
 
19
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ createCanvas: () => (/* binding */ createCanvas)\n/* harmony export */ });\n/**\n * Creates and initializes the canvas inside the specified container.\n */\nfunction createCanvas(containerId) {\n const canvasContainer = document.getElementById(containerId);\n if (!canvasContainer) {\n console.error(`Canvas container with ID '${containerId}' not found.`);\n return null;\n }\n const canvas = document.createElement(\"canvas\");\n canvas.width = canvasContainer.offsetWidth;\n canvas.height = canvasContainer.offsetHeight;\n canvasContainer.appendChild(canvas);\n return canvas;\n}\n\n\n//# sourceURL=webpack://bubble-chart-js/./src/canvas.ts?");
19
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ createCanvas: () => (/* binding */ createCanvas)\n/* harmony export */ });\n/**\n * Creates and initializes the canvas inside the specified container.\n */\nfunction createCanvas(containerId) {\n const canvasContainer = document.getElementById(containerId);\n if (!canvasContainer) {\n console.error(`Canvas container with ID '${containerId}' not found.`);\n return null;\n }\n const canvas = document.createElement(\"canvas\");\n canvas.width = canvasContainer.offsetWidth;\n canvas.height = canvasContainer.offsetHeight;\n Object.assign(canvas.style, {\n border: \"1px solid #ddd\",\n background: \"#f8f8f8\",\n width: \"100%\",\n height: \"100%\",\n display: \"block\",\n imageRendering: \"crisp-edges\",\n aspectRatio: \"1 / 1\",\n });\n // Browser-specific image-rendering properties\n canvas.style.setProperty(\"image-rendering\", \"-moz-crisp-edges\");\n canvas.style.setProperty(\"image-rendering\", \"-webkit-optimize-contrast\");\n canvas.style.setProperty(\"-ms-interpolation-mode\", \"nearest-neighbor\");\n canvasContainer.appendChild(canvas);\n return canvas;\n}\n\n\n//# sourceURL=webpack://bubble-chart-js/./src/canvas.ts?");
20
20
 
21
21
  /***/ }),
22
22
 
@@ -36,7 +36,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
36
36
  \******************************/
37
37
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
38
38
 
39
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ renderChart: () => (/* binding */ renderChart)\n/* harmony export */ });\n/* harmony import */ var _features_textWrapper__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../features/textWrapper */ \"./src/features/textWrapper.ts\");\n/* harmony import */ var _features_tooltip__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../features/tooltip */ \"./src/features/tooltip.ts\");\n/* harmony import */ var _utils_validation__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils/validation */ \"./src/utils/validation.ts\");\n/* harmony import */ var _canvas__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../canvas */ \"./src/canvas.ts\");\n/* harmony import */ var _services_renderService__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../services/renderService */ \"./src/services/renderService.ts\");\n/* harmony import */ var _utils_helper__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../utils/helper */ \"./src/utils/helper.ts\");\n\n\n\n\n\n\nfunction renderChart(config) {\n if (!(0,_utils_validation__WEBPACK_IMPORTED_MODULE_2__.validateConfig)(config))\n return;\n // Create & setup canvas\n let canvas = (0,_canvas__WEBPACK_IMPORTED_MODULE_3__.createCanvas)(config.canvasContainerId);\n if (!canvas)\n return;\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) {\n console.error(\"Invalid context\");\n return;\n }\n const sortedData = (0,_services_renderService__WEBPACK_IMPORTED_MODULE_4__.getChartData)(config, canvas, ctx);\n function draw() {\n if (!canvas || !ctx) {\n console.warn(\"canvas or ctx is not valid\");\n return;\n }\n ctx.clearRect(0, 0, canvas.width, canvas.height);\n sortedData.forEach((item) => {\n const color = config.colorMap[item.label] || config.defaultBubbleColor;\n // Ensure radius is at least minRadius\n const radius = Math.max(item.radius, config.minRadius);\n ctx.beginPath();\n ctx.arc(item.x, item.y, radius, 0, Math.PI * 2);\n ctx.fillStyle = color;\n ctx.fill();\n ctx.strokeStyle = \"black\"; // Border color\n ctx.lineWidth = 0.25; // Border thickness\n ctx.stroke(); // Apply border\n // Text styling\n ctx.fillStyle = config.fontColor;\n const fontSize = (0,_utils_helper__WEBPACK_IMPORTED_MODULE_5__.getFontSize)(radius, config.fontSize);\n ctx.font = `${fontSize}px ${config.fontFamily}`;\n ctx.textAlign = \"center\";\n ctx.textBaseline = \"middle\";\n const padding = 5; // Padding around text\n const maxWidth = radius * 1.5 - padding * 2; // Adjusted for padding\n if (config.textWrap) {\n // Calculate vertical position for lines\n const lineHeight = fontSize * 1.2;\n // Dynamically determine lines if maxLines is not set\n const lines = (0,_features_textWrapper__WEBPACK_IMPORTED_MODULE_0__.getWrappedLines)(ctx, item.label, maxWidth, config.maxLines, radius);\n const startY = item.y - ((lines.length - 1) * lineHeight) / 2;\n lines.forEach((line, index) => {\n ctx.fillText(line, item.x, startY + index * lineHeight);\n });\n }\n else {\n ctx.fillText(item.label, item.x, item.y);\n }\n });\n }\n // Robust approach that handles resizing:\n function resizeCanvas() {\n const canvasContainer = document.getElementById(config.canvasContainerId);\n if (canvasContainer && canvas) {\n canvas.width = canvasContainer.offsetWidth;\n canvas.height = canvasContainer.offsetHeight;\n draw(); // Call your drawing function\n }\n }\n if (config.isResizeCanvasOnWindowSizeChange) {\n resizeCanvas(); // Initial resize\n window.addEventListener(\"resize\", resizeCanvas); // Resize on window resize\n }\n // Initial draw\n draw();\n if (config.showToolTip) {\n const tooltip = (0,_features_tooltip__WEBPACK_IMPORTED_MODULE_1__.createTooltipElement)();\n let animationFrameId = null;\n canvas.addEventListener(\"mousemove\", (event) => {\n if (animationFrameId)\n return; // Prevent excessive calls\n animationFrameId = requestAnimationFrame(() => {\n (0,_features_tooltip__WEBPACK_IMPORTED_MODULE_1__.handleMouseMove)(event, sortedData, canvas, tooltip);\n animationFrameId = null; // Reset after execution\n });\n });\n }\n}\n\n\n//# sourceURL=webpack://bubble-chart-js/./src/core/renderer.ts?");
39
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ renderChart: () => (/* binding */ renderChart)\n/* harmony export */ });\n/* harmony import */ var _features_textWrapper__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../features/textWrapper */ \"./src/features/textWrapper.ts\");\n/* harmony import */ var _features_tooltip__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../features/tooltip */ \"./src/features/tooltip.ts\");\n/* harmony import */ var _utils_validation__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils/validation */ \"./src/utils/validation.ts\");\n/* harmony import */ var _canvas__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../canvas */ \"./src/canvas.ts\");\n/* harmony import */ var _services_renderService__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../services/renderService */ \"./src/services/renderService.ts\");\n/* harmony import */ var _utils_helper__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../utils/helper */ \"./src/utils/helper.ts\");\n\n\n\n\n\n\nfunction renderChart(config) {\n if (!(0,_utils_validation__WEBPACK_IMPORTED_MODULE_2__.validateConfig)(config))\n return;\n // Create & setup canvas\n let canvas = (0,_canvas__WEBPACK_IMPORTED_MODULE_3__.createCanvas)(config.canvasContainerId);\n if (!canvas)\n return;\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) {\n console.error(\"Invalid context\");\n return;\n }\n const sortedData = (0,_services_renderService__WEBPACK_IMPORTED_MODULE_4__.getChartData)(config, canvas, ctx);\n function draw() {\n if (!canvas || !ctx) {\n console.warn(\"canvas or ctx is not valid\");\n return;\n }\n ctx.clearRect(0, 0, canvas.width, canvas.height);\n sortedData.forEach((item) => {\n const color = config.colorMap[item.label] || config.defaultBubbleColor;\n // Ensure radius is at least minRadius\n const radius = Math.max(item.radius, config.minRadius);\n ctx.beginPath();\n ctx.arc(item.x, item.y, radius, 0, Math.PI * 2);\n ctx.fillStyle = color;\n ctx.fill();\n ctx.strokeStyle = \"black\"; // Border color\n ctx.lineWidth = 0.25; // Border thickness\n ctx.stroke(); // Apply border\n // Text styling\n ctx.fillStyle = config.fontColor;\n const fontSize = (0,_utils_helper__WEBPACK_IMPORTED_MODULE_5__.getFontSize)(radius, config.fontSize);\n ctx.font = `${fontSize}px ${config.fontFamily}`;\n ctx.textAlign = \"center\";\n ctx.textBaseline = \"middle\";\n const padding = 5; // Padding around text\n const maxWidth = radius * 1.5 - padding * 2; // Adjusted for padding\n if (config.textWrap) {\n // Calculate vertical position for lines\n const lineHeight = fontSize * 1.2;\n // Dynamically determine lines if maxLines is not set\n const lines = (0,_features_textWrapper__WEBPACK_IMPORTED_MODULE_0__.getWrappedLines)(ctx, item.label, maxWidth, config.maxLines, radius);\n const startY = item.y - ((lines.length - 1) * lineHeight) / 2;\n lines.forEach((line, index) => {\n ctx.fillText(line, item.x, startY + index * lineHeight);\n });\n }\n else {\n ctx.fillText(item.label, item.x, item.y);\n }\n });\n }\n // Robust approach that handles resizing:\n function resizeCanvas() {\n const canvasContainer = document.getElementById(config.canvasContainerId);\n if (canvasContainer && canvas) {\n canvas.width = canvasContainer.offsetWidth;\n canvas.height = canvasContainer.offsetHeight;\n draw(); // Call your drawing function\n }\n }\n if (config.isResizeCanvasOnWindowSizeChange) {\n resizeCanvas(); // Initial resize\n window.addEventListener(\"resize\", resizeCanvas); // Resize on window resize\n }\n // Initial draw\n draw();\n if (config.showToolTip) {\n const tooltip = (0,_features_tooltip__WEBPACK_IMPORTED_MODULE_1__.createTooltipElement)(config.canvasContainerId);\n let animationFrameId = null;\n canvas.addEventListener(\"mousemove\", (event) => {\n if (animationFrameId)\n return; // Prevent excessive calls\n animationFrameId = requestAnimationFrame(() => {\n (0,_features_tooltip__WEBPACK_IMPORTED_MODULE_1__.handleMouseMove)(event, sortedData, canvas, tooltip);\n animationFrameId = null; // Reset after execution\n });\n });\n }\n}\n\n\n//# sourceURL=webpack://bubble-chart-js/./src/core/renderer.ts?");
40
40
 
41
41
  /***/ }),
42
42
 
@@ -56,17 +56,17 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
56
56
  \*********************************/
57
57
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
58
58
 
59
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ createTooltipElement: () => (/* binding */ createTooltipElement),\n/* harmony export */ handleMouseMove: () => (/* binding */ handleMouseMove)\n/* harmony export */ });\n// let hoveredItem: DataItemInfo | null = null;\nfunction createTooltipElement() {\n const tooltip = document.createElement(\"div\");\n tooltip.id = \"tooltip\";\n tooltip.style.display = \"none\";\n document.body.appendChild(tooltip);\n return tooltip;\n}\nfunction handleMouseMove(event, data, canvas, tooltip) {\n const { mouseX, mouseY } = getMousePosition(event, canvas);\n const hoveredItem = findHoveredItem(mouseX, mouseY, data);\n if (hoveredItem) {\n updateTooltip(event, hoveredItem, canvas, tooltip);\n }\n else {\n canvas.style.cursor = \"default\";\n tooltip.style.display = \"none\";\n }\n}\n/**\n * Gets the mouse position relative to the canvas.\n */\nfunction getMousePosition(event, canvas) {\n const rect = canvas.getBoundingClientRect();\n return {\n mouseX: event.clientX - rect.left,\n mouseY: event.clientY - rect.top,\n };\n}\n/**\n * Finds the hovered item based on proximity to circles.\n */\nfunction findHoveredItem(mouseX, mouseY, data) {\n return (data.find((item) => Math.hypot(mouseX - item.x, mouseY - item.y) < item.radius) || null);\n}\n/**\n * Updates the tooltip and cursor based on the hovered item.\n */\nfunction updateTooltip(event, hovered, canvas, tooltip) {\n if ((hovered === null || hovered === void 0 ? void 0 : hovered.label) && (hovered === null || hovered === void 0 ? void 0 : hovered.value) && canvas && tooltip) {\n canvas.style.cursor = \"pointer\";\n tooltip.style.display = \"block\";\n tooltip.innerHTML = `<div>${hovered.label}<br>Value: ${hovered.value}</div>`;\n tooltip.style.left = `${event.pageX + 15}px`;\n tooltip.style.top = `${event.pageY - 30}px`;\n tooltip.style.zIndex = \"9999\";\n }\n}\n\n\n//# sourceURL=webpack://bubble-chart-js/./src/features/tooltip.ts?");
59
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ createTooltipElement: () => (/* binding */ createTooltipElement),\n/* harmony export */ handleMouseMove: () => (/* binding */ handleMouseMove)\n/* harmony export */ });\n// let hoveredItem: DataItemInfo | null = null;\nfunction createTooltipElement(canvasContainerId) {\n const tooltip = document.createElement(\"div\");\n tooltip.id = \"tooltip\";\n tooltip.style.display = \"none\";\n // Apply styles\n Object.assign(tooltip.style, {\n position: \"absolute\",\n padding: \"8px\",\n background: \"rgba(0, 0, 0, 0.85)\",\n color: \"white\",\n borderRadius: \"4px\",\n pointerEvents: \"none\",\n fontFamily: \"Arial, sans-serif\",\n fontSize: \"14px\",\n maxWidth: \"200px\",\n transition: \"opacity 0.2s\",\n });\n if (canvasContainerId) {\n const canvasContainer = document.getElementById(canvasContainerId);\n if (canvasContainer) {\n canvasContainer.appendChild(tooltip);\n return tooltip;\n }\n }\n document.body.appendChild(tooltip);\n return tooltip;\n}\nfunction handleMouseMove(event, data, canvas, tooltip) {\n const { mouseX, mouseY } = getMousePosition(event, canvas);\n const hoveredItem = findHoveredItem(mouseX, mouseY, data);\n if (hoveredItem) {\n updateTooltip(event, hoveredItem, canvas, tooltip);\n }\n else {\n canvas.style.cursor = \"default\";\n tooltip.style.display = \"none\";\n }\n}\n/**\n * Gets the mouse position relative to the canvas.\n */\nfunction getMousePosition(event, canvas) {\n const rect = canvas.getBoundingClientRect();\n return {\n mouseX: event.clientX - rect.left,\n mouseY: event.clientY - rect.top,\n };\n}\n/**\n * Finds the hovered item based on proximity to circles.\n */\nfunction findHoveredItem(mouseX, mouseY, data) {\n return (data.find((item) => Math.hypot(mouseX - item.x, mouseY - item.y) < item.radius) || null);\n}\n/**\n * Updates the tooltip and cursor based on the hovered item.\n */\nfunction updateTooltip(event, hovered, canvas, tooltip) {\n if ((hovered === null || hovered === void 0 ? void 0 : hovered.label) && (hovered === null || hovered === void 0 ? void 0 : hovered.value) && canvas && tooltip) {\n canvas.style.cursor = \"pointer\";\n tooltip.style.display = \"block\";\n tooltip.innerHTML = `<div>${hovered.label}<br>Value: ${hovered.value}</div>`;\n tooltip.style.left = `${event.pageX + 15}px`;\n tooltip.style.top = `${event.pageY - 30}px`;\n tooltip.style.zIndex = \"9999\";\n }\n}\n\n\n//# sourceURL=webpack://bubble-chart-js/./src/features/tooltip.ts?");
60
60
 
61
61
  /***/ }),
62
62
 
63
- /***/ "./src/main.ts":
64
- /*!*********************!*\
65
- !*** ./src/main.ts ***!
66
- \*********************/
63
+ /***/ "./src/index.ts":
64
+ /*!**********************!*\
65
+ !*** ./src/index.ts ***!
66
+ \**********************/
67
67
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
68
68
 
69
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _services_chartService__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./services/chartService */ \"./src/services/chartService.ts\");\n\n// export { initializeChart };\n// @ts-ignore (Ignore TypeScript error for missing window prop)\nwindow.initializeChart = _services_chartService__WEBPACK_IMPORTED_MODULE_0__.initializeChart;\n\n\n//# sourceURL=webpack://bubble-chart-js/./src/main.ts?");
69
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ initializeChart: () => (/* reexport safe */ _services_chartService__WEBPACK_IMPORTED_MODULE_0__.initializeChart)\n/* harmony export */ });\n/* harmony import */ var _services_chartService__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./services/chartService */ \"./src/services/chartService.ts\");\n\n// Explicitly export for TypeScript\n\n// Assign to `window`\nwindow.initializeChart = _services_chartService__WEBPACK_IMPORTED_MODULE_0__.initializeChart;\n\n\n//# sourceURL=webpack://bubble-chart-js/./src/index.ts?");
70
70
 
71
71
  /***/ }),
72
72
 
@@ -180,7 +180,8 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
180
180
  /******/ // startup
181
181
  /******/ // Load entry module and return exports
182
182
  /******/ // This entry module can't be inlined because the eval devtool is used.
183
- /******/ var __webpack_exports__ = __webpack_require__("./src/main.ts");
183
+ /******/ var __webpack_exports__ = __webpack_require__("./src/index.ts");
184
+ /******/ module.exports = __webpack_exports__;
184
185
  /******/
185
186
  /******/ })()
186
187
  ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bubble-chart-js",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
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/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/canvas.ts CHANGED
@@ -11,6 +11,22 @@ export function createCanvas(containerId: string): HTMLCanvasElement | null {
11
11
  const canvas = document.createElement("canvas") as HTMLCanvasElement;
12
12
  canvas.width = canvasContainer.offsetWidth;
13
13
  canvas.height = canvasContainer.offsetHeight;
14
+
15
+ Object.assign(canvas.style, {
16
+ border: "1px solid #ddd",
17
+ background: "#f8f8f8",
18
+ width: "100%",
19
+ height: "100%",
20
+ display: "block",
21
+ imageRendering: "crisp-edges",
22
+ aspectRatio: "1 / 1",
23
+ });
24
+
25
+ // Browser-specific image-rendering properties
26
+ canvas.style.setProperty("image-rendering", "-moz-crisp-edges");
27
+ canvas.style.setProperty("image-rendering", "-webkit-optimize-contrast");
28
+ canvas.style.setProperty("-ms-interpolation-mode", "nearest-neighbor");
29
+
14
30
  canvasContainer.appendChild(canvas);
15
31
 
16
32
  return canvas;
@@ -97,7 +97,7 @@ export function renderChart(config: Configuration) {
97
97
  draw();
98
98
 
99
99
  if (config.showToolTip) {
100
- const tooltip = createTooltipElement();
100
+ const tooltip = createTooltipElement(config.canvasContainerId);
101
101
  let animationFrameId: number | null = null;
102
102
  canvas.addEventListener("mousemove", (event) => {
103
103
  if (animationFrameId) return; // Prevent excessive calls
@@ -0,0 +1 @@
1
+ declare module "bubble-chart-js";
@@ -2,10 +2,36 @@ import { DataItemInfo } from "../models/internal/dataItemInfo";
2
2
 
3
3
  // let hoveredItem: DataItemInfo | null = null;
4
4
 
5
- export function createTooltipElement(): HTMLDivElement {
5
+ export function createTooltipElement(
6
+ canvasContainerId: string
7
+ ): HTMLDivElement {
6
8
  const tooltip = document.createElement("div") as HTMLDivElement;
7
9
  tooltip.id = "tooltip";
8
10
  tooltip.style.display = "none";
11
+
12
+ // Apply styles
13
+ Object.assign(tooltip.style, {
14
+ position: "absolute",
15
+ padding: "8px",
16
+ background: "rgba(0, 0, 0, 0.85)",
17
+ color: "white",
18
+ borderRadius: "4px",
19
+ pointerEvents: "none",
20
+ fontFamily: "Arial, sans-serif",
21
+ fontSize: "14px",
22
+ maxWidth: "200px",
23
+ transition: "opacity 0.2s",
24
+ });
25
+
26
+ if (canvasContainerId) {
27
+ const canvasContainer = document.getElementById(
28
+ canvasContainerId
29
+ ) as HTMLDivElement;
30
+ if (canvasContainer) {
31
+ canvasContainer.appendChild(tooltip);
32
+ return tooltip;
33
+ }
34
+ }
9
35
  document.body.appendChild(tooltip);
10
36
  return tooltip;
11
37
  }
package/src/index.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { initializeChart } from "./services/chartService";
2
+
3
+ // Explicitly export for TypeScript
4
+ export { initializeChart };
5
+
6
+ // Declare the global `window` property correctly
7
+ declare global {
8
+ interface Window {
9
+ initializeChart: typeof initializeChart;
10
+ }
11
+ }
12
+
13
+ // Assign to `window`
14
+ window.initializeChart = initializeChart;
package/tsconfig.json CHANGED
@@ -3,12 +3,14 @@
3
3
  "target": "ES6",
4
4
  "module": "ESNext",
5
5
  "declaration": true,
6
+ "declarationDir": "./dist",
6
7
  "outDir": "./dist",
7
8
  "rootDir": "./src",
8
9
  "strict": true,
9
10
  "esModuleInterop": true,
10
11
  "skipLibCheck": true,
11
- "forceConsistentCasingInFileNames": true
12
+ "forceConsistentCasingInFileNames": true,
13
+ "allowSyntheticDefaultImports": true
12
14
  },
13
15
  "include": ["src/**/*"],
14
16
  "exclude": ["node_modules", "**/*.test.ts"]
package/webpack.config.js CHANGED
@@ -1,10 +1,11 @@
1
1
  const path = require("path");
2
2
 
3
3
  module.exports = {
4
- entry: "./src/main.ts", // Entry point for your application
4
+ entry: "./src/index.ts", // Entry point for your application
5
5
  output: {
6
- filename: "bundle.js", // Output bundle file
6
+ filename: "index.js", // Change from bundle.js to index.js
7
7
  path: path.resolve(__dirname, "dist"), // Output directory
8
+ libraryTarget: "commonjs2", // Ensure it's exportable as an npm package
8
9
  },
9
10
  resolve: {
10
11
  extensions: [".ts", ".js"], // Resolve TypeScript and JavaScript files
package/dist/main.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/src/main.ts DELETED
@@ -1,5 +0,0 @@
1
- import { initializeChart } from "./services/chartService";
2
-
3
- // export { initializeChart };
4
- // @ts-ignore (Ignore TypeScript error for missing window prop)
5
- window.initializeChart = initializeChart as any;