![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/html/libs/absol-full/dist/js/ |
Upload File : |
/*** module: node_modules/absol-vchart/src/DoughnutChart.js ***/ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _VCore = _interopRequireDefault(require("./VCore")); var _Color = _interopRequireDefault(require("absol/src/Color/Color")); var _helper = require("./helper"); require("./style/piechart.css"); var _BChart = _interopRequireDefault(require("./BChart")); var _OOP = _interopRequireDefault(require("absol/src/HTML5/OOP")); var _Vec = _interopRequireDefault(require("absol/src/Math/Vec2")); var _Rectangle = _interopRequireDefault(require("absol/src/Math/Rectangle")); var _Polygon = _interopRequireDefault(require("absol/src/Math/Polygon")); var _ToolTip = require("./ToolTip"); var _utils = require("absol-acomp/js/utils"); var _SelectColorSchemeMenu = require("absol-acomp/js/colorpicker/SelectColorSchemeMenu"); var _ = _VCore.default._; var $ = _VCore.default.$; /*** * @typedef VCPiece * @property {string} name * @property {number} value * @property {string} valueText * @property {string} fillColor * @property {boolean} separated */ /*** * @extends BChart * @constructor */ function DoughnutChart() { _BChart.default.call(this); this.titleCtrl.revokeResource(); delete this.titleCtrl; this.$pieCtn = this.$body; this.$pie = _('gcontainer'); this.$pieCtn.addChild(this.$pie); /*** * * @type {VCPiece[]} */ this.pieces = []; } _OOP.default.mixClass(DoughnutChart, _BChart.default); DoughnutChart.property = Object.assign({}, _BChart.default.property); DoughnutChart.eventHandler = Object.assign({}, _BChart.default.eventHandler); DoughnutChart.prototype.dataKeys = _BChart.default.prototype.dataKeys.concat(['pieces']); DoughnutChart.tag = 'DoughnutChart'.toLowerCase(); DoughnutChart.render = function (data, o, dom) { return _BChart.default.render(data, o, dom).addClass('vc-piece-chart'); }; DoughnutChart.eventHandler.mouseEnterNote = function (idx, event) { var pieceElt = this.$pieces[idx]; var textValueElt = this.$pieceValues[idx]; var title = pieceElt.attr('title'); if (!title) { if (this.tooltipToken) (0, _ToolTip.closeTooltip)(this.tooltipToken); return; } var bound = textValueElt.getBoundingClientRect(); this.tooltipToken = (0, _ToolTip.showTooltip)(title, bound.left - 3, bound.top + bound.height + 3); }; DoughnutChart.eventHandler.mouseLeaveNote = function (idx) { var token = this.tooltipToken; if (!token) return; setTimeout(() => { if (token) (0, _ToolTip.closeTooltip)(token); }, 1000); }; DoughnutChart.prototype._createPie = function () { this.$pie.clearChild(); var thisC = this; this.$pieces = this.pieces.map((piece, idx) => { var pieceElt = _({ tag: 'shape', class: 'vc-piece', style: { fill: (piece.fillColor || this.blockColors[idx]) + '' }, attr: { title: piece.name + ': ' + (piece.valueText || piece.value) }, on: { mouseenter: event => { this.eventHandler.mouseEnterNote(idx, event); }, mouseleave: event => { this.eventHandler.mouseLeaveNote(idx, event); } } }); thisC.$pie.addChild(pieceElt); return pieceElt; }); this.$pieceValues = this.pieces.map((piece, idx) => { var valueElt = _({ tag: 'text', class: 'vc-piece-value', style: { fill: _Color.default.parse((piece.fillColor || this.blockColors[idx]) + '').getContrastYIQ() }, child: { text: piece.valueText || piece.value || '' } }); thisC.$pie.addChild(valueElt); return valueElt; }); }; DoughnutChart.prototype.computeNotes = function () { return this.pieces.map((piece, i) => { return { color: piece.fillColor || this.blockColors[i], text: piece.name, type: 'rect', idx: i }; }); }; DoughnutChart.prototype.createContent = function () { _BChart.default.prototype.createContent.call(this); this._createPie(); }; DoughnutChart.prototype._updatePiePosition = function () { var piece, pieceElt; var sum = this.pieces.reduce(function (ac, cr) { return ac + cr.value; }, 0); this.$pieCenter = _({ tag: 'circle', attr: { cx: 0, cy: 0, r: 1 }, style: { fill: 'transparent' } }); this.$pie.addChild(this.$pieCenter); var pieCenterBound = this.$pieCenter.getBBox(); var piePoly, jj, textRect, canContain; for (var k = 0; k < 50; ++k) { var startAngle = -Math.PI / 2; var endAngle = 0; var valueElt; var valueBound, pieceBound; var x0, y0; var cp, p0; var r = Math.min(this.$pieCtn.box.width - 5, this.$pieCtn.box.height - 5) / 2 * (1 - k / 150); var ri = r * 4 / 9; var sr = Math.max(3, r / 15); var makeVec = (r, angle) => new _Vec.default(r * Math.cos(angle), r * Math.sin(angle)); for (var i = 0; i < this.pieces.length; ++i) { piece = this.pieces[i]; pieceElt = this.$pieces[i]; valueElt = this.$pieceValues[i]; if (piece.value === 0) { pieceElt.addStyle('display', 'none'); valueElt.addStyle('display', 'none'); } else { pieceElt.removeStyle('display'); valueElt.removeStyle('display'); } endAngle = startAngle + Math.PI * 2 * piece.value / sum; x0 = 0; y0 = 0; p0 = new _Vec.default(x0, y0); if (piece.separated) { p0 = p0.add(makeVec(sr, (startAngle + endAngle) / 2)); x0 = p0.x; y0 = p0.y; } pieceElt.begin(); piePoly = []; cp = p0.add(makeVec(r, startAngle)); pieceElt.moveTo(cp.x, cp.y); piePoly.push(cp); cp = p0.add(makeVec(r, (startAngle + endAngle) / 2)); pieceElt.arcTo(cp.x, cp.y, r, r, 0, 1, 0); cp = p0.add(makeVec(r, endAngle)); pieceElt.arcTo(cp.x, cp.y, r, r, 0, 1, 0); for (jj = 8; jj >= 0; --jj) { piePoly.push(p0.add(makeVec(r, startAngle * jj / 8 + endAngle * (8 - jj) / 8))); } cp = p0.add(makeVec(ri, endAngle)); if (piece.value < sum) { pieceElt.lineTo(cp.x, cp.y); } else { pieceElt.closePath(); pieceElt.moveTo(cp.x, cp.y); } cp = p0.add(makeVec(ri, (startAngle + endAngle) / 2)); pieceElt.arcTo(cp.x, cp.y, ri, ri, 0, 0, 1); cp = p0.add(makeVec(ri, startAngle)); pieceElt.arcTo(cp.x, cp.y, ri, ri, 0, 0, 1); for (jj = 0; jj <= 8; ++jj) { piePoly.push(p0.add(makeVec(ri, startAngle * jj / 8 + endAngle * (8 - jj) / 8))); } pieceElt.closePath().end(); valueBound = valueElt.getBBox(); pieceBound = pieceElt.getBBox(); if (piece.value === sum) { valueElt.attr({ x: x0 + (r - 20 - valueBound.width / 2) * Math.cos(-Math.PI / 2), y: y0 + (r - 20 - valueBound.height / 2) * Math.sin(-Math.PI / 2) + 7 }); valueElt.removeStyle('visibility'); } else { valueElt.attr({ x: x0 + (r - 20 - valueBound.width / 2) * Math.cos((startAngle + endAngle) / 2), y: y0 + (r - 20 - valueBound.height / 2) * Math.sin((startAngle + endAngle) / 2) + 7 }); textRect = new _Rectangle.default(x0 + (r - 20 - valueBound.width / 2) * Math.cos((startAngle + endAngle) / 2) - valueBound.width / 2, y0 + (r - 20 - valueBound.height / 2) * Math.sin((startAngle + endAngle) / 2) + 7 - valueBound.height, valueBound.width, valueBound.height); piePoly = new _Polygon.default(piePoly); canContain = [textRect.A(), textRect.B(), textRect.C(), textRect.D()].every(v => piePoly.pointLocalIn(v) > 0); if (canContain) { valueElt.removeStyle('visibility'); } else { valueElt.addStyle('visibility', 'hidden'); } } startAngle = endAngle; } var piePound = this.$pie.getBBox(); if (piePound.width < this.$pieCtn.box.width && piePound.height < this.$pieCtn.box.height) { this.$pie.box.setPosition(this.$pieCtn.box.width / 2 - (piePound.width / 2 - (pieCenterBound.x + 1 - piePound.x)), this.$pieCtn.box.height / 2 - (piePound.height / 2 - (pieCenterBound.y + 1 - piePound.y))); break; } } }; DoughnutChart.prototype.updateBodyPosition = function () { _BChart.default.prototype.updateBodyPosition.call(this); this._updatePiePosition(); }; DoughnutChart.prototype.normalizeData = function () { var colorScheme = this.colorScheme; this.blockColors = (0, _utils.isNaturalNumber)(colorScheme) ? (0, _SelectColorSchemeMenu.generatorColorScheme)(colorScheme, this.pieces.length) : (0, _helper.generateBackgroundColors)(this.pieces.length); }; _VCore.default.install(DoughnutChart); var _default = DoughnutChart; exports.default = _default;