basant307/AI_Governance_Project
048
1import * as util from '../../../util/index.mjs';2import * as is from '../../../is.mjs';3 4import arrowShapes from './arrow-shapes.mjs';5import coordEleMath from './coord-ele-math/index.mjs';6import images from './images.mjs';7import loadListeners from './load-listeners.mjs';8import nodeShapes from './node-shapes.mjs';9import redraw from './redraw.mjs';10 11var BaseRenderer = function( options ){ this.init( options ); };12var BR = BaseRenderer;13var BRp = BR.prototype;14 15BRp.clientFunctions = [ 'redrawHint', 'render', 'renderTo', 'matchCanvasSize', 'nodeShapeImpl', 'arrowShapeImpl' ];16 17BRp.init = function( options ){18 var r = this;19 20 r.options = options;21 22 r.cy = options.cy;23 24 var ctr = r.container = options.cy.container();25 var containerWindow = r.cy.window();26 27 28 // prepend a stylesheet in the head such that29 if( containerWindow ){30 var document = containerWindow.document;31 var head = document.head;32 var stylesheetId = '__________cytoscape_stylesheet';33 var className = '__________cytoscape_container';34 var stylesheetAlreadyExists = document.getElementById( stylesheetId ) != null;35 36 if( ctr.className.indexOf( className ) < 0 ){37 ctr.className = ( ctr.className || '' ) + ' ' + className;38 }39 40 if( !stylesheetAlreadyExists ){41 var stylesheet = document.createElement('style');42 43 stylesheet.id = stylesheetId;44 stylesheet.textContent = '.'+className+' { position: relative; }';45 46 head.insertBefore( stylesheet, head.children[0] ); // first so lowest priority47 }48 49 var computedStyle = containerWindow.getComputedStyle( ctr );50 var position = computedStyle.getPropertyValue('position');51 52 if( position === 'static' ){53 util.warn('A Cytoscape container has style position:static and so can not use UI extensions properly');54 }55 }56 57 r.selection = [ undefined, undefined, undefined, undefined, 0]; // Coordinates for selection box, plus enabled flag58 59 r.bezierProjPcts = [ 0.05, 0.225, 0.4, 0.5, 0.6, 0.775, 0.95 ];60 61 //--Pointer-related data62 r.hoverData = {down: null, last: null,63 downTime: null, triggerMode: null,64 dragging: false,65 initialPan: [ null, null ], capture: false};66 67 r.dragData = {possibleDragElements: []};68 69 r.touchData = {70 start: null, capture: false,71 72 // These 3 fields related to tap, taphold events73 startPosition: [ null, null, null, null, null, null ],74 singleTouchStartTime: null,75 singleTouchMoved: true,76 77 now: [ null, null, null, null, null, null ],78 earlier: [ null, null, null, null, null, null ]79 };80 81 r.redraws = 0;82 r.showFps = options.showFps;83 r.debug = options.debug;84 r.webgl = options.webgl;85 86 r.hideEdgesOnViewport = options.hideEdgesOnViewport;87 r.textureOnViewport = options.textureOnViewport;88 r.wheelSensitivity = options.wheelSensitivity;89 r.motionBlurEnabled = options.motionBlur; // on by default90 r.forcedPixelRatio = is.number(options.pixelRatio) ? options.pixelRatio : null;91 r.motionBlur = options.motionBlur; // for initial kick off92 r.motionBlurOpacity = options.motionBlurOpacity;93 r.motionBlurTransparency = 1 - r.motionBlurOpacity;94 r.motionBlurPxRatio = 1;95 r.mbPxRBlurry = 1; //0.8;96 r.minMbLowQualFrames = 4;97 r.fullQualityMb = false;98 r.clearedForMotionBlur = [];99 r.desktopTapThreshold = options.desktopTapThreshold;100 r.desktopTapThreshold2 = options.desktopTapThreshold * options.desktopTapThreshold;101 r.touchTapThreshold = options.touchTapThreshold;102 r.touchTapThreshold2 = options.touchTapThreshold * options.touchTapThreshold;103 r.tapholdDuration = 500;104 105 r.bindings = [];106 r.beforeRenderCallbacks = [];107 r.beforeRenderPriorities = { // higher priority execs before lower one108 animations: 400,109 eleCalcs: 300,110 eleTxrDeq: 200,111 lyrTxrDeq: 150,112 lyrTxrSkip: 100,113 };114 115 r.registerNodeShapes();116 r.registerArrowShapes();117 r.registerCalculationListeners();118};119 120BRp.notify = function( eventName, eles ) {121 var r = this;122 var cy = r.cy;123 124 // the renderer can't be notified after it's destroyed125 if( this.destroyed ){ return; }126 127 if( eventName === 'init' ){128 r.load();129 return;130 }131 132 if( eventName === 'destroy' ){133 r.destroy();134 return;135 }136 137 if(138 eventName === 'add' 139 || eventName === 'remove'140 || (eventName === 'move' && cy.hasCompoundNodes())141 || eventName === 'load'142 || eventName === 'zorder'143 || eventName === 'mount'144 ){145 r.invalidateCachedZSortedEles();146 }147 148 if( eventName === 'viewport' ){149 r.redrawHint( 'select', true );150 }151 152 if( eventName === 'gc' ){153 r.redrawHint( 'gc', true );154 }155 156 if( eventName === 'load' || eventName === 'resize' || eventName === 'mount' ){157 r.invalidateContainerClientCoordsCache();158 r.matchCanvasSize( r.container );159 }160 161 r.redrawHint( 'eles', true );162 r.redrawHint( 'drag', true );163 164 this.startRenderLoop();165 166 this.redraw();167};168 169BRp.destroy = function(){170 var r = this;171 172 r.destroyed = true;173 174 r.cy.stopAnimationLoop();175 176 for( var i = 0; i < r.bindings.length; i++ ){177 var binding = r.bindings[ i ];178 var b = binding;179 var tgt = b.target;180 181 ( tgt.off || tgt.removeEventListener ).apply( tgt, b.args );182 }183 184 r.bindings = [];185 r.beforeRenderCallbacks = [];186 r.onUpdateEleCalcsFns = [];187 188 if( r.removeObserver ){189 r.removeObserver.disconnect();190 }191 192 if( r.styleObserver ){193 r.styleObserver.disconnect();194 }195 196 if( r.resizeObserver ){197 r.resizeObserver.disconnect();198 }199 200 if( r.labelCalcDiv ){201 try {202 document.body.removeChild( r.labelCalcDiv ); // eslint-disable-line no-undef203 } catch( e ){204 // ie10 issue #1014205 }206 }207};208 209BRp.isHeadless = function(){210 return false;211};212 213[214 arrowShapes,215 coordEleMath,216 images,217 loadListeners,218 nodeShapes,219 redraw220].forEach( function( props ){221 util.extend( BRp, props );222} );223 224export default BR;225 