diff --git a/app/assets/tailwind/application.css b/app/assets/tailwind/application.css index 23c2e39e5..69c9f3a6a 100644 --- a/app/assets/tailwind/application.css +++ b/app/assets/tailwind/application.css @@ -7,3 +7,48 @@ } @custom-variant with-error (.field_with_errors &); + +/* Subject graph tooltip and headers */ +.graph-semester-header { + position: absolute; + pointer-events: none; + font-weight: 600; + white-space: nowrap; + z-index: 10; +} + +.graph-tooltip { + position: fixed; + transform: translateX(-50%); + z-index: 50; + background: white; + border: 1px solid #e2e8f0; + border-radius: 0.5rem; + padding: 0.5rem 0.75rem; + box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1); + pointer-events: auto; + display: flex; + flex-direction: column; + gap: 0.25rem; + max-width: 220px; + white-space: nowrap; +} + +.graph-tooltip-text { + font-size: 0.75rem; + font-weight: 500; + color: #374151; + overflow: hidden; + text-overflow: ellipsis; +} + +.graph-tooltip-link { + font-size: 0.75rem; + color: var(--color-primary); + text-decoration: none; + font-weight: 500; +} + +.graph-tooltip-link:hover { + text-decoration: underline; +} diff --git a/app/components/subject_graph_component.html.erb b/app/components/subject_graph_component.html.erb new file mode 100644 index 000000000..4950fcf44 --- /dev/null +++ b/app/components/subject_graph_component.html.erb @@ -0,0 +1,7 @@ +
+
diff --git a/app/components/subject_graph_component.rb b/app/components/subject_graph_component.rb new file mode 100644 index 000000000..729541307 --- /dev/null +++ b/app/components/subject_graph_component.rb @@ -0,0 +1,81 @@ +class SubjectGraphComponent < ViewComponent::Base + def initialize(subjects:, current_student:, semester_map: nil) + @subjects = subjects + @current_student = current_student + @semester_map = semester_map + end + + def nodes + @subjects.map do |subject| + { + id: subject.id, + code: subject.code, + name: subject.short_name || subject.name, + url: helpers.subject_path(subject), + available: @current_student.available?(subject), + completed: @current_student.approved?(subject), + semester: semester_for(subject) + } + end + end + + def edges + subject_ids = Set.new(@subjects.map(&:id)) + edges = [] + + @subjects.each do |subject| + collect_prerequisite_edges(subject.course&.prerequisite_tree, subject.id, subject_ids, edges) + end + + edges.uniq + end + + def semester_labels + semesters = @subjects.map { |s| semester_for(s) }.uniq.sort + + semesters.index_with do |sem| + semester_display_label(sem) + end + end + + private + + def semester_for(subject) + if @semester_map + @semester_map[subject.id] || 0 + else + index = Subject::CATEGORIES.index(subject.category&.to_sym) + index ? index + 1 : 0 + end + end + + def semester_display_label(semester) + return "Otras" if semester == 0 + + if @semester_map + "Semestre #{semester}" + else + category = Subject::CATEGORIES[semester - 1] + category ? helpers.formatted_category(category.to_s) : "Semestre #{semester}" + end + end + + def collect_prerequisite_edges(prerequisite, target_subject_id, subject_ids, edges) + return unless prerequisite + + case prerequisite + when SubjectPrerequisite + source_subject_id = prerequisite.approvable_needed.subject_id + if subject_ids.include?(source_subject_id) + edges << { source: source_subject_id, target: target_subject_id } + end + when LogicalPrerequisite + # Skip "not" operators - they represent inverse relationships + return if prerequisite.logical_operator == "not" + + prerequisite.operands_prerequisites.each do |child| + collect_prerequisite_edges(child, target_subject_id, subject_ids, edges) + end + end + end +end diff --git a/app/controllers/planner/graphs_controller.rb b/app/controllers/planner/graphs_controller.rb new file mode 100644 index 000000000..fddfbe5fc --- /dev/null +++ b/app/controllers/planner/graphs_controller.rb @@ -0,0 +1,17 @@ +module Planner + class GraphsController < ApplicationController + before_action :authenticate_user! + + def show + subject_plans = current_user.subject_plans + .includes(subject: [:course, :exam]) + + @semester_map = subject_plans.to_h do |subject_plan| + [subject_plan.subject_id, subject_plan.semester] + end + + @subjects = subject_plans.map(&:subject) + TreePreloader.preload(@subjects) + end + end +end diff --git a/app/controllers/subjects/graphs_controller.rb b/app/controllers/subjects/graphs_controller.rb new file mode 100644 index 000000000..4c3e6e0ca --- /dev/null +++ b/app/controllers/subjects/graphs_controller.rb @@ -0,0 +1,13 @@ +module Subjects + class GraphsController < ApplicationController + def show + categories = params[:categories] || [] + + @subjects = current_degree_plan.subjects + .where(category: categories) + .includes(:course, :exam) + + TreePreloader.preload(@subjects) + end + end +end diff --git a/app/javascript/controllers/subject_graph_controller.js b/app/javascript/controllers/subject_graph_controller.js new file mode 100644 index 000000000..03324b991 --- /dev/null +++ b/app/javascript/controllers/subject_graph_controller.js @@ -0,0 +1,467 @@ +import { Controller } from "@hotwired/stimulus" +import cytoscape from "cytoscape" + +export default class extends Controller { + static values = { + nodes: Array, + edges: Array, + semesterLabels: Object + } + + get isMobile() { + return window.innerWidth < 640 + } + + connect() { + this.mobile = this.isMobile + const groups = this.groupBySemester() + const positions = this.mobile + ? this.calculateMobilePositions(groups) + : this.calculateDesktopPositions(groups) + + this.cy = cytoscape({ + container: this.element, + elements: this.buildElements(), + layout: { + name: "preset", + positions: (node) => positions[node.id()] || { x: 0, y: 0 }, + fit: false + }, + minZoom: 0.3, + maxZoom: 3, + autoungrabify: true, + style: this.buildStyles(this.mobile) + }) + + this.headerEls = [] + this.selectedNode = null + this.tooltipEl = null + + if (this.mobile) { + this.cy.zoom(1) + const bb = this.cy.elements().boundingBox() + this.cy.pan({ x: -bb.x1 + 16, y: -bb.y1 + 10 }) + this.cy.userPanningEnabled(true) + this.cy.userZoomingEnabled(false) + this.cy.boxSelectionEnabled(false) + } else { + this.cy.fit(undefined, 40) + } + + this.buildSemesterNodeGroups() + this.createHeaders(this.mobile) + this.cy.on("pan zoom", () => { + this.positionHeaders() + this.positionTooltip() + }) + + this.cy.on("tap", "node", (evt) => this.handleNodeTap(evt.target)) + this.cy.on("tap", (evt) => { + if (evt.target === this.cy) this.clearSelection() + }) + + if (!this.mobile) { + this.cy.on("mouseover", "node", (evt) => { + if (!this.selectedNode) { + evt.target.addClass("hovered") + this.highlightConnected(evt.target, true) + } + }) + this.cy.on("mouseout", "node", (evt) => { + if (!this.selectedNode) { + evt.target.removeClass("hovered") + this.clearHighlight() + } + }) + } + + this.boundResize = this.handleResize.bind(this) + window.addEventListener("resize", this.boundResize) + + // Store reference for testing + this.element.__cytoscape = this.cy + } + + handleNodeTap(node) { + if (this.selectedNode && this.selectedNode.id() === node.id()) { + // Second tap on same node: navigate + const url = node.data("url") + if (url) window.Turbo?.visit(url) + return + } + + this.clearSelection() + this.selectedNode = node + node.addClass("selected") + this.highlightConnected(node, false) + this.showTooltip(node) + } + + highlightConnected(node, hoverOnly) { + const predecessors = node.predecessors() + const successors = node.successors() + const connected = predecessors.union(successors).union(node) + + if (hoverOnly) { + predecessors.nodes().addClass("predecessor-hover") + successors.nodes().addClass("successor-hover") + predecessors.edges().addClass("highlighted-edge") + successors.edges().addClass("highlighted-edge") + return + } + + // Full selection: dim everything, then highlight chain + this.cy.elements().addClass("dimmed") + connected.removeClass("dimmed") + predecessors.nodes().addClass("predecessor") + successors.nodes().addClass("successor") + predecessors.edges().addClass("highlighted-edge") + successors.edges().addClass("highlighted-edge") + node.removeClass("dimmed") + } + + clearHighlight() { + this.cy.elements().removeClass("predecessor-hover successor-hover highlighted-edge") + } + + clearSelection() { + if (!this.selectedNode) return + this.selectedNode.removeClass("selected") + this.selectedNode = null + this.cy.elements().removeClass("dimmed predecessor successor predecessor-hover successor-hover highlighted-edge selected") + this.removeTooltip() + } + + showTooltip(node) { + this.removeTooltip() + + const tooltip = document.createElement("div") + tooltip.className = "graph-tooltip" + + const name = node.data("label").replace("\n", " - ") + const url = node.data("url") + + tooltip.innerHTML = ` + ${name} + Ver detalles → + ` + + // Stop mouse/touch events from reaching Cytoscape's canvas + tooltip.addEventListener("mousedown", (e) => e.stopPropagation()) + tooltip.addEventListener("touchstart", (e) => e.stopPropagation()) + tooltip.addEventListener("pointerdown", (e) => e.stopPropagation()) + + // Append to document body so it renders above the Cytoscape canvas + document.body.appendChild(tooltip) + this.tooltipEl = tooltip + this.tooltipNode = node + this.positionTooltip() + } + + positionTooltip() { + if (!this.tooltipEl || !this.tooltipNode) return + + const rbb = this.tooltipNode.renderedBoundingBox() + const centerX = (rbb.x1 + rbb.x2) / 2 + const bottomY = rbb.y2 + + // Convert from Cytoscape container-relative to viewport coordinates + const containerRect = this.element.getBoundingClientRect() + + this.tooltipEl.style.left = `${containerRect.left + centerX}px` + this.tooltipEl.style.top = `${containerRect.top + bottomY + 8}px` + } + + removeTooltip() { + if (this.tooltipEl) { + this.tooltipEl.remove() + this.tooltipEl = null + this.tooltipNode = null + } + } + + handleResize() { + clearTimeout(this.resizeTimer) + this.resizeTimer = setTimeout(() => { + const wasMobile = this.mobile + this.mobile = this.isMobile + + if (wasMobile !== this.mobile) { + // Layout mode changed, rebuild + this.clearSelection() + this.headerEls.forEach(el => el.remove()) + this.headerEls = [] + + const groups = this.groupBySemester() + const positions = this.mobile + ? this.calculateMobilePositions(groups) + : this.calculateDesktopPositions(groups) + + this.cy.style(this.buildStyles(this.mobile)) + this.cy.nodes().forEach(node => { + const pos = positions[node.id()] + if (pos) node.position(pos) + }) + + if (this.mobile) { + this.cy.zoom(1) + const bb = this.cy.elements().boundingBox() + this.cy.pan({ x: -bb.x1 + 16, y: -bb.y1 + 10 }) + this.cy.userZoomingEnabled(false) + } else { + this.cy.userZoomingEnabled(true) + this.cy.fit(undefined, 40) + } + + this.createHeaders(this.mobile) + } + }, 200) + } + + groupBySemester() { + const groups = new Map() + for (const n of this.nodesValue) { + const sem = n.semester ?? 0 + if (!groups.has(sem)) groups.set(sem, []) + groups.get(sem).push(n) + } + return new Map([...groups.entries()].sort((a, b) => a[0] - b[0])) + } + + calculateDesktopPositions(groups) { + const colWidth = 160 + const nodeHeight = 45 + const nodeGapY = 15 + const topPadding = 40 + + const positions = {} + let col = 0 + + for (const [, nodes] of groups) { + const x = col * colWidth + colWidth / 2 + for (let i = 0; i < nodes.length; i++) { + const y = topPadding + i * (nodeHeight + nodeGapY) + nodeHeight / 2 + positions[nodes[i].id.toString()] = { x, y } + } + col++ + } + + return positions + } + + calculateMobilePositions(groups) { + const nodesPerRow = 2 + const containerW = window.innerWidth + const padding = 16 + const gapX = 14 + const nodeW = Math.floor((containerW - padding * 2 - gapX) / nodesPerRow) + const nodeH = 42 + const rowGap = 14 + const semGap = 44 + + const positions = {} + let y = semGap + + for (const [, nodes] of groups) { + for (let i = 0; i < nodes.length; i++) { + const col = i % nodesPerRow + const row = Math.floor(i / nodesPerRow) + positions[nodes[i].id.toString()] = { + x: padding + col * (nodeW + gapX) + nodeW / 2, + y: y + row * (nodeH + rowGap) + nodeH / 2 + } + } + const rowsInSemester = Math.ceil(nodes.length / nodesPerRow) + y += rowsInSemester * (nodeH + rowGap) + semGap + } + + return positions + } + + buildStyles(mobile) { + const fontSize = mobile ? "11px" : "12px" + const nodeWidth = mobile ? Math.floor((window.innerWidth - 32 - 14) / 2) : 130 + const nodeHeight = mobile ? 42 : 45 + const textMaxWidth = mobile ? `${nodeWidth - 10}px` : "120px" + + return [ + { + selector: "node", + style: { + "label": "data(label)", + "text-wrap": "wrap", + "text-max-width": textMaxWidth, + "background-color": "#6b7280", + "color": "#fff", + "text-valign": "center", + "text-halign": "center", + "padding": "0px", + "shape": "round-rectangle", + "width": nodeWidth, + "height": nodeHeight, + "font-size": fontSize, + "cursor": "pointer", + "border-width": 0, + "border-color": "#000", + "transition-property": "background-color, border-width, border-color, opacity", + "transition-duration": "0.15s" + } + }, + { + selector: "node[?available]", + style: { "background-color": "#3b82f6" } + }, + { + selector: "node[?completed]", + style: { "background-color": "#22c55e" } + }, + // Hover: subtle border + { + selector: "node.hovered", + style: { "border-width": 2, "border-color": "#1d4ed8" } + }, + // Selected node: bold border + { + selector: "node.selected", + style: { "border-width": 3, "border-color": "#1e293b" } + }, + // Dimmed (unrelated to selection) + { + selector: ".dimmed", + style: { "opacity": 0.2 } + }, + // Predecessor chain highlight (upstream) + { + selector: "node.predecessor", + style: { "border-width": 2, "border-color": "#f59e0b" } + }, + // Successor chain highlight (downstream) + { + selector: "node.successor", + style: { "border-width": 2, "border-color": "#8b5cf6" } + }, + // Hover-only highlights (lighter) + { + selector: "node.predecessor-hover", + style: { "border-width": 2, "border-color": "#fbbf24" } + }, + { + selector: "node.successor-hover", + style: { "border-width": 2, "border-color": "#a78bfa" } + }, + // Edges + { + selector: "edge", + style: { + "width": 1.5, + "line-color": "#cbd5e1", + "target-arrow-color": "#cbd5e1", + "target-arrow-shape": "triangle", + "arrow-scale": 0.8, + "curve-style": "bezier", + "opacity": 0.6, + "transition-property": "line-color, target-arrow-color, width, opacity", + "transition-duration": "0.15s" + } + }, + // Highlighted edges (connected to selection/hover) + { + selector: "edge.highlighted-edge", + style: { + "line-color": "#64748b", + "target-arrow-color": "#64748b", + "width": 2.5, + "opacity": 1 + } + } + ] + } + + buildSemesterNodeGroups() { + this.semesterNodeGroups = new Map() + this.cy.nodes().forEach(node => { + const sem = node.data("semester") + if (!this.semesterNodeGroups.has(sem)) this.semesterNodeGroups.set(sem, []) + this.semesterNodeGroups.get(sem).push(node) + }) + } + + createHeaders(mobile) { + for (const [sem] of [...this.semesterNodeGroups.entries()].sort((a, b) => a[0] - b[0])) { + const label = this.semesterLabelsValue[sem.toString()] || `Semestre ${sem}` + + const header = document.createElement("div") + header.textContent = label + header.className = "graph-semester-header" + header.style.color = mobile ? "#374151" : "#6b7280" + header.dataset.semester = sem.toString() + + this.element.appendChild(header) + this.headerEls.push(header) + } + + this.positionHeaders() + } + + positionHeaders() { + if (!this.cy || !this.semesterNodeGroups) return + + const zoom = this.cy.zoom() + + for (const header of this.headerEls) { + const sem = parseInt(header.dataset.semester) + const nodes = this.semesterNodeGroups.get(sem) + if (!nodes || nodes.length === 0) continue + + let minY = Infinity + let sumX = 0 + + for (const node of nodes) { + const rbb = node.renderedBoundingBox() + if (rbb.y1 < minY) minY = rbb.y1 + sumX += (rbb.x1 + rbb.x2) / 2 + } + + const avgX = sumX / nodes.length + + header.style.left = `${avgX}px` + header.style.top = `${minY - 4}px` + header.style.transform = "translate(-50%, -100%)" + header.style.fontSize = `${Math.max(10, 13 * zoom)}px` + } + } + + buildElements() { + const nodes = this.nodesValue.map(n => ({ + data: { + id: n.id.toString(), + label: `${n.code}\n${n.name}`, + url: n.url, + available: n.available, + completed: n.completed, + semester: n.semester ?? 0 + } + })) + + const edges = this.edgesValue.map(e => ({ + data: { + source: e.source.toString(), + target: e.target.toString() + } + })) + + return [...nodes, ...edges] + } + + disconnect() { + if (this.headerEls) { + this.headerEls.forEach(el => el.remove()) + } + this.removeTooltip() + if (this.boundResize) { + window.removeEventListener("resize", this.boundResize) + } + clearTimeout(this.resizeTimer) + this.cy?.destroy() + } +} diff --git a/app/views/planner/graphs/show.html.erb b/app/views/planner/graphs/show.html.erb new file mode 100644 index 000000000..e5e51c53b --- /dev/null +++ b/app/views/planner/graphs/show.html.erb @@ -0,0 +1,25 @@ +
+
+

Grafo de materias planificadas

+
+ + <% if @subjects.any? %> + <%= render "shared/graph_legend" %> + +

+ + Toca una materia para ver sus previas. Toca de nuevo para ver detalles. +

+ + <%= render SubjectGraphComponent.new( + subjects: @subjects, + current_student: current_student, + semester_map: @semester_map + ) %> + <% else %> +
+

No tienes materias planificadas.

+ <%= link_to "Agregar materias", subject_plans_path, class: "mt-4 text-primary hover:underline" %> +
+ <% end %> +
diff --git a/app/views/shared/_graph_legend.html.erb b/app/views/shared/_graph_legend.html.erb new file mode 100644 index 000000000..a289b20c5 --- /dev/null +++ b/app/views/shared/_graph_legend.html.erb @@ -0,0 +1,22 @@ +
+
+ + No disponible +
+
+ + Disponible +
+
+ + Completada +
+
+ + Previa +
+
+ + Dependiente +
+
diff --git a/app/views/shared/_menu.html.erb b/app/views/shared/_menu.html.erb index 65e8c9c2b..a04e56306 100644 --- a/app/views/shared/_menu.html.erb +++ b/app/views/shared/_menu.html.erb @@ -5,6 +5,8 @@ <%= drawer_menu_navigation_item "Todas las Materias", all_subjects_path %> + <%= drawer_menu_navigation_item "Grafo de Dependencias", subjects_graph_path(categories: Subject::CATEGORIES.first(9)) %> + <%= drawer_menu_navigation_item "Materias dictadas en este semestre", current_semester_subjects_path %> <%= drawer_menu_navigation_item "Planificador", subject_plans_path %> diff --git a/app/views/subject_plans/index.html.erb b/app/views/subject_plans/index.html.erb index 21b1a331d..53583ed0e 100644 --- a/app/views/subject_plans/index.html.erb +++ b/app/views/subject_plans/index.html.erb @@ -1,6 +1,6 @@ <% content_for :welcome_banner do %> - <%= render 'shared/banner', - banner_type: 'planner', + <%= render 'shared/banner', + banner_type: 'planner', message: 'Bienvenido a tu planificador de materias: arrastra, suelta y organiza tu semestre' %> <% end %> @@ -10,9 +10,14 @@
-

- Planificador -

+
+

+ Planificador +

+ <%= link_to planner_graph_path, class: "text-gray-500 hover:text-primary", title: "Ver grafo de dependencias" do %> + <%= material_icon("account_tree", class: "text-xl") %> + <% end %> +
<%= render partial: "credits_counter", locals: { planned_subjects: @planned_subjects } %>
diff --git a/app/views/subjects/graphs/show.html.erb b/app/views/subjects/graphs/show.html.erb new file mode 100644 index 000000000..db09f5a44 --- /dev/null +++ b/app/views/subjects/graphs/show.html.erb @@ -0,0 +1,23 @@ +
+
+

Grafo de malla curricular sugerida

+
+ + <% if @subjects.any? %> + <%= render "shared/graph_legend" %> + +

+ + Toca una materia para ver sus previas. Toca de nuevo para ver detalles. +

+ + <%= render SubjectGraphComponent.new( + subjects: @subjects, + current_student: current_student + ) %> + <% else %> +
+

No hay materias para mostrar.

+
+ <% end %> +
diff --git a/config/importmap.rb b/config/importmap.rb index f96650748..30a98e900 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -13,3 +13,6 @@ pin "sortablejs" # @1.15.6 pin "@rails/request.js", to: "@rails--request.js.js" # @0.0.12 + +# Graph visualization for subject dependencies +pin "cytoscape" # @3.33.1 diff --git a/config/routes.rb b/config/routes.rb index 1923faec1..9b7d9a0b1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -42,6 +42,11 @@ namespace :planner do resources :not_planned_subjects, only: :index + resource :graph, only: :show + end + + namespace :subjects do + resource :graph, only: :show end resource :user_onboardings, only: :update diff --git a/spec/components/subject_graph_component_spec.rb b/spec/components/subject_graph_component_spec.rb new file mode 100644 index 000000000..90af9e165 --- /dev/null +++ b/spec/components/subject_graph_component_spec.rb @@ -0,0 +1,160 @@ +require "rails_helper" + +RSpec.describe SubjectGraphComponent, type: :component do + let(:user) { build_stubbed(:user) } + let(:student) { UserStudent.new(user) } + + context "with subjects" do + it "renders the graph container with data attributes" do + subject1 = create(:subject, name: "Subject 1", code: "S1") + + render_inline(described_class.new(subjects: [subject1], current_student: student)) + + expect(page).to have_css "[data-controller='subject-graph']" + expect(page).to have_css "[data-subject-graph-nodes-value]" + expect(page).to have_css "[data-subject-graph-edges-value]" + end + + it "includes subject data in nodes" do + subject1 = create(:subject, name: "Test Subject", short_name: "TS", code: "TS1") + + render_inline(described_class.new(subjects: [subject1], current_student: student)) + + node_data = page.find("[data-subject-graph-nodes-value]")["data-subject-graph-nodes-value"] + nodes = JSON.parse(node_data) + + expect(nodes.length).to eq(1) + expect(nodes.first["id"]).to eq(subject1.id) + expect(nodes.first["code"]).to eq("TS1") + expect(nodes.first["name"]).to eq("TS") + expect(nodes.first["url"]).to eq("/materias/#{subject1.id}") + end + + it "uses full name when short_name is not present" do + subject1 = create(:subject, name: "Full Name Subject", short_name: nil, code: "FN1") + + render_inline(described_class.new(subjects: [subject1], current_student: student)) + + node_data = page.find("[data-subject-graph-nodes-value]")["data-subject-graph-nodes-value"] + nodes = JSON.parse(node_data) + + expect(nodes.first["name"]).to eq("Full Name Subject") + end + + it "marks available subjects as available" do + subject1 = create(:subject, name: "Available Subject", code: "AV1") + + render_inline(described_class.new(subjects: [subject1], current_student: student)) + + node_data = page.find("[data-subject-graph-nodes-value]")["data-subject-graph-nodes-value"] + nodes = JSON.parse(node_data) + + expect(nodes.first["available"]).to be true + end + end + + context "with prerequisites" do + it "creates edges for subject prerequisites within the subject set" do + subject1 = create(:subject, name: "Prereq", code: "PR1") + subject2 = create(:subject, name: "Dependent", code: "DE1") + + create(:subject_prerequisite, approvable: subject2.course, approvable_needed: subject1.course) + + render_inline(described_class.new(subjects: [subject1, subject2], current_student: student)) + + edge_data = page.find("[data-subject-graph-edges-value]")["data-subject-graph-edges-value"] + edges = JSON.parse(edge_data) + + expect(edges.length).to eq(1) + expect(edges.first["source"]).to eq(subject1.id) + expect(edges.first["target"]).to eq(subject2.id) + end + + it "does not create edges for prerequisites outside the subject set" do + subject1 = create(:subject, name: "Outside", code: "OU1") + subject2 = create(:subject, name: "Inside", code: "IN1") + + create(:subject_prerequisite, approvable: subject2.course, approvable_needed: subject1.course) + + # Only include subject2, not subject1 + render_inline(described_class.new(subjects: [subject2], current_student: student)) + + edge_data = page.find("[data-subject-graph-edges-value]")["data-subject-graph-edges-value"] + edges = JSON.parse(edge_data) + + expect(edges).to be_empty + end + + it "handles logical prerequisites with multiple operands" do + subject1 = create(:subject, name: "Prereq 1", code: "PR1") + subject2 = create(:subject, name: "Prereq 2", code: "PR2") + subject3 = create(:subject, name: "Dependent", code: "DE1") + + create(:and_prerequisite, approvable: subject3.course, operands_prerequisites: [ + create(:subject_prerequisite, approvable_needed: subject1.course), + create(:subject_prerequisite, approvable_needed: subject2.course), + ]) + + render_inline(described_class.new(subjects: [subject1, subject2, subject3], current_student: student)) + + edge_data = page.find("[data-subject-graph-edges-value]")["data-subject-graph-edges-value"] + edges = JSON.parse(edge_data) + + expect(edges.length).to eq(2) + sources = edges.map { |e| e["source"] } + expect(sources).to contain_exactly(subject1.id, subject2.id) + expect(edges.all? { |e| e["target"] == subject3.id }).to be true + end + end + + context "semester labels" do + it "renders semester-labels data attribute" do + subject1 = create(:subject, name: "Subject 1", code: "S1", category: "first_semester") + + render_inline(described_class.new(subjects: [subject1], current_student: student)) + + expect(page).to have_css "[data-subject-graph-semester-labels-value]" + end + + it "produces correct labels for curriculum graph" do + subject1 = create(:subject, name: "Subject 1", code: "S1", category: "first_semester") + subject2 = create(:subject, name: "Subject 2", code: "S2", category: "second_semester") + + render_inline(described_class.new(subjects: [subject1, subject2], current_student: student)) + + labels_data = page.find("[data-subject-graph-semester-labels-value]")["data-subject-graph-semester-labels-value"] + labels = JSON.parse(labels_data) + + expect(labels["1"]).to eq("Primer semestre") + expect(labels["2"]).to eq("Segundo semestre") + end + + it "produces correct labels for planner graph with semester_map" do + subject1 = create(:subject, name: "Subject 1", code: "S1") + subject2 = create(:subject, name: "Subject 2", code: "S2") + + semester_map = { subject1.id => 3, subject2.id => 5 } + + render_inline(described_class.new(subjects: [subject1, subject2], current_student: student, + semester_map: semester_map)) + + labels_data = page.find("[data-subject-graph-semester-labels-value]")["data-subject-graph-semester-labels-value"] + labels = JSON.parse(labels_data) + + expect(labels["3"]).to eq("Semestre 3") + expect(labels["5"]).to eq("Semestre 5") + end + end + + context "without subjects" do + it "renders empty arrays for nodes and edges" do + render_inline(described_class.new(subjects: [], current_student: student)) + + node_data = page.find("[data-subject-graph-nodes-value]")["data-subject-graph-nodes-value"] + edge_data = page.find("[data-subject-graph-edges-value]")["data-subject-graph-edges-value"] + + expect(JSON.parse(node_data)).to be_empty + expect(JSON.parse(edge_data)).to be_empty + end + end +end diff --git a/spec/system/planner_graph_spec.rb b/spec/system/planner_graph_spec.rb new file mode 100644 index 000000000..861b271b2 --- /dev/null +++ b/spec/system/planner_graph_spec.rb @@ -0,0 +1,90 @@ +require 'rails_helper' + +RSpec.describe "Planner Graph", type: :system do + let(:user) { create(:user) } + + before do + sign_in user + end + + it "displays graph with planned subjects" do + subject1 = create(:subject, name: "Calculo 1", code: "C1") + subject2 = create(:subject, name: "Calculo 2", code: "C2") + + create(:subject_prerequisite, approvable: subject2.course, approvable_needed: subject1.course) + + create(:subject_plan, user: user, subject: subject1, semester: 1) + create(:subject_plan, user: user, subject: subject2, semester: 2) + + visit planner_graph_path + + expect(page).to have_css "[data-controller='subject-graph']" + expect(page).to have_css "[data-subject-graph-nodes-value]" + expect(page).to have_css "[data-subject-graph-edges-value]" + expect(page).to have_css "[data-subject-graph-semester-labels-value]" + + node_data = find("[data-subject-graph-nodes-value]")["data-subject-graph-nodes-value"] + nodes = JSON.parse(node_data) + + expect(nodes.length).to eq(2) + expect(nodes.map { |n| n["code"] }).to contain_exactly("C1", "C2") + end + + it "shows empty state when no planned subjects" do + visit planner_graph_path + + expect(page).to have_text "No tienes materias planificadas" + expect(page).to have_link "Agregar materias" + end + + it "includes edges for prerequisites within planned subjects" do + subject1 = create(:subject, name: "Base", code: "B1") + subject2 = create(:subject, name: "Advanced", code: "A1") + + create(:subject_prerequisite, approvable: subject2.course, approvable_needed: subject1.course) + + create(:subject_plan, user: user, subject: subject1, semester: 1) + create(:subject_plan, user: user, subject: subject2, semester: 2) + + visit planner_graph_path + + edge_data = find("[data-subject-graph-edges-value]")["data-subject-graph-edges-value"] + edges = JSON.parse(edge_data) + + expect(edges.length).to eq(1) + expect(edges.first["source"]).to eq(subject1.id) + expect(edges.first["target"]).to eq(subject2.id) + end + + it "displays legend with highlight indicators" do + subject1 = create(:subject, name: "Subject", code: "S1") + create(:subject_plan, user: user, subject: subject1, semester: 1) + + visit planner_graph_path + + expect(page).to have_text "Previa" + expect(page).to have_text "Dependiente" + end + + it "displays interaction instructions" do + subject1 = create(:subject, name: "Subject", code: "S1") + create(:subject_plan, user: user, subject: subject1, semester: 1) + + visit planner_graph_path + + expect(page).to have_text("previas", normalize_ws: true) + end + + it "marks available subjects in the graph data" do + subject1 = create(:subject, name: "Available", code: "AV") + create(:subject_plan, user: user, subject: subject1, semester: 1) + + visit planner_graph_path + + node_data = find("[data-subject-graph-nodes-value]")["data-subject-graph-nodes-value"] + nodes = JSON.parse(node_data) + + available_node = nodes.find { |n| n["code"] == "AV" } + expect(available_node["available"]).to be true + end +end diff --git a/spec/system/subjects_graph_spec.rb b/spec/system/subjects_graph_spec.rb new file mode 100644 index 000000000..8018c129d --- /dev/null +++ b/spec/system/subjects_graph_spec.rb @@ -0,0 +1,107 @@ +require 'rails_helper' + +RSpec.describe "Subjects Graph", type: :system do + let(:user) { create(:user) } + + before do + sign_in user + end + + it "displays graph filtered by single category" do + create(:subject, name: "First Sem Subject", code: "FS1", category: "first_semester") + create(:subject, name: "Second Sem Subject", code: "SS1", category: "second_semester") + + visit subjects_graph_path(categories: ["first_semester"]) + + expect(page).to have_css "[data-controller='subject-graph']" + expect(page).to have_css "[data-subject-graph-semester-labels-value]" + + node_data = find("[data-subject-graph-nodes-value]")["data-subject-graph-nodes-value"] + nodes = JSON.parse(node_data) + + expect(nodes.length).to eq(1) + expect(nodes.first["code"]).to eq("FS1") + end + + it "displays graph filtered by multiple categories" do + create(:subject, name: "First Sem Subject", code: "FS1", category: "first_semester") + create(:subject, name: "Second Sem Subject", code: "SS1", category: "second_semester") + create(:subject, name: "Third Sem Subject", code: "TS1", category: "third_semester") + + visit subjects_graph_path(categories: ["first_semester", "second_semester"]) + + node_data = find("[data-subject-graph-nodes-value]")["data-subject-graph-nodes-value"] + nodes = JSON.parse(node_data) + + expect(nodes.length).to eq(2) + expect(nodes.map { |n| n["code"] }).to contain_exactly("FS1", "SS1") + end + + it "shows edges for prerequisites within filtered subjects" do + subject1 = create(:subject, name: "Intro", code: "IN1", category: "first_semester") + subject2 = create(:subject, name: "Advanced", code: "AD1", category: "first_semester") + + create(:subject_prerequisite, approvable: subject2.course, approvable_needed: subject1.course) + + visit subjects_graph_path(categories: ["first_semester"]) + + edge_data = find("[data-subject-graph-edges-value]")["data-subject-graph-edges-value"] + edges = JSON.parse(edge_data) + + expect(edges.length).to eq(1) + expect(edges.first["source"]).to eq(subject1.id) + expect(edges.first["target"]).to eq(subject2.id) + end + + it "shows empty state when no categories provided" do + create(:subject, name: "Some Subject", code: "SS1", category: "first_semester") + + visit subjects_graph_path + + expect(page).to have_text "No hay materias para mostrar" + end + + it "displays legend with all state and highlight indicators" do + create(:subject, name: "Subject", code: "S1", category: "first_semester") + + visit subjects_graph_path(categories: ["first_semester"]) + + expect(page).to have_text "No disponible" + expect(page).to have_text "Disponible" + expect(page).to have_text "Completada" + expect(page).to have_text "Previa" + expect(page).to have_text "Dependiente" + end + + it "displays interaction instructions" do + create(:subject, name: "Subject", code: "S1", category: "first_semester") + + visit subjects_graph_path(categories: ["first_semester"]) + + expect(page).to have_text("previas", normalize_ws: true) + end + + it "marks available subjects based on user approvals" do + prereq_subject = create(:subject, name: "Prerequisite", code: "PR1", category: "first_semester") + dependent_subject = create(:subject, name: "Dependent", code: "DE1", category: "first_semester") + + create(:subject_prerequisite, approvable: dependent_subject.course, approvable_needed: prereq_subject.course) + + # Approve the prerequisite + user.approvals << prereq_subject.course.id + user.save! + + visit subjects_graph_path(categories: ["first_semester"]) + + node_data = find("[data-subject-graph-nodes-value]")["data-subject-graph-nodes-value"] + nodes = JSON.parse(node_data) + + prereq_node = nodes.find { |n| n["code"] == "PR1" } + dependent_node = nodes.find { |n| n["code"] == "DE1" } + + # Prereq has no prereqs, so it's available + expect(prereq_node["available"]).to be true + # Dependent should now be available since prereq is approved + expect(dependent_node["available"]).to be true + end +end diff --git a/vendor/javascript/cytoscape.js b/vendor/javascript/cytoscape.js new file mode 100644 index 000000000..fd4154bb6 --- /dev/null +++ b/vendor/javascript/cytoscape.js @@ -0,0 +1,871 @@ +// cytoscape@3.33.1 downloaded from https://ga.jspm.io/npm:cytoscape@3.33.1/dist/cytoscape.esm.mjs + +function e(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,a=Array(t);r=e.length?{done:true}:{done:false,value:e[a++]}},e:function(e){throw e},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,o=true,s=false;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return o=e.done,e},e:function(e){s=true,i=e},f:function(){try{o||null==r.return||r.return()}finally{if(s)throw i}}}}function s(e,t,r){return(t=p(t))in e?Object.defineProperty(e,t,{value:r,enumerable:true,configurable:true,writable:true}):e[t]=r,e}function l(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function u(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var a,n,i,o,s=[],l=true,u=false;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;l=!1}else for(;!(l=(a=i.call(r)).done)&&(s.push(a.value),s.length!==t);l=!0);}catch(e){u=true,n=e}finally{try{if(!l&&null!=r.return&&(o=r.return(),Object(o)!==o))return}finally{if(u)throw n}}return s}}function v(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function c(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function d(e,r){return t(e)||u(e,r)||y(e,r)||v()}function f(e){return r(e)||l(e)||y(e)||c()}function h(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t);if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}function p(e){var t=h(e,"string");return"symbol"==typeof t?t:t+""}function g(e){return g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},g(e)}function y(t,r){if(t){if("string"==typeof t)return e(t,r);var a={}.toString.call(t).slice(8,-1);return"Object"===a&&t.constructor&&(a=t.constructor.name),"Map"===a||"Set"===a?Array.from(t):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?e(t,r):void 0}}var m=typeof window==="undefined"?null:window;var b=m?m.navigator:null;m?m.document:null;var x=g("");var w=g({});var E=g((function(){}));var T=typeof HTMLElement==="undefined"?"undefined":g(HTMLElement);var k=function(e){return e&&e.instanceString&&P(e.instanceString)?e.instanceString():null};var C=function(e){return e!=null&&g(e)==x};var P=function(e){return e!=null&&g(e)===E};var S=function(e){return!I(e)&&(Array.isArray?Array.isArray(e):e!=null&&e instanceof Array)};var B=function(e){return e!=null&&g(e)===w&&!S(e)&&e.constructor===Object};var D=function(e){return e!=null&&g(e)===w};var _=function(e){return e!=null&&g(e)===g(1)&&!isNaN(e)};var A=function(e){return _(e)&&Math.floor(e)===e};var M=function(e){return"undefined"===T?void 0:null!=e&&e instanceof HTMLElement};var I=function(e){return R(e)||N(e)};var R=function(e){return k(e)==="collection"&&e._private.single};var N=function(e){return k(e)==="collection"&&!e._private.single};var L=function(e){return k(e)==="core"};var O=function(e){return k(e)==="stylesheet"};var z=function(e){return k(e)==="event"};var V=function(e){return e===void 0||e===null||!(e!==""&&!e.match(/^\s+$/))};var F=function(e){return typeof HTMLElement!=="undefined"&&e instanceof HTMLElement};var X=function(e){return B(e)&&_(e.x1)&&_(e.x2)&&_(e.y1)&&_(e.y2)};var j=function(e){return D(e)&&P(e.then)};var Y=function(){return b&&b.userAgent.match(/msie|trident|edge/i)};var q=function(e,t){t||(t=function(){if(arguments.length===1)return arguments[0];if(arguments.length===0)return"undefined";var e=[];for(var t=0;tt?1:0};var ne=function(e,t){return-1*ae(e,t)};var ie=Object.assign!=null?Object.assign.bind(Object):function(e){var t=arguments;for(var r=1;r1&&(r-=1);return r<1/6?e+6*(t-e)*r:r<.5?t:r<2/3?e+(t-e)*(2/3-r)*6:e}var v=new RegExp("^"+J+"$").exec(e);if(v){r=parseInt(v[1]);r<0?r=(360- -1*r%360)%360:r>360&&(r%=360);r/=360;a=parseFloat(v[2]);if(a<0||a>100)return;a/=100;n=parseFloat(v[3]);if(n<0||n>100)return;n/=100;i=v[4];if(i!==void 0){i=parseFloat(i);if(i<0||i>1)return}if(a===0)o=s=l=Math.round(n*255);else{var c=n<.5?n*(1+a):n+a-n*a;var d=2*n-c;o=Math.round(255*u(d,c,r+1/3));s=Math.round(255*u(d,c,r));l=Math.round(255*u(d,c,r-1/3))}t=[o,s,l,i]}return t};var le=function(e){var t;var r=new RegExp("^"+$+"$").exec(e);if(r){t=[];var a=[];for(var n=1;n<=3;n++){var i=r[n];i[i.length-1]==="%"&&(a[n]=true);i=parseFloat(i);a[n]&&(i=i/100*255);if(i<0||i>255)return;t.push(Math.floor(i))}var o=a[1]||a[2]||a[3];var s=a[1]&&a[2]&&a[3];if(o&&!s)return;var l=r[4];if(l!==void 0){l=parseFloat(l);if(l<0||l>1)return;t.push(l)}}return t};var ue=function(e){return ce[e.toLowerCase()]};var ve=function(e){return(S(e)?e:null)||ue(e)||oe(e)||le(e)||se(e)};var ce={transparent:[0,0,0,0],aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],grey:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]};var de=function(e){var t=e.map;var r=e.keys;var a=r.length;for(var n=0;n true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(_.noop); + * // => true + * + * _.isObject(null); + * // => false + */var ge;var ye;function me(){if(ye)return ge;ye=1;function e(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}ge=e;return ge}var be;var xe;function we(){if(xe)return be;xe=1;var e=typeof he=="object"&&he&&he.Object===Object&&he;be=e;return be}var Ee;var Te;function ke(){if(Te)return Ee;Te=1;var e=we();var t=typeof self=="object"&&self&&self.Object===Object&&self;var r=e||t||Function("return this")();Ee=r;return Ee}var Ce;var Pe;function Se(){if(Pe)return Ce;Pe=1;var e=ke(); +/** + * Gets the timestamp of the number of milliseconds that have elapsed since + * the Unix epoch (1 January 1970 00:00:00 UTC). + * + * @static + * @memberOf _ + * @since 2.4.0 + * @category Date + * @returns {number} Returns the timestamp. + * @example + * + * _.defer(function(stamp) { + * console.log(_.now() - stamp); + * }, _.now()); + * // => Logs the number of milliseconds it took for the deferred invocation. + */var t=function(){return e.Date.now()};Ce=t;return Ce}var Be;var De;function _e(){if(De)return Be;De=1;var e=/\s/; +/** + * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace + * character of `string`. + * + * @private + * @param {string} string The string to inspect. + * @returns {number} Returns the index of the last non-whitespace character. + */function t(t){var r=t.length;while(r--&&e.test(t.charAt(r)));return r}Be=t;return Be}var Ae;var Me;function Ie(){if(Me)return Ae;Me=1;var e=_e();var t=/^\s+/; +/** + * The base implementation of `_.trim`. + * + * @private + * @param {string} string The string to trim. + * @returns {string} Returns the trimmed string. + */function r(r){return r?r.slice(0,e(r)+1).replace(t,""):r}Ae=r;return Ae}var Re;var Ne;function Le(){if(Ne)return Re;Ne=1;var e=ke();var t=e.Symbol;Re=t;return Re}var Oe;var ze;function Ve(){if(ze)return Oe;ze=1;var e=Le();var t=Object.prototype;var r=t.hasOwnProperty;var a=t.toString;var n=e?e.toStringTag:void 0; +/** + * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the raw `toStringTag`. + */function i(e){var t=r.call(e,n),i=e[n];try{e[n]=void 0;var o=true}catch(e){}var s=a.call(e);o&&(t?e[n]=i:delete e[n]);return s}Oe=i;return Oe}var Fe;var Xe;function je(){if(Xe)return Fe;Xe=1;var e=Object.prototype;var t=e.toString; +/** + * Converts `value` to a string using `Object.prototype.toString`. + * + * @private + * @param {*} value The value to convert. + * @returns {string} Returns the converted string. + */function r(e){return t.call(e)}Fe=r;return Fe}var Ye;var qe;function We(){if(qe)return Ye;qe=1;var e=Le(),t=Ve(),r=je();var a="[object Null]",n="[object Undefined]";var i=e?e.toStringTag:void 0; +/** + * The base implementation of `getTag` without fallbacks for buggy environments. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the `toStringTag`. + */function o(e){return e==null?e===void 0?n:a:i&&i in Object(e)?t(e):r(e)}Ye=o;return Ye} +/** + * Checks if `value` is object-like. A value is object-like if it's not `null` + * and has a `typeof` result of "object". + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is object-like, else `false`. + * @example + * + * _.isObjectLike({}); + * // => true + * + * _.isObjectLike([1, 2, 3]); + * // => true + * + * _.isObjectLike(_.noop); + * // => false + * + * _.isObjectLike(null); + * // => false + */var Ue;var Ge;function He(){if(Ge)return Ue;Ge=1;function e(e){return e!=null&&typeof e=="object"}Ue=e;return Ue}var Ke;var Ze;function $e(){if(Ze)return Ke;Ze=1;var e=We(),t=He();var r="[object Symbol]"; +/** + * Checks if `value` is classified as a `Symbol` primitive or object. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. + * @example + * + * _.isSymbol(Symbol.iterator); + * // => true + * + * _.isSymbol('abc'); + * // => false + */function a(a){return typeof a=="symbol"||t(a)&&e(a)==r}Ke=a;return Ke}var Qe;var Je;function et(){if(Je)return Qe;Je=1;var e=Ie(),t=me(),r=$e();var a=NaN;var n=/^[-+]0x[0-9a-f]+$/i;var i=/^0b[01]+$/i;var o=/^0o[0-7]+$/i;var s=parseInt; +/** + * Converts `value` to a number. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to process. + * @returns {number} Returns the number. + * @example + * + * _.toNumber(3.2); + * // => 3.2 + * + * _.toNumber(Number.MIN_VALUE); + * // => 5e-324 + * + * _.toNumber(Infinity); + * // => Infinity + * + * _.toNumber('3.2'); + * // => 3.2 + */function l(l){if(typeof l=="number")return l;if(r(l))return a;if(t(l)){var u=typeof l.valueOf=="function"?l.valueOf():l;l=t(u)?u+"":u}if(typeof l!="string")return l===0?l:+l;l=e(l);var v=i.test(l);return v||o.test(l)?s(l.slice(2),v?2:8):n.test(l)?a:+l}Qe=l;return Qe}var tt;var rt;function at(){if(rt)return tt;rt=1;var e=me(),t=Se(),r=et();var a="Expected a function";var n=Math.max,i=Math.min; +/** + * Creates a debounced function that delays invoking `func` until after `wait` + * milliseconds have elapsed since the last time the debounced function was + * invoked. The debounced function comes with a `cancel` method to cancel + * delayed `func` invocations and a `flush` method to immediately invoke them. + * Provide `options` to indicate whether `func` should be invoked on the + * leading and/or trailing edge of the `wait` timeout. The `func` is invoked + * with the last arguments provided to the debounced function. Subsequent + * calls to the debounced function return the result of the last `func` + * invocation. + * + * **Note:** If `leading` and `trailing` options are `true`, `func` is + * invoked on the trailing edge of the timeout only if the debounced function + * is invoked more than once during the `wait` timeout. + * + * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred + * until to the next tick, similar to `setTimeout` with a timeout of `0`. + * + * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) + * for details over the differences between `_.debounce` and `_.throttle`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {Function} func The function to debounce. + * @param {number} [wait=0] The number of milliseconds to delay. + * @param {Object} [options={}] The options object. + * @param {boolean} [options.leading=false] + * Specify invoking on the leading edge of the timeout. + * @param {number} [options.maxWait] + * The maximum time `func` is allowed to be delayed before it's invoked. + * @param {boolean} [options.trailing=true] + * Specify invoking on the trailing edge of the timeout. + * @returns {Function} Returns the new debounced function. + * @example + * + * // Avoid costly calculations while the window size is in flux. + * jQuery(window).on('resize', _.debounce(calculateLayout, 150)); + * + * // Invoke `sendMail` when clicked, debouncing subsequent calls. + * jQuery(element).on('click', _.debounce(sendMail, 300, { + * 'leading': true, + * 'trailing': false + * })); + * + * // Ensure `batchLog` is invoked once after 1 second of debounced calls. + * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 }); + * var source = new EventSource('/stream'); + * jQuery(source).on('message', debounced); + * + * // Cancel the trailing debounced invocation. + * jQuery(window).on('popstate', debounced.cancel); + */function o(o,s,l){var u,v,c,d,f,h,p=0,g=false,y=false,m=true;if(typeof o!="function")throw new TypeError(a);s=r(s)||0;if(e(l)){g=!!l.leading;y="maxWait"in l;c=y?n(r(l.maxWait)||0,s):c;m="trailing"in l?!!l.trailing:m}function b(e){var t=u,r=v;u=v=void 0;p=e;d=o.apply(r,t);return d}function x(e){p=e;f=setTimeout(T,s);return g?b(e):d}function w(e){var t=e-h,r=e-p,a=s-t;return y?i(a,c-r):a}function E(e){var t=e-h,r=e-p;return h===void 0||t>=s||t<0||y&&r>=c}function T(){var e=t();if(E(e))return k(e);f=setTimeout(T,w(e))}function k(e){f=void 0;if(m&&u)return b(e);u=v=void 0;return d}function C(){f!==void 0&&clearTimeout(f);p=0;u=h=v=f=void 0}function P(){return f===void 0?d:k(t())}function S(){var e=t(),r=E(e);u=arguments;v=this;h=e;if(r){if(f===void 0)return x(h);if(y){clearTimeout(f);f=setTimeout(T,s);return b(h)}}f===void 0&&(f=setTimeout(T,s));return d}S.cancel=C;S.flush=P;return S}tt=o;return tt}var nt=at();var it=pe(nt);var ot=m?m.performance:null;var st=ot&&ot.now?function(){return ot.now()}:function(){return Date.now()};var lt=function(){if(m){if(m.requestAnimationFrame)return function(e){m.requestAnimationFrame(e)};if(m.mozRequestAnimationFrame)return function(e){m.mozRequestAnimationFrame(e)};if(m.webkitRequestAnimationFrame)return function(e){m.webkitRequestAnimationFrame(e)};if(m.msRequestAnimationFrame)return function(e){m.msRequestAnimationFrame(e)}}return function(e){e&&setTimeout((function(){e(st())}),1e3/60)}}();var ut=function(e){return lt(e)};var vt=st;var ct=9261;var dt=65599;var ft=5381;var ht=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:ct;var r=t;var a;for(;;){a=e.next();if(a.done)break;r=r*dt+a.value|0}return r};var pt=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:ct;return t*dt+e|0};var gt=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:ft;return(t<<5)+t+e|0};var yt=function(e,t){return e*2097152+t};var mt=function(e){return e[0]*2097152+e[1]};var bt=function(e,t){return[pt(e[0],t[0]),gt(e[1],t[1])]};var xt=function(e,t){var r={value:0,done:false};var a=0;var n=e.length;var i={next:function(){a=0;a--)e[a]===t&&e.splice(a,1)};var Ut=function(e){e.splice(0,e.length)};var Gt=function(e,t){for(var r=0;r2&&arguments[2]!==void 0)||arguments[2];if(e!==void 0&&t!==void 0&&L(e)){var a=t.group;a==null&&(a=t.data&&t.data.source!=null&&t.data.target!=null?"edges":"nodes");if(a==="nodes"||a==="edges"){this.length=1;this[0]=this;var n=this._private={cy:e,single:true,data:t.data||{},position:t.position||{x:0,y:0},autoWidth:void 0,autoHeight:void 0,autoPadding:void 0,compoundBoundsClean:false,listeners:[],group:a,style:{},rstyle:{},styleCxts:[],styleKeys:{},removed:true,selected:!!t.selected,selectable:t.selectable===void 0||!!t.selectable,locked:!!t.locked,grabbed:false,grabbable:t.grabbable===void 0||!!t.grabbable,pannable:t.pannable===void 0?a==="edges":!!t.pannable,active:false,classes:new er,animation:{current:[],queue:[]},rscratch:{},scratch:t.scratch||{},edges:[],children:[],parent:t.parent&&t.parent.isNode()?t.parent:null,traversalCache:{},backgrounding:false,bbCache:null,bbCacheShift:{x:0,y:0},bodyBounds:null,overlayBounds:null,labelBounds:{all:null,source:null,target:null,main:null},arrowBounds:{source:null,target:null,"mid-source":null,"mid-target":null}};n.position.x==null&&(n.position.x=0);n.position.y==null&&(n.position.y=0);if(t.renderedPosition){var i=t.renderedPosition;var o=e.pan();var s=e.zoom();n.position={x:(i.x-o.x)/s,y:(i.y-o.y)/s}}var l=[];S(t.classes)?l=t.classes:C(t.classes)&&(l=t.classes.split(/\s+/));for(var u=0,v=l.length;ut?1:0};u=function(e,t,n,i,o){var s;n==null&&(n=0);o==null&&(o=r);if(n<0)throw new Error("lo must be non-negative");i==null&&(i=e.length);while(nr;0<=r?t++:t--)u.push(t);return u}.apply(this).reverse();l=[];for(i=0,o=s.length;ip;0<=p?++d:--d)g.push(i(e,a));return g};h=function(e,t,a,n){var i,o,s;n==null&&(n=r);i=e[a];while(a>t){s=a-1>>1;o=e[s];if(!(n(i,o)<0))break;e[a]=o;a=s}return e[a]=i};p=function(e,t,a){var n,i,o,s,l;a==null&&(a=r);i=e.length;l=t;o=e[t];n=2*t+1;while(n0){var w=y.pop();var E=p(w);var T=w.id();c[T]=E;if(E!==Infinity){var k=w.neighborhood().intersect(f);for(var P=0;P0){r.unshift(t);while(v[n]){var i=v[n];r.unshift(i.edge);r.unshift(i.node);a=i.node;n=a.id()}}return o.spawn(r)}}}};var pr={kruskal:function(e){e=e||function(e){return 1};var t=this.byGroup(),r=t.nodes,a=t.edges;var n=r.length;var i=new Array(n);var o=r;var s=function(e){for(var t=0;t0){x();E++;if(b===u){var T=[];var k=n;var C=u;var P=g[C];for(;;){T.unshift(k);P!=null&&T.unshift(P);k=p[C];if(k==null)break;C=k.id();P=g[C]}return{found:true,distance:v[b],path:this.spawn(T),steps:E}}d[b]=true;var S=m._private.edges;for(var B=0;BS){f[P]=S;y[P]=k;m[P]=x}if(!n){var B=k*u+T;if(!n&&f[B]>S){f[B]=S;y[B]=T;m[B]=x}}}}for(var D=0;D1&&arguments[1]!==void 0?arguments[1]:i;var a=m(e);var n=[];var o=a;for(;;){if(o==null)return t.spawn();var l=y(o),u=l.edge,v=l.pred;n.unshift(o[0]);if(o.same(r)&&n.length>0)break;u!=null&&n.unshift(u);o=v}return s.spawn(n)};for(var w=0;w=0;u--){var v=l[u];var c=v[1];var d=v[2];(t[c]===o&&t[d]===s||t[c]===s&&t[d]===o)&&l.splice(u,1)}for(var f=0;fa){var n=Math.floor(Math.random()*t.length);t=Tr(n,e,t);r--}return t};var Cr={kargerStein:function(){var e=this;var t=this.byGroup(),r=t.nodes,a=t.edges;a.unmergeBy((function(e){return e.isLoop()}));var n=r.length;var i=a.length;var o=Math.ceil(Math.pow(Math.log(n)/Math.LN2,2));var s=Math.floor(n/Er);if(!(n<2)){var l=[];for(var u=0;u1&&arguments[1]!==void 0?arguments[1]:0;var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:e.length;var a=Infinity;for(var n=t;n1&&arguments[1]!==void 0?arguments[1]:0;var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:e.length;var a=-Infinity;for(var n=t;n1&&arguments[1]!==void 0?arguments[1]:0;var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:e.length;var a=0;var n=0;for(var i=t;i1&&arguments[1]!==void 0?arguments[1]:0;var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:e.length;var a=!(arguments.length>3&&arguments[3]!==void 0)||arguments[3];var n=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4];var i=!(arguments.length>5&&arguments[5]!==void 0)||arguments[5];if(a)e=e.slice(t,r);else{r0&&e.splice(0,t)}var o=0;for(var s=e.length-1;s>=0;s--){var l=e[s];if(i){if(!isFinite(l)){e[s]=-Infinity;o++}}else e.splice(s,1)}n&&e.sort((function(e,t){return e-t}));var u=e.length;var v=Math.floor(u/2);return u%2!==0?e[v+1+o]:(e[v-1+o]+e[v+o])/2};var Nr=function(e){return Math.PI*e/180};var Lr=function(e,t){return Math.atan2(t,e)-Math.PI/2};var Or=Math.log2||function(e){return Math.log(e)/Math.log(2)};var zr=function(e){return e>0?1:e<0?-1:0};var Vr=function(e,t){return Math.sqrt(Fr(e,t))};var Fr=function(e,t){var r=t.x-e.x;var a=t.y-e.y;return r*r+a*a};var Xr=function(e){var t=e.length;var r=0;for(var a=0;a=e.x1&&e.y2>=e.y1)return{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,w:e.x2-e.x1,h:e.y2-e.y1};if(e.w!=null&&e.h!=null&&e.w>=0&&e.h>=0)return{x1:e.x1,y1:e.y1,x2:e.x1+e.w,y2:e.y1+e.h,w:e.w,h:e.h}}};var Gr=function(e){return{x1:e.x1,x2:e.x2,w:e.w,y1:e.y1,y2:e.y2,h:e.h}};var Hr=function(e){e.x1=Infinity;e.y1=Infinity;e.x2=-Infinity;e.y2=-Infinity;e.w=0;e.h=0};var Kr=function(e,t){e.x1=Math.min(e.x1,t.x1);e.x2=Math.max(e.x2,t.x2);e.w=e.x2-e.x1;e.y1=Math.min(e.y1,t.y1);e.y2=Math.max(e.y2,t.y2);e.h=e.y2-e.y1};var Zr=function(e,t,r){e.x1=Math.min(e.x1,t);e.x2=Math.max(e.x2,t);e.w=e.x2-e.x1;e.y1=Math.min(e.y1,r);e.y2=Math.max(e.y2,r);e.h=e.y2-e.y1};var $r=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;e.x1-=t;e.x2+=t;e.y1-=t;e.y2+=t;e.w=e.x2-e.x1;e.h=e.y2-e.y1;return e};var Qr=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[0];var r,a,n,i;if(t.length===1)r=a=n=i=t[0];else if(t.length===2){r=n=t[0];i=a=t[1]}else if(t.length===4){var o=d(t,4);r=o[0];a=o[1];n=o[2];i=o[3]}e.x1-=i;e.x2+=a;e.y1-=r;e.y2+=n;e.w=e.x2-e.x1;e.h=e.y2-e.y1;return e};var Jr=function(e,t){e.x1=t.x1;e.y1=t.y1;e.x2=t.x2;e.y2=t.y2;e.w=e.x2-e.x1;e.h=e.y2-e.y1};var ea=function(e,t){return!(e.x1>t.x2)&&(!(t.x1>e.x2)&&(!(e.x2t.y2)&&!(t.y1>e.y2)))))))};var ta=function(e,t,r){return e.x1<=t&&t<=e.x2&&e.y1<=r&&r<=e.y2};var ra=function(e,t){return ta(e,t.x,t.y)};var aa=function(e,t){return ta(e,t.x1,t.y1)&&ta(e,t.x2,t.y2)};var na=(Pr=Math.hypot)!==null&&Pr!==void 0?Pr:function(e,t){return Math.sqrt(e*e+t*t)};function ia(e,t){if(e.length<3)throw new Error("Need at least 3 vertices");var r=function(e,t){return{x:e.x+t.x,y:e.y+t.y}};var a=function(e,t){return{x:e.x-t.x,y:e.y-t.y}};var n=function(e,t){return{x:e.x*t,y:e.y*t}};var i=function(e,t){return e.x*t.y-e.y*t.x};var o=function(e){var t=na(e.x,e.y);return t===0?{x:0,y:0}:{x:e.x/t,y:e.y/t}};var s=function(e){var t=0;for(var r=0;r7&&arguments[7]!==void 0?arguments[7]:"auto";var l=s==="auto"?Aa(n,i):s;var u=n/2;var v=i/2;l=Math.min(l,u,v);var c=l!==u,d=l!==v;var f;if(c){var h=r-u+l-o;var p=a-v-o;var g=r+u-l+o;var y=p;f=Ta(e,t,r,a,h,p,g,y,false);if(f.length>0)return f}if(d){var m=r+u+o;var b=a-v+l-o;var x=m;var w=a+v-l+o;f=Ta(e,t,r,a,m,b,x,w,false);if(f.length>0)return f}if(c){var E=r-u+l-o;var T=a+v+o;var k=r+u-l+o;var C=T;f=Ta(e,t,r,a,E,T,k,C,false);if(f.length>0)return f}if(d){var P=r-u-o;var S=a-v+l-o;var B=P;var D=a+v-l+o;f=Ta(e,t,r,a,P,S,B,D,false);if(f.length>0)return f}var _;var A=r-u+l;var M=a-v+l;_=wa(e,t,r,a,A,M,l+o);if(_.length>0&&_[0]<=A&&_[1]<=M)return[_[0],_[1]];var I=r+u-l;var R=a-v+l;_=wa(e,t,r,a,I,R,l+o);if(_.length>0&&_[0]>=I&&_[1]<=R)return[_[0],_[1]];var N=r+u-l;var L=a+v-l;_=wa(e,t,r,a,N,L,l+o);if(_.length>0&&_[0]>=N&&_[1]>=L)return[_[0],_[1]];var O=r-u+l;var z=a+v-l;_=wa(e,t,r,a,O,z,l+o);return _.length>0&&_[0]<=O&&_[1]>=z?[_[0],_[1]]:[]};var la=function(e,t,r,a,n,i,o){var s=o;var l=Math.min(r,n);var u=Math.max(r,n);var v=Math.min(a,i);var c=Math.max(a,i);return l-s<=e&&e<=u+s&&v-s<=t&&t<=c+s};var ua=function(e,t,r,a,n,i,o,s,l){var u={x1:Math.min(r,o,n)-l,x2:Math.max(r,o,n)+l,y1:Math.min(a,s,i)-l,y2:Math.max(a,s,i)+l};return!(eu.x2||tu.y2)};var va=function(e,t,r,a){r-=a;var n=t*t-4*e*r;if(n<0)return[];var i=Math.sqrt(n);var o=2*e;var s=(-t+i)/o;var l=(-t-i)/o;return[s,l]};var ca=function(e,t,r,a,n){var i=1e-5;e===0&&(e=i);t/=e;r/=e;a/=e;var o,s,l,u,v,c,d,f;s=(3*r-t*t)/9;l=-27*a+t*(9*r-t*t*2);l/=54;o=s*s*s+l*l;n[1]=0;d=t/3;if(o>0){v=l+Math.sqrt(o);v=v<0?-Math.pow(-v,1/3):Math.pow(v,1/3);c=l-Math.sqrt(o);c=c<0?-Math.pow(-c,1/3):Math.pow(c,1/3);n[0]=-d+v+c;d+=(v+c)/2;n[4]=n[2]=-d;d=Math.sqrt(3)*(-c+v)/2;n[3]=d;n[5]=-d}else{n[5]=n[3]=0;if(o!==0){s=-s;u=s*s*s;u=Math.acos(l/Math.sqrt(u));f=2*Math.sqrt(s);n[0]=-d+f*Math.cos(u/3);n[2]=-d+f*Math.cos((u+2*Math.PI)/3);n[4]=-d+f*Math.cos((u+4*Math.PI)/3)}else{f=l<0?-Math.pow(-l,1/3):Math.pow(l,1/3);n[0]=2*f-d;n[4]=n[2]=-(f+d)}}};var da=function(e,t,r,a,n,i,o,s){var l=1*r*r-4*r*n+2*r*o+4*n*n-4*n*o+o*o+a*a-4*a*i+2*a*s+4*i*i-4*i*s+s*s;var u=9*r*n-3*r*r-3*r*o-6*n*n+3*n*o+9*a*i-3*a*a-3*a*s-6*i*i+3*i*s;var v=3*r*r-6*r*n+r*o-r*e+2*n*n+2*n*e-o*e+3*a*a-6*a*i+a*s-a*t+2*i*i+2*i*t-s*t;var c=1*r*n-r*r+r*e-n*e+a*i-a*a+a*t-i*t;var d=[];ca(l,u,v,c,d);var f=1e-7;var h=[];for(var p=0;p<6;p+=2)Math.abs(d[p+1])=0&&d[p]<=1&&h.push(d[p]);h.push(1);h.push(0);var g=-1;var y,m,b;for(var x=0;x=0?bl?(e-n)*(e-n)+(t-i)*(t-i):u-c};var ha=function(e,t,r){var a,n,i,o;var s;var l=0;for(var u=0;u=e&&e>=i||a<=e&&e<=i))continue;s=(e-a)/(i-a)*(o-n)+n;s>t&&l++}}return l%2!==0};var pa=function(e,t,r,a,n,i,o,s,l){var u=new Array(r.length);var v;if(s[0]!=null){v=Math.atan(s[1]/s[0]);s[0]<0?v+=Math.PI/2:v=-v-Math.PI/2}else v=s;var c=Math.cos(-v);var d=Math.sin(-v);for(var f=0;f0){var p=ma(u,-l);h=ya(p)}else h=u;return ha(e,t,h)};var ga=function(e,t,r,a,n,i,o,s){var l=new Array(r.length*2);for(var u=0;u=0&&p<=1&&y.push(p);g>=0&&g<=1&&y.push(g);if(y.length===0)return[];var m=y[0]*s[0]+e;var b=y[0]*s[1]+t;if(y.length>1){if(y[0]==y[1])return[m,b];var x=y[1]*s[0]+e;var w=y[1]*s[1]+t;return[m,b,x,w]}return[m,b]};var Ea=function(e,t,r){return t<=e&&e<=r||r<=e&&e<=t?e:e<=t&&t<=r||r<=t&&t<=e?t:r};var Ta=function(e,t,r,a,n,i,o,s,l){var u=e-n;var v=r-e;var c=o-n;var d=t-i;var f=a-t;var h=s-i;var p=c*d-h*u;var g=v*d-f*u;var y=h*v-c*f;if(y!==0){var m=p/y;var b=g/y;var x=.001;var w=0-x;var E=1+x;return w<=m&&m<=E&&w<=b&&b<=E||l?[e+m*v,t+m*f]:[]}return p===0||g===0?Ea(e,r,o)===o?[o,s]:Ea(e,r,n)===n?[n,i]:Ea(n,o,r)===r?[r,a]:[]:[]};var ka=function(e,t,r,a,n){var i=[];var o=a/2;var s=n/2;var l=t;var u=r;i.push({x:l+o*e[0],y:u+s*e[1]});for(var v=1;v0){var h=ma(v,-s);d=ya(h)}else d=v}else d=r;var p,g,y,m;for(var b=0;b2){var f=[u[0],u[1]];var h=Math.pow(f[0]-e,2)+Math.pow(f[1]-t,2);for(var p=1;pu&&(u=t)},get:function(e){return l[e]}};for(var c=0;c0?m.edgesTo(y)[0]:y.edgesTo(m)[0];var x=a(b);y=y.id();if(u[y]>u[h]+x){u[y]=u[h]+x;c.nodes.indexOf(y)<0?c.push(y):c.updateItem(y);l[y]=0;r[y]=[]}if(u[y]==u[h]+x){l[y]=l[y]+l[h];r[y].push(h)}}else for(var w=0;w0){var C=t.pop();for(var P=0;P0&&o.push(r[s]);o.length!==0&&n.push(a.collection(o))}return n};var tn=function(e,t){for(var r=0;r5&&arguments[5]!==void 0?arguments[5]:on;var o=a;var s,l;for(var u=0;u=2?dn(e,t,r,0,un,vn):dn(e,t,r,0,ln)},squaredEuclidean:function(e,t,r){return dn(e,t,r,0,un)},manhattan:function(e,t,r){return dn(e,t,r,0,ln)},max:function(e,t,r){return dn(e,t,r,-Infinity,cn)}};fn["squared-euclidean"]=fn.squaredEuclidean;fn.squaredeuclidean=fn.squaredEuclidean;function hn(e,t,r,a,n,i){var o;o=P(e)?e:fn[e]||fn.euclidean;return t===0&&P(e)?o(n,i):o(t,r,a,n,i)}var pn=qt({k:2,m:2,sensitivityThreshold:1e-4,distance:"euclidean",maxIterations:10,attributes:[],testMode:false,testCentroids:null});var gn=function(e){return pn(e)};var yn=function(e,t,r,a,n){var i=n!=="kMedoids";var o=i?function(e){return r[e]}:function(e){return a[e](r)};var s=function(e){return a[e](t)};var l=r;var u=t;return hn(e,a.length,o,s,l,u)};var mn=function(e,t,r){var a=r.length;var n=new Array(a);var i=new Array(a);var o=new Array(t);var s=null;for(var l=0;lr)return false}return true};var Tn=function(e,t,r){for(var a=0;ao){o=t[l][u];s=u}n[s].push(e[l])}for(var v=0;v=n.threshold||n.mode==="dendrogram"&&e.length===1)return false;var f=t[i];var h=t[a[i]];var p;p=n.mode==="dendrogram"?{left:f,right:h,key:f.key}:{value:f.value.concat(h.value),key:f.key};e[f.index]=p;e.splice(h.index,1);t[f.key]=p;for(var g=0;gr[h.key][y.key]&&(s=r[h.key][y.key])}else if(n.linkage==="max"){s=r[f.key][y.key];r[f.key][y.key]0&&a.push(n);return a};var Gn=function(e,t,r){var a=[];for(var n=0;no){i=l;o=t[n*e+l]}}i>0&&a.push(i)}for(var u=0;ul){s=u;l=v}}r[n]=i[s]}a=Gn(e,t,r);return a};var Kn=function(e){var t=this.cy();var r=this.nodes();var a=Yn(e);var n={};for(var i=0;i=P){S=P;P=D;B=_}else D>S&&(S=D)}for(var A=0;A0?1:0;E[k%a.minIterations*o+O]=z;L+=z}if(L>0&&(k>=a.minIterations-1||k==a.maxIterations-1)){var V=0;for(var F=0;F1||n>1)&&(o=true);v[t]=[];e.outgoers().forEach((function(e){e.isEdge()&&v[t].push(e.id())}))}else c[t]=[void 0,e.target().id()]})):i.forEach((function(e){var t=e.id();if(e.isNode()){var r=e.degree(true);r%2&&(s?l?o=true:l=t:s=t);v[t]=[];e.connectedEdges().forEach((function(e){return v[t].push(e.id())}))}else c[t]=[e.source().id(),e.target().id()]}));var d={found:false,trail:void 0};if(o)return d;if(l&&s)if(n){if(u&&l!=u)return d;u=l}else{if(u&&l!=u&&s!=u)return d;u||(u=l)}else u||(u=i[0].id());var f=function(e){var t=e;var r=[e];var a,i,o;while(v[t].length){a=v[t].shift();i=c[a][0];o=c[a][1];if(t!=o){v[o]=v[o].filter((function(e){return e!=a}));t=o}else if(!n&&t!=i){v[i]=v[i].filter((function(e){return e!=a}));t=i}r.unshift(a);r.unshift(t)}return r};var h=[];var p=[];p=f(u);while(p.length!=1)if(v[p[0]].length==0){h.unshift(i.getElementById(p.shift()));h.unshift(i.getElementById(p.shift()))}else p=f(p.shift()).concat(p);h.unshift(i.getElementById(p.shift()));for(var g in v)if(v[g].length)return d;d.found=true;d.trail=this.spawn(h,true);return d}};var Jn=function(){var e=this;var t={};var r=0;var a=0;var n=[];var i=[];var o={};var s=function(r,a){var o=i.length-1;var s=[];var l=e.spawn();while(i[o].x!=r||i[o].y!=a){s.push(i.pop().edge);o--}s.push(i.pop().edge);s.forEach((function(r){var a=r.connectedNodes().intersection(e);l.merge(r);a.forEach((function(r){var a=r.id();var n=r.connectedEdges().intersection(e);l.merge(r);t[a].cutVertex?l.merge(n.filter((function(e){return e.isLoop()}))):l.merge(n)}))}));n.push(l)};var l=function(u,v,c){u===c&&(a+=1);t[v]={id:r,low:r++,cutVertex:false};var d=e.getElementById(v).connectedEdges().intersection(e);if(d.size()===0)n.push(e.spawn(e.getElementById(v)));else{var f,h,p,g;d.forEach((function(e){f=e.source().id();h=e.target().id();p=f===v?h:f;if(p!==c){g=e.id();if(!o[g]){o[g]=true;i.push({x:v,y:p,edge:e})}if(p in t)t[v].low=Math.min(t[v].low,t[p].id);else{l(u,p,v);t[v].low=Math.min(t[v].low,t[p].low);if(t[v].id<=t[p].low){t[v].cutVertex=true;s(v,p)}}}}))}};e.forEach((function(e){if(e.isNode()){var r=e.id();if(!(r in t)){a=0;l(r,r);t[r].cutVertex=a>1}}}));var u=Object.keys(t).filter((function(e){return t[e].cutVertex})).map((function(t){return e.getElementById(t)}));return{cut:e.spawn(u),components:n}};var ei={hopcroftTarjanBiconnected:Jn,htbc:Jn,htb:Jn,hopcroftTarjanBiconnectedComponents:Jn};var ti=function(){var e=this;var t={};var r=0;var a=[];var n=[];var i=e.spawn(e);var o=function(s){n.push(s);t[s]={index:r,low:r++,explored:false};var l=e.getElementById(s).connectedEdges().intersection(e);l.forEach((function(e){var r=e.target().id();if(r!==s){r in t||o(r);t[r].explored||(t[s].low=Math.min(t[s].low,t[r].low))}}));if(t[s].index===t[s].low){var u=e.spawn();for(;;){var v=n.pop();u.merge(e.getElementById(v));t[v].low=t[s].index;t[v].explored=true;if(v===s)break}var c=u.edgesWith(u);var d=u.merge(c);a.push(d);i=i.difference(d)}};e.forEach((function(e){if(e.isNode()){var r=e.id();r in t||o(r)}}));return{cut:i,components:a}};var ri={tarjanStronglyConnected:ti,tsc:ti,tscc:ti,tarjanStronglyConnectedComponents:ti};var ai={};[ar,hr,pr,yr,br,wr,Cr,za,Fa,ja,qa,nn,Mn,Xn,Zn,Qn,ei,ri].forEach((function(e){ie(ai,e)}));var ni=0;var ii=1;var oi=2;var si=function(e){if(!(this instanceof si))return new si(e);this.id="Thenable/1.0.7";this.state=ni;this.fulfillValue=void 0;this.rejectReason=void 0;this.onFulfilled=[];this.onRejected=[];this.proxy={then:this.then.bind(this)};typeof e==="function"&&e.call(this,this.fulfill.bind(this),this.reject.bind(this))};si.prototype={fulfill:function(e){return li(this,ii,"fulfillValue",e)},reject:function(e){return li(this,oi,"rejectReason",e)},then:function(e,t){var r=this;var a=new si;r.onFulfilled.push(ci(e,a,"fulfill"));r.onRejected.push(ci(t,a,"reject"));ui(r);return a.proxy}};var li=function(e,t,r,a){if(e.state===ni){e.state=t;e[r]=a;ui(e)}return e};var ui=function(e){e.state===ii?vi(e,"onFulfilled",e.fulfillValue):e.state===oi&&vi(e,"onRejected",e.rejectReason)};var vi=function(e,t,r){if(e[t].length!==0){var a=e[t];e[t]=[];var n=function(){for(var e=0;e0:void 0}},clearQueue:function(){return function(){var e=this;var t=e.length!==void 0;var r=t?e:[e];var a=this._private.cy||this;if(!a.styleEnabled())return this;for(var n=0;n true + * + * _.isArray(document.body.children); + * // => false + * + * _.isArray('abc'); + * // => false + * + * _.isArray(_.noop); + * // => false + */var yi;var mi;function bi(){if(mi)return yi;mi=1;var e=Array.isArray;yi=e;return yi}var xi;var wi;function Ei(){if(wi)return xi;wi=1;var e=bi(),t=$e();var r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,a=/^\w*$/; +/** + * Checks if `value` is a property name and not a property path. + * + * @private + * @param {*} value The value to check. + * @param {Object} [object] The object to query keys on. + * @returns {boolean} Returns `true` if `value` is a property name, else `false`. + */function n(n,i){if(e(n))return false;var o=typeof n;return!(o!="number"&&o!="symbol"&&o!="boolean"&&n!=null&&!t(n))||(a.test(n)||!r.test(n)||i!=null&&n in Object(i))}xi=n;return xi}var Ti;var ki;function Ci(){if(ki)return Ti;ki=1;var e=We(),t=me();var r="[object AsyncFunction]",a="[object Function]",n="[object GeneratorFunction]",i="[object Proxy]"; +/** + * Checks if `value` is classified as a `Function` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a function, else `false`. + * @example + * + * _.isFunction(_); + * // => true + * + * _.isFunction(/abc/); + * // => false + */function o(o){if(!t(o))return false;var s=e(o);return s==a||s==n||s==r||s==i}Ti=o;return Ti}var Pi;var Si;function Bi(){if(Si)return Pi;Si=1;var e=ke();var t=e["__core-js_shared__"];Pi=t;return Pi}var Di;var _i;function Ai(){if(_i)return Di;_i=1;var e=Bi();var t=function(){var t=/[^.]+$/.exec(e&&e.keys&&e.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(); +/** + * Checks if `func` has its source masked. + * + * @private + * @param {Function} func The function to check. + * @returns {boolean} Returns `true` if `func` is masked, else `false`. + */function r(e){return!!t&&t in e}Di=r;return Di}var Mi;var Ii;function Ri(){if(Ii)return Mi;Ii=1;var e=Function.prototype;var t=e.toString; +/** + * Converts `func` to its source code. + * + * @private + * @param {Function} func The function to convert. + * @returns {string} Returns the source code. + */function r(e){if(e!=null){try{return t.call(e)}catch(e){}try{return e+""}catch(e){}}return""}Mi=r;return Mi}var Ni;var Li;function Oi(){if(Li)return Ni;Li=1;var e=Ci(),t=Ai(),r=me(),a=Ri();var n=/[\\^$.*+?()[\]{}|]/g;var i=/^\[object .+?Constructor\]$/;var o=Function.prototype,s=Object.prototype;var l=o.toString;var u=s.hasOwnProperty;var v=RegExp("^"+l.call(u).replace(n,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"); +/** + * The base implementation of `_.isNative` without bad shim checks. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a native function, + * else `false`. + */function c(n){if(!r(n)||t(n))return false;var o=e(n)?v:i;return o.test(a(n))}Ni=c;return Ni} +/** + * Gets the value at `key` of `object`. + * + * @private + * @param {Object} [object] The object to query. + * @param {string} key The key of the property to get. + * @returns {*} Returns the property value. + */var zi;var Vi;function Fi(){if(Vi)return zi;Vi=1;function e(e,t){return e==null?void 0:e[t]}zi=e;return zi}var Xi;var ji;function Yi(){if(ji)return Xi;ji=1;var e=Oi(),t=Fi(); +/** + * Gets the native function at `key` of `object`. + * + * @private + * @param {Object} object The object to query. + * @param {string} key The key of the method to get. + * @returns {*} Returns the function if it's native, else `undefined`. + */function r(r,a){var n=t(r,a);return e(n)?n:void 0}Xi=r;return Xi}var qi;var Wi;function Ui(){if(Wi)return qi;Wi=1;var e=Yi();var t=e(Object,"create");qi=t;return qi}var Gi;var Hi;function Ki(){if(Hi)return Gi;Hi=1;var e=Ui();function t(){this.__data__=e?e(null):{};this.size=0}Gi=t;return Gi} +/** + * Removes `key` and its value from the hash. + * + * @private + * @name delete + * @memberOf Hash + * @param {Object} hash The hash to modify. + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */var Zi;var $i;function Qi(){if($i)return Zi;$i=1;function e(e){var t=this.has(e)&&delete this.__data__[e];this.size-=t?1:0;return t}Zi=e;return Zi}var Ji;var eo;function to(){if(eo)return Ji;eo=1;var e=Ui();var t="__lodash_hash_undefined__";var r=Object.prototype;var a=r.hasOwnProperty; +/** + * Gets the hash value for `key`. + * + * @private + * @name get + * @memberOf Hash + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */function n(r){var n=this.__data__;if(e){var i=n[r];return i===t?void 0:i}return a.call(n,r)?n[r]:void 0}Ji=n;return Ji}var ro;var ao;function no(){if(ao)return ro;ao=1;var e=Ui();var t=Object.prototype;var r=t.hasOwnProperty; +/** + * Checks if a hash value for `key` exists. + * + * @private + * @name has + * @memberOf Hash + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */function a(t){var a=this.__data__;return e?a[t]!==void 0:r.call(a,t)}ro=a;return ro}var io;var oo;function so(){if(oo)return io;oo=1;var e=Ui();var t="__lodash_hash_undefined__"; +/** + * Sets the hash `key` to `value`. + * + * @private + * @name set + * @memberOf Hash + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the hash instance. + */function r(r,a){var n=this.__data__;this.size+=this.has(r)?0:1;n[r]=e&&a===void 0?t:a;return this}io=r;return io}var lo;var uo;function vo(){if(uo)return lo;uo=1;var e=Ki(),t=Qi(),r=to(),a=no(),n=so(); +/** + * Creates a hash object. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */function i(e){var t=-1,r=e==null?0:e.length;this.clear();while(++t true + * + * _.eq(object, other); + * // => false + * + * _.eq('a', 'a'); + * // => true + * + * _.eq('a', Object('a')); + * // => false + * + * _.eq(NaN, NaN); + * // => true + */var po;var go;function yo(){if(go)return po;go=1;function e(e,t){return e===t||e!==e&&t!==t}po=e;return po}var mo;var bo;function xo(){if(bo)return mo;bo=1;var e=yo(); +/** + * Gets the index at which the `key` is found in `array` of key-value pairs. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} key The key to search for. + * @returns {number} Returns the index of the matched value, else `-1`. + */function t(t,r){var a=t.length;while(a--)if(e(t[a][0],r))return a;return-1}mo=t;return mo}var wo;var Eo;function To(){if(Eo)return wo;Eo=1;var e=xo();var t=Array.prototype;var r=t.splice; +/** + * Removes `key` and its value from the list cache. + * + * @private + * @name delete + * @memberOf ListCache + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */function a(t){var a=this.__data__,n=e(a,t);if(n<0)return false;var i=a.length-1;n==i?a.pop():r.call(a,n,1);--this.size;return true}wo=a;return wo}var ko;var Co;function Po(){if(Co)return ko;Co=1;var e=xo(); +/** + * Gets the list cache value for `key`. + * + * @private + * @name get + * @memberOf ListCache + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */function t(t){var r=this.__data__,a=e(r,t);return a<0?void 0:r[a][1]}ko=t;return ko}var So;var Bo;function Do(){if(Bo)return So;Bo=1;var e=xo(); +/** + * Checks if a list cache value for `key` exists. + * + * @private + * @name has + * @memberOf ListCache + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */function t(t){return e(this.__data__,t)>-1}So=t;return So}var _o;var Ao;function Mo(){if(Ao)return _o;Ao=1;var e=xo(); +/** + * Sets the list cache `key` to `value`. + * + * @private + * @name set + * @memberOf ListCache + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the list cache instance. + */function t(t,r){var a=this.__data__,n=e(a,t);if(n<0){++this.size;a.push([t,r])}else a[n][1]=r;return this}_o=t;return _o}var Io;var Ro;function No(){if(Ro)return Io;Ro=1;var e=ho(),t=To(),r=Po(),a=Do(),n=Mo(); +/** + * Creates an list cache object. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */function i(e){var t=-1,r=e==null?0:e.length;this.clear();while(++t [1, 2] + * + * values(other); + * // => [3, 4] + * + * object.a = 2; + * values(object); + * // => [1, 2] + * + * // Modify the result cache. + * values.cache.set(object, ['a', 'b']); + * values(object); + * // => ['a', 'b'] + * + * // Replace `_.memoize.Cache`. + * _.memoize.Cache = WeakMap; + */function r(a,n){if(typeof a!="function"||n!=null&&typeof n!="function")throw new TypeError(t);var i=function(){var e=arguments,t=n?n.apply(this,e):e[0],r=i.cache;if(r.has(t))return r.get(t);var o=a.apply(this,e);i.cache=r.set(t,o)||r;return o};i.cache=new(r.Cache||e);return i}r.Cache=e;us=r;return us}var ds;var fs;function hs(){if(fs)return ds;fs=1;var e=cs();var t=500; +/** + * A specialized version of `_.memoize` which clears the memoized function's + * cache when it exceeds `MAX_MEMOIZE_SIZE`. + * + * @private + * @param {Function} func The function to have its output memoized. + * @returns {Function} Returns the new memoized function. + */function r(r){var a=e(r,(function(e){n.size===t&&n.clear();return e}));var n=a.cache;return a}ds=r;return ds}var ps;var gs;function ys(){if(gs)return ps;gs=1;var e=hs();var t=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;var r=/\\(\\)?/g; +/** + * Converts `string` to a property path array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the property path array. + */var a=e((function(e){var a=[];e.charCodeAt(0)===46&&a.push("");e.replace(t,(function(e,t,n,i){a.push(n?i.replace(r,"$1"):t||e)}));return a}));ps=a;return ps} +/** + * A specialized version of `_.map` for arrays without support for iteratee + * shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the new mapped array. + */var ms;var bs;function xs(){if(bs)return ms;bs=1;function e(e,t){var r=-1,a=e==null?0:e.length,n=Array(a);while(++r '' + * + * _.toString(-0); + * // => '-0' + * + * _.toString([1, 2, 3]); + * // => '1,2,3' + */function t(t){return t==null?"":e(t)}ks=t;return ks}var Ss;var Bs;function Ds(){if(Bs)return Ss;Bs=1;var e=bi(),t=Ei(),r=ys(),a=Ps(); +/** + * Casts `value` to a path array if it's not one. + * + * @private + * @param {*} value The value to inspect. + * @param {Object} [object] The object to query keys on. + * @returns {Array} Returns the cast property path array. + */function n(n,i){return e(n)?n:t(n,i)?[n]:r(a(n))}Ss=n;return Ss}var _s;var As;function Ms(){if(As)return _s;As=1;var e=$e(); +/** + * Converts `value` to a string key if it's not a string or symbol. + * + * @private + * @param {*} value The value to inspect. + * @returns {string|symbol} Returns the key. + */function t(t){if(typeof t=="string"||e(t))return t;var r=t+"";return r=="0"&&1/t==-Infinity?"-0":r}_s=t;return _s}var Is;var Rs;function Ns(){if(Rs)return Is;Rs=1;var e=Ds(),t=Ms(); +/** + * The base implementation of `_.get` without support for default values. + * + * @private + * @param {Object} object The object to query. + * @param {Array|string} path The path of the property to get. + * @returns {*} Returns the resolved value. + */function r(r,a){a=e(a,r);var n=0,i=a.length;while(r!=null&&n 3 + * + * _.get(object, ['a', '0', 'b', 'c']); + * // => 3 + * + * _.get(object, 'a.b.c', 'default'); + * // => 'default' + */function t(t,r,a){var n=t==null?void 0:e(t,r);return n===void 0?a:n}Ls=t;return Ls}var Vs=zs();var Fs=pe(Vs);var Xs;var js;function Ys(){if(js)return Xs;js=1;var e=Yi();var t=function(){try{var t=e(Object,"defineProperty");t({},"",{});return t}catch(e){}}();Xs=t;return Xs}var qs;var Ws;function Us(){if(Ws)return qs;Ws=1;var e=Ys(); +/** + * The base implementation of `assignValue` and `assignMergeValue` without + * value checks. + * + * @private + * @param {Object} object The object to modify. + * @param {string} key The key of the property to assign. + * @param {*} value The value to assign. + */function t(t,r,a){r=="__proto__"&&e?e(t,r,{configurable:true,enumerable:true,value:a,writable:true}):t[r]=a}qs=t;return qs}var Gs;var Hs;function Ks(){if(Hs)return Gs;Hs=1;var e=Us(),t=yo();var r=Object.prototype;var a=r.hasOwnProperty; +/** + * Assigns `value` to `key` of `object` if the existing value is not equivalent + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. + * + * @private + * @param {Object} object The object to modify. + * @param {string} key The key of the property to assign. + * @param {*} value The value to assign. + */function n(r,n,i){var o=r[n];a.call(r,n)&&t(o,i)&&(i!==void 0||n in r)||e(r,n,i)}Gs=n;return Gs}var Zs;var $s;function Qs(){if($s)return Zs;$s=1;var e=9007199254740991;var t=/^(?:0|[1-9]\d*)$/; +/** + * Checks if `value` is a valid array-like index. + * + * @private + * @param {*} value The value to check. + * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. + * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. + */function r(r,a){var n=typeof r;a=a==null?e:a;return!!a&&(n=="number"||n!="symbol"&&t.test(r))&&r>-1&&r%1==0&&r 4 + * + * _.set(object, ['x', '0', 'y', 'z'], 5); + * console.log(object.x[0].y.z); + * // => 5 + */function t(t,r,a){return t==null?t:e(t,r,a)}rl=t;return rl}var il=nl();var ol=pe(il); +/** + * Copies the values of `source` to `array`. + * + * @private + * @param {Array} source The array to copy values from. + * @param {Array} [array=[]] The array to copy values to. + * @returns {Array} Returns `array`. + */var sl;var ll;function ul(){if(ll)return sl;ll=1;function e(e,t){var r=-1,a=e.length;t||(t=Array(a));while(++r ['a', 'b', 'c'] + * + * _.toPath('a[0].b.c'); + * // => ['a', '0', 'b', 'c'] + */function s(s){return r(s)?e(s,i):a(s)?[s]:t(n(o(s)))}vl=s;return vl}var fl=dl();var hl=pe(fl);var pl={data:function(e){var t={field:"data",bindingEvent:"data",allowBinding:false,allowSetting:false,allowGetting:false,settingEvent:"data",settingTriggersEvent:false,triggerFnName:"trigger",immutableKeys:{},updateStyle:false,beforeGet:function(e){},beforeSet:function(e,t){},onSet:function(e){},canSet:function(e){return true}};e=ie({},t,e);return function(t,r){var a=e;var n=this;var i=n.length!==void 0;var o=i?n:[n];var l=i?n[0]:n;if(C(t)){var u=t.indexOf(".")!==-1;var v=u&&hl(t);if(a.allowGetting&&r===void 0){var c;if(l){a.beforeGet(l);c=v&&l._private[a.field][t]===void 0?Fs(l._private[a.field],v):l._private[a.field][t]}return c}if(a.allowSetting&&r!==void 0){var d=!a.immutableKeys[t];if(d){var f=s({},t,r);a.beforeSet(n,f);for(var h=0,p=o.length;h0&&this.spawn(a).updateStyle().emit("class");return t},addClass:function(e){return this.toggleClass(e,true)},hasClass:function(e){var t=this[0];return t!=null&&t._private.classes.has(e)},toggleClass:function(e,t){S(e)||(e=e.match(/\S+/g)||[]);var r=this;var a=t===void 0;var n=[];for(var i=0,o=r.length;i0&&this.spawn(n).updateStyle().emit("class");return r},removeClass:function(e){return this.toggleClass(e,false)},flashClass:function(e,t){var r=this;if(t==null)t=250;else if(t===0)return r;r.addClass(e);setTimeout((function(){r.removeClass(e)}),t);return r}};bl.className=bl.classNames=bl.classes;var xl={metaChar:"[\\!\\\"\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\]\\^\\`\\{\\|\\}\\~]",comparatorOp:"=|\\!=|>|>=|<|<=|\\$=|\\^=|\\*=",boolOp:"\\?|\\!|\\^",string:"\"(?:\\\\\"|[^\"])*\"|'(?:\\\\'|[^'])*'",number:Z,meta:"degree|indegree|outdegree",separator:"\\s*,\\s*",descendant:"\\s+",child:"\\s+>\\s+",subject:"\\$",group:"node|edge|\\*",directedEdge:"\\s+->\\s+",undirectedEdge:"\\s+<->\\s+"};xl.variable="(?:[\\w-.]|(?:\\\\"+xl.metaChar+"))+";xl.className="(?:[\\w-]|(?:\\\\"+xl.metaChar+"))+";xl.value=xl.string+"|"+xl.number;xl.id=xl.variable;(function(){var e,t,r;e=xl.comparatorOp.split("|");for(r=0;r=0||t!=="="&&(xl.comparatorOp+="|\\!"+t)}})();var wl=function(){return{checks:[]}};var El={GROUP:0,COLLECTION:1,FILTER:2,DATA_COMPARE:3,DATA_EXIST:4,DATA_BOOL:5,META_COMPARE:6,STATE:7,ID:8,CLASS:9,UNDIRECTED_EDGE:10,DIRECTED_EDGE:11,NODE_SOURCE:12,NODE_TARGET:13,NODE_NEIGHBOR:14,CHILD:15,DESCENDANT:16,PARENT:17,ANCESTOR:18,COMPOUND_SPLIT:19,TRUE:20};var Tl=[{selector:":selected",matches:function(e){return e.selected()}},{selector:":unselected",matches:function(e){return!e.selected()}},{selector:":selectable",matches:function(e){return e.selectable()}},{selector:":unselectable",matches:function(e){return!e.selectable()}},{selector:":locked",matches:function(e){return e.locked()}},{selector:":unlocked",matches:function(e){return!e.locked()}},{selector:":visible",matches:function(e){return e.visible()}},{selector:":hidden",matches:function(e){return!e.visible()}},{selector:":transparent",matches:function(e){return e.transparent()}},{selector:":grabbed",matches:function(e){return e.grabbed()}},{selector:":free",matches:function(e){return!e.grabbed()}},{selector:":removed",matches:function(e){return e.removed()}},{selector:":inside",matches:function(e){return!e.removed()}},{selector:":grabbable",matches:function(e){return e.grabbable()}},{selector:":ungrabbable",matches:function(e){return!e.grabbable()}},{selector:":animated",matches:function(e){return e.animated()}},{selector:":unanimated",matches:function(e){return!e.animated()}},{selector:":parent",matches:function(e){return e.isParent()}},{selector:":childless",matches:function(e){return e.isChildless()}},{selector:":child",matches:function(e){return e.isChild()}},{selector:":orphan",matches:function(e){return e.isOrphan()}},{selector:":nonorphan",matches:function(e){return e.isChild()}},{selector:":compound",matches:function(e){return e.isNode()?e.isParent():e.source().isParent()||e.target().isParent()}},{selector:":loop",matches:function(e){return e.isLoop()}},{selector:":simple",matches:function(e){return e.isSimple()}},{selector:":active",matches:function(e){return e.active()}},{selector:":inactive",matches:function(e){return!e.active()}},{selector:":backgrounding",matches:function(e){return e.backgrounding()}},{selector:":nonbackgrounding",matches:function(e){return!e.backgrounding()}}].sort((function(e,t){return ne(e.selector,t.selector)}));var kl=function(){var e={};var t;for(var r=0;r0&&u.edgeCount>0){Ot("The selector `"+e+"` is invalid because it uses both a compound selector and an edge selector");return false}if(u.edgeCount>1){Ot("The selector `"+e+"` is invalid because it uses multiple edge selectors");return false}u.edgeCount===1&&Ot("The selector `"+e+"` is deprecated. Edge selectors do not take effect on changes to source and target nodes after an edge is added, for performance reasons. Use a class or data selector on edges instead, updating the class or data of an edge when your app detects a change in source or target nodes.")}return true}; +/** + * Get the selector represented as a string. This value uses default formatting, + * so things like spacing may differ from the input text passed to the constructor. + * @returns {string} The selector string + */var Il=function(){if(this.toStringCache!=null)return this.toStringCache;var e=function(e){return e==null?"":e};var t=function(t){return C(t)?'"'+t+'"':e(t)};var r=function(e){return" "+e+" "};var a=function(a,i){var o=a.type,s=a.value;switch(o){case El.GROUP:var l=e(s);return l.substring(0,l.length-1);case El.DATA_COMPARE:var u=a.field,v=a.operator;return"["+u+r(e(v))+t(s)+"]";case El.DATA_BOOL:var c=a.operator,d=a.field;return"["+e(c)+d+"]";case El.DATA_EXIST:var f=a.field;return"["+f+"]";case El.META_COMPARE:var h=a.operator,p=a.field;return"[["+p+r(e(h))+t(s)+"]]";case El.STATE:return s;case El.ID:return"#"+s;case El.CLASS:return"."+s;case El.PARENT:case El.CHILD:return n(a.parent,i)+r(">")+n(a.child,i);case El.ANCESTOR:case El.DESCENDANT:return n(a.ancestor,i)+" "+n(a.descendant,i);case El.COMPOUND_SPLIT:var g=n(a.left,i);var y=n(a.subject,i);var m=n(a.right,i);return g+(g.length>0?" ":"")+y+m;case El.TRUE:return""}};var n=function(e,t){return e.checks.reduce((function(r,n,i){return r+(t===e&&i===0?"$":"")+a(n,t)}),"")};var i="";for(var o=0;o1&&o=0){t=t.replace("!","");v=true}if(t.indexOf("@")>=0){t=t.replace("@","");u=true}if(n||o||u){s=n||i?""+e:"";l=""+r}if(u){e=s=s.toLowerCase();r=l=l.toLowerCase()}switch(t){case"*=":a=s.indexOf(l)>=0;break;case"$=":a=s.indexOf(l,s.length-l.length)>=0;break;case"^=":a=s.indexOf(l)===0;break;case"=":a=e===r;break;case">":c=true;a=e>r;break;case">=":c=true;a=e>=r;break;case"<":c=true;a=e0){var v=n.shift();t(v);i.add(v.id());s&&a(n,i,v)}return e}function $l(e,t,r){if(r.isParent()){var a=r._private.children;for(var n=0;n1&&arguments[1]!==void 0)||arguments[1];return Zl(this,e,t,$l)};function Ql(e,t,r){if(r.isChild()){var a=r._private.parent;t.has(a.id())||e.push(a)}}Kl.forEachUp=function(e){var t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];return Zl(this,e,t,Ql)};function Jl(e,t,r){Ql(e,t,r);$l(e,t,r)}Kl.forEachUpAndDown=function(e){var t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];return Zl(this,e,t,Jl)};Kl.ancestors=Kl.parents;var eu,tu;eu=tu={data:yl.data({field:"data",bindingEvent:"data",allowBinding:true,allowSetting:true,settingEvent:"data",settingTriggersEvent:true,triggerFnName:"trigger",allowGetting:true,immutableKeys:{id:true,source:true,target:true,parent:true},updateStyle:true}),removeData:yl.removeData({field:"data",event:"data",triggerFnName:"trigger",triggerEvent:true,immutableKeys:{id:true,source:true,target:true,parent:true},updateStyle:true}),scratch:yl.data({field:"scratch",bindingEvent:"scratch",allowBinding:true,allowSetting:true,settingEvent:"scratch",settingTriggersEvent:true,triggerFnName:"trigger",allowGetting:true,updateStyle:true}),removeScratch:yl.removeData({field:"scratch",event:"scratch",triggerFnName:"trigger",triggerEvent:true,updateStyle:true}),rscratch:yl.data({field:"rscratch",allowBinding:false,allowSetting:true,settingTriggersEvent:false,allowGetting:true}),removeRscratch:yl.removeData({field:"rscratch",triggerEvent:false}),id:function(){var e=this[0];if(e)return e._private.data.id}};eu.attr=eu.data;eu.removeAttr=eu.removeData;var ru=tu;var au={};function nu(e){return function(t){var r=this;t===void 0&&(t=true);if(r.length!==0&&r.isNode()&&!r.removed()){var a=0;var n=r[0];var i=n._private.edges;for(var o=0;ot})),minIndegree:iu("indegree",(function(e,t){return et})),minOutdegree:iu("outdegree",(function(e,t){return et}))});ie(au,{totalDegree:function(e){var t=0;var r=this.nodes();for(var a=0;a0;var v=u;u&&(l=l[0]);var c=v?l.position():{x:0,y:0};n={x:s.x-c.x,y:s.y-c.y};return e===void 0?n:n[e]}for(var d=0;d0;var g=p;p&&(h=h[0]);var y=g?h.position():{x:0,y:0};t!==void 0?f.position(e,t+y[e]):n!==void 0&&f.position({x:n.x+y.x,y:n.y+y.y})}}else if(!i)return;return this}};ou.modelPosition=ou.point=ou.position;ou.modelPositions=ou.points=ou.positions;ou.renderedPoint=ou.renderedPosition;ou.relativePoint=ou.relativePosition;var vu=su;var cu,du;cu=du={};du.renderedBoundingBox=function(e){var t=this.boundingBox(e);var r=this.cy();var a=r.zoom();var n=r.pan();var i=t.x1*a+n.x;var o=t.x2*a+n.x;var s=t.y1*a+n.y;var l=t.y2*a+n.y;return{x1:i,x2:o,y1:s,y2:l,w:o-i,h:l-s}};du.dirtyCompoundBoundsCache=function(){var e=arguments.length>0&&arguments[0]!==void 0&&arguments[0];var t=this.cy();if(!t.styleEnabled()||!t.hasCompoundNodes())return this;this.forEachUp((function(t){if(t.isParent()){var r=t._private;r.compoundBoundsClean=false;r.bbCache=null;e||t.emitAndNotify("bounds")}}));return this};du.updateCompoundBounds=function(){var e=arguments.length>0&&arguments[0]!==void 0&&arguments[0];var t=this.cy();if(!t.styleEnabled()||!t.hasCompoundNodes())return this;if(!e&&t.batching())return this;function r(e){if(e.isParent()){var t=e._private;var r=e.children();var a=e.pstyle("compound-sizing-wrt-labels").value==="include";var n={width:{val:e.pstyle("min-width").pfValue,left:e.pstyle("min-width-bias-left"),right:e.pstyle("min-width-bias-right")},height:{val:e.pstyle("min-height").pfValue,top:e.pstyle("min-height-bias-top"),bottom:e.pstyle("min-height-bias-bottom")}};var i=r.boundingBox({includeLabels:a,includeOverlays:false,useCache:false});var o=t.position;if(i.w===0||i.h===0){i={w:e.pstyle("width").pfValue,h:e.pstyle("height").pfValue};i.x1=o.x-i.w/2;i.x2=o.x+i.w/2;i.y1=o.y-i.h/2;i.y2=o.y+i.h/2}var s=n.width.left.value;n.width.left.units==="px"&&n.width.val>0&&(s=s*100/n.width.val);var l=n.width.right.value;n.width.right.units==="px"&&n.width.val>0&&(l=l*100/n.width.val);var u=n.height.top.value;n.height.top.units==="px"&&n.height.val>0&&(u=u*100/n.height.val);var v=n.height.bottom.value;n.height.bottom.units==="px"&&n.height.val>0&&(v=v*100/n.height.val);var c=y(n.width.val-i.w,s,l);var d=c.biasDiff;var f=c.biasComplementDiff;var h=y(n.height.val-i.h,u,v);var p=h.biasDiff;var g=h.biasComplementDiff;t.autoPadding=m(i.w,i.h,e.pstyle("padding"),e.pstyle("padding-relative-to").value);t.autoWidth=Math.max(i.w,n.width.val);o.x=(-d+i.x1+i.x2+f)/2;t.autoHeight=Math.max(i.h,n.height.val);o.y=(-p+i.y1+i.y2+g)/2}function y(e,t,r){var a=0;var n=0;var i=t+r;if(e>0&&i>0){a=t/i*e;n=r/i*e}return{biasDiff:a,biasComplementDiff:n}}function m(e,t,r,a){if(r.units!=="%")return r.units==="px"?r.pfValue:0;switch(a){case"width":return e>0?r.pfValue*e:0;case"height":return t>0?r.pfValue*t:0;case"average":return e>0&&t>0?r.pfValue*(e+t)/2:0;case"min":return e>0&&t>0?e>t?r.pfValue*t:r.pfValue*e:0;case"max":return e>0&&t>0?e>t?r.pfValue*e:r.pfValue*t:0;default:return 0}}}for(var a=0;ae.x2?a:e.x2;e.y1=re.y2?n:e.y2;e.w=e.x2-e.x1;e.h=e.y2-e.y1}};var pu=function(e,t){return t==null?e:hu(e,t.x1,t.y1,t.x2,t.y2)};var gu=function(e,t,r){return Ht(e,t,r)};var yu=function(e,t,r){if(!t.cy().headless()){var a=t._private;var n=a.rstyle;var i=n.arrowWidth/2;var o=t.pstyle(r+"-arrow-shape").value;var s;var l;if(o!=="none"){if(r==="source"){s=n.srcX;l=n.srcY}else if(r==="target"){s=n.tgtX;l=n.tgtY}else{s=n.midX;l=n.midY}var u=a.arrowBounds=a.arrowBounds||{};var v=u[r]=u[r]||{};v.x1=s-i;v.y1=l-i;v.x2=s+i;v.y2=l+i;v.w=v.x2-v.x1;v.h=v.y2-v.y1;$r(v,1);hu(e,v.x1,v.y1,v.x2,v.y2)}}};var mu=function(e,t,r){if(!t.cy().headless()){var a;a=r?r+"-":"";var n=t._private;var i=n.rstyle;var o=t.pstyle(a+"label").strValue;if(o){var s=t.pstyle("text-halign");var l=t.pstyle("text-valign");var u=gu(i,"labelWidth",r);var v=gu(i,"labelHeight",r);var c=gu(i,"labelX",r);var d=gu(i,"labelY",r);var f=t.pstyle(a+"text-margin-x").pfValue;var h=t.pstyle(a+"text-margin-y").pfValue;var p=t.isEdge();var g=t.pstyle(a+"text-rotation");var y=t.pstyle("text-outline-width").pfValue;var m=t.pstyle("text-border-width").pfValue;var b=m/2;var x=t.pstyle("text-background-padding").pfValue;var w=2;var E=v;var T=u;var k=T/2;var C=E/2;var P,S,B,D;if(p){P=c-k;S=c+k;B=d-C;D=d+C}else{switch(s.value){case"left":P=c-T;S=c;break;case"center":P=c-k;S=c+k;break;case"right":P=c;S=c+T;break}switch(l.value){case"top":B=d-E;D=d;break;case"center":B=d-C;D=d+C;break;case"bottom":B=d;D=d+E;break}}var _=f-Math.max(y,b)-x-w;var A=f+Math.max(y,b)+x+w;var M=h-Math.max(y,b)-x-w;var I=h+Math.max(y,b)+x+w;P+=_;S+=A;B+=M;D+=I;var R=r||"main";var N=n.labelBounds;var L=N[R]=N[R]||{};L.x1=P;L.y1=B;L.x2=S;L.y2=D;L.w=S-P;L.h=D-B;L.leftPad=_;L.rightPad=A;L.topPad=M;L.botPad=I;var O=p&&g.strValue==="autorotate";var z=g.pfValue!=null&&g.pfValue!==0;if(O||z){var V=O?gu(n.rstyle,"labelAngle",r):g.pfValue;var F=Math.cos(V);var X=Math.sin(V);var j=(P+S)/2;var Y=(B+D)/2;if(!p){switch(s.value){case"left":j=S;break;case"right":j=P;break}switch(l.value){case"top":Y=D;break;case"bottom":Y=B;break}}var q=function(e,t){e-=j;t-=Y;return{x:e*F-t*X+j,y:e*X+t*F+Y}};var W=q(P,B);var U=q(P,D);var G=q(S,B);var H=q(S,D);P=Math.min(W.x,U.x,G.x,H.x);S=Math.max(W.x,U.x,G.x,H.x);B=Math.min(W.y,U.y,G.y,H.y);D=Math.max(W.y,U.y,G.y,H.y)}var K=R+"Rot";var Z=N[K]=N[K]||{};Z.x1=P;Z.y1=B;Z.x2=S;Z.y2=D;Z.w=S-P;Z.h=D-B;hu(e,P,B,S,D);hu(n.labelBounds.all,P,B,S,D)}return e}};var bu=function(e,t){if(!t.cy().headless()){var r=t.pstyle("outline-opacity").value;var a=t.pstyle("outline-width").value;var n=t.pstyle("outline-offset").value;var i=a+n;xu(e,t,r,i,"outside",i/2)}};var xu=function(e,t,r,a,n,i){if(!(r===0||a<=0||n==="inside")){var o=t.cy();var s=t.pstyle("shape").value;var l=o.renderer().nodeShapes[s];var u=t.position(),v=u.x,c=u.y;var d=t.width();var f=t.height();if(l.hasMiterBounds){n==="center"&&(a/=2);var h=l.miterBounds(v,c,d,f,a);pu(e,h)}else i!=null&&i>0&&Qr(e,[i,i,i,i])}};var wu=function(e,t){if(!t.cy().headless()){var r=t.pstyle("border-opacity").value;var a=t.pstyle("border-width").pfValue;var n=t.pstyle("border-position").value;xu(e,t,r,a,n)}};var Eu=function(e,t){var r=e._private.cy;var a=r.styleEnabled();var n=r.headless();var i=Ur();var o=e._private;var s=e.isNode();var l=e.isEdge();var u,v,c,d;var f,h;var p=o.rstyle;var g=s&&a?e.pstyle("bounds-expansion").pfValue:[0];var y=function(e){return e.pstyle("display").value!=="none"};var m=!a||y(e)&&(!l||y(e.source())&&y(e.target()));if(m){var b=0;var x=0;if(a&&t.includeOverlays){b=e.pstyle("overlay-opacity").value;b!==0&&(x=e.pstyle("overlay-padding").value)}var w=0;var E=0;if(a&&t.includeUnderlays){w=e.pstyle("underlay-opacity").value;w!==0&&(E=e.pstyle("underlay-padding").value)}var T=Math.max(x,E);var k=0;var C=0;if(a){k=e.pstyle("width").pfValue;C=k/2}if(s&&t.includeNodes){var P=e.position();f=P.x;h=P.y;var S=e.outerWidth();var B=S/2;var D=e.outerHeight();var _=D/2;u=f-B;v=f+B;c=h-_;d=h+_;hu(i,u,c,v,d);a&&bu(i,e);a&&t.includeOutlines&&!n&&bu(i,e);a&&wu(i,e)}else if(l&&t.includeEdges)if(a&&!n){var A=e.pstyle("curve-style").strValue;u=Math.min(p.srcX,p.midX,p.tgtX);v=Math.max(p.srcX,p.midX,p.tgtX);c=Math.min(p.srcY,p.midY,p.tgtY);d=Math.max(p.srcY,p.midY,p.tgtY);u-=C;v+=C;c-=C;d+=C;hu(i,u,c,v,d);if(A==="haystack"){var M=p.haystackPts;if(M&&M.length===2){u=M[0].x;c=M[0].y;v=M[1].x;d=M[1].y;if(u>v){var I=u;u=v;v=I}if(c>d){var R=c;c=d;d=R}hu(i,u-C,c-C,v+C,d+C)}}else if(A==="bezier"||A==="unbundled-bezier"||K(A,"segments")||K(A,"taxi")){var N;switch(A){case"bezier":case"unbundled-bezier":N=p.bezierPts;break;case"segments":case"taxi":case"round-segments":case"round-taxi":N=p.linePts;break}if(N!=null)for(var L=0;Lv){var j=u;u=v;v=j}if(c>d){var Y=c;c=d;d=Y}u-=C;v+=C;c-=C;d+=C;hu(i,u,c,v,d)}if(a&&t.includeEdges&&l){yu(i,e,"mid-source");yu(i,e,"mid-target");yu(i,e,"source");yu(i,e,"target")}if(a){var q=e.pstyle("ghost").value==="yes";if(q){var W=e.pstyle("ghost-offset-x").pfValue;var U=e.pstyle("ghost-offset-y").pfValue;hu(i,i.x1+W,i.y1+U,i.x2+W,i.y2+U)}}var G=o.bodyBounds=o.bodyBounds||{};Jr(G,i);Qr(G,g);$r(G,1);if(a){u=i.x1;v=i.x2;c=i.y1;d=i.y2;hu(i,u-T,c-T,v+T,d+T)}var H=o.overlayBounds=o.overlayBounds||{};Jr(H,i);Qr(H,g);$r(H,1);var Z=o.labelBounds=o.labelBounds||{};Z.all!=null?Hr(Z.all):Z.all=Ur();if(a&&t.includeLabels){t.includeMainLabels&&mu(i,e,null);if(l){t.includeSourceLabels&&mu(i,e,"source");t.includeTargetLabels&&mu(i,e,"target")}}}i.x1=fu(i.x1);i.y1=fu(i.y1);i.x2=fu(i.x2);i.y2=fu(i.y2);i.w=fu(i.x2-i.x1);i.h=fu(i.y2-i.y1);if(i.w>0&&i.h>0&&m){Qr(i,g);$r(i,1)}return i};var Tu=function(e){var t=0;var r=function(e){return(e?1:0)<0&&arguments[0]!==void 0?arguments[0]:Ju;var t=arguments.length>1?arguments[1]:void 0;for(var r=0;r=0;s--)o(s);return this};tv.removeAllListeners=function(){return this.removeListener("*")};tv.emit=tv.trigger=function(e,t,r){var a=this.listeners;var n=a.length;this.emitting++;S(t)||(t=[t]);nv(this,(function(e,i){if(r!=null){a=[{event:i.event,type:i.type,namespace:i.namespace,callback:r}];n=a.length}var o=function(){var r=a[s];if(r.type===i.type&&(!r.namespace||r.namespace===i.namespace||r.namespace===Zu)&&e.eventMatches(e.context,r,i)){var n=[i];t!=null&&Gt(n,t);e.beforeEmit(e.context,r,i);r.conf&&r.conf.one&&(e.listeners=e.listeners.filter((function(e){return e!==r})));var o=e.callbackContext(e.context,r,i);var l=r.callback.apply(o,n);e.afterEmit(e.context,r,i);if(l===false){i.stopPropagation();i.preventDefault()}}};for(var s=0;s1&&!i){var o=this.length-1;var s=this[o];var l=s._private.data.id;this[o]=void 0;this[e]=s;n.set(l,{ele:s,index:e})}this.length--;return this},unmergeOne:function(e){e=e[0];var t=this._private;var r=e._private.data.id;var a=t.map;var n=a.get(r);if(!n)return this;var i=n.index;this.unmergeAt(i);return this},unmerge:function(e){var t=this._private.cy;if(!e)return this;if(e&&C(e)){var r=e;e=t.mutableElements().filter(r)}for(var a=0;a=0;t--){var r=this[t];e(r)&&this.unmergeAt(t)}return this},map:function(e,t){var r=[];var a=this;for(var n=0;nr){r=s;a=o}}return{value:r,ele:a}},min:function(e,t){var r=Infinity;var a;var n=this;for(var i=0;i=0&&n1&&arguments[1]!==void 0)||arguments[1];var r=this[0];var a=r.cy();if(a.styleEnabled()&&r){if(r._private.styleDirty){r._private.styleDirty=false;a.style().apply(r)}var n=r._private.style[e];return n!=null?n:t?a.style().getDefaultProperty(e):null}},numericStyle:function(e){var t=this[0];if(t.cy().styleEnabled()&&t){var r=t.pstyle(e);return r.pfValue!==void 0?r.pfValue:r.value}},numericStyleUnits:function(e){var t=this[0];if(t.cy().styleEnabled())return t?t.pstyle(e).units:void 0},renderedStyle:function(e){var t=this.cy();if(!t.styleEnabled())return this;var r=this[0];return r?t.style().getRenderedStyle(r,e):void 0},style:function(e,t){var r=this.cy();if(!r.styleEnabled())return this;var a=false;var n=r.style();if(B(e)){var i=e;n.applyBypass(this,i,a);this.emitAndNotify("style")}else if(C(e)){if(t===void 0){var o=this[0];return o?n.getStylePropertyValue(o,e):void 0}n.applyBypass(this,e,t,a);this.emitAndNotify("style")}else if(e===void 0){var s=this[0];return s?n.getRawStyle(s):void 0}return this},removeStyle:function(e){var t=this.cy();if(!t.styleEnabled())return this;var r=false;var a=t.style();var n=this;if(e===void 0)for(var i=0;i0&&t.push(v[0]);t.push(s[0])}}return this.spawn(t,true).filter(e)}),"neighborhood"),closedNeighborhood:function(e){return this.neighborhood().add(this).filter(e)},openNeighborhood:function(e){return this.neighborhood(e)}});_v.neighbourhood=_v.neighborhood;_v.closedNeighbourhood=_v.closedNeighborhood;_v.openNeighbourhood=_v.openNeighborhood;ie(_v,{source:Hl((function(e){var t=this[0];var r;t&&(r=t._private.source||t.cy().collection());return r&&e?r.filter(e):r}),"source"),target:Hl((function(e){var t=this[0];var r;t&&(r=t._private.target||t.cy().collection());return r&&e?r.filter(e):r}),"target"),sources:Rv({attr:"source"}),targets:Rv({attr:"target"})});function Rv(e){return function(t){var r=[];for(var a=0;a0);return i},component:function(){var e=this[0];return e.cy().mutableElements().components(e)[0]}});_v.componentsOf=_v.components;var Ov=function(e,t){var r=arguments.length>2&&arguments[2]!==void 0&&arguments[2];var a=arguments.length>3&&arguments[3]!==void 0&&arguments[3];if(e!==void 0){var n=new $t;var i=false;if(t){if(t.length>0&&B(t[0])&&!R(t[0])){i=true;var o=[];var s=new er;for(var l=0,u=t.length;l0&&arguments[0]!==void 0)||arguments[0];var t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];var r=this;var a=r.cy();var n=a._private;var i=[];var o=[];var s;for(var l=0,u=r.length;l0){var O=s.length===r.length?r:new Ov(a,s);for(var z=0;z0&&arguments[0]!==void 0)||arguments[0];var t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];var r=this;var a=[];var n={};var i=r._private.cy;function o(e){var t=e._private.edges;for(var r=0;r0&&(e?S.emitAndNotify("remove"):t&&S.emit("remove"));for(var B=0;B0?n=l:a=l}while(Math.abs(i)>o&&++u=i?m(t,v):c===0?v:x(t,a,a+u)}var E=false;function T(){E=true;e===t&&r===a||b()}var k=function(n){E||T();return e===t&&r===a?n:n===0?0:n===1?1:g(w(n),t,a)};k.getControlPoints=function(){return[{x:e,y:t},{x:r,y:a}]};var C="generateBezier("+[e,t,r,a]+")";k.toString=function(){return C};return k}var Xv=function(){function e(e){return-e.tension*e.x-e.friction*e.v}function t(t,r,a){var n={x:t.x+a.dx*r,v:t.v+a.dv*r,tension:t.tension,friction:t.friction};return{dx:n.v,dv:e(n)}}function r(r,a){var n={dx:r.v,dv:e(r)},i=t(r,a*.5,n),o=t(r,a*.5,i),s=t(r,a,o),l=1/6*(n.dx+2*(i.dx+o.dx)+s.dx),u=1/6*(n.dv+2*(i.dv+o.dv)+s.dv);r.x=r.x+l*a;r.v=r.v+u*a;return r}return function e(t,a,n){var i,o,s,l={x:-1,v:0,tension:null,friction:null},u=[0],v=0,c=1e-4,d=.016;t=parseFloat(t)||500;a=parseFloat(a)||20;n=n||null;l.tension=t;l.friction=a;i=n!==null;if(i){v=e(t,a);o=v/n*d}else o=d;for(;;){s=r(s||l,o);u.push(1+s.x);v+=16;if(!(Math.abs(s.x)>c&&Math.abs(s.v)>c))break}return i?function(e){return u[e*(u.length-1)|0]}:v}}();var jv=function(e,t,r,a){var n=Fv(e,t,r,a);return function(e,t,r){return e+(t-e)*n(r)}};var Yv={linear:function(e,t,r){return e+(t-e)*r},ease:jv(.25,.1,.25,1),"ease-in":jv(.42,0,1,1),"ease-out":jv(0,0,.58,1),"ease-in-out":jv(.42,0,.58,1),"ease-in-sine":jv(.47,0,.745,.715),"ease-out-sine":jv(.39,.575,.565,1),"ease-in-out-sine":jv(.445,.05,.55,.95),"ease-in-quad":jv(.55,.085,.68,.53),"ease-out-quad":jv(.25,.46,.45,.94),"ease-in-out-quad":jv(.455,.03,.515,.955),"ease-in-cubic":jv(.55,.055,.675,.19),"ease-out-cubic":jv(.215,.61,.355,1),"ease-in-out-cubic":jv(.645,.045,.355,1),"ease-in-quart":jv(.895,.03,.685,.22),"ease-out-quart":jv(.165,.84,.44,1),"ease-in-out-quart":jv(.77,0,.175,1),"ease-in-quint":jv(.755,.05,.855,.06),"ease-out-quint":jv(.23,1,.32,1),"ease-in-out-quint":jv(.86,0,.07,1),"ease-in-expo":jv(.95,.05,.795,.035),"ease-out-expo":jv(.19,1,.22,1),"ease-in-out-expo":jv(1,0,0,1),"ease-in-circ":jv(.6,.04,.98,.335),"ease-out-circ":jv(.075,.82,.165,1),"ease-in-out-circ":jv(.785,.135,.15,.86),spring:function(e,t,r){if(r===0)return Yv.linear;var a=Xv(e,t,r);return function(e,t,r){return e+(t-e)*a(r)}},"cubic-bezier":jv};function qv(e,t,r,a,n){if(a===1)return r;if(t===r)return r;var i=n(t,r,a);if(e==null)return i;(e.roundValue||e.color)&&(i=Math.round(i));e.min!==void 0&&(i=Math.max(i,e.min));e.max!==void 0&&(i=Math.min(i,e.max));return i}function Wv(e,t){return e.pfValue!=null||e.value!=null?e.pfValue==null||t!=null&&t.type.units==="%"?e.value:e.pfValue:e}function Uv(e,t,r,a,n){var i=n!=null?n.type:null;r<0?r=0:r>1&&(r=1);var o=Wv(e,n);var s=Wv(t,n);if(_(o)&&_(s))return qv(i,o,s,r,a);if(S(o)&&S(s)){var l=[];for(var u=0;u0){f==="spring"&&h.push(o.duration);o.easingImpl=Yv[f].apply(null,h)}else o.easingImpl=Yv[f]}var p=o.easingImpl;var g;g=o.duration===0?1:(r-l)/o.duration;o.applying&&(g=o.progress);g<0?g=0:g>1&&(g=1);if(o.delay==null){var y=o.startPosition;var m=o.position;if(m&&n&&!e.locked()){var b={};Hv(y.x,m.x)&&(b.x=Uv(y.x,m.x,g,p));Hv(y.y,m.y)&&(b.y=Uv(y.y,m.y,g,p));e.position(b)}var x=o.startPan;var w=o.pan;var E=i.pan;var T=w!=null&&a;if(T){Hv(x.x,w.x)&&(E.x=Uv(x.x,w.x,g,p));Hv(x.y,w.y)&&(E.y=Uv(x.y,w.y,g,p));e.emit("pan")}var k=o.startZoom;var P=o.zoom;var S=P!=null&&a;if(S){Hv(k,P)&&(i.zoom=Wr(i.minZoom,Uv(k,P,g,p),i.maxZoom));e.emit("zoom")}(T||S)&&e.emit("viewport");var B=o.style;if(B&&B.length>0&&n){for(var D=0;D=0;t--){var r=e[t];r()}e.splice(0,e.length)};for(var v=i.length-1;v>=0;v--){var c=i[v];var d=c._private;if(d.stopped){i.splice(v,1);d.hooked=false;d.playing=false;d.started=false;u(d.frames)}else if(d.playing||d.applying){d.playing&&d.applying&&(d.applying=false);d.started||Kv(t,c,e);Gv(t,c,e,r);d.applying&&(d.applying=false);u(d.frames);d.step!=null&&d.step(e);if(c.completed()){i.splice(v,1);d.hooked=false;d.playing=false;d.started=false;u(d.completes)}s=true}}r||i.length!==0||o.length!==0||a.push(t);return s}var i=false;for(var o=0;o0?t.notify("draw",r):t.notify("draw"));r.unmerge(a);t.emit("step")}var $v={animate:yl.animate(),animation:yl.animation(),animated:yl.animated(),clearQueue:yl.clearQueue(),delay:yl.delay(),delayAnimation:yl.delayAnimation(),stop:yl.stop(),addToAnimationPool:function(e){var t=this;t.styleEnabled()&&t._private.aniEles.merge(e)},stopAnimationLoop:function(){this._private.animationsRunning=false},startAnimationLoop:function(){var e=this;e._private.animationsRunning=true;if(e.styleEnabled()){var t=e.renderer();t&&t.beforeRender?t.beforeRender((function(t,r){Zv(r,e)}),t.beforeRenderPriorities.animations):r()}function r(){e._private.animationsRunning&&ut((function(t){Zv(t,e);r()}))}}};var Qv={qualifierCompare:function(e,t){return e==null||t==null?e==null&&t==null:e.sameText(t)},eventMatches:function(e,t,r){var a=t.qualifier;return a==null||e!==r.target&&R(r.target)&&a.matches(r.target)},addEventFields:function(e,t){t.cy=e;t.target=e},callbackContext:function(e,t,r){return t.qualifier!=null?r.target:e}};var Jv=function(e){return C(e)?new Wl(e):e};var ec={createEmitter:function(){var e=this._private;e.emitter||(e.emitter=new ev(Qv,this));return this},emitter:function(){return this._private.emitter},on:function(e,t,r){this.emitter().on(e,Jv(t),r);return this},removeListener:function(e,t,r){this.emitter().removeListener(e,Jv(t),r);return this},removeAllListeners:function(){this.emitter().removeAllListeners();return this},one:function(e,t,r){this.emitter().one(e,Jv(t),r);return this},once:function(e,t,r){this.emitter().one(e,Jv(t),r);return this},emit:function(e,t){this.emitter().emit(e,t);return this},emitAndNotify:function(e,t){this.emit(e);this.notify(e,t);return this}};yl.eventAliasesOn(ec);var tc={png:function(e){var t=this._private.renderer;e=e||{};return t.png(e)},jpg:function(e){var t=this._private.renderer;e=e||{};e.bg=e.bg||"#fff";return t.jpg(e)}};tc.jpeg=tc.jpg;var rc={layout:function(e){var t=this;if(e!=null)if(e.name!=null){var r=e.name;var a=t.extension("layout",r);if(a!=null){var n;n=C(e.eles)?t.$(e.eles):e.eles!=null?e.eles:t.$();var i=new a(ie({},e,{cy:t,eles:n}));return i}Nt("No such layout `"+r+"` found. Did you forget to import it and `cytoscape.use()` it?")}else Nt("A `name` must be specified to make a layout");else Nt("Layout options must be specified to make a layout")}};rc.createLayout=rc.makeLayout=rc.layout;var ac={notify:function(e,t){var r=this._private;if(this.batching()){r.batchNotifications=r.batchNotifications||{};var a=r.batchNotifications[e]=r.batchNotifications[e]||this.collection();t!=null&&a.merge(t)}else if(r.notificationsEnabled){var n=this.renderer();!this.destroyed()&&n&&n.notify(e,t)}},notifications:function(e){var t=this._private;if(e===void 0)return t.notificationsEnabled;t.notificationsEnabled=!!e;return this},noNotifications:function(e){this.notifications(false);e();this.notifications(true)},batching:function(){return this._private.batchCount>0},startBatch:function(){var e=this._private;e.batchCount==null&&(e.batchCount=0);if(e.batchCount===0){e.batchStyleEles=this.collection();e.batchNotifications={}}e.batchCount++;return this},endBatch:function(){var e=this._private;if(e.batchCount===0)return this;e.batchCount--;if(e.batchCount===0){e.batchStyleEles.updateStyle();var t=this.renderer();Object.keys(e.batchNotifications).forEach((function(r){var a=e.batchNotifications[r];a.empty()?t.notify(r):t.notify(r,a)}))}return this},batch:function(e){this.startBatch();e();this.endBatch();return this},batchData:function(e){var t=this;return this.batch((function(){var r=Object.keys(e);for(var a=0;a0)t.removeChild(t.childNodes[0])}e._private.renderer=null;e.mutableElements().forEach((function(e){var t=e._private;t.rscratch={};t.rstyle={};t.animation.current=[];t.animation.queue=[]}))},onRender:function(e){return this.on("render",e)},offRender:function(e){return this.off("render",e)}};ic.invalidateDimensions=ic.resize;var oc={collection:function(e,t){if(C(e))return this.$(e);if(I(e))return e.collection();if(S(e)){t||(t={});return new Ov(this,e,t.unique,t.removed)}return new Ov(this)},nodes:function(e){var t=this.$((function(e){return e.isNode()}));return e?t.filter(e):t},edges:function(e){var t=this.$((function(e){return e.isEdge()}));return e?t.filter(e):t},$:function(e){var t=this._private.elements;return e?t.filter(e):t.spawnSelf()},mutableElements:function(){return this._private.elements}};oc.elements=oc.filter=oc.$;var sc={};var lc="t";var uc="f";sc.apply=function(e){var t=this;var r=t._private;var a=r.cy;var n=a.collection();for(var i=0;i0;if(d||c&&f){var h=void 0;d&&f||d?h=u.properties:f&&(h=u.mappedProperties);for(var p=0;p1&&(x=1);if(s.color){var E=a.valueMin[0];var T=a.valueMax[0];var k=a.valueMin[1];var C=a.valueMax[1];var P=a.valueMin[2];var S=a.valueMax[2];var B=a.valueMin[3]==null?1:a.valueMin[3];var D=a.valueMax[3]==null?1:a.valueMax[3];var A=[Math.round(E+(T-E)*x),Math.round(k+(C-k)*x),Math.round(P+(S-P)*x),Math.round(B+(D-B)*x)];i={bypass:a.bypass,name:a.name,value:A,strValue:"rgb("+A[0]+", "+A[1]+", "+A[2]+")"}}else{if(!s.number)return false;var M=a.valueMin+(a.valueMax-a.valueMin)*x;i=this.parse(a.name,M,a.bypass,d)}if(!i){p();return false}i.mapping=a;a=i;break;case o.data:var I=a.field.split(".");var R=c.data;for(var N=0;N0&&i>0){var s={};var l=false;for(var u=0;u0?e.delayAnimation(o).play().promise().then(t):t()})).then((function(){return e.animation({style:s,duration:i,easing:e.pstyle("transition-timing-function").value,queue:false}).play().promise()})).then((function(){r.removeBypasses(e,n);e.emitAndNotify("style");a.transitioning=false}))}else if(a.transitioning){this.removeBypasses(e,n);e.emitAndNotify("style");a.transitioning=false}};sc.checkTrigger=function(e,t,r,a,n,i){var o=this.properties[t];var s=n(o);e.removed()||s!=null&&s(r,a,e)&&i(o)};sc.checkZOrderTrigger=function(e,t,r,a){var n=this;this.checkTrigger(e,t,r,a,(function(e){return e.triggersZOrder}),(function(){n._private.cy.notify("zorder",e)}))};sc.checkBoundsTrigger=function(e,t,r,a){this.checkTrigger(e,t,r,a,(function(e){return e.triggersBounds}),(function(t){e.dirtyCompoundBoundsCache();e.dirtyBoundingBoxCache()}))};sc.checkConnectedEdgesBoundsTrigger=function(e,t,r,a){this.checkTrigger(e,t,r,a,(function(e){return e.triggersBoundsOfConnectedEdges}),(function(t){e.connectedEdges().forEach((function(e){e.dirtyBoundingBoxCache()}))}))};sc.checkParallelEdgesBoundsTrigger=function(e,t,r,a){this.checkTrigger(e,t,r,a,(function(e){return e.triggersBoundsOfParallelEdges}),(function(t){e.parallelEdges().forEach((function(e){e.dirtyBoundingBoxCache()}))}))};sc.checkTriggers=function(e,t,r,a){e.dirtyStyleCache();this.checkZOrderTrigger(e,t,r,a);this.checkBoundsTrigger(e,t,r,a);this.checkConnectedEdgesBoundsTrigger(e,t,r,a);this.checkParallelEdgesBoundsTrigger(e,t,r,a)};var vc={};vc.applyBypass=function(e,t,r,a){var n=this;var i=[];var o=true;if(t==="*"||t==="**"){if(r!==void 0)for(var s=0;sn.length?a.substr(n.length):""}function l(){i=i.length>o.length?i.substr(o.length):""}for(;;){var u=a.match(/^\s*$/);if(u)break;var v=a.match(/^\s*((?:.|\s)+?)\s*\{((?:.|\s)+?)\}/);if(!v){Ot("Halting stylesheet parsing: String stylesheet contains more to parse but no selector and block found in: "+a);break}n=v[0];var c=v[1];if(c!=="core"){var d=new Wl(c);if(d.invalid){Ot("Skipping parsing of block: Invalid selector found in string stylesheet: "+c);s();continue}}var f=v[2];var h=false;i=f;var p=[];for(;;){var g=i.match(/^\s*$/);if(g)break;var y=i.match(/^\s*(.+?)\s*:\s*(.+?)(?:\s*;|\s*$)/);if(!y){Ot("Skipping parsing of block: Invalid formatting of style property and value definitions found in:"+f);h=true;break}o=y[0];var m=y[1];var b=y[2];var x=t.properties[m];if(x){var w=r.parse(m,b);if(w){p.push({name:m,val:b});l()}else{Ot("Skipping property: Invalid property definition in: "+o);l()}}else{Ot("Skipping property: Invalid property name in: "+o);l()}}if(h){s();break}r.selector(c);for(var E=0;E=7&&t[0]==="d"&&(v=new RegExp(s.data.regex).exec(t))){if(r)return false;var d=s.data;return{name:e,value:v,strValue:""+t,mapped:d,field:v[1],bypass:r}}if(t.length>=10&&t[0]==="m"&&(c=new RegExp(s.mapData.regex).exec(t))){if(r)return false;if(u.multiple)return false;var f=s.mapData;if(!(u.color||u.number))return false;var h=this.parse(e,c[4]);if(!h||h.mapped)return false;var p=this.parse(e,c[5]);if(!p||p.mapped)return false;if(h.pfValue===p.pfValue||h.strValue===p.strValue){Ot("`"+e+": "+t+"` is not a valid mapper because the output range is zero; converting to `"+e+": "+h.strValue+"`");return this.parse(e,h.strValue)}if(u.color){var g=h.value;var y=p.value;var m=g[0]===y[0]&&g[1]===y[1]&&g[2]===y[2]&&(g[3]===y[3]||(g[3]==null||g[3]===1)&&(y[3]==null||y[3]===1));if(m)return false}return{name:e,value:c,strValue:""+t,mapped:f,field:c[1],fieldMin:parseFloat(c[2]),fieldMax:parseFloat(c[3]),valueMin:h.value,valueMax:p.value,bypass:r}}}if(u.multiple&&a!=="multiple"){var b;b=l?t.split(/\s+/):S(t)?t:[t];if(u.evenMultiple&&b.length%2!==0)return null;var x=[];var w=[];var E=[];var T="";var k=false;for(var B=0;B0?" ":"")+D.strValue}return u.validate&&!u.validate(x,w)?null:u.singleEnum&&k?x.length===1&&C(x[0])?{name:e,value:x[0],strValue:x[0],bypass:r}:null:{name:e,value:x,pfValue:E,strValue:T,bypass:r,units:w}}var _=function(){for(var a=0;au.max||u.strictMax&&t===u.max))return null;var L={name:e,value:t,strValue:""+t+(M||""),units:M,bypass:r};u.unitless||M!=="px"&&M!=="em"?L.pfValue=t:L.pfValue=M!=="px"&&M?this.getEmSizeInPixels()*t:t;M!=="ms"&&M!=="s"||(L.pfValue=M==="ms"?t:1e3*t);M!=="deg"&&M!=="rad"||(L.pfValue=M==="rad"?t:Nr(t));M==="%"&&(L.pfValue=t/100);return L}if(u.propList){var O=[];var z=""+t;if(z==="none");else{var V=z.split(/\s*,\s*|\s+/);for(var F=0;F0&&o>0&&!isNaN(r.w)&&!isNaN(r.h)&&r.w>0&&r.h>0){s=Math.min((i-2*t)/r.w,(o-2*t)/r.h);s=s>this._private.maxZoom?this._private.maxZoom:s;s=s=r.minZoom&&(r.maxZoom=t);return this},minZoom:function(e){return e===void 0?this._private.minZoom:this.zoomRange({min:e})},maxZoom:function(e){return e===void 0?this._private.maxZoom:this.zoomRange({max:e})},getZoomedViewport:function(e){var t=this._private;var r=t.pan;var a=t.zoom;var n;var i;var o=false;t.zoomingEnabled||(o=true);if(_(e))i=e;else if(B(e)){i=e.level;e.position!=null?n=Br(e.position,a,r):e.renderedPosition!=null&&(n=e.renderedPosition);n==null||t.panningEnabled||(o=true)}i=i>t.maxZoom?t.maxZoom:i;i=it.maxZoom||!t.zoomingEnabled)i=true;else{t.zoom=s;n.push("zoom")}}if(a&&(!i||!e.cancelOnFailedZoom)&&t.panningEnabled){var l=e.pan;if(_(l.x)){t.pan.x=l.x;o=false}if(_(l.y)){t.pan.y=l.y;o=false}o||n.push("pan")}if(n.length>0){n.push("viewport");this.emit(n.join(" "));this.notify("viewport")}return this},center:function(e){var t=this.getCenterPan(e);if(t){this._private.pan=t;this.emit("pan viewport");this.notify("viewport")}return this},getCenterPan:function(e,t){if(this._private.panningEnabled){if(C(e)){var r=e;e=this.mutableElements().filter(r)}else I(e)||(e=this.mutableElements());if(e.length!==0){var a=e.boundingBox();var n=this.width();var i=this.height();t=t===void 0?this._private.zoom:t;var o={x:(n-t*(a.x1+a.x2))/2,y:(i-t*(a.y1+a.y2))/2};return o}}},reset:function(){if(!this._private.panningEnabled||!this._private.zoomingEnabled)return this;this.viewport({pan:{x:0,y:0},zoom:1});return this},invalidateSize:function(){this._private.sizeCache=null},size:function(){var e=this._private;var t=e.container;var r=this;return e.sizeCache=e.sizeCache||(t?function(){var e=r.window().getComputedStyle(t);var a=function(t){return parseFloat(e.getPropertyValue(t))};return{width:t.clientWidth-a("padding-left")-a("padding-right"),height:t.clientHeight-a("padding-top")-a("padding-bottom")}}():{width:1,height:1})},width:function(){return this.size().width},height:function(){return this.size().height},extent:function(){var e=this._private.pan;var t=this._private.zoom;var r=this.renderedExtent();var a={x1:(r.x1-e.x)/t,x2:(r.x2-e.x)/t,y1:(r.y1-e.y)/t,y2:(r.y2-e.y)/t};a.w=a.x2-a.x1;a.h=a.y2-a.y1;return a},renderedExtent:function(){var e=this.width();var t=this.height();return{x1:0,y1:0,x2:e,y2:t,w:e,h:t}},multiClickDebounceTime:function(e){if(!e)return this._private.multiClickDebounceTime;this._private.multiClickDebounceTime=e;return this}};wc.centre=wc.center;wc.autolockNodes=wc.autolock;wc.autoungrabifyNodes=wc.autoungrabify;var Ec={data:yl.data({field:"data",bindingEvent:"data",allowBinding:true,allowSetting:true,settingEvent:"data",settingTriggersEvent:true,triggerFnName:"trigger",allowGetting:true,updateStyle:true}),removeData:yl.removeData({field:"data",event:"data",triggerFnName:"trigger",triggerEvent:true,updateStyle:true}),scratch:yl.data({field:"scratch",bindingEvent:"scratch",allowBinding:true,allowSetting:true,settingEvent:"scratch",settingTriggersEvent:true,triggerFnName:"trigger",allowGetting:true,updateStyle:true}),removeScratch:yl.removeData({field:"scratch",event:"scratch",triggerFnName:"trigger",triggerEvent:true,updateStyle:true})};Ec.attr=Ec.data;Ec.removeAttr=Ec.removeData;var Tc=function(e){var t=this;e=ie({},e);var r=e.container;r&&!M(r)&&M(r[0])&&(r=r[0]);var a=r?r._cyreg:null;a=a||{};if(a&&a.cy){a.cy.destroy();a={}}var n=a.readies=a.readies||[];r&&(r._cyreg=a);a.cy=t;var i=m!==void 0&&r!==void 0&&!e.headless;var o=e;o.layout=ie({name:i?"grid":"null"},o.layout);o.renderer=ie({name:i?"canvas":"null"},o.renderer);var s=function(e,t,r){return t!==void 0?t:r!==void 0?r:e};var l=this._private={container:r,ready:false,options:o,elements:new Ov(this),listeners:[],aniEles:new Ov(this),data:o.data||{},scratch:{},layout:null,renderer:null,destroyed:false,notificationsEnabled:true,minZoom:1e-50,maxZoom:1e50,zoomingEnabled:s(true,o.zoomingEnabled),userZoomingEnabled:s(true,o.userZoomingEnabled),panningEnabled:s(true,o.panningEnabled),userPanningEnabled:s(true,o.userPanningEnabled),boxSelectionEnabled:s(true,o.boxSelectionEnabled),autolock:s(false,o.autolock,o.autolockNodes),autoungrabify:s(false,o.autoungrabify,o.autoungrabifyNodes),autounselectify:s(false,o.autounselectify),styleEnabled:o.styleEnabled===void 0?i:o.styleEnabled,zoom:_(o.zoom)?o.zoom:1,pan:{x:B(o.pan)&&_(o.pan.x)?o.pan.x:0,y:B(o.pan)&&_(o.pan.y)?o.pan.y:0},animation:{current:[],queue:[]},hasCompoundNodes:false,multiClickDebounceTime:s(250,o.multiClickDebounceTime)};this.createEmitter();this.selectionType(o.selectionType);this.zoomRange({min:o.minZoom,max:o.maxZoom});var u=function(e,t){var r=e.some(j);if(r)return fi.all(e).then(t);t(e)};l.styleEnabled&&t.setStyle([]);var v=ie({},o,o.renderer);t.initRenderer(v);var c=function(e,r,a){t.notifications(false);var n=t.mutableElements();n.length>0&&n.remove();e!=null&&(B(e)||S(e))&&t.add(e);t.one("layoutready",(function(e){t.notifications(true);t.emit(e);t.one("load",r);t.emitAndNotify("load")})).one("layoutstop",(function(){t.one("done",a);t.emit("done")}));var i=ie({},t._private.options.layout);i.eles=t.elements();t.layout(i).run()};u([o.style,o.elements],(function(e){var r=e[0];var i=e[1];l.styleEnabled&&t.style().append(r);c(i,(function(){t.startAnimationLoop();l.ready=true;P(o.ready)&&t.on("ready",o.ready);for(var e=0;e0;var s=!!e.boundingBox;var l=Ur(s?e.boundingBox:structuredClone(t.extent()));var u;if(I(e.roots))u=e.roots;else if(S(e.roots)){var v=[];for(var c=0;c0){var M=A();var R=P(M,D);if(R)M.outgoers().filter((function(e){return e.isNode()&&r.has(e)})).forEach(_);else if(R===null){Ot("Detected double maximal shift for node `"+M.id()+"`. Bailing maximal adjustment due to cycle. Use `options.maximal: true` only on DAGs.");break}}}var N=0;if(e.avoidOverlap)for(var L=0;L0&&y[0].length<=3?i/2:0);var u=2*Math.PI/y[a].length*n;a===0&&y[0].length===1&&(o=1);return{x:$.x+o*Math.cos(u),y:$.y+o*Math.sin(u)}}var v=y[a].length;var c=Math.max(v===1?0:s?(l.w-e.padding*2-Q.w)/((e.grid?ee:v)-1):(l.w-e.padding*2-Q.w)/((e.grid?ee:v)+1),N);var d={x:$.x+(n+1-(v+1)/2)*c,y:$.y+(a+1-(q+1)/2)*J};return d};var re={downward:0,leftward:90,upward:180,rightward:-90};Object.keys(re).indexOf(e.direction)===-1&&Nt("Invalid direction '".concat(e.direction,"' specified for breadthfirst layout. Valid values are: ").concat(Object.keys(re).join(", ")));var ne=function(t){return Pt(te(t),l,re[e.direction])};r.nodes().layoutPositions(this,e,ne);return this};var _c={fit:true,padding:30,boundingBox:void 0,avoidOverlap:true,nodeDimensionsIncludeLabels:false,spacingFactor:void 0,radius:void 0,startAngle:1.5*Math.PI,sweep:void 0,clockwise:true,sort:void 0,animate:false,animationDuration:500,animationEasing:void 0,animateFilter:function(e,t){return true},ready:void 0,stop:void 0,transform:function(e,t){return t}};function Ac(e){this.options=ie({},_c,e)}Ac.prototype.run=function(){var e=this.options;var t=e;var r=e.cy;var a=t.eles;var n=t.counterclockwise!==void 0?!t.counterclockwise:t.clockwise;var i=a.nodes().not(":parent");t.sort&&(i=i.sort(t.sort));var o=Ur(t.boundingBox?t.boundingBox:{x1:0,y1:0,w:r.width(),h:r.height()});var s={x:o.x1+o.w/2,y:o.y1+o.h/2};var l=t.sweep===void 0?2*Math.PI-2*Math.PI/i.length:t.sweep;var u=l/Math.max(1,i.length-1);var v;var c=0;for(var d=0;d1&&t.avoidOverlap){c*=1.75;var y=Math.cos(u)-Math.cos(0);var m=Math.sin(u)-Math.sin(0);var b=Math.sqrt(c*c/(y*y+m*m));v=Math.max(b,v)}var x=function(e,r){var a=t.startAngle+r*u*(n?1:-1);var i=v*Math.cos(a);var o=v*Math.sin(a);var l={x:s.x+i,y:s.y+o};return l};a.nodes().layoutPositions(this,t,x);return this};var Mc={fit:true,padding:30,startAngle:1.5*Math.PI,sweep:void 0,clockwise:true,equidistant:false,minNodeSpacing:10,boundingBox:void 0,avoidOverlap:true,nodeDimensionsIncludeLabels:false,height:void 0,width:void 0,spacingFactor:void 0,concentric:function(e){return e.degree()},levelWidth:function(e){return e.maxDegree()/4},animate:false,animationDuration:500,animationEasing:void 0,animateFilter:function(e,t){return true},ready:void 0,stop:void 0,transform:function(e,t){return t}};function Ic(e){this.options=ie({},Mc,e)}Ic.prototype.run=function(){var e=this.options;var t=e;var r=t.counterclockwise!==void 0?!t.counterclockwise:t.clockwise;var a=e.cy;var n=t.eles;var i=n.nodes().not(":parent");var o=Ur(t.boundingBox?t.boundingBox:{x1:0,y1:0,w:a.width(),h:a.height()});var s={x:o.x1+o.w/2,y:o.y1+o.h/2};var l=[];var u=0;for(var v=0;v0){var w=Math.abs(m[0].value-x.value);if(w>=g){m=[];y.push(m)}}m.push(x)}var E=u+t.minNodeSpacing;if(!t.avoidOverlap){var T=y.length>0&&y[0].length>1;var k=Math.min(o.w,o.h)/2-E;var C=k/(y.length+T?1:0);E=Math.min(E,C)}var P=0;for(var S=0;S1&&t.avoidOverlap){var A=Math.cos(_)-Math.cos(0);var M=Math.sin(_)-Math.sin(0);var I=Math.sqrt(E*E/(A*A+M*M));P=Math.max(I,P)}B.r=P;P+=E}if(t.equidistant){var R=0;var N=0;for(var L=0;L=e.numIter)return false;qc(a,e);a.temperature=a.temperature*e.coolingFactor;return!(a.temperature=e.animationThreshold&&i();ut(v)}else{rd(a,e);s()}};v()}else{while(u){u=o(l);l++}rd(a,e);s()}return this};Lc.prototype.stop=function(){this.stopped=true;this.thread&&this.thread.stop();this.emit("layoutstop");return this};Lc.prototype.destroy=function(){this.thread&&this.thread.stop();return this};var Oc=function(e,t,r){var a=r.eles.edges();var n=r.eles.nodes();var i=Ur(r.boundingBox?r.boundingBox:{x1:0,y1:0,w:e.width(),h:e.height()});var o={isCompound:e.hasCompoundNodes(),layoutNodes:[],idToIndex:{},nodeSize:n.size(),graphSet:[],indexToGraph:[],layoutEdges:[],edgeSize:a.size(),temperature:r.initialTemp,clientWidth:i.w,clientHeight:i.h,boundingBox:i};var s=r.eles.components();var l={};for(var u=0;u0){o.graphSet.push(T);for(u=0;ua.count?0:a.graph};var Vc=function(e,t,r,a){var n=a.graphSet[r];if(-10){var v=a.nodeOverlap*u;var c=Math.sqrt(o*o+s*s);var d=v*o/c;var f=v*s/c}else{var h=Kc(e,o,s);var p=Kc(t,-1*o,-1*s);var g=p.x-h.x;var y=p.y-h.y;var m=g*g+y*y;c=Math.sqrt(m);v=(e.nodeRepulsion+t.nodeRepulsion)/m;d=v*g/c;f=v*y/c}if(!e.isLocked){e.offsetX-=d;e.offsetY-=f}if(!t.isLocked){t.offsetX+=d;t.offsetY+=f}}};var Hc=function(e,t,r,a){if(r>0)var n=e.maxX-t.minX;else n=t.maxX-e.minX;if(a>0)var i=e.maxY-t.minY;else i=t.maxY-e.minY;return n>=0&&i>=0?Math.sqrt(n*n+i*i):0};var Kc=function(e,t,r){var a=e.positionX;var n=e.positionY;var i=e.height||1;var o=e.width||1;var s=r/t;var l=i/o;var u={};if(0===t&&0r){u.x=a;u.y=n+i/2;return u}if(0t&&-1*l<=s&&s<=l){u.x=a-o/2;u.y=n-o*r/2/t;return u}if(0=l)){u.x=a+i*t/2/r;u.y=n+i/2;return u}if(0>r&&(s<=-1*l||s>=l)){u.x=a-i*t/2/r;u.y=n-i/2;return u}return u};var Zc=function(e,t){for(var r=0;rr){var p=t.gravity*d/h;var g=t.gravity*f/h;c.offsetX+=p;c.offsetY+=g}}}}}};var Qc=function(e,t){var r=[];var a=0;var n=-1;r.push.apply(r,e.graphSet[0]);n+=e.graphSet[0].length;while(a<=n){var i=r[a++];var o=e.idToIndex[i];var s=e.layoutNodes[o];var l=s.children;if(0r)var n={x:r*e/a,y:r*t/a};else n={x:e,y:t};return n};var td=function(e,t){var r=e.parentId;if(null!=r){var a=t.layoutNodes[t.idToIndex[r]];var n=false;if(null==a.maxX||e.maxX+a.padRight>a.maxX){a.maxX=e.maxX+a.padRight;n=true}if(null==a.minX||e.minX-a.padLefta.maxY){a.maxY=e.maxY+a.padBottom;n=true}if(null==a.minY||e.minY-a.padTopg){f+=p+t.componentSpacing;d=0;h=0;p=0}}}};var ad={fit:true,padding:30,boundingBox:void 0,avoidOverlap:true,avoidOverlapPadding:10,nodeDimensionsIncludeLabels:false,spacingFactor:void 0,condense:false,rows:void 0,cols:void 0,position:function(e){},sort:void 0,animate:false,animationDuration:500,animationEasing:void 0,animateFilter:function(e,t){return true},ready:void 0,stop:void 0,transform:function(e,t){return t}};function nd(e){this.options=ie({},ad,e)}nd.prototype.run=function(){var e=this.options;var t=e;var r=e.cy;var a=t.eles;var n=a.nodes().not(":parent");t.sort&&(n=n.sort(t.sort));var i=Ur(t.boundingBox?t.boundingBox:{x1:0,y1:0,w:r.width(),h:r.height()});if(i.h===0||i.w===0)a.nodes().layoutPositions(this,t,(function(e){return{x:i.x1,y:i.y1}}));else{var o=n.size();var s=Math.sqrt(o*i.h/i.w);var l=Math.round(s);var u=Math.round(i.w/i.h*s);var v=function(e){if(e==null)return Math.min(l,u);var t=Math.min(l,u);t==l?l=e:u=e};var c=function(e){if(e==null)return Math.max(l,u);var t=Math.max(l,u);t==l?l=e:u=e};var d=t.rows;var f=t.cols!=null?t.cols:t.columns;if(d!=null&&f!=null){l=d;u=f}else if(d!=null&&f==null){l=d;u=Math.ceil(o/l)}else if(d==null&&f!=null){u=f;l=Math.ceil(o/u)}else if(u*l>o){var h=v();var p=c();(h-1)*p>=o?v(h-1):(p-1)*h>=o&&c(p-1)}else while(u*l=o?c(y+1):v(g+1)}var m=i.w/u;var b=i.h/l;if(t.condense){m=0;b=0}if(t.avoidOverlap)for(var x=0;x=u){A=0;_++}};var I={};for(var R=0;R(b=fa(e,t,x[w],x[w+1],x[w+2],x[w+3]))){g(r,b);return true}}else if(o.edgeType==="bezier"||o.edgeType==="multibezier"||o.edgeType==="self"||o.edgeType==="compound"){x=o.allpts;for(w=0;w+5(b=da(e,t,x[w],x[w+1],x[w+2],x[w+3],x[w+4],x[w+5]))){g(r,b);return true}}p=p||a.source;m=m||a.target;var E=n.getArrowWidth(l,c);var T=[{name:"source",x:o.arrowStartX,y:o.arrowStartY,angle:o.srcArrowAngle},{name:"target",x:o.arrowEndX,y:o.arrowEndY,angle:o.tgtArrowAngle},{name:"mid-source",x:o.midX,y:o.midY,angle:o.midsrcArrowAngle},{name:"mid-target",x:o.midX,y:o.midY,angle:o.midtgtArrowAngle}];for(w=0;w0){y(p);y(m)}}function b(e,t,r){return Ht(e,t,r)}function x(r,a){var n=r._private;var i=d;var o;o=a?a+"-":"";r.boundingBox();var s=n.labelBounds[a||"main"];var l=r.pstyle(o+"label").value;var u=r.pstyle("text-events").strValue==="yes";if(u&&l){var v=b(n.rscratch,"labelX",a);var c=b(n.rscratch,"labelY",a);var f=b(n.rscratch,"labelAngle",a);var h=r.pstyle(o+"text-margin-x").pfValue;var p=r.pstyle(o+"text-margin-y").pfValue;var y=s.x1-i-h;var m=s.x2+i-h;var x=s.y1-i-p;var w=s.y2+i-p;if(f){var E=Math.cos(f);var T=Math.sin(f);var k=function(e,t){e-=v;t-=c;return{x:e*E-t*T+v,y:e*T+t*E+c}};var C=k(y,x);var P=k(y,w);var S=k(m,x);var B=k(m,w);var D=[C.x+h,C.y+p,S.x+h,S.y+p,B.x+h,B.y+p,P.x+h,P.y+p];if(ha(e,t,D)){g(r);return true}}else if(ta(s,e,t)){g(r);return true}}}for(var w=o.length-1;w>=0;w--){var E=o[w];E.isNode()?y(E)||x(E):m(E)||x(E)||x(E,"source")||x(E,"target")}return s};gd.getAllInBox=function(e,t,r,a){var n=this.getCachedZSortedEles().interactive;var i=this.cy.zoom();var o=2/i;var s=[];var l=Math.min(e,r);var u=Math.max(e,r);var v=Math.min(t,a);var c=Math.max(t,a);e=l;r=u;t=v;a=c;var f=Ur({x1:e,y1:t,x2:r,y2:a});var h=[{x:f.x1,y:f.y1},{x:f.x2,y:f.y1},{x:f.x2,y:f.y2},{x:f.x1,y:f.y2}];var p=[[h[0],h[1]],[h[1],h[2]],[h[2],h[3]],[h[3],h[0]]];function g(e,t,r){return Ht(e,t,r)}function y(e,t){var r=e._private;var a=o;var n="";e.boundingBox();var i=r.labelBounds.main;if(!i)return null;var s=g(r.rscratch,"labelX",t);var l=g(r.rscratch,"labelY",t);var u=g(r.rscratch,"labelAngle",t);var v=e.pstyle(n+"text-margin-x").pfValue;var c=e.pstyle(n+"text-margin-y").pfValue;var d=i.x1-a-v;var f=i.x2+a-v;var h=i.y1-a-c;var p=i.y2+a-c;if(u){var y=Math.cos(u);var m=Math.sin(u);var b=function(e,t){e-=s;t-=l;return{x:e*y-t*m+s,y:e*m+t*y+l}};return[b(d,h),b(f,h),b(f,p),b(d,p)]}return[{x:d,y:h},{x:f,y:h},{x:f,y:p},{x:d,y:p}]}function m(e,t,r,a){function n(e,t,r){return(r.y-e.y)*(t.x-e.x)>(t.y-e.y)*(r.x-e.x)}return n(e,r,a)!==n(t,r,a)&&n(e,t,r)!==n(e,t,a)}for(var b=0;b0?-(Math.PI-e.ang):Math.PI+e.ang};var Vd=function(e,t,r,a,n){e!==Ld?Od(t,e,_d):zd(Ad,_d);Od(t,r,Ad);xd=_d.nx*Ad.ny-_d.ny*Ad.nx;wd=_d.nx*Ad.nx-_d.ny*-Ad.ny;kd=Math.asin(Math.max(-1,Math.min(1,xd)));if(Math.abs(kd)<1e-6){md=t.x;bd=t.y;Pd=Bd=0}else{Ed=1;Td=false;if(wd<0)if(kd<0)kd=Math.PI+kd;else{kd=Math.PI-kd;Ed=-1;Td=true}else if(kd>0){Ed=-1;Td=true}Bd=t.radius!==void 0?t.radius:a;Cd=kd/2;Dd=Math.min(_d.len/2,Ad.len/2);if(n){Sd=Math.abs(Math.cos(Cd)*Bd/Math.sin(Cd));if(Sd>Dd){Sd=Dd;Pd=Math.abs(Sd*Math.sin(Cd)/Math.cos(Cd))}else Pd=Bd}else{Sd=Math.min(Dd,Bd);Pd=Math.abs(Sd*Math.sin(Cd)/Math.cos(Cd))}Rd=t.x+Ad.nx*Sd;Nd=t.y+Ad.ny*Sd;md=Rd-Ad.ny*Pd*Ed;bd=Nd+Ad.nx*Pd*Ed;Md=t.x+_d.nx*Sd;Id=t.y+_d.ny*Sd;Ld=t}}; +/** + * Draw corner provided by {@link getRoundCorner} + * + * @param ctx :CanvasRenderingContext2D + * @param roundCorner {{cx:number, cy:number, radius:number, endAngle: number, startAngle: number, counterClockwise: boolean}} + */function Fd(e,t){t.radius===0?e.lineTo(t.cx,t.cy):e.arc(t.cx,t.cy,t.radius,t.startAngle,t.endAngle,t.counterClockwise)} +/** + * Get round corner from a point and its previous and next neighbours in a path + * + * @param previousPoint {{x: number, y:number, radius: number?}} + * @param currentPoint {{x: number, y:number, radius: number?}} + * @param nextPoint {{x: number, y:number, radius: number?}} + * @param radiusMax :number + * @param isArcRadius :boolean + * @return {{ + * cx:number, cy:number, radius:number, + * startX:number, startY:number, + * stopX:number, stopY: number, + * endAngle: number, startAngle: number, counterClockwise: boolean + * }} + */function Xd(e,t,r,a){var n=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4];if(a===0||t.radius===0)return{cx:t.x,cy:t.y,radius:0,startX:t.x,startY:t.y,stopX:t.x,stopY:t.y,startAngle:void 0,endAngle:void 0,counterClockwise:void 0};Vd(e,t,r,a,n);return{cx:md,cy:bd,radius:Pd,startX:Md,startY:Id,stopX:Rd,stopY:Nd,startAngle:_d.ang+Math.PI/2*Ed,endAngle:Ad.ang-Math.PI/2*Ed,counterClockwise:Td}}var jd=.01;var Yd=Math.sqrt(2*jd);var qd={};qd.findMidptPtsEtc=function(e,t){var r=t.posPts,a=t.intersectionPts,n=t.vectorNormInverse;var i;var o=e.pstyle("source-endpoint");var s=e.pstyle("target-endpoint");var l=o.units!=null&&s.units!=null;var u=function(e,t,r,a){var n=a-t;var i=r-e;var o=Math.sqrt(i*i+n*n);return{x:-n/o,y:i/o}};var v=e.pstyle("edge-distances").value;switch(v){case"node-position":i=r;break;case"intersection":i=a;break;case"endpoints":if(l){var c=this.manualEndptToPx(e.source()[0],o),f=d(c,2),h=f[0],p=f[1];var g=this.manualEndptToPx(e.target()[0],s),y=d(g,2),m=y[0],b=y[1];var x={x1:h,y1:p,x2:m,y2:b};n=u(h,p,m,b);i=x}else{Ot("Edge ".concat(e.id()," has edge-distances:endpoints specified without manual endpoints specified via source-endpoint and target-endpoint. Falling back on edge-distances:intersection (default)."));i=a}break}return{midptPts:i,vectorNormInverse:n}};qd.findHaystackPoints=function(e){for(var t=0;t0?Math.max(e-t,0):Math.min(e+t,0)};var D=B(P,k);var _=B(S,C);var A=false;if(m===u)y=Math.abs(D)>Math.abs(_)?n:a;else if(m===l||m===s){y=a;A=true}else if(m===i||m===o){y=n;A=true}var M=y===a;var I=M?_:D;var R=M?S:P;var N=zr(R);var L=false;if(!(A&&(x||E))&&(m===s&&R<0||m===l&&R>0||m===i&&R>0||m===o&&R<0)){N*=-1;I=N*Math.abs(I);L=true}var O;if(x){var z=w<0?1+w:w;O=z*I}else{var V=w<0?I:0;O=V+w*N}var F=function(e){return Math.abs(e)=Math.abs(I)};var X=F(O);var j=F(Math.abs(I)-Math.abs(O));var Y=X||j;if(Y&&!L)if(M){var q=Math.abs(R)<=d/2;var W=Math.abs(P)<=f/2;if(q){var U=(v.x1+v.x2)/2;var G=v.y1,H=v.y2;r.segpts=[U,G,U,H]}else if(W){var K=(v.y1+v.y2)/2;var Z=v.x1,$=v.x2;r.segpts=[Z,K,$,K]}else r.segpts=[v.x1,v.y2]}else{var Q=Math.abs(R)<=c/2;var J=Math.abs(S)<=h/2;if(Q){var ee=(v.y1+v.y2)/2;var te=v.x1,re=v.x2;r.segpts=[te,ee,re,ee]}else if(J){var ae=(v.x1+v.x2)/2;var ne=v.y1,ie=v.y2;r.segpts=[ae,ne,ae,ie]}else r.segpts=[v.x2,v.y1]}else if(M){var oe=v.y1+O+(g?d/2*N:0);var se=v.x1,le=v.x2;r.segpts=[se,oe,le,oe]}else{var ue=v.x1+O+(g?c/2*N:0);var ve=v.y1,ce=v.y2;r.segpts=[ue,ve,ue,ce]}if(r.isRound){var de=e.pstyle("taxi-radius").value;var fe=e.pstyle("radius-type").value[0]==="arc-radius";r.radii=new Array(r.segpts.length/2).fill(de);r.isArcRadius=new Array(r.segpts.length/2).fill(fe)}};qd.tryToCorrectInvalidPoints=function(e,t){var r=e._private.rscratch;if(r.edgeType==="bezier"){var a=t.srcPos,n=t.tgtPos,i=t.srcW,o=t.srcH,s=t.tgtW,l=t.tgtH,u=t.srcShape,v=t.tgtShape,c=t.srcCornerRadius,d=t.tgtCornerRadius,f=t.srcRs,h=t.tgtRs;var p=!_(r.startX)||!_(r.startY);var g=!_(r.arrowStartX)||!_(r.arrowStartY);var y=!_(r.endX)||!_(r.endY);var m=!_(r.arrowEndX)||!_(r.arrowEndY);var b=3;var x=this.getArrowWidth(e.pstyle("width").pfValue,e.pstyle("arrow-scale").value)*this.arrowShapeWidth;var w=b*x;var E=Vr({x:r.ctrlpts[0],y:r.ctrlpts[1]},{x:r.startX,y:r.startY});var T=Ep.poolIndex()){var g=h;h=p;p=g}var y=v.srcPos=h.position();var m=v.tgtPos=p.position();var b=v.srcW=h.outerWidth();var x=v.srcH=h.outerHeight();var w=v.tgtW=p.outerWidth();var E=v.tgtH=p.outerHeight();var T=v.srcShape=r.nodeShapes[t.getNodeShape(h)];var C=v.tgtShape=r.nodeShapes[t.getNodeShape(p)];var P=v.srcCornerRadius=h.pstyle("corner-radius").value==="auto"?"auto":h.pstyle("corner-radius").pfValue;var S=v.tgtCornerRadius=p.pstyle("corner-radius").value==="auto"?"auto":p.pstyle("corner-radius").pfValue;var B=v.tgtRs=p._private.rscratch;var D=v.srcRs=h._private.rscratch;v.dirCounts={north:0,west:0,south:0,east:0,northwest:0,southwest:0,northeast:0,southeast:0};for(var A=0;A=Yd||(W=Math.sqrt(Math.max(q*q,jd)+Math.max(Y*Y,jd)));var U=v.vector={x:q,y:Y};var G=v.vectorNorm={x:U.x/W,y:U.y/W};var H={x:-G.y,y:G.x};v.nodesOverlap=!_(W)||C.checkPoint(O[0],O[1],0,w,E,m.x,m.y,S,B)||T.checkPoint(V[0],V[1],0,b,x,y.x,y.y,P,D);v.vectorNormInverse=H;c={nodesOverlap:v.nodesOverlap,dirCounts:v.dirCounts,calculatedIntersection:true,hasBezier:v.hasBezier,hasUnbundled:v.hasUnbundled,eles:v.eles,srcPos:m,srcRs:B,tgtPos:y,tgtRs:D,srcW:w,srcH:E,tgtW:b,tgtH:x,srcIntn:F,tgtIntn:z,srcShape:C,tgtShape:T,posPts:{x1:j.x2,y1:j.y2,x2:j.x1,y2:j.y1},intersectionPts:{x1:X.x2,y1:X.y2,x2:X.x1,y2:X.y1},vector:{x:-U.x,y:-U.y},vectorNorm:{x:-G.x,y:-G.y},vectorNormInverse:{x:-H.x,y:-H.y}}}var Z=L?c:v;I.nodesOverlap=Z.nodesOverlap;I.srcIntn=Z.srcIntn;I.tgtIntn=Z.tgtIntn;I.isRound=R.startsWith("round");n&&(h.isParent()||h.isChild()||p.isParent()||p.isChild())&&(h.parents().anySame(p)||p.parents().anySame(h)||h.same(p)&&h.isParent())?t.findCompoundLoopPoints(M,Z,A,N):h===p?t.findLoopPoints(M,Z,A,N):R.endsWith("segments")?t.findSegmentsPoints(M,Z):R.endsWith("taxi")?t.findTaxiPoints(M,Z):R==="straight"||!N&&v.eles.length%2===1&&A===Math.floor(v.eles.length/2)?t.findStraightEdgePoints(M):t.findBezierPoints(M,Z,A,N,L);t.findEndpoints(M);t.tryToCorrectInvalidPoints(M,Z);t.checkForInvalidEdgeWarning(M);t.storeAllpts(M);t.storeEdgeProjections(M);t.calculateArrowAngles(M);t.recalculateEdgeLabelProjections(M);t.calculateLabelAngles(M)}};for(var k=0;k0){var re=u;var ae=Fr(re,_r(o));var ne=Fr(re,_r(te));var ie=ae;if(ne2){var oe=Fr(re,{x:te[2],y:te[3]});oe0){var be=v;var xe=Fr(be,_r(o));var we=Fr(be,_r(me));var Ee=xe;if(we2){var Te=Fr(be,{x:me[2],y:me[3]});Te=u||m){c={cp:p,segment:y};break}}if(c)break}var b=c.cp;var x=c.segment;var w=(u-d)/x.length;var E=x.t1-x.t0;var T=s?x.t0+E*w:x.t1-E*w;T=Wr(0,T,1);t=Yr(b.p0,b.p1,b.p2,T);n=Qd(b.p0,b.p1,b.p2,T);break;case"straight":case"segments":case"haystack":var k,C,P=0;var S,B;var D=a.allpts.length;for(var _=0;_+3=u)break}var A=u-C;var M=A/k;M=Wr(0,M,1);t=qr(S,B,M);n=$d(S,B);break}o("labelX",r,t.x);o("labelY",r,t.y);o("labelAutoAngle",r,n)}};u("source");u("target");this.applyLabelDimensions(e)}};Kd.applyLabelDimensions=function(e){this.applyPrefixedLabelDimensions(e);if(e.isEdge()){this.applyPrefixedLabelDimensions(e,"source");this.applyPrefixedLabelDimensions(e,"target")}};Kd.applyPrefixedLabelDimensions=function(e,t){var r=e._private;var a=this.getLabelText(e,t);var n=wt(a,e._private.labelDimsKey);if(Ht(r.rscratch,"prefixedLabelDimsKey",t)!==n){Kt(r.rscratch,"prefixedLabelDimsKey",t,n);var i=this.calculateLabelDimensions(e,a);var o=e.pstyle("line-height").pfValue;var s=e.pstyle("text-wrap").strValue;var l=Ht(r.rscratch,"labelWrapCachedLines",t)||[];var u=s!=="wrap"?1:Math.max(l.length,1);var v=i.height/u;var c=v*o;var d=i.width;var f=i.height+(u-1)*(o-1)*v;Kt(r.rstyle,"labelWidth",t,d);Kt(r.rscratch,"labelWidth",t,d);Kt(r.rstyle,"labelHeight",t,f);Kt(r.rscratch,"labelHeight",t,f);Kt(r.rscratch,"labelLineHeight",t,c)}};Kd.getLabelText=function(e,t){var r=e._private;var a=t?t+"-":"";var n=e.pstyle(a+"label").strValue;var i=e.pstyle("text-transform").value;var s=function(e,a){if(a){Kt(r.rscratch,e,t,a);return a}return Ht(r.rscratch,e,t)};if(!n)return"";i=="none"||(i=="uppercase"?n=n.toUpperCase():i=="lowercase"&&(n=n.toLowerCase()));var l=e.pstyle("text-wrap").value;if(l==="wrap"){var u=s("labelKey");if(u!=null&&s("labelWrapKey")===u)return s("labelWrapCachedText");var v="​";var c=n.split("\n");var d=e.pstyle("text-max-width").pfValue;var f=e.pstyle("text-overflow-wrap").value;var h=f==="anywhere";var p=[];var g=/[\s\u200b]+|$/g;for(var y=0;yd){var E=m.matchAll(g);var T="";var k=0;var C,P=o(E);try{for(P.s();!(C=P.n()).done;){var S=C.value;var B=S[0];var D=m.substring(k,S.index);k=S.index+B.length;var _=T.length===0?D:T+D+B;var A=this.calculateLabelDimensions(e,_);var M=A.width;if(M<=d)T+=D+B;else{T&&p.push(T);T=D+B}}}catch(e){P.e(e)}finally{P.f()}T.match(/^[\s\u200b]+$/)||p.push(T)}else p.push(m)}s("labelWrapCachedLines",p);n=s("labelWrapCachedText",p.join("\n"));s("labelWrapKey",u)}else if(l==="ellipsis"){var I=e.pstyle("text-max-width").pfValue;var R="";var N="…";var L=false;if(this.calculateLabelDimensions(e,n).widthI)break;R+=n[O];O===n.length-1&&(L=true)}L||(R+=N);return R}return n};Kd.getLabelJustification=function(e){var t=e.pstyle("text-justification").strValue;var r=e.pstyle("text-halign").strValue;if(t!=="auto")return t;if(!e.isNode())return"center";switch(r){case"left":return"right";case"right":return"left";default:return"center"}};Kd.calculateLabelDimensions=function(e,t){var r=this;var a=r.cy.window();var n=a.document;var i=0;var o=e.pstyle("font-style").strValue;var s=e.pstyle("font-size").pfValue;var l=e.pstyle("font-family").strValue;var u=e.pstyle("font-weight").strValue;var v=this.labelCalcCanvas;var c=this.labelCalcCanvasContext;if(!v){v=this.labelCalcCanvas=n.createElement("canvas");c=this.labelCalcCanvasContext=v.getContext("2d");var d=v.style;d.position="absolute";d.left="-9999px";d.top="-9999px";d.zIndex="-1";d.visibility="hidden";d.pointerEvents="none"}c.font="".concat(o," ").concat(u," ").concat(s,"px ").concat(l);var f=0;var h=0;var p=t.split("\n");for(var g=0;g1&&arguments[1]!==void 0)||arguments[1];t.merge(e);if(r)for(var a=0;a=e.desktopTapThreshold2}var B=i(t);w&&(e.hoverData.tapholdCancelled=true);var D=function(){var t=e.hoverData.dragDelta=e.hoverData.dragDelta||[];if(t.length===0){t.push(b[0]);t.push(b[1])}else{t[0]+=b[0];t[1]+=b[1]}};a=true;n(h,["mousemove","vmousemove","tapdrag"],t,{x:v[0],y:v[1]});var A=function(e){return{originalEvent:t,type:e,position:{x:v[0],y:v[1]}}};var M=function(){e.data.bgActivePosistion=void 0;e.hoverData.selecting||s.emit(A("boxstart"));f[4]=1;e.hoverData.selecting=true;e.redrawHint("select",true);e.redraw()};if(e.hoverData.which===3){if(w){var I=A("cxtdrag");m?m.emit(I):s.emit(I);e.hoverData.cxtDragged=true;if(!e.hoverData.cxtOver||h!==e.hoverData.cxtOver){e.hoverData.cxtOver&&e.hoverData.cxtOver.emit(A("cxtdragout"));e.hoverData.cxtOver=h;h&&h.emit(A("cxtdragover"))}}}else if(e.hoverData.dragging){a=true;if(s.panningEnabled()&&s.userPanningEnabled()){var R;if(e.hoverData.justStartedPan){var N=e.hoverData.mdownPos;R={x:(v[0]-N[0])*l,y:(v[1]-N[1])*l};e.hoverData.justStartedPan=false}else R={x:b[0]*l,y:b[1]*l};s.panBy(R);s.emit(A("dragpan"));e.hoverData.dragged=true}v=e.projectIntoViewport(t.clientX,t.clientY)}else if(f[4]!=1||m!=null&&!m.pannable()){m&&m.pannable()&&m.active()&&m.unactivate();if((!m||!m.grabbed())&&h!=g){g&&n(g,["mouseout","tapdragout"],t,{x:v[0],y:v[1]});h&&n(h,["mouseover","tapdragover"],t,{x:v[0],y:v[1]});e.hoverData.last=h}if(m)if(w){if(s.boxSelectionEnabled()&&B){if(m&&m.grabbed()){y(x);m.emit(A("freeon"));x.emit(A("free"));if(e.dragData.didDrag){m.emit(A("dragfreeon"));x.emit(A("dragfree"))}}M()}else if(m&&m.grabbed()&&e.nodeIsDraggable(m)){var L=!e.dragData.didDrag;L&&e.redrawHint("eles",true);e.dragData.didDrag=true;e.hoverData.draggingEles||p(x,{inDragLayer:true});var O={x:0,y:0};if(_(b[0])&&_(b[1])){O.x+=b[0];O.y+=b[1];if(L){var z=e.hoverData.dragDelta;if(z&&_(z[0])&&_(z[1])){O.x+=z[0];O.y+=z[1]}}}e.hoverData.draggingEles=true;x.silentShift(O).emit(A("position")).emit(A("drag"));e.redrawHint("drag",true);e.redraw()}}else D();a=true}else if(w){if(e.hoverData.dragging||!s.boxSelectionEnabled()||!B&&s.panningEnabled()&&s.userPanningEnabled()){if(!e.hoverData.selecting&&s.panningEnabled()&&s.userPanningEnabled()){var V=o(m,e.hoverData.downs);if(V){e.hoverData.dragging=true;e.hoverData.justStartedPan=true;f[4]=0;e.data.bgActivePosistion=_r(c);e.redrawHint("select",true);e.redraw()}}}else M();m&&m.pannable()&&m.active()&&m.unactivate()}f[2]=v[0];f[3]=v[1];if(a){t.stopPropagation&&t.stopPropagation();t.preventDefault&&t.preventDefault();return false}}}),false);var B,D,A;e.registerBinding(t,"mouseup",(function(t){if(e.hoverData.which!==1||t.which===1||!e.hoverData.capture){var a=e.hoverData.capture;if(a){e.hoverData.capture=false;var o=e.cy;var s=e.projectIntoViewport(t.clientX,t.clientY);var l=e.selection;var u=e.findNearestElement(s[0],s[1],true,false);var v=e.dragData.possibleDragElements;var c=e.hoverData.down;var d=i(t);if(e.data.bgActivePosistion){e.redrawHint("select",true);e.redraw()}e.hoverData.tapholdCancelled=true;e.data.bgActivePosistion=void 0;c&&c.unactivate();var f=function(e){return{originalEvent:t,type:e,position:{x:s[0],y:s[1]}}};if(e.hoverData.which===3){var h=f("cxttapend");c?c.emit(h):o.emit(h);if(!e.hoverData.cxtDragged){var p=f("cxttap");c?c.emit(p):o.emit(p)}e.hoverData.cxtDragged=false;e.hoverData.which=null}else if(e.hoverData.which===1){n(u,["mouseup","tapend","vmouseup"],t,{x:s[0],y:s[1]});if(!e.dragData.didDrag&&!e.hoverData.dragged&&!e.hoverData.selecting&&!e.hoverData.isOverThresholdDrag){n(c,["click","tap","vclick"],t,{x:s[0],y:s[1]});D=false;if(t.timeStamp-A<=o.multiClickDebounceTime()){B&&clearTimeout(B);D=true;A=null;n(c,["dblclick","dbltap","vdblclick"],t,{x:s[0],y:s[1]})}else{B=setTimeout((function(){D||n(c,["oneclick","onetap","voneclick"],t,{x:s[0],y:s[1]})}),o.multiClickDebounceTime());A=t.timeStamp}}if(c==null&&!e.dragData.didDrag&&!e.hoverData.selecting&&!e.hoverData.dragged&&!i(t)){o.$(r).unselect(["tapunselect"]);v.length>0&&e.redrawHint("eles",true);e.dragData.possibleDragElements=v=o.collection()}if(u==c&&!e.dragData.didDrag&&!e.hoverData.selecting&&u!=null&&u._private.selectable){if(e.hoverData.dragging);else if(o.selectionType()==="additive"||d)u.selected()?u.unselect(["tapunselect"]):u.select(["tapselect"]);else if(!d){o.$(r).unmerge(u).unselect(["tapunselect"]);u.select(["tapselect"])}e.redrawHint("eles",true)}if(e.hoverData.selecting){var g=o.collection(e.getAllInBox(l[0],l[1],l[2],l[3]));e.redrawHint("select",true);g.length>0&&e.redrawHint("eles",true);o.emit(f("boxend"));var m=function(e){return e.selectable()&&!e.selected()};if(o.selectionType()==="additive")g.emit(f("box")).stdFilter(m).select().emit(f("boxselect"));else{d||o.$(r).unmerge(g).unselect();g.emit(f("box")).stdFilter(m).select().emit(f("boxselect"))}e.redraw()}if(e.hoverData.dragging){e.hoverData.dragging=false;e.redrawHint("select",true);e.redrawHint("eles",true);e.redraw()}if(!l[4]){e.redrawHint("drag",true);e.redrawHint("eles",true);var b=c&&c.grabbed();y(v);if(b){c.emit(f("freeon"));v.emit(f("free"));if(e.dragData.didDrag){c.emit(f("dragfreeon"));v.emit(f("dragfree"))}}}}l[4]=0;e.hoverData.down=null;e.hoverData.cxtStarted=false;e.hoverData.draggingEles=false;e.hoverData.selecting=false;e.hoverData.isOverThresholdDrag=false;e.dragData.didDrag=false;e.hoverData.dragged=false;e.hoverData.dragDelta=[];e.hoverData.mdownPos=null;e.hoverData.mdownGPos=null;e.hoverData.which=null}}}),false);var M=[];var I=4;var R;var N=1e5;var L=function(e,t){for(var r=0;r=I){var n=M;R=L(n,5);if(!R){var i=Math.abs(n[0]);R=O(n)&&i>5}if(R)for(var o=0;o5&&(a=zr(a)*5);d=a/-250;if(R){d/=N;d*=3}d*=e.wheelSensitivity;var f=t.deltaMode===1;f&&(d*=33);var h=s.zoom()*Math.pow(10,d);t.type==="gesturechange"&&(h=e.gestureStartZoom*t.scale);s.zoom({level:h,renderedPosition:{x:c[0],y:c[1]}});s.emit({type:t.type==="gesturechange"?"pinchzoom":"scrollzoom",originalEvent:t,position:{x:v[0],y:v[1]}})}}}};e.registerBinding(e.container,"wheel",z,true);e.registerBinding(t,"scroll",(function(t){e.scrollingPage=true;clearTimeout(e.scrollingPageTimeout);e.scrollingPageTimeout=setTimeout((function(){e.scrollingPage=false}),250)}),true);e.registerBinding(e.container,"gesturestart",(function(t){e.gestureStartZoom=e.cy.zoom();e.hasTouchStarted||t.preventDefault()}),true);e.registerBinding(e.container,"gesturechange",(function(t){e.hasTouchStarted||z(t)}),true);e.registerBinding(e.container,"mouseout",(function(t){var r=e.projectIntoViewport(t.clientX,t.clientY);e.cy.emit({originalEvent:t,type:"mouseout",position:{x:r[0],y:r[1]}})}),false);e.registerBinding(e.container,"mouseover",(function(t){var r=e.projectIntoViewport(t.clientX,t.clientY);e.cy.emit({originalEvent:t,type:"mouseover",position:{x:r[0],y:r[1]}})}),false);var V,F,X,j;var Y,q;var W,U;var G,H;var K,Z;var $;var Q=function(e,t,r,a){return Math.sqrt((r-e)*(r-e)+(a-t)*(a-t))};var J=function(e,t,r,a){return(r-e)*(r-e)+(a-t)*(a-t)};var ee;e.registerBinding(e.container,"touchstart",ee=function(t){e.hasTouchStarted=true;if(P(t)){b();e.touchData.capture=true;e.data.bgActivePosistion=void 0;var r=e.cy;var a=e.touchData.now;var i=e.touchData.earlier;if(t.touches[0]){var o=e.projectIntoViewport(t.touches[0].clientX,t.touches[0].clientY);a[0]=o[0];a[1]=o[1]}if(t.touches[1]){o=e.projectIntoViewport(t.touches[1].clientX,t.touches[1].clientY);a[2]=o[0];a[3]=o[1]}if(t.touches[2]){o=e.projectIntoViewport(t.touches[2].clientX,t.touches[2].clientY);a[4]=o[0];a[5]=o[1]}var s=function(e){return{originalEvent:t,type:e,position:{x:a[0],y:a[1]}}};if(t.touches[1]){e.touchData.singleTouchMoved=true;y(e.dragData.touchDragEles);var l=e.findContainerClientCoords();G=l[0];H=l[1];K=l[2];Z=l[3];V=t.touches[0].clientX-G;F=t.touches[0].clientY-H;X=t.touches[1].clientX-G;j=t.touches[1].clientY-H;$=0<=V&&V<=K&&0<=X&&X<=K&&0<=F&&F<=Z&&0<=j&&j<=Z;var u=r.pan();var v=r.zoom();Y=Q(V,F,X,j);q=J(V,F,X,j);W=[(V+X)/2,(F+j)/2];U=[(W[0]-u.x)/v,(W[1]-u.y)/v];var d=200;var f=d*d;if(q=1){var k=e.touchData.startPosition=[null,null,null,null,null,null];for(var C=0;C=e.touchTapThreshold2}if(r&&e.touchData.cxt){t.preventDefault();var T=t.touches[0].clientX-G,k=t.touches[0].clientY-H;var C=t.touches[1].clientX-G,S=t.touches[1].clientY-H;var B=J(T,k,C,S);var D=B/q;var A=150;var M=A*A;var I=1.5;var R=I*I;if(D>=R||B>=M){e.touchData.cxt=false;e.data.bgActivePosistion=void 0;e.redrawHint("select",true);var N=c("cxttapend");if(e.touchData.start){e.touchData.start.unactivate().emit(N);e.touchData.start=null}else i.emit(N)}}if(r&&e.touchData.cxt){N=c("cxtdrag");e.data.bgActivePosistion=void 0;e.redrawHint("select",true);e.touchData.start?e.touchData.start.emit(N):i.emit(N);e.touchData.start&&(e.touchData.start._private.grabbed=false);e.touchData.cxtDragged=true;var L=e.findNearestElement(s[0],s[1],true,true);if(!e.touchData.cxtOver||L!==e.touchData.cxtOver){e.touchData.cxtOver&&e.touchData.cxtOver.emit(c("cxtdragout"));e.touchData.cxtOver=L;L&&L.emit(c("cxtdragover"))}}else if(r&&t.touches[2]&&i.boxSelectionEnabled()){t.preventDefault();e.data.bgActivePosistion=void 0;this.lastThreeTouch=+new Date;e.touchData.selecting||i.emit(c("boxstart"));e.touchData.selecting=true;e.touchData.didSelect=true;a[4]=1;if(a&&a.length!==0&&a[0]!==void 0){a[2]=(s[0]+s[2]+s[4])/3;a[3]=(s[1]+s[3]+s[5])/3}else{a[0]=(s[0]+s[2]+s[4])/3;a[1]=(s[1]+s[3]+s[5])/3;a[2]=(s[0]+s[2]+s[4])/3+1;a[3]=(s[1]+s[3]+s[5])/3+1}e.redrawHint("select",true);e.redraw()}else if(r&&t.touches[1]&&!e.touchData.didSelect&&i.zoomingEnabled()&&i.panningEnabled()&&i.userZoomingEnabled()&&i.userPanningEnabled()){t.preventDefault();e.data.bgActivePosistion=void 0;e.redrawHint("select",true);var O=e.dragData.touchDragEles;if(O){e.redrawHint("drag",true);for(var z=0;z0&&!e.hoverData.draggingEles&&!e.swipePanning&&e.data.bgActivePosistion!=null){e.data.bgActivePosistion=void 0;e.redrawHint("select",true);e.redraw()}}},false);var re;e.registerBinding(t,"touchcancel",re=function(t){var r=e.touchData.start;e.touchData.capture=false;r&&r.unactivate()});var ae,ne,ie,oe;e.registerBinding(t,"touchend",ae=function(t){var a=e.touchData.start;var i=e.touchData.capture;if(i){t.touches.length===0&&(e.touchData.capture=false);t.preventDefault();var o=e.selection;e.swipePanning=false;e.hoverData.draggingEles=false;var s=e.cy;var l=s.zoom();var u=e.touchData.now;var v=e.touchData.earlier;if(t.touches[0]){var c=e.projectIntoViewport(t.touches[0].clientX,t.touches[0].clientY);u[0]=c[0];u[1]=c[1]}if(t.touches[1]){c=e.projectIntoViewport(t.touches[1].clientX,t.touches[1].clientY);u[2]=c[0];u[3]=c[1]}if(t.touches[2]){c=e.projectIntoViewport(t.touches[2].clientX,t.touches[2].clientY);u[4]=c[0];u[5]=c[1]}var d=function(e){return{originalEvent:t,type:e,position:{x:u[0],y:u[1]}}};a&&a.unactivate();var f;if(e.touchData.cxt){f=d("cxttapend");a?a.emit(f):s.emit(f);if(!e.touchData.cxtDragged){var h=d("cxttap");a?a.emit(h):s.emit(h)}e.touchData.start&&(e.touchData.start._private.grabbed=false);e.touchData.cxt=false;e.touchData.start=null;e.redraw()}else{if(!t.touches[2]&&s.boxSelectionEnabled()&&e.touchData.selecting){e.touchData.selecting=false;var p=s.collection(e.getAllInBox(o[0],o[1],o[2],o[3]));o[0]=void 0;o[1]=void 0;o[2]=void 0;o[3]=void 0;o[4]=0;e.redrawHint("select",true);s.emit(d("boxend"));var g=function(e){return e.selectable()&&!e.selected()};p.emit(d("box")).stdFilter(g).select().emit(d("boxselect"));p.nonempty()&&e.redrawHint("eles",true);e.redraw()}a!=null&&a.unactivate();if(t.touches[2]){e.data.bgActivePosistion=void 0;e.redrawHint("select",true)}else if(t.touches[1]);else if(t.touches[0]);else if(!t.touches[0]){e.data.bgActivePosistion=void 0;e.redrawHint("select",true);var m=e.dragData.touchDragEles;if(a!=null){var b=a._private.grabbed;y(m);e.redrawHint("drag",true);e.redrawHint("eles",true);if(b){a.emit(d("freeon"));m.emit(d("free"));if(e.dragData.didDrag){a.emit(d("dragfreeon"));m.emit(d("dragfree"))}}n(a,["touchend","tapend","vmouseup","tapdragout"],t,{x:u[0],y:u[1]});a.unactivate();e.touchData.start=null}else{var x=e.findNearestElement(u[0],u[1],true,true);n(x,["touchend","tapend","vmouseup","tapdragout"],t,{x:u[0],y:u[1]})}var w=e.touchData.startPosition[0]-u[0];var E=w*w;var T=e.touchData.startPosition[1]-u[1];var k=T*T;var C=E+k;var P=C*l*l;if(!e.touchData.singleTouchMoved){a||s.$(":selected").unselect(["tapunselect"]);n(a,["tap","vclick"],t,{x:u[0],y:u[1]});ne=false;if(t.timeStamp-oe<=s.multiClickDebounceTime()){ie&&clearTimeout(ie);ne=true;oe=null;n(a,["dbltap","vdblclick"],t,{x:u[0],y:u[1]})}else{ie=setTimeout((function(){ne||n(a,["onetap","voneclick"],t,{x:u[0],y:u[1]})}),s.multiClickDebounceTime());oe=t.timeStamp}}if(a!=null&&!e.dragData.didDrag&&a._private.selectable&&P0)return h[0]}return null};var f=Object.keys(c);for(var h=0;h0?d:sa(n,i,e,t,r,a,o,s)},checkPoint:function(e,t,r,a,n,i,o,s){s=s==="auto"?Aa(a,n):s;var l=2*s;if(pa(e,t,this.points,i,o,a,n-l,[0,-1],r))return true;if(pa(e,t,this.points,i,o,a-l,n,[0,-1],r))return true;var u=a/2+2*r;var v=n/2+2*r;var c=[i-u,o-v,i-u,o,i+u,o,i+u,o-v];return!!ha(e,t,c)||(!!xa(e,t,l,l,i+a/2-s,o+n/2-s,r)||!!xa(e,t,l,l,i-a/2+s,o+n/2-s,r))}}};lf.registerNodeShapes=function(){var e=this.nodeShapes={};var t=this;this.generateEllipse();this.generatePolygon("triangle",Ba(3,0));this.generateRoundPolygon("round-triangle",Ba(3,0));this.generatePolygon("rectangle",Ba(4,0));e.square=e.rectangle;this.generateRoundRectangle();this.generateCutRectangle();this.generateBarrel();this.generateBottomRoundrectangle();var r=[0,1,1,0,0,-1,-1,0];this.generatePolygon("diamond",r);this.generateRoundPolygon("round-diamond",r);this.generatePolygon("pentagon",Ba(5,0));this.generateRoundPolygon("round-pentagon",Ba(5,0));this.generatePolygon("hexagon",Ba(6,0));this.generateRoundPolygon("round-hexagon",Ba(6,0));this.generatePolygon("heptagon",Ba(7,0));this.generateRoundPolygon("round-heptagon",Ba(7,0));this.generatePolygon("octagon",Ba(8,0));this.generateRoundPolygon("round-octagon",Ba(8,0));var a=new Array(20);var n=_a(5,0);var i=_a(5,Math.PI/5);var o=.5*(3-Math.sqrt(5));o*=1.57;for(var s=0;s=e.deqFastCost*p)break}else if(n){if(f>=e.deqCost*l||f>=e.deqAvgCost*s)break}else if(h>=e.deqNoDrawCost*hf)break;var g=e.deq(t,c,v);if(!(g.length>0))break;for(var y=0;y0){e.onDeqd(t,u);!n&&e.shouldRedraw(t,u,c,v)&&a()}};var i=e.priority||Rt;r.beforeRender(n,i(t))}}}};var gf=function(){function e(t){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Mt;a(this,e);this.idsByKey=new $t;this.keyForId=new $t;this.cachesByLvl=new $t;this.lvls=[];this.getKey=t;this.doesEleInvalidateKey=r}return i(e,[{key:"getIdsFor",value:function(e){e==null&&Nt("Can not get id list for null key");var t=this.idsByKey;var r=this.idsByKey.get(e);if(!r){r=new er;t.set(e,r)}return r}},{key:"addIdForKey",value:function(e,t){e!=null&&this.getIdsFor(e).add(t)}},{key:"deleteIdForKey",value:function(e,t){e!=null&&this.getIdsFor(e).delete(t)}},{key:"getNumberOfIdsForKey",value:function(e){return e==null?0:this.getIdsFor(e).size}},{key:"updateKeyMappingFor",value:function(e){var t=e.id();var r=this.keyForId.get(t);var a=this.getKey(e);this.deleteIdForKey(r,t);this.addIdForKey(a,t);this.keyForId.set(t,a)}},{key:"deleteKeyMappingFor",value:function(e){var t=e.id();var r=this.keyForId.get(t);this.deleteIdForKey(r,t);this.keyForId.delete(t)}},{key:"keyHasChangedFor",value:function(e){var t=e.id();var r=this.keyForId.get(t);var a=this.getKey(e);return r!==a}},{key:"isInvalid",value:function(e){return this.keyHasChangedFor(e)||this.doesEleInvalidateKey(e)}},{key:"getCachesAt",value:function(e){var t=this.cachesByLvl,r=this.lvls;var a=t.get(e);if(!a){a=new $t;t.set(e,a);r.push(e)}return a}},{key:"getCache",value:function(e,t){return this.getCachesAt(t).get(e)}},{key:"get",value:function(e,t){var r=this.getKey(e);var a=this.getCache(r,t);a!=null&&this.updateKeyMappingFor(e);return a}},{key:"getForCachedKey",value:function(e,t){var r=this.keyForId.get(e.id());var a=this.getCache(r,t);return a}},{key:"hasCache",value:function(e,t){return this.getCachesAt(t).has(e)}},{key:"has",value:function(e,t){var r=this.getKey(e);return this.hasCache(r,t)}},{key:"setCache",value:function(e,t,r){r.key=e;this.getCachesAt(t).set(e,r)}},{key:"set",value:function(e,t,r){var a=this.getKey(e);this.setCache(a,t,r);this.updateKeyMappingFor(e)}},{key:"deleteCache",value:function(e,t){this.getCachesAt(t).delete(e)}},{key:"delete",value:function(e,t){var r=this.getKey(e);this.deleteCache(r,t)}},{key:"invalidateKey",value:function(e){var t=this;this.lvls.forEach((function(r){return t.deleteCache(e,r)}))}},{key:"invalidate",value:function(e){var t=e.id();var r=this.keyForId.get(t);this.deleteKeyMappingFor(e);var a=this.doesEleInvalidateKey(e);a&&this.invalidateKey(r);return a||this.getNumberOfIdsForKey(r)===0}}])}();var yf=25;var mf=50;var bf=-4;var xf=3;var wf=7.99;var Ef=8;var Tf=1024;var kf=1024;var Cf=1024;var Pf=.2;var Sf=.8;var Bf=10;var Df=.15;var _f=.1;var Af=.9;var Mf=.9;var If=100;var Rf=1;var Nf={dequeue:"dequeue",downscale:"downscale",highQuality:"highQuality"};var Lf=qt({getKey:null,doesEleInvalidateKey:Mt,drawElement:null,getBoundingBox:null,getRotationPoint:null,getRotationOffset:null,isVisible:At,allowEdgeTxrCaching:true,allowParentTxrCaching:true});var Of=function(e,t){var r=this;r.renderer=e;r.onDequeues=[];var a=Lf(t);ie(r,a);r.lookup=new gf(a.getKey,a.doesEleInvalidateKey);r.setupDequeueing()};var zf=Of.prototype;zf.reasons=Nf;zf.getTextureQueue=function(e){var t=this;t.eleImgCaches=t.eleImgCaches||{};return t.eleImgCaches[e]=t.eleImgCaches[e]||[]};zf.getRetiredTextureQueue=function(e){var t=this;var r=t.eleImgCaches.retired=t.eleImgCaches.retired||{};var a=r[e]=r[e]||[];return a};zf.getElementQueue=function(){var e=this;var t=e.eleCacheQueue=e.eleCacheQueue||new dr((function(e,t){return t.reqs-e.reqs}));return t};zf.getElementKeyToQueue=function(){var e=this;var t=e.eleKeyToCacheQueue=e.eleKeyToCacheQueue||{};return t};zf.getElement=function(e,t,r,a,n){var i=this;var o=this.renderer;var s=o.cy.zoom();var l=this.lookup;if(!t||t.w===0||t.h===0||isNaN(t.w)||isNaN(t.h)||!e.visible()||e.removed())return null;if(!i.allowEdgeTxrCaching&&e.isEdge()||!i.allowParentTxrCaching&&e.isParent())return null;a==null&&(a=Math.ceil(Or(s*r)));if(a=wf||a>xf)return null;var u=Math.pow(2,a);var v=t.h*u;var c=t.w*u;var d=o.eleTextBiggerThanMin(e,u);if(!this.isVisible(e,d))return null;var f=l.get(e,a);if(f&&f.invalidated){f.invalidated=false;f.texture.invalidatedWidth-=f.width}if(f)return f;var h;h=v<=yf?yf:v<=mf?mf:Math.ceil(v/mf)*mf;if(v>Cf||c>kf)return null;var p=i.getTextureQueue(h);var g=p[p.length-2];var y=function(){return i.recycleTexture(h,c)||i.addTexture(h,c)};g||(g=p[p.length-1]);g||(g=y());g.width-g.usedWidtha;S--)C=i.getElement(e,t,r,S,Nf.downscale);P()}else{var B;if(!b&&!x&&!w)for(var D=a-1;D>=bf;D--){var _=l.get(e,D);if(_){B=_;break}}if(m(B)){i.queueElement(e,a);return B}g.context.translate(g.usedWidth,0);g.context.scale(u,u);this.drawElement(g.context,e,t,d,false);g.context.scale(1/u,1/u);g.context.translate(-g.usedWidth,0)}f={x:g.usedWidth,texture:g,level:a,scale:u,width:c,height:v,scaledLabelShown:d};g.usedWidth+=Math.ceil(c+Ef);g.eleCaches.push(f);l.set(e,a,f);i.checkTextureFullness(g);return f};zf.invalidateElements=function(e){for(var t=0;t=Pf*e.width&&this.retireTexture(e)};zf.checkTextureFullness=function(e){var t=this;var r=t.getTextureQueue(e.height);e.usedWidth/e.width>Sf&&e.fullnessChecks>=Bf?Wt(r,e):e.fullnessChecks++};zf.retireTexture=function(e){var t=this;var r=e.height;var a=t.getTextureQueue(r);var n=this.lookup;Wt(a,e);e.retired=true;var i=e.eleCaches;for(var o=0;o=t){o.retired=false;o.usedWidth=0;o.invalidatedWidth=0;o.fullnessChecks=0;Ut(o.eleCaches);o.context.setTransform(1,0,0,1,0,0);o.context.clearRect(0,0,o.width,o.height);Wt(n,o);a.push(o);return o}}};zf.queueElement=function(e,t){var r=this;var a=r.getElementQueue();var n=r.getElementKeyToQueue();var i=this.getKey(e);var o=n[i];if(o){o.level=Math.max(o.level,t);o.eles.merge(e);o.reqs++;a.updateItem(o)}else{var s={eles:e.spawn().merge(e),level:t,reqs:1,key:i};a.push(s);n[i]=s}};zf.dequeue=function(e){var t=this;var r=t.getElementQueue();var a=t.getElementKeyToQueue();var n=[];var i=t.lookup;for(var o=0;o0))break;var s=r.pop();var l=s.key;var u=s.eles[0];var v=i.hasCache(u,s.level);a[l]=null;if(!v){n.push(s);var c=t.getBoundingBox(u);t.getElement(u,c,e,s.level,Nf.dequeue)}}return n};zf.removeFromQueue=function(e){var t=this;var r=t.getElementQueue();var a=t.getElementKeyToQueue();var n=this.getKey(e);var i=a[n];if(i!=null)if(i.eles.length===1){i.reqs=_t;r.updateItem(i);r.pop();a[n]=null}else i.eles.unmerge(e)};zf.onDequeue=function(e){this.onDequeues.push(e)};zf.offDequeue=function(e){Wt(this.onDequeues,e)};zf.setupDequeueing=pf.setupDequeueing({deqRedrawThreshold:If,deqCost:Df,deqAvgCost:_f,deqNoDrawCost:Af,deqFastCost:Mf,deq:function(e,t,r){return e.dequeue(t,r)},onDeqd:function(e,t){for(var r=0;r=jf||r>Xf)return null}a.validateLayersElesOrdering(r,e);var l=a.layersByLevel;var u=Math.pow(2,r);var v=l[r]=l[r]||[];var c;var d=a.levelIsComplete(r,e);var f;var h=function(){var t=function(t){a.validateLayersElesOrdering(t,e);if(a.levelIsComplete(t,e)){f=l[t];return true}};var n=function(e){if(!f)for(var a=r+e;Ff<=a&&a<=Xf;a+=e)if(t(a))break};n(1);n(-1);for(var i=v.length-1;i>=0;i--){var o=v[i];o.invalid&&Wt(v,o)}};if(d)return v;h();var p=function(){if(!c){c=Ur();for(var t=0;tQf||i>Qf)return null;var o=n*i;if(o>$f)return null;var s=a.makeLayer(c,r);if(t!=null){var l=v.indexOf(t)+1;v.splice(l,0,s)}else(e.insert===void 0||e.insert)&&v.unshift(s);return s};if(a.skipping&&!s)return null;var y=null;var m=e.length/Vf;var b=!s;for(var x=0;x=m||!aa(y.bb,w.boundingBox())){y=g({insert:true,after:y});if(!y)return null}f||b?a.queueLayer(y,w):a.drawEleInLayer(y,w,r,t);y.eles.push(w);T[r]=y}}return f||(b?null:v)};th.getEleLevelForLayerLevel=function(e,t){return e};th.drawEleInLayer=function(e,t,r,a){var n=this;var i=this.renderer;var o=e.context;var s=t.boundingBox();if(s.w!==0&&s.h!==0&&t.visible()){r=n.getEleLevelForLayerLevel(r,a);i.setImgSmoothing(o,false);i.drawCachedElement(o,t,null,null,r,Jf);i.setImgSmoothing(o,true)}};th.levelIsComplete=function(e,t){var r=this;var a=r.layersByLevel[e];if(!a||a.length===0)return false;var n=0;for(var i=0;i0)return false;if(o.invalid)return false;n+=o.eles.length}return n===t.length};th.validateLayersElesOrdering=function(e,t){var r=this.layersByLevel[e];if(r)for(var a=0;a0){t=true;break}}return t};th.invalidateElements=function(e){var t=this;if(e.length!==0){t.lastInvalidationTime=vt();e.length!==0&&t.haveLayers()&&t.updateElementsInLayers(e,(function(e,r,a){t.invalidateLayer(e)}))}};th.invalidateLayer=function(e){this.lastInvalidationTime=vt();if(!e.invalid){var t=e.level;var r=e.eles;var a=this.layersByLevel[t];Wt(a,e);e.elesQueue=[];e.invalid=true;e.replacement&&(e.replacement.invalid=true);for(var n=0;n3&&arguments[3]!==void 0)||arguments[3];var n=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4];var i=!(arguments.length>5&&arguments[5]!==void 0)||arguments[5];var o=this;var s=t._private.rscratch;if((!i||t.visible())&&!s.badLine&&s.allpts!=null&&!isNaN(s.allpts[0])){var l;if(r){l=r;e.translate(-l.x1,-l.y1)}var u=i?t.pstyle("opacity").value:1;var v=i?t.pstyle("line-opacity").value:1;var c=t.pstyle("curve-style").value;var d=t.pstyle("line-style").value;var f=t.pstyle("width").pfValue;var h=t.pstyle("line-cap").value;var p=t.pstyle("line-outline-width").value;var g=t.pstyle("line-outline-color").value;var y=u*v;var m=u*v;var b=function(){var r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:y;if(c==="straight-triangle"){o.eleStrokeStyle(e,t,r);o.drawEdgeTrianglePath(t,e,s.allpts)}else{e.lineWidth=f;e.lineCap=h;o.eleStrokeStyle(e,t,r);o.drawEdgePath(t,e,s.allpts,d);e.lineCap="butt"}};var x=function(){var r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:y;e.lineWidth=f+p;e.lineCap=h;if(p>0){o.colorStrokeStyle(e,g[0],g[1],g[2],r);if(c==="straight-triangle")o.drawEdgeTrianglePath(t,e,s.allpts);else{o.drawEdgePath(t,e,s.allpts,d);e.lineCap="butt"}}else e.lineCap="butt"};var w=function(){n&&o.drawEdgeOverlay(e,t)};var E=function(){n&&o.drawEdgeUnderlay(e,t)};var T=function(){var r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:m;o.drawArrowheads(e,t,r)};var k=function(){o.drawElementText(e,t,null,a)};e.lineJoin="round";var C=t.pstyle("ghost").value==="yes";if(C){var P=t.pstyle("ghost-offset-x").pfValue;var S=t.pstyle("ghost-offset-y").pfValue;var B=t.pstyle("ghost-opacity").value;var D=y*B;e.translate(P,S);b(D);T(D);e.translate(-P,-S)}else x();E();b();T();w();k();r&&e.translate(l.x1,l.y1)}};var bh=function(e){if(!["overlay","underlay"].includes(e))throw new Error("Invalid state");return function(t,r){if(r.visible()){var a=r.pstyle("".concat(e,"-opacity")).value;if(a!==0){var n=this;var i=n.usePaths();var o=r._private.rscratch;var s=r.pstyle("".concat(e,"-padding")).pfValue;var l=2*s;var u=r.pstyle("".concat(e,"-color")).value;t.lineWidth=l;o.edgeType!=="self"||i?t.lineCap="round":t.lineCap="butt";n.colorStrokeStyle(t,u[0],u[1],u[2],a);n.drawEdgePath(r,t,o.allpts,"solid")}}}};mh.drawEdgeOverlay=bh("overlay");mh.drawEdgeUnderlay=bh("underlay");mh.drawEdgePath=function(e,t,r,a){var n=e._private.rscratch;var i=t;var s;var l=false;var u=this.usePaths();var v=e.pstyle("line-dash-pattern").pfValue;var c=e.pstyle("line-dash-offset").pfValue;if(u){var d=r.join("$");var f=n.pathCacheKey&&n.pathCacheKey===d;if(f){s=t=n.pathCache;l=true}else{s=t=new Path2D;n.pathCacheKey=d;n.pathCache=s}}if(i.setLineDash)switch(a){case"dotted":i.setLineDash([1,1]);break;case"dashed":i.setLineDash(v);i.lineDashOffset=c;break;case"solid":i.setLineDash([]);break}if(!l&&!n.badLine){t.beginPath&&t.beginPath();t.moveTo(r[0],r[1]);switch(n.edgeType){case"bezier":case"self":case"compound":case"multibezier":for(var h=2;h+35&&arguments[5]!==void 0)||arguments[5];var o=this;if(a==null){if(i&&!o.eleTextBiggerThanMin(t))return}else if(a===false)return;if(t.isNode()){var s=t.pstyle("label");if(!s||!s.value)return;var l=o.getLabelJustification(t);e.textAlign=l;e.textBaseline="bottom"}else{var u=t.element()._private.rscratch.badLine;var v=t.pstyle("label");var c=t.pstyle("source-label");var d=t.pstyle("target-label");if(u||(!v||!v.value)&&(!c||!c.value)&&(!d||!d.value))return;e.textAlign="center";e.textBaseline="bottom"}var f=!r;var h;if(r){h=r;e.translate(-h.x1,-h.y1)}if(n==null){o.drawText(e,t,null,f,i);if(t.isEdge()){o.drawText(e,t,"source",f,i);o.drawText(e,t,"target",f,i)}}else o.drawText(e,t,n,f,i);r&&e.translate(h.x1,h.y1)};wh.getFontCache=function(e){var t;this.fontCaches=this.fontCaches||[];for(var r=0;r2&&arguments[2]!==void 0)||arguments[2];var a=t.pstyle("font-style").strValue;var n=t.pstyle("font-size").pfValue+"px";var i=t.pstyle("font-family").strValue;var o=t.pstyle("font-weight").strValue;var s=r?t.effectiveOpacity()*t.pstyle("text-opacity").value:1;var l=t.pstyle("text-outline-opacity").value*s;var u=t.pstyle("color").value;var v=t.pstyle("text-outline-color").value;e.font=a+" "+o+" "+n+" "+i;e.lineJoin="round";this.colorFillStyle(e,u[0],u[1],u[2],s);this.colorStrokeStyle(e,v[0],v[1],v[2],l)};function Eh(e,t,r,a,n){var i=Math.min(a,n);var o=i/2;var s=t+a/2;var l=r+n/2;e.beginPath();e.arc(s,l,o,0,Math.PI*2);e.closePath()}function Th(e,t,r,a,n){var i=arguments.length>5&&arguments[5]!==void 0?arguments[5]:5;var o=Math.min(i,a/2,n/2);e.beginPath();e.moveTo(t+o,r);e.lineTo(t+a-o,r);e.quadraticCurveTo(t+a,r,t+a,r+o);e.lineTo(t+a,r+n-o);e.quadraticCurveTo(t+a,r+n,t+a-o,r+n);e.lineTo(t+o,r+n);e.quadraticCurveTo(t,r+n,t,r+n-o);e.lineTo(t,r+o);e.quadraticCurveTo(t,r,t+o,r);e.closePath()}wh.getTextAngle=function(e,t){var r;var a=e._private;var n=a.rscratch;var i=t?t+"-":"";var o=e.pstyle(i+"text-rotation");if(o.strValue==="autorotate"){var s=Ht(n,"labelAngle",t);r=e.isEdge()?s:0}else r=o.strValue==="none"?0:o.pfValue;return r};wh.drawText=function(e,t,r){var a=!(arguments.length>3&&arguments[3]!==void 0)||arguments[3];var n=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4];var i=t._private;var o=i.rscratch;var s=n?t.effectiveOpacity():1;if(!n||s!==0&&t.pstyle("text-opacity").value!==0){r==="main"&&(r=null);var l=Ht(o,"labelX",r);var u=Ht(o,"labelY",r);var v,c;var d=this.getLabelText(t,r);if(d!=null&&d!==""&&!isNaN(l)&&!isNaN(u)){this.setupTextStyle(e,t,n);var f=r?r+"-":"";var h=Ht(o,"labelWidth",r);var p=Ht(o,"labelHeight",r);var g=t.pstyle(f+"text-margin-x").pfValue;var y=t.pstyle(f+"text-margin-y").pfValue;var m=t.isEdge();var b=t.pstyle("text-halign").value;var x=t.pstyle("text-valign").value;if(m){b="center";x="center"}l+=g;u+=y;var w;w=a?this.getTextAngle(t,r):0;if(w!==0){v=l;c=u;e.translate(v,c);e.rotate(w);l=0;u=0}switch(x){case"top":break;case"center":u+=p/2;break;case"bottom":u+=p;break}var E=t.pstyle("text-background-opacity").value;var T=t.pstyle("text-border-opacity").value;var k=t.pstyle("text-border-width").pfValue;var C=t.pstyle("text-background-padding").pfValue;var P=t.pstyle("text-background-shape").strValue;var S=P==="round-rectangle"||P==="roundrectangle";var B=P==="circle";var D=2;if(E>0||k>0&&T>0){var _=e.fillStyle;var A=e.strokeStyle;var M=e.lineWidth;var I=t.pstyle("text-background-color").value;var R=t.pstyle("text-border-color").value;var N=t.pstyle("text-border-style").value;var L=E>0;var O=k>0&&T>0;var z=l-C;switch(b){case"left":z-=h;break;case"center":z-=h/2;break}var V=u-p-C;var F=h+2*C;var X=p+2*C;L&&(e.fillStyle="rgba(".concat(I[0],",").concat(I[1],",").concat(I[2],",").concat(E*s,")"));if(O){e.strokeStyle="rgba(".concat(R[0],",").concat(R[1],",").concat(R[2],",").concat(T*s,")");e.lineWidth=k;if(e.setLineDash)switch(N){case"dotted":e.setLineDash([1,1]);break;case"dashed":e.setLineDash([4,2]);break;case"double":e.lineWidth=k/4;e.setLineDash([]);break;case"solid":default:e.setLineDash([]);break}}if(S){e.beginPath();Th(e,z,V,F,X,D)}else if(B){e.beginPath();Eh(e,z,V,F,X)}else{e.beginPath();e.rect(z,V,F,X)}L&&e.fill();O&&e.stroke();if(O&&N==="double"){var j=k/2;e.beginPath();S?Th(e,z+j,V+j,F-2*j,X-2*j,D):e.rect(z+j,V+j,F-2*j,X-2*j);e.stroke()}e.fillStyle=_;e.strokeStyle=A;e.lineWidth=M;e.setLineDash&&e.setLineDash([])}var Y=2*t.pstyle("text-outline-width").pfValue;Y>0&&(e.lineWidth=Y);if(t.pstyle("text-wrap").value==="wrap"){var q=Ht(o,"labelWrapCachedLines",r);var W=Ht(o,"labelLineHeight",r);var U=h/2;var G=this.getLabelJustification(t);G==="auto"||(b==="left"?G==="left"?l+=-h:G==="center"&&(l+=-U):b==="center"?G==="left"?l+=-U:G==="right"&&(l+=U):b==="right"&&(G==="center"?l+=U:G==="right"&&(l+=h)));switch(x){case"top":u-=(q.length-1)*W;break;case"center":case"bottom":u-=(q.length-1)*W;break}for(var H=0;H0&&e.strokeText(q[H],l,u);e.fillText(q[H],l,u);u+=W}}else{Y>0&&e.strokeText(d,l,u);e.fillText(d,l,u)}if(w!==0){e.rotate(-w);e.translate(-v,-c)}}}};var kh={};kh.drawNode=function(e,t,r){var a=!(arguments.length>3&&arguments[3]!==void 0)||arguments[3];var n=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4];var i=!(arguments.length>5&&arguments[5]!==void 0)||arguments[5];var o=this;var s,l;var u=t._private;var v=u.rscratch;var c=t.position();if(_(c.x)&&_(c.y)&&(!i||t.visible())){var d=i?t.effectiveOpacity():1;var f=o.usePaths();var h;var p=false;var g=t.padding();s=t.width()+2*g;l=t.height()+2*g;var y;if(r){y=r;e.translate(-y.x1,-y.y1)}var m=t.pstyle("background-image");var b=m.value;var x=new Array(b.length);var w=new Array(b.length);var E=0;for(var T=0;T0&&arguments[0]!==void 0?arguments[0]:D;o.eleFillStyle(e,t,r)};var U=function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:z;o.colorStrokeStyle(e,A[0],A[1],A[2],t)};var G=function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:j;o.colorStrokeStyle(e,F[0],F[1],F[2],t)};var H=function(e,t,r,a){var n=o.nodePathCache=o.nodePathCache||[];var i=Et(r==="polygon"?r+","+a.join(","):r,""+t,""+e,""+q);var s=n[i];var l;var u=false;if(s!=null){l=s;u=true;v.pathCache=l}else{l=new Path2D;n[i]=v.pathCache=l}return{path:l,cacheHit:u}};var K=t.pstyle("shape").strValue;var Z=t.pstyle("shape-polygon-points").pfValue;if(f){e.translate(c.x,c.y);var $=H(s,l,K,Z);h=$.path;p=$.cacheHit}var Q=function(){if(!p){var r=c;f&&(r={x:0,y:0});o.nodeShapes[o.getNodeShape(t)].draw(h||e,r.x,r.y,s,l,q,v)}f?e.fill(h):e.fill()};var J=function(){var r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:d;var a=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];var n=u.backgrounding;var i=0;for(var s=0;s0&&arguments[0]!==void 0&&arguments[0];var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:d;if(o.hasPie(t)){o.drawPie(e,t,a);r&&(f||o.nodeShapes[o.getNodeShape(t)].draw(e,c.x,c.y,s,l,q,v))}};var te=function(){var r=arguments.length>0&&arguments[0]!==void 0&&arguments[0];var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:d;if(o.hasStripe(t)){e.save();if(f)e.clip(v.pathCache);else{o.nodeShapes[o.getNodeShape(t)].draw(e,c.x,c.y,s,l,q,v);e.clip()}o.drawStripe(e,t,a);e.restore();r&&(f||o.nodeShapes[o.getNodeShape(t)].draw(e,c.x,c.y,s,l,q,v))}};var re=function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:d;var r=(S>0?S:-S)*t;var a=S>0?0:255;if(S!==0){o.colorFillStyle(e,a,a,a,r);f?e.fill(h):e.fill()}};var ae=function(){if(B>0){e.lineWidth=B;e.lineCap=R;e.lineJoin=I;if(e.setLineDash)switch(M){case"dotted":e.setLineDash([1,1]);break;case"dashed":e.setLineDash(L);e.lineDashOffset=O;break;case"solid":case"double":e.setLineDash([]);break}if(N!=="center"){e.save();e.lineWidth*=2;if(N==="inside")f?e.clip(h):e.clip();else{var t=new Path2D;t.rect(-s/2-B,-l/2-B,s+2*B,l+2*B);t.addPath(h);e.clip(t,"evenodd")}f?e.stroke(h):e.stroke();e.restore()}else f?e.stroke(h):e.stroke();if(M==="double"){e.lineWidth=B/3;var r=e.globalCompositeOperation;e.globalCompositeOperation="destination-out";f?e.stroke(h):e.stroke();e.globalCompositeOperation=r}e.setLineDash&&e.setLineDash([])}};var ne=function(){if(V>0){e.lineWidth=V;e.lineCap="butt";if(e.setLineDash)switch(X){case"dotted":e.setLineDash([1,1]);break;case"dashed":e.setLineDash([4,2]);break;case"solid":case"double":e.setLineDash([]);break}var r=c;f&&(r={x:0,y:0});var a=o.getNodeShape(t);var n=B;N==="inside"&&(n=0);N==="outside"&&(n*=2);var i=(s+n+(V+Y))/s;var u=(l+n+(V+Y))/l;var v=s*i;var d=l*u;var h=o.nodeShapes[a].points;var p;if(f){var g=H(v,d,a,h);p=g.path}if(a==="ellipse")o.drawEllipsePath(p||e,r.x,r.y,v,d);else if(["round-diamond","round-heptagon","round-hexagon","round-octagon","round-pentagon","round-polygon","round-triangle","round-tag"].includes(a)){var y=0;var m=0;var b=0;if(a==="round-diamond")y=(n+Y+V)*1.4;else if(a==="round-heptagon"){y=(n+Y+V)*1.075;b=-(n/2+Y+V)/35}else if(a==="round-hexagon")y=(n+Y+V)*1.12;else if(a==="round-pentagon"){y=(n+Y+V)*1.13;b=-(n/2+Y+V)/15}else if(a==="round-tag"){y=(n+Y+V)*1.12;m=(n/2+V+Y)*.07}else if(a==="round-triangle"){y=(n+Y+V)*(Math.PI/2);b=-(n+Y/2+V)/Math.PI}if(y!==0){i=(s+y)/s;v=s*i;if(!["round-hexagon","round-tag"].includes(a)){u=(l+y)/l;d=l*u}}q=q==="auto"?Ma(v,d):q;var x=v/2;var w=d/2;var E=q+(n+V+Y)/2;var T=new Array(h.length/2);var k=new Array(h.length/2);for(var C=0;C0){a=a||r.position();if(n==null||i==null){var d=r.padding();n=r.width()+2*d;i=r.height()+2*d}o.colorFillStyle(t,u[0],u[1],u[2],l);o.nodeShapes[v].draw(t,a.x,a.y,n+s*2,i+s*2,c);t.fill()}}}};kh.drawNodeOverlay=Ch("overlay");kh.drawNodeUnderlay=Ch("underlay");kh.hasPie=function(e){e=e[0];return e._private.hasPie};kh.hasStripe=function(e){e=e[0];return e._private.hasStripe};kh.drawPie=function(e,t,r,a){t=t[0];a=a||t.position();var n=t.cy().style();var i=t.pstyle("pie-size");var o=t.pstyle("pie-hole");var s=t.pstyle("pie-start-angle").pfValue;var l=a.x;var u=a.y;var v=t.width();var c=t.height();var d=Math.min(v,c)/2;var f;var h=0;var p=this.usePaths();if(p){l=0;u=0}i.units==="%"?d*=i.pfValue:i.pfValue!==void 0&&(d=i.pfValue/2);o.units==="%"?f=d*o.pfValue:o.pfValue!==void 0&&(f=o.pfValue/2);if(!(f>=d))for(var g=1;g<=n.pieBackgroundN;g++){var y=t.pstyle("pie-"+g+"-background-size").value;var m=t.pstyle("pie-"+g+"-background-color").value;var b=t.pstyle("pie-"+g+"-background-opacity").value*r;var x=y/100;x+h>1&&(x=1-h);var w=1.5*Math.PI+2*Math.PI*h;w+=s;var E=2*Math.PI*x;var T=w+E;if(!(y===0||h>=1||h+x>1)){if(f===0){e.beginPath();e.moveTo(l,u);e.arc(l,u,d,w,T);e.closePath()}else{e.beginPath();e.arc(l,u,d,w,T);e.arc(l,u,f,T,w,true);e.closePath()}this.colorFillStyle(e,m[0],m[1],m[2],b);e.fill();h+=x}}};kh.drawStripe=function(e,t,r,a){t=t[0];a=a||t.position();var n=t.cy().style();var i=a.x;var o=a.y;var s=t.width();var l=t.height();var u=0;var v=this.usePaths();e.save();var c=t.pstyle("stripe-direction").value;var d=t.pstyle("stripe-size");switch(c){case"vertical":break;case"righward":e.rotate(-Math.PI/2);break}var f=s;var h=l;if(d.units==="%"){f*=d.pfValue;h*=d.pfValue}else if(d.pfValue!==void 0){f=d.pfValue;h=d.pfValue}if(v){i=0;o=0}o-=f/2;i-=h/2;for(var p=1;p<=n.stripeBackgroundN;p++){var g=t.pstyle("stripe-"+p+"-background-size").value;var y=t.pstyle("stripe-"+p+"-background-color").value;var m=t.pstyle("stripe-"+p+"-background-opacity").value*r;var b=g/100;b+u>1&&(b=1-u);if(!(g===0||u>=1||u+b>1)){e.beginPath();e.rect(i,o+h*u,f,h*b);e.closePath();this.colorFillStyle(e,y[0],y[1],y[2],m);e.fill();u+=b}}e.restore()};var Ph={};var Sh=100;Ph.getPixelRatio=function(){var e=this.data.contexts[0];if(this.forcedPixelRatio!=null)return this.forcedPixelRatio;var t=this.cy.window();var r=e.backingStorePixelRatio||e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1;return(t.devicePixelRatio||1)/r};Ph.paintCache=function(e){var t=this.paintCaches=this.paintCaches||[];var r=true;var a;for(var n=0;nt.minMbLowQualFrames&&(t.motionBlurPxRatio=t.mbPxRBlurry)}t.clearingMotionBlur&&(t.motionBlurPxRatio=1);if(t.textureDrawLastFrame&&!c){v[t.NODE]=true;v[t.SELECT_BOX]=true}var m=r.style();var b=r.zoom();var x=o!==void 0?o:b;var w=r.pan();var E={x:w.x,y:w.y};var T={zoom:b,pan:{x:w.x,y:w.y}};var k=t.prevViewport;var C=k===void 0||T.zoom!==k.zoom||T.pan.x!==k.pan.x||T.pan.y!==k.pan.y;C||p&&!h||(t.motionBlurPxRatio=1);s&&(E=s);x*=l;E.x*=l;E.y*=l;var P=t.getCachedZSortedEles();function S(e,r,a,n,i){var o=e.globalCompositeOperation;e.globalCompositeOperation="destination-out";t.colorFillStyle(e,255,255,255,t.motionBlurTransparency);e.fillRect(r,a,n,i);e.globalCompositeOperation=o}function B(e,r){var i,l,v,c;if(t.clearingMotionBlur||e!==u.bufferContexts[t.MOTIONBLUR_BUFFER_NODE]&&e!==u.bufferContexts[t.MOTIONBLUR_BUFFER_DRAG]){i=E;l=x;v=t.canvasWidth;c=t.canvasHeight}else{i={x:w.x*f,y:w.y*f};l=b*f;v=t.canvasWidth*f;c=t.canvasHeight*f}e.setTransform(1,0,0,1,0,0);r==="motionBlur"?S(e,0,0,v,c):a||r!==void 0&&!r||e.clearRect(0,0,v,c);if(!n){e.translate(i.x,i.y);e.scale(l,l)}s&&e.translate(s.x,s.y);o&&e.scale(o,o)}c||(t.textureDrawLastFrame=false);if(c){t.textureDrawLastFrame=true;if(!t.textureCache){t.textureCache={};t.textureCache.bb=r.mutableElements().boundingBox();t.textureCache.texture=t.data.bufferCanvases[t.TEXTURE_BUFFER];var D=t.data.bufferContexts[t.TEXTURE_BUFFER];D.setTransform(1,0,0,1,0,0);D.clearRect(0,0,t.canvasWidth*t.textureMult,t.canvasHeight*t.textureMult);t.render({forcedContext:D,drawOnlyNodeLayer:true,forcedPxRatio:l*t.textureMult});T=t.textureCache.viewport={zoom:r.zoom(),pan:r.pan(),width:t.canvasWidth,height:t.canvasHeight};T.mpan={x:(0-T.pan.x)/T.zoom,y:(0-T.pan.y)/T.zoom}}v[t.DRAG]=false;v[t.NODE]=false;var _=u.contexts[t.NODE];var A=t.textureCache.texture;T=t.textureCache.viewport;_.setTransform(1,0,0,1,0,0);d?S(_,0,0,T.width,T.height):_.clearRect(0,0,T.width,T.height);var M=m.core("outside-texture-bg-color").value;var I=m.core("outside-texture-bg-opacity").value;t.colorFillStyle(_,M[0],M[1],M[2],I);_.fillRect(0,0,T.width,T.height);b=r.zoom();B(_,false);_.clearRect(T.mpan.x,T.mpan.y,T.width/T.zoom/l,T.height/T.zoom/l);_.drawImage(A,T.mpan.x,T.mpan.y,T.width/T.zoom/l,T.height/T.zoom/l)}else t.textureOnViewport&&!a&&(t.textureCache=null);var R=r.extent();var N=t.pinching||t.hoverData.dragging||t.swipePanning||t.data.wheelZooming||t.hoverData.draggingEles||t.cy.animated();var L=t.hideEdgesOnViewport&&N;var O=[];O[t.NODE]=!v[t.NODE]&&d&&!t.clearedForMotionBlur[t.NODE]||t.clearingMotionBlur;O[t.NODE]&&(t.clearedForMotionBlur[t.NODE]=true);O[t.DRAG]=!v[t.DRAG]&&d&&!t.clearedForMotionBlur[t.DRAG]||t.clearingMotionBlur;O[t.DRAG]&&(t.clearedForMotionBlur[t.DRAG]=true);if(v[t.NODE]||n||i||O[t.NODE]){var z=d&&!O[t.NODE]&&f!==1;_=a||(z?t.data.bufferContexts[t.MOTIONBLUR_BUFFER_NODE]:u.contexts[t.NODE]);var V=d&&!z?"motionBlur":void 0;B(_,V);L?t.drawCachedNodes(_,P.nondrag,l,R):t.drawLayeredElements(_,P.nondrag,l,R);t.debug&&t.drawDebugPoints(_,P.nondrag);n||d||(v[t.NODE]=false)}if(!i&&(v[t.DRAG]||n||O[t.DRAG])){z=d&&!O[t.DRAG]&&f!==1;_=a||(z?t.data.bufferContexts[t.MOTIONBLUR_BUFFER_DRAG]:u.contexts[t.DRAG]);B(_,d&&!z?"motionBlur":void 0);L?t.drawCachedNodes(_,P.drag,l,R):t.drawCachedElements(_,P.drag,l,R);t.debug&&t.drawDebugPoints(_,P.drag);n||d||(v[t.DRAG]=false)}this.drawSelectionRectangle(e,B);if(d&&f!==1){var F=u.contexts[t.NODE];var X=t.data.bufferCanvases[t.MOTIONBLUR_BUFFER_NODE];var j=u.contexts[t.DRAG];var Y=t.data.bufferCanvases[t.MOTIONBLUR_BUFFER_DRAG];var q=function(e,r,a){e.setTransform(1,0,0,1,0,0);a||!y?e.clearRect(0,0,t.canvasWidth,t.canvasHeight):S(e,0,0,t.canvasWidth,t.canvasHeight);var n=f;e.drawImage(r,0,0,t.canvasWidth*n,t.canvasHeight*n,0,0,t.canvasWidth,t.canvasHeight)};if(v[t.NODE]||O[t.NODE]){q(F,X,O[t.NODE]);v[t.NODE]=false}if(v[t.DRAG]||O[t.DRAG]){q(j,Y,O[t.DRAG]);v[t.DRAG]=false}}t.prevViewport=T;if(t.clearingMotionBlur){t.clearingMotionBlur=false;t.motionBlurCleared=true;t.motionBlur=true}d&&(t.motionBlurTimeout=setTimeout((function(){t.motionBlurTimeout=null;t.clearedForMotionBlur[t.NODE]=false;t.clearedForMotionBlur[t.DRAG]=false;t.motionBlur=false;t.clearingMotionBlur=!c;t.mbFrames=0;v[t.NODE]=true;v[t.DRAG]=true;t.redraw()}),Sh));a||r.emit("render")};var Bh;Ph.drawSelectionRectangle=function(e,t){var r=this;var a=r.cy;var n=r.data;var i=a.style();var o=e.drawOnlyNodeLayer;var s=e.drawAllLayers;var l=n.canvasNeedsRedraw;var u=e.forcedContext;if(r.showFps||!o&&l[r.SELECT_BOX]&&!s){var v=u||n.contexts[r.SELECT_BOX];t(v);if(r.selection[4]==1&&(r.hoverData.selecting||r.touchData.selecting)){var c=r.cy.zoom();var d=i.core("selection-box-border-width").value/c;v.lineWidth=d;v.fillStyle="rgba("+i.core("selection-box-color").value[0]+","+i.core("selection-box-color").value[1]+","+i.core("selection-box-color").value[2]+","+i.core("selection-box-opacity").value+")";v.fillRect(r.selection[0],r.selection[1],r.selection[2]-r.selection[0],r.selection[3]-r.selection[1]);if(d>0){v.strokeStyle="rgba("+i.core("selection-box-border-color").value[0]+","+i.core("selection-box-border-color").value[1]+","+i.core("selection-box-border-color").value[2]+","+i.core("selection-box-opacity").value+")";v.strokeRect(r.selection[0],r.selection[1],r.selection[2]-r.selection[0],r.selection[3]-r.selection[1])}}if(n.bgActivePosistion&&!r.hoverData.selecting){c=r.cy.zoom();var f=n.bgActivePosistion;v.fillStyle="rgba("+i.core("active-bg-color").value[0]+","+i.core("active-bg-color").value[1]+","+i.core("active-bg-color").value[2]+","+i.core("active-bg-opacity").value+")";v.beginPath();v.arc(f.x,f.y,i.core("active-bg-size").pfValue/c,0,2*Math.PI);v.fill()}var h=r.lastRedrawTime;if(r.showFps&&h){h=Math.round(h);var p=Math.round(1e3/h);var g="1 frame = "+h+" ms = "+p+" fps";v.setTransform(1,0,0,1,0,0);v.fillStyle="rgba(255, 0, 0, 0.75)";v.strokeStyle="rgba(255, 0, 0, 0.75)";v.font="30px Arial";if(!Bh){var y=v.measureText(g);Bh=y.actualBoundingBoxAscent}v.fillText(g,0,Bh);var m=60;v.strokeRect(0,Bh+10,250,20);v.fillRect(0,Bh+10,250*Math.min(p/m,1),20)}s||(l[r.SELECT_BOX]=false)}};function Dh(e,t,r){var a=e.createShader(t);e.shaderSource(a,r);e.compileShader(a);if(!e.getShaderParameter(a,e.COMPILE_STATUS))throw new Error(e.getShaderInfoLog(a));return a}function _h(e,t,r){var a=Dh(e,e.VERTEX_SHADER,t);var n=Dh(e,e.FRAGMENT_SHADER,r);var i=e.createProgram();e.attachShader(i,a);e.attachShader(i,n);e.linkProgram(i);if(!e.getProgramParameter(i,e.LINK_STATUS))throw new Error("Could not initialize shaders");return i}function Ah(e,t,r){r===void 0&&(r=t);var a=e.makeOffscreenCanvas(t,r);var n=a.context=a.getContext("2d");a.clear=function(){return n.clearRect(0,0,a.width,a.height)};a.clear();return a}function Mh(e){var t=e.pixelRatio;var r=e.cy.zoom();var a=e.cy.pan();return{zoom:r*t,pan:{x:a.x*t,y:a.y*t}}}function Ih(e){var t=e.pixelRatio;var r=e.cy.zoom();return r*t}function Rh(e,t,r,a,n){var i=a*r+t.x;var o=n*r+t.y;o=Math.round(e.canvasHeight-o);return[i,o]}function Nh(e){return e.pstyle("background-fill").value==="solid"&&(e.pstyle("background-image").strValue==="none"&&(e.pstyle("border-width").value===0||(e.pstyle("border-opacity").value===0||e.pstyle("border-style").value==="solid")))}function Lh(e,t){if(e.length!==t.length)return false;for(var r=0;r>8&255)/255;r[2]=(e>>16&255)/255;r[3]=(e>>24&255)/255;return r}function Vh(e){return e[0]+(e[1]<<8)+(e[2]<<16)+(e[3]<<24)}function Fh(e,t){var r=e.createTexture();r.buffer=function(t){e.bindTexture(e.TEXTURE_2D,r);e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE);e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR);e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR_MIPMAP_NEAREST);e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,true);e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t);e.generateMipmap(e.TEXTURE_2D);e.bindTexture(e.TEXTURE_2D,null)};r.deleteTexture=function(){e.deleteTexture(r)};return r}function Xh(e,t){switch(t){case"float":return[1,e.FLOAT,4];case"vec2":return[2,e.FLOAT,4];case"vec3":return[3,e.FLOAT,4];case"vec4":return[4,e.FLOAT,4];case"int":return[1,e.INT,4];case"ivec2":return[2,e.INT,4]}}function jh(e,t,r){switch(t){case e.FLOAT:return new Float32Array(r);case e.INT:return new Int32Array(r)}}function Yh(e,t,r,a,n,i){switch(t){case e.FLOAT:return new Float32Array(r.buffer,i*a,n);case e.INT:return new Int32Array(r.buffer,i*a,n)}} +/** @param {WebGLRenderingContext} gl */function qh(e,t,r,a){var n=Xh(e,t),i=d(n,2),o=i[0],s=i[1];var l=jh(e,s,a);var u=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,u);e.bufferData(e.ARRAY_BUFFER,l,e.STATIC_DRAW);s===e.FLOAT?e.vertexAttribPointer(r,o,s,false,0,0):s===e.INT&&e.vertexAttribIPointer(r,o,s,0,0);e.enableVertexAttribArray(r);e.bindBuffer(e.ARRAY_BUFFER,null);return u} +/** + * Creates a float buffer with gl.DYNAMIC_DRAW. + * The returned buffer object contains functions to easily set instance data and buffer the data before a draw call. + * @param {WebGLRenderingContext} gl + */function Wh(e,t,r,a){var n=Xh(e,r),i=d(n,3),o=i[0],s=i[1],l=i[2];var u=jh(e,s,t*o);var v=o*l;var c=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,c);e.bufferData(e.ARRAY_BUFFER,t*v,e.DYNAMIC_DRAW);e.enableVertexAttribArray(a);s===e.FLOAT?e.vertexAttribPointer(a,o,s,false,v,0):s===e.INT&&e.vertexAttribIPointer(a,o,s,v,0);e.vertexAttribDivisor(a,1);e.bindBuffer(e.ARRAY_BUFFER,null);var f=new Array(t);for(var h=0;hn){i=n/t;o=t*i;s=r*i}return{scale:i,texW:o,texH:s}}},{key:"draw",value:function(e,t,r){var a=this;if(this.locked)throw new Error("can't draw, atlas is locked");var n=this.texSize,i=this.texRows,o=this.texHeight;var s=this.getScale(t),l=s.scale,u=s.texW,v=s.texH;var c=function(e,a){if(r&&a){var n=a.context;var i=e.x,s=e.row;var u=i;var v=o*s;n.save();n.translate(u,v);n.scale(l,l);r(n,t);n.restore()}};var d=[null,null];var f=function(){c(a.freePointer,a.canvas);d[0]={x:a.freePointer.x,y:a.freePointer.row*o,w:u,h:v};d[1]={x:a.freePointer.x+u,y:a.freePointer.row*o,w:0,h:v};a.freePointer.x+=u;if(a.freePointer.x==n){a.freePointer.x=0;a.freePointer.row++}};var h=function(){var e=a.scratch,t=a.canvas;e.clear();c({x:0,row:0},e);var r=n-a.freePointer.x;var i=u-r;var s=o;var l=a.freePointer.x;var f=a.freePointer.row*o;var h=r;t.context.drawImage(e,0,0,h,s,l,f,h,s);d[0]={x:l,y:f,w:h,h:v};var p=r;var g=(a.freePointer.row+1)*o;var y=i;t&&t.context.drawImage(e,p,0,y,s,0,g,y,s);d[1]={x:0,y:g,w:y,h:v};a.freePointer.x=i;a.freePointer.row++};var p=function(){a.freePointer.x=0;a.freePointer.row++};if(this.freePointer.x+u<=n)f();else{if(this.freePointer.row>=i-1)return false;if(this.freePointer.x===n){p();f()}else if(this.enableWrapping)h();else{p();f()}}this.keyToLocation.set(e,d);this.needsBuffer=true;return d}},{key:"getOffsets",value:function(e){return this.keyToLocation.get(e)}},{key:"isEmpty",value:function(){return this.freePointer.x===0&&this.freePointer.row===0}},{key:"canFit",value:function(e){if(this.locked)return false;var t=this.texSize,r=this.texRows;var a=this.getScale(e),n=a.texW;return!(this.freePointer.x+n>t)||this.freePointer.row1&&arguments[1]!==void 0?arguments[1]:{},a=r.forceRedraw,n=a!==void 0&&a,i=r.filterEle,s=i===void 0?function(){return true}:i,l=r.filterType,u=l===void 0?function(){return true}:l;var v=false;var c=false;var d,f=o(e);try{for(f.s();!(d=f.n()).done;){var h=d.value;if(s(h)){var p,g=o(this.renderTypes.values());try{var y=function(){var e=p.value;var r=e.type;if(u(r)){var a=t.collections.get(e.collection);var i=e.getKey(h);var o=Array.isArray(i)?i:[i];if(n){o.forEach((function(e){return a.markKeyForGC(e)}));c=true}else{var s=e.getID?e.getID(h):h.id();var l=t._key(r,s);var d=t.typeAndIdToKey.get(l);if(d!==void 0&&!Lh(o,d)){v=true;t.typeAndIdToKey.delete(l);d.forEach((function(e){return a.markKeyForGC(e)}))}}}};for(g.s();!(p=g.n()).done;)y()}catch(e){g.e(e)}finally{g.f()}}}}catch(e){f.e(e)}finally{f.f()}if(c){this.gc();v=false}return v}},{key:"gc",value:function(){var e,t=o(this.collections.values());try{for(t.s();!(e=t.n()).done;){var r=e.value;r.gc()}}catch(e){t.e(e)}finally{t.f()}}},{key:"getOrCreateAtlas",value:function(e,t,r,a){var n=this.renderTypes.get(t);var i=this.collections.get(n.collection);var o=false;var s=i.draw(a,r,(function(t){if(n.drawClipped){t.save();t.beginPath();t.rect(0,0,r.w,r.h);t.clip();n.drawElement(t,e,r,true,true);t.restore()}else n.drawElement(t,e,r,true,true);o=true}));if(o){var l=n.getID?n.getID(e):e.id();var u=this._key(t,l);this.typeAndIdToKey.has(u)?this.typeAndIdToKey.get(u).push(a):this.typeAndIdToKey.set(u,[a])}return s}},{key:"getAtlasInfo",value:function(e,t){var r=this;var a=this.renderTypes.get(t);var n=a.getKey(e);var i=Array.isArray(n)?n:[n];return i.map((function(n){var i=a.getBoundingBox(e,n);var o=r.getOrCreateAtlas(e,t,i,n);var s=o.getOffsets(n),l=d(s,2),u=l[0],v=l[1];return{atlas:o,tex:u,tex1:u,tex2:v,bb:i}}))}},{key:"getDebugInfo",value:function(){var e=[];var t,r=o(this.collections);try{for(r.s();!(t=r.n()).done;){var a=d(t.value,2),n=a[0],i=a[1];var s=i.getCounts(),l=s.keyCount,u=s.atlasCount;e.push({type:n,keyCount:l,atlasCount:u})}}catch(e){r.e(e)}finally{r.f()}return e}}])}();var op=function(){function e(t){a(this,e);this.globalOptions=t;this.atlasSize=t.webglTexSize;this.maxAtlasesPerBatch=t.webglTexPerBatch;this.batchAtlases=[]}return i(e,[{key:"getMaxAtlasesPerBatch",value:function(){return this.maxAtlasesPerBatch}},{key:"getAtlasSize",value:function(){return this.atlasSize}},{key:"getIndexArray",value:function(){return Array.from({length:this.maxAtlasesPerBatch},(function(e,t){return t}))}},{key:"startBatch",value:function(){this.batchAtlases=[]}},{key:"getAtlasCount",value:function(){return this.batchAtlases.length}},{key:"getAtlases",value:function(){return this.batchAtlases}},{key:"canAddToCurrentBatch",value:function(e){return this.batchAtlases.length!==this.maxAtlasesPerBatch||this.batchAtlases.includes(e)}},{key:"getAtlasIndexForBatch",value:function(e){var t=this.batchAtlases.indexOf(e);if(t<0){if(this.batchAtlases.length===this.maxAtlasesPerBatch)throw new Error("cannot add more atlases to batch");this.batchAtlases.push(e);t=this.batchAtlases.length-1}return t}}])}();var sp="\n float circleSD(vec2 p, float r) {\n return distance(vec2(0), p) - r; // signed distance\n }\n";var lp="\n float rectangleSD(vec2 p, vec2 b) {\n vec2 d = abs(p)-b;\n return distance(vec2(0),max(d,0.0)) + min(max(d.x,d.y),0.0);\n }\n";var up="\n float roundRectangleSD(vec2 p, vec2 b, vec4 cr) {\n cr.xy = (p.x > 0.0) ? cr.xy : cr.zw;\n cr.x = (p.y > 0.0) ? cr.x : cr.y;\n vec2 q = abs(p) - b + cr.x;\n return min(max(q.x, q.y), 0.0) + distance(vec2(0), max(q, 0.0)) - cr.x;\n }\n";var vp="\n float ellipseSD(vec2 p, vec2 ab) {\n p = abs( p ); // symmetry\n\n // find root with Newton solver\n vec2 q = ab*(p-ab);\n float w = (q.x1.0) ? d : -d;\n }\n";var cp={SCREEN:{name:"screen",screen:true},PICKING:{name:"picking",picking:true}};var dp={IGNORE:1,USE_BB:2};var fp=0;var hp=1;var pp=2;var gp=3;var yp=4;var mp=5;var bp=6;var xp=7;var wp=function(){ +/** + * @param {WebGLRenderingContext} gl + */ +function e(t,r,n){a(this,e);this.r=t;this.gl=r;this.maxInstances=n.webglBatchSize;this.atlasSize=n.webglTexSize;this.bgColor=n.bgColor;this.debug=n.webglDebug;this.batchDebugInfo=[];n.enableWrapping=true;n.createTextureCanvas=Ah;this.atlasManager=new ip(t,n);this.batchManager=new op(n);this.simpleShapeOptions=new Map;this.program=this._createShaderProgram(cp.SCREEN);this.pickingProgram=this._createShaderProgram(cp.PICKING);this.vao=this._createVAO()} +/** + * @param { string } collectionName + * @param {{ texRows: number }} opts + */return i(e,[{key:"addAtlasCollection",value:function(e,t){this.atlasManager.addAtlasCollection(e,t)} +/** + * @typedef { Object } TextureRenderTypeOpts + * @property { string } collection - name of atlas collection to render textures to + * @property { function } getKey - returns the "style key" for an element, may be a single value or an array for multi-line lables + * @property { function } drawElement - uses a canvas renderer to draw the element to the texture atlas + * @property { boolean } drawClipped - if true the context will be clipped to the bounding box before drawElement() is called, may affect performance + * @property { function } getBoundingBox - returns the bounding box for an element + * @property { function } getRotation + * @property { function } getRotationPoint + * @property { function } getRotationOffset + * @property { function } isVisible - an extra check for visibility in addition to ele.visible() + * @property { function } getTexPickingMode - returns a value from the TEX_PICKING_MODE enum + */ +/** + * @param { string } typeName + * @param { TextureRenderTypeOpts } opts + */},{key:"addTextureAtlasRenderType",value:function(e,t){this.atlasManager.addRenderType(e,t)} +/** + * @typedef { Object } SimpleShapeRenderTypeOpts + * @property { function } getBoundingBox - returns the bounding box for an element + * @property { function } isVisible - this is an extra check for visibility in addition to ele.visible() + * @property { function } isSimple - check if element is a simple shape, or if it needs to fall back to texture rendering + * @property { ShapeVisualProperties } shapeProps + */ +/** + * @typedef { Object } ShapeVisualProperties + * @property { string } shape + * @property { string } color + * @property { string } opacity + * @property { string } padding + * @property { string } radius + * @property { boolean } border + */ +/** + * @param { string } typeName + * @param { SimpleShapeRenderTypeOpts } opts + */},{key:"addSimpleShapeRenderType",value:function(e,t){this.simpleShapeOptions.set(e,t)}},{key:"invalidate",value:function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=t.type;var a=this.atlasManager;return r?a.invalidate(e,{filterType:function(e){return e===r},forceRedraw:true}):a.invalidate(e)}},{key:"gc",value:function(){this.atlasManager.gc()}},{key:"_createShaderProgram",value:function(e){var t=this.gl;var r="#version 300 es\n precision highp float;\n\n uniform mat3 uPanZoomMatrix;\n uniform int uAtlasSize;\n \n // instanced\n in vec2 aPosition; // a vertex from the unit square\n \n in mat3 aTransform; // used to transform verticies, eg into a bounding box\n in int aVertType; // the type of thing we are rendering\n\n // the z-index that is output when using picking mode\n in vec4 aIndex;\n \n // For textures\n in int aAtlasId; // which shader unit/atlas to use\n in vec4 aTex; // x/y/w/h of texture in atlas\n\n // for edges\n in vec4 aPointAPointB;\n in vec4 aPointCPointD;\n in vec2 aLineWidth; // also used for node border width\n\n // simple shapes\n in vec4 aCornerRadius; // for round-rectangle [top-right, bottom-right, top-left, bottom-left]\n in vec4 aColor; // also used for edges\n in vec4 aBorderColor; // aLineWidth is used for border width\n\n // output values passed to the fragment shader\n out vec2 vTexCoord;\n out vec4 vColor;\n out vec2 vPosition;\n // flat values are not interpolated\n flat out int vAtlasId; \n flat out int vVertType;\n flat out vec2 vTopRight;\n flat out vec2 vBotLeft;\n flat out vec4 vCornerRadius;\n flat out vec4 vBorderColor;\n flat out vec2 vBorderWidth;\n flat out vec4 vIndex;\n \n void main(void) {\n int vid = gl_VertexID;\n vec2 position = aPosition; // TODO make this a vec3, simplifies some code below\n\n if(aVertType == ".concat(fp,") {\n float texX = aTex.x; // texture coordinates\n float texY = aTex.y;\n float texW = aTex.z;\n float texH = aTex.w;\n\n if(vid == 1 || vid == 2 || vid == 4) {\n texX += texW;\n }\n if(vid == 2 || vid == 4 || vid == 5) {\n texY += texH;\n }\n\n float d = float(uAtlasSize);\n vTexCoord = vec2(texX / d, texY / d); // tex coords must be between 0 and 1\n\n gl_Position = vec4(uPanZoomMatrix * aTransform * vec3(position, 1.0), 1.0);\n }\n else if(aVertType == ").concat(yp," || aVertType == ").concat(xp," \n || aVertType == ").concat(mp," || aVertType == ").concat(bp,") { // simple shapes\n\n // the bounding box is needed by the fragment shader\n vBotLeft = (aTransform * vec3(0, 0, 1)).xy; // flat\n vTopRight = (aTransform * vec3(1, 1, 1)).xy; // flat\n vPosition = (aTransform * vec3(position, 1)).xy; // will be interpolated\n\n // calculations are done in the fragment shader, just pass these along\n vColor = aColor;\n vCornerRadius = aCornerRadius;\n vBorderColor = aBorderColor;\n vBorderWidth = aLineWidth;\n\n gl_Position = vec4(uPanZoomMatrix * aTransform * vec3(position, 1.0), 1.0);\n }\n else if(aVertType == ").concat(hp,") {\n vec2 source = aPointAPointB.xy;\n vec2 target = aPointAPointB.zw;\n\n // adjust the geometry so that the line is centered on the edge\n position.y = position.y - 0.5;\n\n // stretch the unit square into a long skinny rectangle\n vec2 xBasis = target - source;\n vec2 yBasis = normalize(vec2(-xBasis.y, xBasis.x));\n vec2 point = source + xBasis * position.x + yBasis * aLineWidth[0] * position.y;\n\n gl_Position = vec4(uPanZoomMatrix * vec3(point, 1.0), 1.0);\n vColor = aColor;\n } \n else if(aVertType == ").concat(pp,") {\n vec2 pointA = aPointAPointB.xy;\n vec2 pointB = aPointAPointB.zw;\n vec2 pointC = aPointCPointD.xy;\n vec2 pointD = aPointCPointD.zw;\n\n // adjust the geometry so that the line is centered on the edge\n position.y = position.y - 0.5;\n\n vec2 p0, p1, p2, pos;\n if(position.x == 0.0) { // The left side of the unit square\n p0 = pointA;\n p1 = pointB;\n p2 = pointC;\n pos = position;\n } else { // The right side of the unit square, use same approach but flip the geometry upside down\n p0 = pointD;\n p1 = pointC;\n p2 = pointB;\n pos = vec2(0.0, -position.y);\n }\n\n vec2 p01 = p1 - p0;\n vec2 p12 = p2 - p1;\n vec2 p21 = p1 - p2;\n\n // Find the normal vector.\n vec2 tangent = normalize(normalize(p12) + normalize(p01));\n vec2 normal = vec2(-tangent.y, tangent.x);\n\n // Find the vector perpendicular to p0 -> p1.\n vec2 p01Norm = normalize(vec2(-p01.y, p01.x));\n\n // Determine the bend direction.\n float sigma = sign(dot(p01 + p21, normal));\n float width = aLineWidth[0];\n\n if(sign(pos.y) == -sigma) {\n // This is an intersecting vertex. Adjust the position so that there's no overlap.\n vec2 point = 0.5 * width * normal * -sigma / dot(normal, p01Norm);\n gl_Position = vec4(uPanZoomMatrix * vec3(p1 + point, 1.0), 1.0);\n } else {\n // This is a non-intersecting vertex. Treat it like a mitre join.\n vec2 point = 0.5 * width * normal * sigma * dot(normal, p01Norm);\n gl_Position = vec4(uPanZoomMatrix * vec3(p1 + point, 1.0), 1.0);\n }\n\n vColor = aColor;\n } \n else if(aVertType == ").concat(gp," && vid < 3) {\n // massage the first triangle into an edge arrow\n if(vid == 0)\n position = vec2(-0.15, -0.3);\n if(vid == 1)\n position = vec2( 0.0, 0.0);\n if(vid == 2)\n position = vec2( 0.15, -0.3);\n\n gl_Position = vec4(uPanZoomMatrix * aTransform * vec3(position, 1.0), 1.0);\n vColor = aColor;\n }\n else {\n gl_Position = vec4(2.0, 0.0, 0.0, 1.0); // discard vertex by putting it outside webgl clip space\n }\n\n vAtlasId = aAtlasId;\n vVertType = aVertType;\n vIndex = aIndex;\n }\n ");var a=this.batchManager.getIndexArray();var n="#version 300 es\n precision highp float;\n\n // declare texture unit for each texture atlas in the batch\n ".concat(a.map((function(e){return"uniform sampler2D uTexture".concat(e,";")})).join("\n\t"),"\n\n uniform vec4 uBGColor;\n uniform float uZoom;\n\n in vec2 vTexCoord;\n in vec4 vColor;\n in vec2 vPosition; // model coordinates\n\n flat in int vAtlasId;\n flat in vec4 vIndex;\n flat in int vVertType;\n flat in vec2 vTopRight;\n flat in vec2 vBotLeft;\n flat in vec4 vCornerRadius;\n flat in vec4 vBorderColor;\n flat in vec2 vBorderWidth;\n\n out vec4 outColor;\n\n ").concat(sp,"\n ").concat(lp,"\n ").concat(up,"\n ").concat(vp,"\n\n vec4 blend(vec4 top, vec4 bot) { // blend colors with premultiplied alpha\n return vec4( \n top.rgb + (bot.rgb * (1.0 - top.a)),\n top.a + (bot.a * (1.0 - top.a)) \n );\n }\n\n vec4 distInterp(vec4 cA, vec4 cB, float d) { // interpolate color using Signed Distance\n // scale to the zoom level so that borders don't look blurry when zoomed in\n // note 1.5 is an aribitrary value chosen because it looks good\n return mix(cA, cB, 1.0 - smoothstep(0.0, 1.5 / uZoom, abs(d))); \n }\n\n void main(void) {\n if(vVertType == ").concat(fp,") {\n // look up the texel from the texture unit\n ").concat(a.map((function(e){return"if(vAtlasId == ".concat(e,") outColor = texture(uTexture").concat(e,", vTexCoord);")})).join("\n\telse "),"\n } \n else if(vVertType == ").concat(gp,") {\n // mimics how canvas renderer uses context.globalCompositeOperation = 'destination-out';\n outColor = blend(vColor, uBGColor);\n outColor.a = 1.0; // make opaque, masks out line under arrow\n }\n else if(vVertType == ").concat(yp," && vBorderWidth == vec2(0.0)) { // simple rectangle with no border\n outColor = vColor; // unit square is already transformed to the rectangle, nothing else needs to be done\n }\n else if(vVertType == ").concat(yp," || vVertType == ").concat(xp," \n || vVertType == ").concat(mp," || vVertType == ").concat(bp,") { // use SDF\n\n float outerBorder = vBorderWidth[0];\n float innerBorder = vBorderWidth[1];\n float borderPadding = outerBorder * 2.0;\n float w = vTopRight.x - vBotLeft.x - borderPadding;\n float h = vTopRight.y - vBotLeft.y - borderPadding;\n vec2 b = vec2(w/2.0, h/2.0); // half width, half height\n vec2 p = vPosition - vec2(vTopRight.x - b[0] - outerBorder, vTopRight.y - b[1] - outerBorder); // translate to center\n\n float d; // signed distance\n if(vVertType == ").concat(yp,") {\n d = rectangleSD(p, b);\n } else if(vVertType == ").concat(xp," && w == h) {\n d = circleSD(p, b.x); // faster than ellipse\n } else if(vVertType == ").concat(xp,") {\n d = ellipseSD(p, b);\n } else {\n d = roundRectangleSD(p, b, vCornerRadius.wzyx);\n }\n\n // use the distance to interpolate a color to smooth the edges of the shape, doesn't need multisampling\n // we must smooth colors inwards, because we can't change pixels outside the shape's bounding box\n if(d > 0.0) {\n if(d > outerBorder) {\n discard;\n } else {\n outColor = distInterp(vBorderColor, vec4(0), d - outerBorder);\n }\n } else {\n if(d > innerBorder) {\n vec4 outerColor = outerBorder == 0.0 ? vec4(0) : vBorderColor;\n vec4 innerBorderColor = blend(vBorderColor, vColor);\n outColor = distInterp(innerBorderColor, outerColor, d);\n } \n else {\n vec4 outerColor;\n if(innerBorder == 0.0 && outerBorder == 0.0) {\n outerColor = vec4(0);\n } else if(innerBorder == 0.0) {\n outerColor = vBorderColor;\n } else {\n outerColor = blend(vBorderColor, vColor);\n }\n outColor = distInterp(vColor, outerColor, d - innerBorder);\n }\n }\n }\n else {\n outColor = vColor;\n }\n\n ").concat(e.picking?"if(outColor.a == 0.0) discard;\n else outColor = vIndex;":"","\n }\n ");var i=_h(t,r,n);i.aPosition=t.getAttribLocation(i,"aPosition");i.aIndex=t.getAttribLocation(i,"aIndex");i.aVertType=t.getAttribLocation(i,"aVertType");i.aTransform=t.getAttribLocation(i,"aTransform");i.aAtlasId=t.getAttribLocation(i,"aAtlasId");i.aTex=t.getAttribLocation(i,"aTex");i.aPointAPointB=t.getAttribLocation(i,"aPointAPointB");i.aPointCPointD=t.getAttribLocation(i,"aPointCPointD");i.aLineWidth=t.getAttribLocation(i,"aLineWidth");i.aColor=t.getAttribLocation(i,"aColor");i.aCornerRadius=t.getAttribLocation(i,"aCornerRadius");i.aBorderColor=t.getAttribLocation(i,"aBorderColor");i.uPanZoomMatrix=t.getUniformLocation(i,"uPanZoomMatrix");i.uAtlasSize=t.getUniformLocation(i,"uAtlasSize");i.uBGColor=t.getUniformLocation(i,"uBGColor");i.uZoom=t.getUniformLocation(i,"uZoom");i.uTextures=[];for(var o=0;o1&&arguments[1]!==void 0?arguments[1]:cp.SCREEN;this.panZoomMatrix=e;this.renderTarget=t;this.batchDebugInfo=[];this.wrappedCount=0;this.simpleCount=0;this.startBatch()}},{key:"startBatch",value:function(){this.instanceCount=0;this.batchManager.startBatch()}},{key:"endFrame",value:function(){this.endBatch()}},{key:"_isVisible",value:function(e,t){return!!e.visible()&&(!t||!t.isVisible||t.isVisible(e))}},{key:"drawTexture",value:function(e,t,r){var a=this.atlasManager,n=this.batchManager;var i=a.getRenderTypeOpts(r);if(this._isVisible(e,i)&&(!e.isEdge()||this._isValidEdge(e))){if(this.renderTarget.picking&&i.getTexPickingMode){var s=i.getTexPickingMode(e);if(s===dp.IGNORE)return;if(s==dp.USE_BB){this.drawPickingRectangle(e,t,r);return}}var l=a.getAtlasInfo(e,r);var u,v=o(l);try{for(v.s();!(u=v.n()).done;){var c=u.value;var f=c.atlas,h=c.tex1,p=c.tex2;n.canAddToCurrentBatch(f)||this.endBatch();var g=n.getAtlasIndexForBatch(f);for(var y=0,m=[[h,true],[p,false]];y=this.maxInstances&&this.endBatch()}}}}catch(e){v.e(e)}finally{v.f()}}}},{key:"setTransformMatrix",value:function(e,t,r,a){var n=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4];var i=0;r.shapeProps&&r.shapeProps.padding&&(i=e.pstyle(r.shapeProps.padding).pfValue);if(a){var o=a.bb,s=a.tex1,l=a.tex2;var u=s.w/(s.w+l.w);n||(u=1-u);var v=this._getAdjustedBB(o,i,n,u);this._applyTransformMatrix(t,v,r,e)}else{var c=r.getBoundingBox(e);var d=this._getAdjustedBB(c,i,true,1);this._applyTransformMatrix(t,d,r,e)}}},{key:"_applyTransformMatrix",value:function(e,t,r,a){var n,i;Zh(e);var o=r.getRotation?r.getRotation(a):0;if(o!==0){var s=r.getRotationPoint(a),l=s.x,u=s.y;Qh(e,e,[l,u]);Jh(e,e,o);var v=r.getRotationOffset(a);n=v.x+(t.xOffset||0);i=v.y+(t.yOffset||0)}else{n=t.x1;i=t.y1}Qh(e,e,[n,i]);ep(e,e,[t.w,t.h])} +/** + * Adjusts a node or label BB to accomodate padding and split for wrapped textures. + * @param bb - the original bounding box + * @param padding - the padding to add to the bounding box + * @param first - whether this is the first part of a wrapped texture + * @param ratio - the ratio of the texture width of part of the text to the entire texture + */},{key:"_getAdjustedBB",value:function(e,t,r,a){var n=e.x1,i=e.y1,o=e.w,s=e.h,l=e.yOffset;if(t){n-=t;i-=t;o+=2*t;s+=2*t}var u=0;var v=o*a;if(r&&a<1)o=v;else if(!r&&a<1){u=o-v;n+=u;o=v}return{x1:n,y1:i,w:o,h:s,xOffset:u,yOffset:l}}},{key:"drawPickingRectangle",value:function(e,t,r){var a=this.atlasManager.getRenderTypeOpts(r);var n=this.instanceCount;this.vertTypeBuffer.getView(n)[0]=yp;var i=this.indexBuffer.getView(n);zh(t,i);var o=this.colorBuffer.getView(n);Oh([0,0,0],1,o);var s=this.transformBuffer.getMatrixView(n);this.setTransformMatrix(e,s,a);this.simpleCount++;this.instanceCount++;this.instanceCount>=this.maxInstances&&this.endBatch()}},{key:"drawNode",value:function(e,t,r){var a=this.simpleShapeOptions.get(r);if(this._isVisible(e,a)){var n=a.shapeProps;var i=this._getVertTypeForShape(e,n.shape);if(i===void 0||a.isSimple&&!a.isSimple(e))this.drawTexture(e,t,r);else{var o=this.instanceCount;this.vertTypeBuffer.getView(o)[0]=i;if(i===mp||i===bp){var s=a.getBoundingBox(e);var l=this._getCornerRadius(e,n.radius,s);var u=this.cornerRadiusBuffer.getView(o);u[0]=l;u[1]=l;u[2]=l;u[3]=l;if(i===bp){u[0]=0;u[2]=0}}var v=this.indexBuffer.getView(o);zh(t,v);var c=e.pstyle(n.color).value;var d=e.pstyle(n.opacity).value;var f=this.colorBuffer.getView(o);Oh(c,d,f);var h=this.lineWidthBuffer.getView(o);h[0]=0;h[1]=0;if(n.border){var p=e.pstyle("border-width").value;if(p>0){var g=e.pstyle("border-color").value;var y=e.pstyle("border-opacity").value;var m=this.borderColorBuffer.getView(o);Oh(g,y,m);var b=e.pstyle("border-position").value;if(b==="inside"){h[0]=0;h[1]=-p}else if(b==="outside"){h[0]=p;h[1]=0}else{var x=p/2;h[0]=x;h[1]=-x}}}var w=this.transformBuffer.getMatrixView(o);this.setTransformMatrix(e,w,a);this.simpleCount++;this.instanceCount++;this.instanceCount>=this.maxInstances&&this.endBatch()}}}},{key:"_getVertTypeForShape",value:function(e,t){var r=e.pstyle(t).value;switch(r){case"rectangle":return yp;case"ellipse":return xp;case"roundrectangle":case"round-rectangle":return mp;case"bottom-round-rectangle":return bp;default:return}}},{key:"_getCornerRadius",value:function(e,t,r){var a=r.w,n=r.h;if(e.pstyle(t).value==="auto")return Aa(a,n);var i=e.pstyle(t).pfValue;var o=a/2;var s=n/2;return Math.min(i,s,o)}},{key:"drawEdgeArrow",value:function(e,t,r){if(e.visible()){var a=e._private.rscratch;var n,i,o;if(r==="source"){n=a.arrowStartX;i=a.arrowStartY;o=a.srcArrowAngle}else{n=a.arrowEndX;i=a.arrowEndY;o=a.tgtArrowAngle}if(!(isNaN(n)||n==null||isNaN(i)||i==null||isNaN(o)||o==null)){var s=e.pstyle(r+"-arrow-shape").value;if(s!=="none"){var l=e.pstyle(r+"-arrow-color").value;var u=e.pstyle("opacity").value;var v=e.pstyle("line-opacity").value;var c=u*v;var d=e.pstyle("width").pfValue;var f=e.pstyle("arrow-scale").value;var h=this.r.getArrowWidth(d,f);var p=this.instanceCount;var g=this.transformBuffer.getMatrixView(p);Zh(g);Qh(g,g,[n,i]);ep(g,g,[h,h]);Jh(g,g,o);this.vertTypeBuffer.getView(p)[0]=gp;var y=this.indexBuffer.getView(p);zh(t,y);var m=this.colorBuffer.getView(p);Oh(l,c,m);this.instanceCount++;this.instanceCount>=this.maxInstances&&this.endBatch()}}}}},{key:"drawEdgeLine",value:function(e,t){if(e.visible()){var r=this._getEdgePoints(e);if(r){var a=e.pstyle("opacity").value;var n=e.pstyle("line-opacity").value;var i=e.pstyle("width").pfValue;var o=e.pstyle("line-color").value;var s=a*n;r.length/2+this.instanceCount>this.maxInstances&&this.endBatch();if(r.length==4){var l=this.instanceCount;this.vertTypeBuffer.getView(l)[0]=hp;var u=this.indexBuffer.getView(l);zh(t,u);var v=this.colorBuffer.getView(l);Oh(o,s,v);var c=this.lineWidthBuffer.getView(l);c[0]=i;var d=this.pointAPointBBuffer.getView(l);d[0]=r[0];d[1]=r[1];d[2]=r[2];d[3]=r[3];this.instanceCount++;this.instanceCount>=this.maxInstances&&this.endBatch()}else for(var f=0;f=this.maxInstances&&this.endBatch()}}}}},{key:"_isValidEdge",value:function(e){var t=e._private.rscratch;return!t.badLine&&t.allpts!=null&&!isNaN(t.allpts[0])}},{key:"_getEdgePoints",value:function(e){var t=e._private.rscratch;if(this._isValidEdge(e)){var r=t.allpts;if(r.length==4)return r;var a=this._getNumSegments(e);return this._getCurveSegmentPoints(r,a)}}},{key:"_getNumSegments",value:function(e){var t=15;return Math.min(Math.max(t,5),this.maxInstances)}},{key:"_getCurveSegmentPoints",value:function(e,t){if(e.length==4)return e;var r=Array((t+1)*2);for(var a=0;a<=t;a++)if(a==0){r[0]=e[0];r[1]=e[1]}else if(a==t){r[a*2]=e[e.length-2];r[a*2+1]=e[e.length-1]}else{var n=a/t;this._setCurvePoint(e,n,r,a*2)}return r}},{key:"_setCurvePoint",value:function(e,t,r,a){if(!(e.length<=2)){var n=Array(e.length-2);for(var i=0;i0}};var s=function(e){var t=e.pstyle("text-events").strValue==="yes";return t?dp.USE_BB:dp.IGNORE};var l=function(e){var t=e.position(),r=t.x,a=t.y;var n=e.outerWidth();var i=e.outerHeight();return{w:n,h:i,x1:r-n/2,y1:a-i/2}};r.drawing.addAtlasCollection("node",{texRows:e.webglTexRowsNodes});r.drawing.addAtlasCollection("label",{texRows:e.webglTexRows});r.drawing.addTextureAtlasRenderType("node-body",{collection:"node",getKey:t.getStyleKey,getBoundingBox:t.getElementBox,drawElement:t.drawElement});r.drawing.addSimpleShapeRenderType("node-body",{getBoundingBox:l,isSimple:Nh,shapeProps:{shape:"shape",color:"background-color",opacity:"background-opacity",radius:"corner-radius",border:true}});r.drawing.addSimpleShapeRenderType("node-overlay",{getBoundingBox:l,isVisible:o("overlay"),shapeProps:{shape:"overlay-shape",color:"overlay-color",opacity:"overlay-opacity",padding:"overlay-padding",radius:"overlay-corner-radius"}});r.drawing.addSimpleShapeRenderType("node-underlay",{getBoundingBox:l,isVisible:o("underlay"),shapeProps:{shape:"underlay-shape",color:"underlay-color",opacity:"underlay-opacity",padding:"underlay-padding",radius:"underlay-corner-radius"}});r.drawing.addTextureAtlasRenderType("label",{collection:"label",getTexPickingMode:s,getKey:Cp(t.getLabelKey,null),getBoundingBox:Pp(t.getLabelBox,null),drawClipped:true,drawElement:t.drawLabel,getRotation:n(null),getRotationPoint:t.getLabelRotationPoint,getRotationOffset:t.getLabelRotationOffset,isVisible:i("label")});r.drawing.addTextureAtlasRenderType("edge-source-label",{collection:"label",getTexPickingMode:s,getKey:Cp(t.getSourceLabelKey,"source"),getBoundingBox:Pp(t.getSourceLabelBox,"source"),drawClipped:true,drawElement:t.drawSourceLabel,getRotation:n("source"),getRotationPoint:t.getSourceLabelRotationPoint,getRotationOffset:t.getSourceLabelRotationOffset,isVisible:i("source-label")});r.drawing.addTextureAtlasRenderType("edge-target-label",{collection:"label",getTexPickingMode:s,getKey:Cp(t.getTargetLabelKey,"target"),getBoundingBox:Pp(t.getTargetLabelBox,"target"),drawClipped:true,drawElement:t.drawTargetLabel,getRotation:n("target"),getRotationPoint:t.getTargetLabelRotationPoint,getRotationOffset:t.getTargetLabelRotationOffset,isVisible:i("target-label")});var u=it((function(){console.log("garbage collect flag set");r.data.gc=true}),1e4);r.onUpdateEleCalcs((function(e,t){var a=false;t&&t.length>0&&(a|=r.drawing.invalidate(t));a&&u()}));Sp(r)};function Tp(e){var t=e.cy.container();var r=t&&t.style&&t.style.backgroundColor||"white";return ve(r)}function kp(e,t){var r=e._private.rscratch;return Ht(r,"labelWrapCachedLines",t)||[]}var Cp=function(e,t){return function(r){var a=e(r);var n=kp(r,t);return n.length>1?n.map((function(e,t){return"".concat(a,"_").concat(t)})):a}};var Pp=function(e,t){return function(r,a){var n=e(r);if(typeof a==="string"){var i=a.indexOf("_");if(i>0){var o=Number(a.substring(i+1));var s=kp(r,t);var l=n.h/s.length;var u=l*o;var v=n.y1+u;return{x1:n.x1,w:n.w,y1:v,h:l,yOffset:u}}}return n}};function Sp(e){var t=e.render;e.render=function(r){r=r||{};var a=e.cy;if(e.webgl)if(a.zoom()>wf){Bp(e);t.call(e,r)}else{Dp(e);zp(e,r,cp.SCREEN)}};var r=e.matchCanvasSize;e.matchCanvasSize=function(t){r.call(e,t);e.pickingFrameBuffer.setFramebufferAttachmentSizes(e.canvasWidth,e.canvasHeight);e.pickingFrameBuffer.needsDraw=true};e.findNearestElements=function(t,r,a,n){return Lp(e,t,r)};var a=e.invalidateCachedZSortedEles;e.invalidateCachedZSortedEles=function(){a.call(e);e.pickingFrameBuffer.needsDraw=true};var n=e.notify;e.notify=function(t,r){n.call(e,t,r);t==="viewport"||t==="bounds"?e.pickingFrameBuffer.needsDraw=true:t==="background"&&e.drawing.invalidate(r,{type:"node-body"})}}function Bp(e){var t=e.data.contexts[e.WEBGL];t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT)}function Dp(e){var t=function(t){t.save();t.setTransform(1,0,0,1,0,0);t.clearRect(0,0,e.canvasWidth,e.canvasHeight);t.restore()};t(e.data.contexts[e.NODE]);t(e.data.contexts[e.DRAG])}function _p(e){var t=e.canvasWidth;var r=e.canvasHeight;var a=Mh(e),n=a.pan,i=a.zoom;var o=Kh();Qh(o,o,[n.x,n.y]);ep(o,o,[i,i]);var s=Kh();tp(s,t,r);var l=Kh();$h(l,s,o);return l}function Ap(e,t){var r=e.canvasWidth;var a=e.canvasHeight;var n=Mh(e),i=n.pan,o=n.zoom;t.setTransform(1,0,0,1,0,0);t.clearRect(0,0,r,a);t.translate(i.x,i.y);t.scale(o,o)}function Mp(e,t){e.drawSelectionRectangle(t,(function(t){return Ap(e,t)}))}function Ip(e){var t=e.data.contexts[e.NODE];t.save();Ap(e,t);t.strokeStyle="rgba(0, 0, 0, 0.3)";t.beginPath();t.moveTo(-1e3,0);t.lineTo(1e3,0);t.stroke();t.beginPath();t.moveTo(0,-1e3);t.lineTo(0,1e3);t.stroke();t.restore()}function Rp(e){var t=function(t,r,a){var n=t.atlasManager.getAtlasCollection(r);var i=e.data.contexts[e.NODE];var o=n.atlases;for(var s=0;s=0&&w.add(k)}return w}function Lp(e,t,r){var a=Np(e,t,r);var n=e.getCachedZSortedEles();var i,s;var l,u=o(a);try{for(u.s();!(l=u.n()).done;){var v=l.value;var c=n[v];!i&&c.isNode()&&(i=c);!s&&c.isEdge()&&(s=c);if(i&&s)break}}catch(e){u.e(e)}finally{u.f()}return[i,s].filter(Boolean)}function Op(e,t,r){var a=e.drawing;t+=1;if(r.isNode()){a.drawNode(r,t,"node-underlay");a.drawNode(r,t,"node-body");a.drawTexture(r,t,"label");a.drawNode(r,t,"node-overlay")}else{a.drawEdgeLine(r,t);a.drawEdgeArrow(r,t,"source");a.drawEdgeArrow(r,t,"target");a.drawTexture(r,t,"label");a.drawTexture(r,t,"edge-source-label");a.drawTexture(r,t,"edge-target-label")}}function zp(e,t,r){var a;e.webglDebug&&(a=performance.now());var n=e.drawing;var i=0;r.screen&&e.data.canvasNeedsRedraw[e.SELECT_BOX]&&Mp(e,t);if(e.data.canvasNeedsRedraw[e.NODE]||r.picking){var s=e.data.contexts[e.WEBGL];if(r.screen){s.clearColor(0,0,0,0);s.enable(s.BLEND);s.blendFunc(s.ONE,s.ONE_MINUS_SRC_ALPHA)}else s.disable(s.BLEND);s.clear(s.COLOR_BUFFER_BIT|s.DEPTH_BUFFER_BIT);s.viewport(0,0,s.canvas.width,s.canvas.height);var l=_p(e);var u=e.getCachedZSortedEles();i=u.length;n.startFrame(l,r);if(r.screen){for(var v=0;v0&&o>0){f.clearRect(0,0,i,o);f.globalCompositeOperation="source-over";var h=this.getCachedZSortedEles();if(e.full){f.translate(-a.x1*u,-a.y1*u);f.scale(u,u);this.drawElements(f,h);f.scale(1/u,1/u);f.translate(a.x1*u,a.y1*u)}else{var p=t.pan();var g={x:p.x*u,y:p.y*u};u*=t.zoom();f.translate(g.x,g.y);f.scale(u,u);this.drawElements(f,h);f.scale(1/u,1/u);f.translate(-g.x,-g.y)}if(e.bg){f.globalCompositeOperation="destination-over";f.fillStyle=e.bg;f.rect(0,0,i,o);f.fill()}}return d};function Gp(e,t){var r=atob(e);var a=new ArrayBuffer(r.length);var n=new Uint8Array(a);for(var i=0;i