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-acomp__js__TreeChart.js
/*** module: node_modules/absol-acomp/js/TreeChart.js ***/
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

require("../css/treechart.css");

var _ACore = _interopRequireWildcard(require("../ACore"));

var _generator = require("absol/src/JSMaker/generator");

var _ResizeSystem = _interopRequireDefault(require("absol/src/HTML5/ResizeSystem"));

var _utils = require("./utils");

var _Color = _interopRequireDefault(require("absol/src/Color/Color"));

var _DomSignal = _interopRequireDefault(require("absol/src/HTML5/DomSignal"));




function autoThemeVariable(viewElt) {
  var cp = getComputedStyle(document.body);
  var color = cp.getPropertyValue('--menu-background-color') || cp.getPropertyValue('--variant-color-primary') || 'blue';
  color = _Color.default.parse(color.trim());
  var hsla = color.toHSLA();
  hsla[2] = (hsla[2] + 1) / 2;
  hsla[1] = (hsla[1] + 0.2) / 2;

  var nColor = _Color.default.fromHSLA(hsla[0], hsla[1], hsla[2], hsla[3]);

  viewElt.addStyle('--vert-node-background-color', nColor.toString('rgba'));
  nColor = nColor.getContrastYIQ();
  viewElt.addStyle('--vert-node-text-color', nColor.toString('rgba'));
  hsla[0] += 0.1;
  if (hsla[0] > 1) hsla[0] -= 1;
  nColor = _Color.default.fromHSLA(hsla[0], hsla[1], hsla[2], hsla[3]);
  viewElt.addStyle('--horz-node-background-color', nColor.toString('rgba'));
  nColor = nColor.getContrastYIQ();
  viewElt.addStyle('--horz-node-text-color', nColor.toString('rgba'));
  hsla[0] -= 0.2;
  if (hsla[0] < 0) hsla[0] += 1;
  nColor = _Color.default.fromHSLA(hsla[0], hsla[1], hsla[2], hsla[3]);
  viewElt.addStyle('--root-background-color', nColor.toString('rgba'));
  nColor = nColor.getContrastYIQ();
  viewElt.addStyle('--root-text-color', nColor.toString('rgba'));
}
/***
 * @extends AElement
 * @constructor
 */


function TreeChart() {
  // autoThemeVariable(this);
  this.$domSignal = (0, _ACore._)('attachhook').addTo(this);
  this.domSignal = new _DomSignal.default(this.$domSignal);
  this.domSignal.on('formatSize', this._formatSize.bind(this));
  this.domSignal.on('fixWidth', this._fixWidth.bind(this));
  this.$root = null;
  this._maxHorizonLevel = 2;
  /***
   * @name data
   * @type {any}
   * @memberOf TreeChart#
   */

  /***
   * @name maxHorizonLevel
   * @type {number}
   * @memberOf TreeChart#
   */
}

TreeChart.tag = 'TreeChart';

TreeChart.render = function () {
  return (0, _ACore._)({
    class: 'as-tree-chart'
  });
};

TreeChart.prototype._updateContent = function () {
  if (this.$root) {
    this.$root.remove();
    this.$root = null;
  }

  var data = this.data;
  if (!data) return;

  var makeTree = (nodeData, level) => {
    var textChildren = [];

    if (nodeData.icon) {
      textChildren.push((0, _ACore._)(nodeData.icon).addClass('as-tree-chart-icon'));
    }

    textChildren.push({
      tag: 'span',
      class: 'as-tree-chart-text',
      child: {
        text: nodeData.text || nodeData.name
      }
    });
    var elt = (0, _ACore._)({
      class: 'as-tree-chart-node',
      attr: {
        "data-level": level + ''
      },
      child: [{
        class: 'as-tree-chart-content-ctn',
        child: {
          class: 'as-tree-chart-content',
          child: textChildren
        }
      }, {
        class: 'as-tree-chart-child-ctn'
      }]
    });
    elt.$content = (0, _ACore.$)('.as-tree-chart-content', elt);
    elt.$childCtn = (0, _ACore.$)('.as-tree-chart-child-ctn', elt);
    var fillColor, textColor;

    if (typeof nodeData.fill === "string") {
      fillColor = _Color.default.parse(nodeData.fill);
    } else if (nodeData.fill instanceof _Color.default) {
      fillColor = nodeData.fill;
    }

    if (fillColor) {
      textColor = fillColor.getContrastYIQ();
      elt.$content.addStyle({
        color: textColor.toString('hex8'),
        backgroundColor: fillColor.toString('hex8')
      });
    }

    if (level === this.maxHorizonLevel) elt.addClass('as-horizontal');
    if (nodeData.isLeaf) elt.addClass('as-is-leaf');

    if (nodeData.items && nodeData.items.length > 0) {
      elt.addClass('as-has-children');
      /***
       * @type {AElement[]}
       */

      elt.$children = nodeData.items.map(it => makeTree(it, level + 1));
      elt.$childCtn.addChild(elt.$children);
    }

    return elt;
  };

  this.$root = makeTree(data, 0).addTo(this);
  this.domSignal.emit('formatSize');
};

TreeChart.prototype._formatSize = function () {
  if (!this.$root) return;
  var cBound = this.getBoundingClientRect();
  var maxHorizonLevel = this.maxHorizonLevel;

  var visit = (elt, level) => {
    if (!elt.$children) return;
    var sArr, maxS;

    if (level < maxHorizonLevel) {
      sArr = elt.$children.map(e => e.$content.getBoundingClientRect().height);
      maxS = Math.max.apply(Math, sArr);
      elt.$children.forEach((elt, i) => {
        if (sArr[i] < maxS) {
          elt.$content.addStyle('height', maxS + 'px');
        }
      });
    } else {
      sArr = elt.$children.map(e => e.$content.getBoundingClientRect().width);
      maxS = Math.max.apply(Math, sArr);
      elt.$children.forEach((elt, i) => {
        if (sArr[i] < maxS) {
          elt.$content.addStyle('width', maxS + 'px');
        }
      });
    }

    elt.$children.forEach(c => visit(c, level + 1));
  };

  visit(this.$root, 0);
  var newBound = this.getBoundingClientRect();

  if (cBound.width !== newBound.width || cBound.height !== newBound.height) {
    _ResizeSystem.default.update();
  }

  this.domSignal.emit('fixWidth');
};

TreeChart.prototype._fixWidth = function () {
  if (!this.$root) return;
  var cBound = this.getBoundingClientRect();
  var maxHorizonLevel = this.maxHorizonLevel;

  var visit = elt => {
    if (!elt.$children) return;
    elt.$children.forEach(c => visit(c));
    var bound, cBound;
    bound = elt.$childCtn.getBoundingClientRect();
    cBound = elt.$childCtn.getBoundingRecursiveRect(100);

    if (cBound.width > bound.width) {
      elt.$childCtn.addStyle('width', cBound.width + 'px');
    }
  };

  visit(this.$root);
  var newBound = this.getBoundingClientRect();

  if (cBound.width !== newBound.width || cBound.height !== newBound.height) {
    _ResizeSystem.default.update();
  }
};

TreeChart.property = {};
TreeChart.property.data = {
  set: function (data) {
    data = (0, _generator.copyJSVariable)(data || null);
    this._data = data;

    this._updateContent();
  },
  get: function () {
    return this._data;
  }
};
TreeChart.property.maxHorizonLevel = {
  set: function (value) {
    if (!(0, _utils.isNaturalNumber)(value)) value = 2; //default

    this._maxHorizonLevel = value;

    this._updateContent();
  },
  get: function () {
    return this._maxHorizonLevel;
  }
};

_ACore.default.install(TreeChart);

var _default = TreeChart;
exports.default = _default;

VaKeR 2022