@@ -268,6 +268,8 @@ GraphResultsViewer.prototype.initD3 = function(jqid) {
268268 // Append graphic element to svg which are groups for graph elements
269269 this . link_group = this . svg . append ( "g" ) . classed ( "links" , true ) ;
270270 this . node_group = this . svg . append ( "g" ) . classed ( "nodes" , true ) ;
271+
272+ this . image_group = this . svg . append ( "g" ) . classed ( "images" , true ) ;
271273}
272274
273275GraphResultsViewer . prototype . zoomed = function ( ) {
@@ -302,9 +304,6 @@ GraphResultsViewer.prototype.updateGraph = function(nodes, links) {
302304
303305 /*Create and place the "blocks" containing the circle and the text */
304306 var node_enter = this . node_elements . enter ( ) . append ( "g" ) ;
305- node_enter . attr ( "transform" , function ( d ) { return "translate(" + d . x + "," + d . y + ")" ; } ) ;
306-
307- //node_enter. attr("y", function(node){ return node.y})
308307
309308 // enter and create new ones
310309 node_enter . append ( "circle" )
@@ -318,17 +317,6 @@ GraphResultsViewer.prototype.updateGraph = function(nodes, links) {
318317 . on ( "mouseout" , function ( d ) { d3 . select ( this ) . style ( "cursor" , "default" ) ; } )
319318 . on ( 'click' , follow_node_wrapper )
320319
321- /*node_enter.append("text")
322- .attr("x", function(node){ return node.x})
323- .attr("y", function(node){ return node.y})
324- .append("tspan")
325-
326-
327- .text(function(node) { return self.getNodeIconUnicode(node)})*/
328-
329-
330-
331-
332320
333321 // merge new and old nodes
334322 this . node_elements = node_enter . merge ( this . node_elements ) ;
@@ -386,14 +374,6 @@ GraphResultsViewer.prototype.updateGraph = function(nodes, links) {
386374 //if(el_enter) this.edgelabels = el_enter.merge(this.edgelabels)
387375
388376 this . edgelabels = this . svg . selectAll ( ".edgelabel" ) . data ( links )
389- /*this.edgelabels.append('textPath')
390- //this link the test with the path created
391- .attr('xlink:href',function(d,i) {return '#edgepath'+i})
392- .style("pointer-events", "none")
393- .style("text-anchor","middle")
394- //.attr("startOffset","10%")
395- // this get the test to see in the link
396- .text(function(d,i){return self.getEdgeIconText(d)});*/
397377
398378 if ( ep_tems ) this . path_items = ep_tems . merge ( this . path_items )
399379
@@ -473,61 +453,74 @@ GraphResultsViewer.prototype.updateSimulation = function(mode) {
473453 }
474454 }
475455}
456+
457+
458+ GraphResultsViewer . prototype . getNodeId = function ( id ) {
459+ return id . replace ( "/" , "__" )
460+ }
461+
476462//function(d) { return color(d.text); })
477463GraphResultsViewer . prototype . styleNodeElements = function ( ) {
478464 //const nodeImg= this.getNodeImage({id:"Part/3020",radius:30,image:"https://cdn.rebrickable.com/media/parts/elements/4211395.jpg"})
479465 var self = this ;
480466 if ( this . node_elements ) {
481467 this . node_elements . each ( function ( node ) {
482- var g = d3 . select ( this ) ;
483- var sel = g . select ( "circle" ) ;
484- sel . select ( "title" ) . remove ( ) ;
485- sel . attr ( 'r' , self . getRadius ( node ) ) ;
486- sel . attr ( "stroke" , "white" )
487- sel . attr ( "stroke-width" , 3 )
488- //sel.attr("opacity", 0.2)
489- sel . classed ( "highlighted" , function ( node ) { return self . focusNodes . indexOf ( node . id ) != - 1 } ) ;
490-
491-
492-
493- if ( node . image ) {
494- sel . style ( "fill" , "#fff" )
495- sel . style ( "fill" , function ( node ) { return self . getNodeImage ( node ) } )
496- } else {
497- g . append ( "text" )
498- . attr ( "x" , function ( node ) { return node . x } )
499- . attr ( "y" , function ( node ) { return node . y } )
500- . append ( "tspan" )
501- . text ( function ( node ) { return self . getNodeIconUnicode ( node ) } )
502-
503-
504- sel . style ( "fill" , self . getNodeColour ( node ) ) ;
505- sel . append ( "title" )
506- . classed ( "terminus-gnode-title" , true )
507- . text ( self . getNodeText ( node ) ) ;
508- var txt = g . select ( "text" ) ;
509-
510- txt . select ( "title" ) . remove ( ) ;
511- //to see a text in the right top corner
512- if ( node . toptext ) txt . append ( "tspan" ) . text ( node . toptext ) . attr ( "dy" , - 15 )
513- txt . attr ( 'text-anchor' , 'middle' )
514- //.attr('class','labelClassName')
515- . attr ( "title" , self . getNodeText ( node ) )
516- . attr ( 'dominant-baseline' , 'central' )
517- . style ( 'font-family' , "'" + self . fontfam + "'" )
518- . style ( 'font-weight' , self . getNodeIconWeight ( node ) )
519- . style ( 'font-size' , self . getNodeIconSize ( node ) )
520- . style ( "fill" , self . getNodeIconColour ( node ) )
521- // .text(self.getNodeIconUnicode(node))//"\uf061")
522- . append ( "title" )
523- . classed ( "terminus-gnode-title" , true )
524- . text ( self . getNodeText ( node ) ) ;
525-
526- }
468+ var gNode = d3 . select ( this ) ;
469+ gNode . attr ( "id" , self . getNodeId ( node . id ) )
470+ var sel = gNode . select ( "circle" ) ;
471+ self . styleNode ( gNode , sel , node , self )
527472 } ) ;
528473 }
529474}
530475
476+ GraphResultsViewer . prototype . styleNode = function ( g , sel , node , self ) {
477+ //sel.attr("id",node.id)
478+ sel . select ( "title" ) . remove ( ) ;
479+
480+ sel . attr ( 'r' , this . getRadius ( node ) ) ;
481+ sel . attr ( "stroke" , "white" )
482+ sel . attr ( "stroke-width" , 3 )
483+ //sel.attr("opacity", 0.2)
484+ sel . classed ( "highlighted" , function ( node ) { return self . focusNodes . indexOf ( node . id ) != - 1 } ) ;
485+
486+ if ( node . image ) {
487+ sel . style ( "fill" , "#fff" )
488+ sel . style ( "fill" , function ( node ) { return self . getNodeImage ( node ) } )
489+ } else {
490+ g . select ( "text" ) . remove ( ) ;
491+
492+ g . append ( "text" )
493+ . attr ( "x" , function ( node ) { return node . x } )
494+ . attr ( "y" , function ( node ) { return node . y } )
495+ . append ( "tspan" )
496+ . text ( function ( node ) { return self . getNodeIconUnicode ( node ) } )
497+ sel . style ( "fill" , self . getNodeColour ( node ) ) ;
498+
499+ }
500+ //to be review
501+ sel . append ( "title" )
502+ . classed ( "terminus-gnode-title" , true )
503+ . text ( self . getNodeText ( node ) ) ;
504+ var txt = g . select ( "text" ) ;
505+
506+ txt . select ( "title" ) . remove ( ) ;
507+ //to see a text in the right top corner
508+ if ( node . toptext ) txt . append ( "tspan" ) . text ( node . toptext ) . attr ( "dy" , - 15 )
509+ txt . attr ( 'text-anchor' , 'middle' )
510+ //.attr('class','labelClassName')
511+ . attr ( "title" , self . getNodeText ( node ) )
512+ . attr ( 'dominant-baseline' , 'central' )
513+ . style ( 'font-family' , "'" + self . fontfam + "'" )
514+ . style ( 'font-weight' , self . getNodeIconWeight ( node ) )
515+ . style ( 'font-size' , self . getNodeIconSize ( node ) )
516+ . style ( "fill" , self . getNodeIconColour ( node ) )
517+ // .text(self.getNodeIconUnicode(node))//"\uf061")
518+ . append ( "title" )
519+ . classed ( "terminus-gnode-title" , true )
520+ . text ( self . getNodeText ( node ) ) ;
521+
522+ //}
523+ }
531524
532525GraphResultsViewer . prototype . styleLinkElements = function ( ) {
533526 var self = this ;
@@ -567,19 +560,24 @@ GraphResultsViewer.prototype.styleTextElements = function() {
567560
568561GraphResultsViewer . prototype . getNodeImage = function ( node ) {
569562 const getHas = node . id . substring ( node . id . indexOf ( "/" ) + 1 )
570- const imgId = `image__${ getHas } `
571- this . svg . append ( 'svg:defs' ) . selectAll ( "pattern" )
563+ const imgId = `image__${ getHas } `
564+ const pathId = `path__${ getHas } `
565+
566+ this . image_group . select ( `#${ pathId } ` ) . remove ( )
567+
568+ const radius = this . getRadius ( node )
569+ this . image_group . append ( 'svg:defs' ) . attr ( "id" , pathId ) .
570+ selectAll ( "pattern" )
572571 . data ( [ imgId ] )
573572 . join ( "pattern" )
574-
575573// defs.append("svg:pattern")
576574 . attr ( "id" , imgId )
577- . attr ( "width" , node . radius * 2 )
578- . attr ( "height" , node . radius * 2 )
575+ . attr ( "width" , radius * 2 )
576+ . attr ( "height" , radius * 2 )
579577 . attr ( "patternUnits" , "objectBoundingBox" )
580578 . append ( "svg:image" )
581- . attr ( "width" , node . radius * 2 )
582- . attr ( "height" , node . radius * 2 )
579+ . attr ( "width" , radius * 2 )
580+ . attr ( "height" , radius * 2 )
583581 . attr ( "xlink:href" , node . image )
584582 . attr ( "x" , 0 )
585583 . attr ( "y" , 0 ) ;
@@ -602,18 +600,8 @@ GraphResultsViewer.prototype.getEdgeArrow = function(edge) {
602600 const markerHeight = markerBoxHeight / 2 ;
603601
604602 const arrowPoints = [ [ 0 , 0 ] , [ 0 , 7 ] , [ 7 , 3.5 ] ] ;
605-
606-
607- /*.attr("viewBox", "0 -5 10 10")
608- .attr("refX", function(d) {
609- return force.nodes()[d.target].radius + 10; // Add the marker's width
610- })
611- .attr("refY", 0)
612- .attr("markerWidth", 10) // markerWidth equals viewBox width
613- .attr("markerHeight", 10)*/
614- //if(dir){ // "target": propValue,
615603
616- const id = `${ edge . source } __${ edge . target } __${ edge . text } `
604+ const id = `${ edge . source } __${ edge . target } __${ edge . text } `
617605 var col = this . getArrowColour ( edge ) ;
618606 this . svg . append ( "svg:defs" ) . selectAll ( "marker" )
619607 . data ( [ id ] )
@@ -640,20 +628,30 @@ GraphResultsViewer.prototype.getEdgeArrow = function(edge) {
640628
641629GraphResultsViewer . prototype . nodeSelected = function ( selected_node ) {
642630 var self = this ;
643- if ( this . selected_id == selected_node . id && this . selection_grows ) {
644- this . selection_grows = false ;
645- this . styleNodeElements ( ) ;
646- }
647- else {
648- this . selection_grows = true ;
649- this . selected_id = selected_node . id ;
650- this . styleNodeElements ( ) ;
651- if ( this . onClick ) this . onClick ( selected_node . id , selected_node )
631+ const previewSelected = this . selected_id
632+ const previewNode = this . nodeSelectedObj
633+
634+ this . selected_id = selected_node . id
635+ this . nodeSelectedObj = selected_node
636+
637+ if ( previewSelected === selected_node . id ) { //&& this.selection_grows){
638+ this . selected_id = null
639+ } else if ( previewSelected ) {
640+ //if preview selected
641+ const gNodeP = this . node_group . select ( `#${ this . getNodeId ( previewSelected ) } ` )
642+ const gCircleP = gNodeP . select ( "circle" )
643+ this . styleNode ( gNodeP , gCircleP , previewNode , this )
644+ }
645+ //change the style of current clicked node
646+ const gNode = this . node_group . select ( `#${ this . getNodeId ( selected_node . id ) } ` )
647+ const gCircle = gNode . select ( "circle" )
648+ this . styleNode ( gNode , gCircle , selected_node , this )
649+ if ( this . onClick ) this . onClick ( selected_node . id , selected_node )
650+
652651 //this.browser.nodeSelected(selected_node);
653- if ( this . isFringe ( selected_node ) ) {
654- //this.browser.followNode(selected_node);
655- }
656- }
652+ //if(this.isFringe(selected_node)){
653+ //this.browser.followNode(selected_node);
654+ //}
657655}
658656
659657GraphResultsViewer . prototype . getScaleTransform = function ( x , y , scale_factor ) {
@@ -787,7 +785,7 @@ GraphResultsViewer.prototype.setConfigOptions = function(config) {
787785 */
788786GraphResultsViewer . prototype . getMultiplier = function ( node ) {
789787 var mult = ( node && node . size ? node . size : 1 ) ;
790- if ( node . id == this . selected_id && this . selection_grows ) {
788+ if ( node . id == this . selected_id ) { // && this.selection_grows){
791789 mult = mult * 2 ;
792790 }
793791 return mult ;
0 commit comments