UNPKG

@trap_stevo/legendarybuilderproreact-ui

Version:

The legendary UI & utility API that makes your application a legendary application. ~ Created by Steven Compton

61 lines (58 loc) 1.97 kB
/* Created by Hassan Steven Compton. March 7, 2024. */ import React, { useRef, useEffect } from 'react'; import { HUDUniversalHUDUtilityManager } from "../HUDManagers/HUDUniversalHUDUtilityManager.js"; import Chart from 'chart.js/auto'; function BarChart(_ref) { var _ref$barChartContaine = _ref.barChartContainerConfigurationSettings, barChartContainerConfigurationSettings = _ref$barChartContaine === void 0 ? {} : _ref$barChartContaine, _ref$barColors = _ref.barColors, barColors = _ref$barColors === void 0 ? null : _ref$barColors, _ref$options = _ref.options, options = _ref$options === void 0 ? null : _ref$options, updateGraph = _ref.updateGraph, dataLabel = _ref.dataLabel, barPoints = _ref.barPoints, labels = _ref.labels, data = _ref.data; var chartRef = useRef(null); useEffect(function () { if (updateGraph) { var barChartRef = chartRef.current.getContext("2d"); var backgroundColors = !barColors ? HUDUniversalHUDUtilityManager.GenerateBackgroundColors(barPoints.length) : barColors; if (window.barChart instanceof Chart) { window.barChart.destroy(); } window.barChart = new Chart(barChartRef, { type: 'bar', data: data || { labels: labels, datasets: [{ label: dataLabel, data: barPoints, backgroundColor: backgroundColors, borderColor: backgroundColors, borderWidth: 1 }] }, options: options || { scales: { y: { beginAtZero: true } } } }); } return function () {}; }, [updateGraph, labels, dataLabel, barPoints, data, barColors, options]); return /*#__PURE__*/React.createElement("div", { style: barChartContainerConfigurationSettings }, /*#__PURE__*/React.createElement("canvas", { ref: chartRef })); } ; export default BarChart;