vis.js - how to place item in center of graph - vis.js

I have tree structure like next :
id: 1
id: 2
id: 8
id: 9
id: 10
id: 11
id: 12
id: 3
id: 13
id: 4
id: 5
id: 6
id: 7
id: 8
And need to show it (as network graph, not as tree)
After page loading graph must be centered on {id:1} item.
How can I make it?

Related

how to make select query for Infinite level of tree, using a recusive method

I want to make an SQL query that can select all the children trees that belongs to the chosen parent for example:
the foolowing picture will explain.
if I choose parent hot i must get{tea,green tea, lemon tea,reg tea,cofee,espresso,cappuchino,late}
if I choose "juice" i get also all children belongs for it {mango,orange,lemonade}
I think it should be a recusive select method that can call it self untill all levels of sub childrens are called.
(https://i.stack.imgur.com/h5FGc.png)
DRINK-hot-tea-green,reg,lemontea
| |_Coffe-Cappuchino,espresso,late
|
|____cold-shake-coktail,strawbery,banann
|__Juice-mango,orange,...
|__water-still,sparkling,flavoured,..
it should be a recursive select method that can call itself until all levels ofsub-childrenn are called.
the table can be
id name ref
1 drink 0
2 cold 1
3 hot 1
4 tea 3
5 coffe 3
6 shake 2
7 juice 2
8 water 2
9 espreso 5
10 capucino 5
11 late 5
12 mango 7
13 coktail 6
14 still 8
15 sparkling 8
table

How do I output from a (doubly) recursive function?

How do I get the output of this function in R?
nodes2 <- c(1,2,4,5,10,11,20,21)
getLeftOrder <- function(root, snodes, nodes) {
if ( length(nodes) == 0 ) {
return(snodes)
} else {
nodes <- nodes[-(which(nodes == (2*root)))]
getLeftOrder(2*root, snodes, nodes)
snodes <- c(snodes, root)
cat(root, fill = TRUE)
nodes <- nodes[-(which(nodes == (2*root+1)))]
getLeftOrder(2*root+1, snodes, nodes)
}
}
tnodes <- getLeftOrder(1, vector('integer'), nodes2)
The in-order traversal/reordering output from cat() is fine but the output in tnodes is not. I would like to avoid using <<- operator.
The function needs to [at least sometimes] return something interesting, and collect results as recursive calls return. Trying to keep the current logic the same, you want the roots from the first set of recursive calls, the current root, and the roots from the second set of recursive calls. Adding in some message() calls so we can see what's happening:
nodes2 <- c(1,2,4,5,10,11,20,21)
getLeftOrder <- function(root, nodes) {
message('root: ', root, ' nodes: ', paste(nodes, collapse = ' '))
if ( length(nodes) == 0 ) {
return(NULL)
} else {
nodes <- nodes[-which(nodes == 2*root)]
r1 <- getLeftOrder(2*root, nodes)
message(root)
nodes <- nodes[-which(nodes == 2*root + 1)]
r2 <- getLeftOrder(2*root+1, nodes)
return(c(r1, root, r2))
}
}
which runs like so:
tnodes <- getLeftOrder(1, nodes2)
#> root: 1 nodes: 1 2 4 5 10 11 20 21
#> root: 2 nodes: 1 4 5 10 11 20 21
#> root: 4 nodes: 1 5 10 11 20 21
#> root: 8 nodes:
#> 4
#> root: 9 nodes:
#> 2
#> root: 5 nodes: 1 10 11 20 21
#> root: 10 nodes: 1 11 20 21
#> root: 20 nodes: 1 11 21
#> root: 40 nodes:
#> 20
#> root: 41 nodes:
#> 10
#> root: 21 nodes: 1 11
#> root: 42 nodes:
#> 21
#> root: 43 nodes:
#> 5
#> root: 11 nodes: 1 20 21
#> root: 22 nodes:
#> 11
#> root: 23 nodes:
#> 1
#> root: 3 nodes:
tnodes
#> [1] 4 2 20 10 21 5 11 1
I still don't quite understand the logic here, though; there's quite likely a simpler way to do this.

How to get the ID of each node from topological sort?

I have a network (a directed acyclic graph):
dag_1 <- barabasi.game(20)
I applied a topological sort:
top1 <- topo_sort(dag_1)
top1
+ 20/20 vertices, from 0ee5d26:
[1] 5 8 11 13 14 15 16 17 18 20 4 7 12 19 2 10 9 6 3 1
If I type top1 and hit enter, the results are above. I need to access the vector
5 8 11 13, ..., 1
I tried top1[1] and top1[[1]]. Neither of them gave me the vector.
How can I get it?
top1 is an igraph.vs class object, and indexing e.g. top1[1:10] returns the vertices of the graph. To return a vector of the vertices use:
as.vector(top1)

Make camera follow height map terrain using raycaster

I'm trying to make the camera follow the contours of a heightmap landscape.
I've added a raycaster that points down, but it is not reporting any changes in the intersection.
I've had to detach the raycaster from the camera, as the camera would rotate the raycaster.
Can anyone tell me what I'm doing wrong here?
How do I get the distance from the raycaster to the terrain?
Full code:
Live demo - the blue vertical line is the raycaster
<script>
// A custom follow the terrain component
//
// the idea is to use a raycaster pointing down to work out the distance between camera and the terrain
// and then adjust the camera's z value accordingly
AFRAME.registerComponent('collider-check', {
dependencies: ['raycaster'],
init: function () {
var myHeight = 2.0;
var cam = this.el.object3D;
this.el.addEventListener('raycaster-intersected', function (evt) {
// I've got the camera here and the intersection, so I should be able to adjust camera to match terrain?
var dist = evt.detail.intersection.distance;
// these values do not change :(
console.log('Raycaster (camera y, distance to terrain, terrain.y)', cam.position.y, dist, evt.detail.intersection.point.y);
});
}
});
// when we move the camera, we drag the raycaster object with us - it's not attached to the camera so it won't rotate the ray
AFRAME.registerComponent('moving', {
schema: { type: 'selector', default: '#theray'},
init: function () {
// this.data is the raycaster component
},
tick: function() {
// camera
var c = this.el.object3D.position;
// set raycaster position to match camera - have shifted it over a bit so we can see it
this.data.setAttribute('position', '' + (c.x - 2.0) + ' ' + (c.y - 2.0) + ' ' + c.z);
}
});
</script>
<a-scene>
<!-- place camera in the middle of our map -->
<a-camera position="6 0.2 6" rotation="0 90 0" moving>
<a-cursor color="#4CC3D9" fuse="true" fuse-timeout="100"></a-cursor>
</a-camera>
<!-- if I attach this raycaster to the camera, it will rotate with the camera - and that's not what we want -->
<a-entity collider-check id='theray' rotation="0 0 0" position="6 1 6" visible="true">
<!-- the aframe inspector barfs on this -->
<a-entity raycaster="objects:.walkonthis;direction:0 -1 0;showLine:true;origin:0 1 0" line="start:0 0 0;end:0 -5 0:color:red;opacity:1.0"></a-entity>
</a-entity>
<!-- the landscape -->
<a-entity heightgrid='xdimension: 12; zdimension: 10; yscale: 0.5; heights:
5 4 3 2 1 1 1 1 2 3 3 6
5 4 3 2 1 1 1 1 2 3 3 3
3 3 0 0 1 1 1 1 2 3 3 3
3 3 1 0 1 1 1 1 2 3 3 3
3 3 2 1 1 1 1 1 2 3 3 3
3 3 2 1 1 1 1 1 2 3 3 3
3 3 2 1 1 1 1 1 2 3 3 3
3 3 1 0 1 1 1 1 2 3 3 3
3 3 0 0 1 1 1 1 2 3 3 3
3 3 0 0 1 1 1 1 2 3 3 6
;
' material="color: #ccc" class='walkonthis'></a-entity>
</a-scene>

Textbox in xlsxwriter

I am trying to insert a textbox into a chartsheet using xlsxwriter in python 3.4 to give more information about the chart. Is there a way to insert a textbox into a chartsheet? I could insert it into a worksheet and not a chartsheet.
Also, is there a way to edit the legend using xlsxwriter? I have a row of 30 values and I want to plot in a batch of 10
batch1 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
I dont want "batch1" to be shown in the legend 3 times. I want to customize it as iteration1,iteration2,iteration3. Is there a way?
Inserting a textbox into a chart, or chartsheet, isn't supported.
In relation to the second question, you can remove items from the legend in XlsxWriter using the delete_series feature of set_legend():
# Delete/hide series index 0 and 2 from the legend.
chart.set_legend({'delete_series': [0, 2]})
See the docs on set_legend()

Resources