Drag+drop in Panopticon
This commit is contained in:
parent
b4167574df
commit
c5d5db267e
1 changed files with 38 additions and 13 deletions
|
@ -332,7 +332,7 @@ class Graph {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 'delete'),
|
}, 'delete'),
|
||||||
crel( 'h1', { 'class': 'msg__id' }, msg['@id'] ),
|
crel( 'h1', { 'class': 'msg__id' }, msg['@id'] + ` (${panopticon.graph.distances[msg['@id']]})` ),
|
||||||
crel( 'label',
|
crel( 'label',
|
||||||
crel( 'span', 'Text' ),
|
crel( 'span', 'Text' ),
|
||||||
crel( 'input', {
|
crel( 'input', {
|
||||||
|
@ -916,7 +916,8 @@ class Graph {
|
||||||
this.data = [...this.messages, ...this.conditions,
|
this.data = [...this.messages, ...this.conditions,
|
||||||
...this.directions, ...this.diversions]
|
...this.directions, ...this.diversions]
|
||||||
let d = [];
|
let d = [];
|
||||||
let toRemove = ['sourceX', 'sourceY', 'targetX', 'targetY', 'x', 'y', 'vx', 'vy']
|
// let toRemove = ['sourceX', 'sourceY', 'targetX', 'targetY', 'x', 'y', 'vx', 'vy']
|
||||||
|
let toRemove = ['sourceX', 'sourceY', 'targetX', 'targetY', 'vx', 'vy']
|
||||||
for ( let node of this.data ) {
|
for ( let node of this.data ) {
|
||||||
let n = {};
|
let n = {};
|
||||||
console.log( node['source'] );
|
console.log( node['source'] );
|
||||||
|
@ -1045,7 +1046,7 @@ class Graph {
|
||||||
console.log('fx', m['@id'], panopticon.graph.distances[m['@id']], fx);
|
console.log('fx', m['@id'], panopticon.graph.distances[m['@id']], fx);
|
||||||
return fx;
|
return fx;
|
||||||
}).strength(50))
|
}).strength(50))
|
||||||
.force( "forceY", d3.forceY(m => panopticon.graph.distances[m['@id']] !== null ? 0 : panopticon.graph.nodeSize * 3 ).strength(30))
|
// .force( "forceY", d3.forceY(m => panopticon.graph.distances[m['@id']] !== null ? 0 : panopticon.graph.nodeSize * 3 ).strength(30))
|
||||||
;
|
;
|
||||||
this.simulation.velocityDecay(.99);
|
this.simulation.velocityDecay(.99);
|
||||||
|
|
||||||
|
@ -1054,13 +1055,13 @@ class Graph {
|
||||||
.selectAll( "g" )
|
.selectAll( "g" )
|
||||||
.data( this.messages, n => n['@id'] )
|
.data( this.messages, n => n['@id'] )
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
// Update existing nodes
|
// Update existing nodes
|
||||||
let newNode = node.enter();
|
let newNode = node.enter();
|
||||||
|
|
||||||
let newNodeG = newNode.append( "g" )
|
let newNodeG = newNode.append( "g" )
|
||||||
.attr( 'id', d => d['@id'] )
|
.attr( 'id', d => d['@id'] )
|
||||||
// .call( d3.drag( this.simulation ) )
|
|
||||||
.on( 'click', function( d ) {
|
.on( 'click', function( d ) {
|
||||||
this.clickMsg( d );
|
this.clickMsg( d );
|
||||||
}.bind( this ) )
|
}.bind( this ) )
|
||||||
|
@ -1083,6 +1084,7 @@ class Graph {
|
||||||
// remove
|
// remove
|
||||||
node.exit().remove();
|
node.exit().remove();
|
||||||
node = node.merge( newNodeG );
|
node = node.merge( newNodeG );
|
||||||
|
|
||||||
|
|
||||||
// for all existing nodes:
|
// for all existing nodes:
|
||||||
node.attr( 'class', msg => {
|
node.attr( 'class', msg => {
|
||||||
|
@ -1096,6 +1098,27 @@ class Graph {
|
||||||
|
|
||||||
return classes.join( ' ' );
|
return classes.join( ' ' );
|
||||||
} )
|
} )
|
||||||
|
|
||||||
|
.on(".drag", null)
|
||||||
|
.call(
|
||||||
|
d3.drag( this.simulation )
|
||||||
|
.on("start", function(d){
|
||||||
|
if (!d3.event.active) panopticon.graph.simulation.alphaTarget(0.3).restart();
|
||||||
|
d.fx = d.x;
|
||||||
|
d.fy = d.y;
|
||||||
|
})
|
||||||
|
.on('drag', function(d){
|
||||||
|
d.fx = d3.event.x;
|
||||||
|
d.fy = d3.event.y;
|
||||||
|
})
|
||||||
|
.on("end", function(d){
|
||||||
|
if (!d3.event.active) panopticon.graph.simulation.alphaTarget(0);
|
||||||
|
d.fx = null;
|
||||||
|
d.fy = null;
|
||||||
|
})
|
||||||
|
// .container(document.getElementById('container'))
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
let link = this.linkG
|
let link = this.linkG
|
||||||
.selectAll( "line" )
|
.selectAll( "line" )
|
||||||
|
@ -1184,10 +1207,8 @@ class Graph {
|
||||||
|
|
||||||
// this.simulation.alpha(1);
|
// this.simulation.alpha(1);
|
||||||
// this.simulation.restart();
|
// this.simulation.restart();
|
||||||
if ( typeof isInit != 'undefined' && isInit ) {
|
for ( let i = 0, n = Math.ceil( Math.log( this.simulation.alphaMin() ) / Math.log( 1 - this.simulation.alphaDecay() ) ); i < n; ++i ) {
|
||||||
for ( let i = 0, n = Math.ceil( Math.log( this.simulation.alphaMin() ) / Math.log( 1 - this.simulation.alphaDecay() ) ); i < n; ++i ) {
|
this.simulation.tick();
|
||||||
// this.simulation.tick();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return this.svg.node();
|
return this.svg.node();
|
||||||
}
|
}
|
||||||
|
@ -1198,12 +1219,12 @@ class Graph {
|
||||||
console.error("No start set");
|
console.error("No start set");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let startMsg = starts[0];
|
|
||||||
|
|
||||||
//initiate distances
|
//initiate distances
|
||||||
let distances = {};
|
let distances = {};
|
||||||
for(let msg of this.messages) {
|
for(let msg of this.messages) {
|
||||||
distances[msg['@id']] = msg === startMsg ? 0 : null;
|
// distances[msg['@id']] = msg === startMsg ? 0 : null;
|
||||||
|
distances[msg['@id']] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let targetsPerMsg = {};
|
let targetsPerMsg = {};
|
||||||
|
@ -1247,7 +1268,12 @@ class Graph {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
traverseMsg(startMsg['@id'], 1 , true);
|
for(let startMsg of starts) {
|
||||||
|
if(distances[startMsg['@id']] === null) {
|
||||||
|
distances[startMsg['@id']] = 0;
|
||||||
|
}
|
||||||
|
traverseMsg(startMsg['@id'], 1 , true);
|
||||||
|
}
|
||||||
|
|
||||||
// now we have the formal tree, lets try to polish the rest:
|
// now we have the formal tree, lets try to polish the rest:
|
||||||
for(let msgId in distances) {
|
for(let msgId in distances) {
|
||||||
|
@ -1270,7 +1296,6 @@ class Graph {
|
||||||
// traverseMsg(msgId, additionalsDepth+1, true);
|
// traverseMsg(msgId, additionalsDepth+1, true);
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return distances;
|
return distances;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue