VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/libs/absol-full/dist/js/mdls__absol-vchart__src__PieChart.js
/*** module: node_modules/absol-vchart/src/PieChart.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 PieChart() {
  _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(PieChart, _BChart.default);

PieChart.property = Object.assign({}, _BChart.default.property);
PieChart.eventHandler = Object.assign({}, _BChart.default.eventHandler);
PieChart.tag = 'PieChart'.toLowerCase();

PieChart.render = function (data, o, dom) {
  return _BChart.default.render(data, o, dom).addClass('vc-piece-chart');
};

PieChart.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);
};

PieChart.eventHandler.mouseLeaveNote = function (idx) {
  var token = this.tooltipToken;
  if (!token) return;
  setTimeout(() => {
    (0, _ToolTip.closeTooltip)(token);
  }, 1000);
};

PieChart.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 + ''
      },
      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(function (piece) {
    var valueElt = _({
      tag: 'text',
      class: 'vc-piece-value',
      style: {
        fill: _Color.default.parse(piece.fillColor + '').getContrastYIQ()
      },
      child: {
        text: piece.valueText || piece.value || ''
      }
    });

    thisC.$pie.addChild(valueElt);
    return valueElt;
  });
};

PieChart.prototype.computeNotes = function () {
  return this.pieces.map(function (piece, i) {
    return {
      color: piece.fillColor,
      text: piece.name,
      type: 'rect',
      idx: i
    };
  });
};

PieChart.prototype.createContent = function () {
  _BChart.default.prototype.createContent.call(this);

  this._createPie();
};

PieChart.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 r = Math.min(this.$pieCtn.box.width - 5, this.$pieCtn.box.height - 5) / 2 * (1 - k / 150);
    var sr = Math.max(3, r / 15);

    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;

      if (piece.separated) {
        x0 += sr * Math.cos((startAngle + endAngle) / 2);
        y0 += sr * Math.sin((startAngle + endAngle) / 2);
      }

      pieceElt.begin();
      piePoly = [];

      if (piece.value < sum) {
        pieceElt.moveTo(x0, y0);
        pieceElt.lineTo(x0 + r * Math.cos(startAngle), y0 + r * Math.sin(startAngle));
        piePoly.push(new _Vec.default(x0, y0));
        piePoly.push(new _Vec.default(x0 + r * Math.cos(startAngle), y0 + r * Math.sin(startAngle)));
      } else {
        pieceElt.moveTo(x0 + r * Math.cos(startAngle), y0 + r * Math.sin(startAngle));
        piePoly.push(new _Vec.default(x0 + r * Math.cos(startAngle), y0 + r * Math.sin(startAngle)));
      }

      pieceElt.arcTo(x0 + r * Math.cos((startAngle + endAngle) / 2), y0 + r * Math.sin((startAngle + endAngle) / 2), r, r, 0, 1, 0).arcTo(x0 + r * Math.cos(endAngle), y0 + r * Math.sin(endAngle), r, r, 0, 1, 0).closePath().end();

      for (jj = 8; jj >= 0; --jj) {
        piePoly.push(new _Vec.default(x0 + r * Math.cos(startAngle * jj / 8 + endAngle * (8 - jj) / 8), y0 + r * Math.sin(startAngle * jj / 8 + endAngle * (8 - jj) / 8)));
      }

      valueBound = valueElt.getBBox();
      pieceBound = pieceElt.getBBox();

      if (piece.value === sum) {
        valueElt.attr({
          x: 0,
          y: 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;
    }
  }
};

PieChart.prototype.updateBodyPosition = function () {
  _BChart.default.prototype.updateBodyPosition.call(this);

  this._updatePiePosition();
};

PieChart.prototype.normalizeData = function () {
  var colorScheme = this.colorScheme;
  var blockColors = (0, _utils.isNaturalNumber)(colorScheme) ? (0, _SelectColorSchemeMenu.generatorColorScheme)(colorScheme, this.pieces.length) : (0, _helper.generateBackgroundColors)(this.pieces.length);
  this.pieces.forEach(function (piece, i) {
    piece.fillColor = piece.fillColor || blockColors[i];
  });
};

_VCore.default.install(PieChart);

var _default = PieChart;
exports.default = _default;

VaKeR 2022