diff --git a/graph.js b/graph.js index 6245e72..bc891af 100644 --- a/graph.js +++ b/graph.js @@ -1,1132 +1,1875 @@ import Victor from "https://cdn.skypack.dev/victor@1.1.0"; -'use strict'; +("use strict"); /** + * @name Core + * + * @description + * Core of the module for creating graphs + * + * {@link https://git.mirzaev.sexy/mirzaev/graph.mjs} + * + * @class + * @public + * + * @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License * @author Arsen Mirzaev Tatyano-Muradovich + * + * @example Creating a simple graph + * // Initializing the graph instance + * сonst instance = new graph(document.getElementById('graph')); + * + * // Writing settings of the graph instance + * instance.living = 3000; + * instance.camera = true; + * instance.operate = true; + * + * // Initializing nodes + * const bebra = instance.node(new node(document.getElementById('bebra'))); + * const feet = instance.node(new node(document.getElementById('feet'))); + * + * // Writing setting of every node + * instance.nodes.forEach((node) => { node.variables.get("inputs").type = "deg" }); + * + * // Initializing edges + * instance.edge(new edge(feet, bebra)); */ -class graph { - // Идентификатор HTML-элемента-оболочки (instanceof HTMLElement) - #id = 'graph'; +export default class core { + /** + * @name Shell + * + * @description + * Shell of nodes + * + * @type {HTMLElement} + * + * @protected + */ + #shell; - // Прочитать идентификатор HTML-элемента-оболочки (instanceof HTMLElement) - get id() { - return this.#id; - } - - // Классы которые будут записаны в HTML-элементы - classes = { - node: { - shell: ['nodes'], - element: ['node'], - onmouseenter: ['onmouseenter'], - title: ['title'], - cover: ['cover'], - description: { - both: ['description'], - hidden: ['hidden'], - shown: ['shown'] - }, - close: { - both: ['close'], - hidden: ['hidden'], - shown: ['shown'] - }, - wrappers: { - both: ['wrapper'], - left: ['left'], - right: ['right'] - }, - animation: ['animation'] - }, - connection: { - shell: ['connections'], - element: ['connection'] - } - }; - - // Оболочка (instanceof HTMLElement) - #shell = document.getElementById(this.id); + /** + * @name Shell (get) + * + * @description + * Shell of nodes + * + * @type {HTMLElement} + * + * @public + */ get shell() { return this.#shell; } - // Реестр узлов - #nodes = new Set; + /** + * @name Left (x-coordinate) + * + * @type {number} Value in pixels + * + * @protected + */ + #left; + + /** + * @name Left (x-coordinate) (get) + * + * @description + * Getter for `this.#left` + * + * @type {number} Value in pixels + * + * @public + */ + get left() { + return this.#left; + } + + /** + * @name Top (y-coordinate) + * + * @type {number} Value in pixels + * + * @protected + */ + #top; + + /** + * @name Top (y-coordinate) (get) + * + * @description + * Getter for `this.#top` + * + * @type {number} Value in pixels + * + * @public + */ + get top() { + return this.#top; + } + + /** + * @name Nodes + * + * @description + * Registry of nodes + * + * @type {Set} + * + * @protected + */ + #nodes = new Set(); + + /** + * @name Nodes (get) + * + * @description + * Getter for `this.#nodes` + * + * @type {Set} + * + * @public + */ get nodes() { return this.#nodes; } - // Реестр соединений - #connections = new Set; - get connections() { - return this.#connections; - } - - // Статус активации функций взаимодействий узлов - actions = { - pushing: true, - pulling: true, - move: { - shell: true, - node: true - } - } - - // Класс узла - #node = class node { - // Реестр входящих соединений - #inputs = new Set(); - - // Прочитать реестр входящих соединений - get inputs() { return this.#inputs } - - // Реестр исходящих соединений - #outputs = new Set(); - - // Прочитать реестр исходящих соединений - get outputs() { return this.#outputs } - - // Оператор - #operator; - - // Прочитать оператора - get operator() { return this.#operator } - - // HTML-элемент-оболочка - #shell; - - // Прочитать HTML-элемент-оболочка - get shell() { return this.#shell } - - // HTML-элемент - #element; - - // Прочитать HTML-элемент - get element() { return this.#element } - - // Наблюдатель - #observer = null; - - // Прочитать наблюдатель - get observer() { return this.#observer } - - // Реестр запрещённых к изменению параметров - #block = new Set(['events']); - - // Прочитать реестр запрещённых к изменению параметров - get block() { return this.#block } - - // Диаметр узла - #diameter = 100; - - // Прочитать диаметр узла - get diameter() { return this.#diameter } - - // Степень увеличения диаметра - #increase = 0; - - // Прочитать степень увеличения диаметра - get increase() { return this.#increase } - - // Величина степени увеличения диаметра - #addition = 12; - - // Прочитать величину степени увеличения диаметра - get addition() { return this.#addition } - - // Величина степени увеличения притягивания и отталкивания - #shift = 0; - - // Прочитать величину степени увеличения притягивания и отталкивания - get shift() { return this.#shift } - - /** - * Обработка событий - * - * max - максимум итераций в процессе - * current - текущая итерация в процессе - */ - actions = { - move: { - active: true, - unlimit: false - }, - pushing: { - active: true, - max: 100, - current: 0 - }, - pulling: { - active: true, - max: 100, - current: 0 - } - }; - - /** - * Отталкивания - * - * Реестр узлов которые обработали отталкивание с целевым узлом в потоке - */ - pushings = new Set; - - /** - * Притягивания - * - * Реестр узлов которые обработали притягивание с целевым узлом в потоке - */ - pullings = new Set; - - /** - * Расчёт времени анимации - */ - #timing = 'cubic-bezier(0, 1, 1, 1)'; - - /** - * Прочитать расчёт времени анимации - */ - get timing() { return this.#timing } - - /** - * Длительность анимации (в секундах) - */ - #duration = '3'; - - /** - * Прочитать длительность анимации (в секундах) - */ - get duration() { return this.#duration } - - /** - * Анимация (HTMLElement