I want to use sigma.js to show some DOT graph. But it seems that sigma.js only support json graph format.
Is there some bash tools or javascript module can transform a DOT graph to json graph?
For example from DOT graph:
graph {
n1 [Label = "n1"];
n2 [Label = "n2"];
n3 [Label = "n3"];
n1 -- n2;
n1 -- n3;
n2 -- n2;
}
Transfer to JSON graph:
{
"nodes": [
{
"id": "n0",
"label": "A node",
"x": 0,
"y": 0,
"size": 3
},
{
"id": "n1",
"label": "Another node",
"x": 3,
"y": 1,
"size": 2
},
{
"id": "n2",
"label": "And a last one",
"x": 1,
"y": 3,
"size": 1
}
],
"edges": [
{
"id": "e0",
"source": "n0",
"target": "n1"
},
{
"id": "e1",
"source": "n1",
"target": "n2"
},
{
"id": "e2",
"source": "n2",
"target": "n0"
}
]
}
dot -Txdot_json -ogrpaph.json graph.dot
See https://www.graphviz.org/doc/info/output.html#a:xdot_json
If you can use python and install 3 packages (networkx and pygraphviz and pydot), here is a short script to convert a dot graph to json graph:
# dot_to_json_graph.py
# http://stackoverflow.com/questions/40262441/how-to-transform-a-dot-graph-to-json-graph
# Packages needed :
# sudo aptitude install python-networkx python-pygraphviz python-pydot
#
# Syntax :
# python dot_to_json_graph.py graph.dot
import networkx as nx
from networkx.readwrite import json_graph
import sys
import json
if len(sys.argv)==1:
sys.stderr.write("Syntax : python %s dot_file\n" % sys.argv[0])
else:
dot_graph = nx.nx_pydot.read_dot(sys.argv[1])
print(json.dumps(json_graph.node_link_data(dot_graph)))
Here is your example, converted to json graph:
{"directed": false, "graph": [["node", {"Label": ""}], ["graph",
{"file": "test.dot"}], ["edge", {}], ["name", ""]], "nodes": [{"id":
"n1", "Label": "n1"}, {"id": "n2", "Label": "n2"}, {"id": "n3",
"Label": "n3"}], "links": [{"source": 0, "target": 1, "key": 0},
{"source": 0, "target": 2, "key": 0}, {"source": 1, "target": 1,
"key": 0}], "multigraph": true}
I could not install pygraphviz both in Windows and Linux, and I've ran in the same problem recently.
networkx now have support to dumping into json more easily, including d3.js formats (info in this page)
I've come with two workarounds:
1- Use PyDot
Likely to be outdated soon! PyDot may not be used so frequently now that we have graphviz interface in python.
def dot_to_json(file_in):
import networkx
from networkx.readwrite import json_graph
import pydot
graph_netx = networkx.drawing.nx_pydot.read_dot(file_in)
graph_json = json_graph.node_link_data( graph_netx )
return json_graph.node_link_data(graph_netx)
2- Use graphviz Source
As shown in this part of the graphviz interface documentation, you can create a graph from a .dot source file.
Related
Is it possible to filter records with Vega-lite by strings?
Example:
record: "ABCD"
record: "AMFK"
record: "AMRK"
I would like to process only records where the string starts with "AM".
I studied the documentation and found solutions only for comparing the entire string. Is it possible to truncate the string? Or use something like "LEFT()" in Excel? Or something completely different?
Edit:
Possibly of importance, I'm using the Vega-lite app in Airtable.
You can do this using a filter transform along with an appropriate vega expression. For example (open in editor):
{
"data": {
"values": [
{"key": "ABCD", "value": 1},
{"key": "AMFK", "value": 2},
{"key": "AMRK", "value": 3}
]
},
"transform": [{"filter": "slice(datum.key, 0, 2) == 'AM'"}],
"mark": "bar",
"encoding": {
"x": {"type": "quantitative", "field": "value"},
"y": {"type": "nominal", "field": "key"}
}
}
My experiment is to change the ui_guage according to the numbers from a csv file. Each number is delayed for 5 sec.(code at end)
Input to csv file is a multi-line msg.payload with three values per line.i.e,
name1, numerical1,numerical11
name2 numerical2,numerical22, etc
problem: i get no delay of 5sec per message on the gauge...it directly shows the final value present in the last column (i have used a delay node also but still...)
example: display column 3 numericals as indicator with 5 sec delay on gauge.
gauge output: numerical22 (the indicator sets to this position at once)
So, the required per message delay (5 sec) is absent.
I require the delay.
I'am working on IBM cloud lite plan, node red v1.0.6
please review the following code
any help is welcome
if similar is answered before please re-direct me the solution.
To run following code:
open Node-RED
Click the three lines (top right)
import
Copy & paste the following flow json code and click "import" button
know more : Importing and Exporting Flows in Node-RED
The code:
[
{
"id": "c9b43c3a.da2e4",
"type": "ui_gauge",
"z": "ac0d0d22.69ebb",
"name": "",
"group": "c604d450.9712c8",
"order": 13,
"width": "5",
"height": "5",
"gtype": "gage",
"title": "<img height=\"50\" width=\"50\" src=\"https://upload.wikimedia.org/wikipedia/commons/b/bf/Pressure_gauge.svg\"/>",
"label": "units",
"format": " {{msg.payload.col3}}",
"min": 0,
"max": 10,
"colors": [
"#00b500",
"#e6e600",
"#ca3838"
],
"seg1": "",
"seg2": "",
"x": 840,
"y": 320,
"wires": []
},
{
"id": "c604d450.9712c8",
"type": "ui_group",
"z": "",
"name": "tab1",
"tab": "c733c61c.6e4828",
"order": 1,
"disp": true,
"width": "12",
"collapse": false
},
{
"id": "c733c61c.6e4828",
"type": "ui_tab",
"z": "",
"name": "Home1",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]
I have created a packed bubble chart using d3.layout.pack() for the following json which contains '0' values.
{ "children": [{ "className": "a", "value": 0},
{ "className": "b", "value": 1},
{ "className": "c", "value": 0},
{ "className": "d", "value": 0},
{ "className": "f", "value": 0},
{ "className": "g", "value": 8},
{ "className": "h", "value": 2},
{ "className": "i", "value": 6},
{ "className": "j", "value": 8},
{ "className": "k", "value": 4},
{ "className": "l", "value": 3}] };
While creating this chart, some bubble are overlapping.
https://jsfiddle.net/remila_antony/chrrp3ww/
How can I fix this issue?
This is a known issue. According to Mike Bostock:
Probably [you] should just filter out zero values (even very small values) when computing the pack layout. The problem is the pack intersection test fails when the two values being compared are very different (one is very small, say near zero, and the other very large).
Thus, the solution is filtering out the zeros:
flat.children = flat.children.filter(d=>d.value>0);
Here is your Fiddle: https://jsfiddle.net/2umsqjt1/
I am drawing a intractive graph using amcharts. I want to draw several line graphs in one single graph. But my code draw only one graph. When I add code for second line graph , it did not show anything due to error. How I can add second line graph in it. Here is .js file.
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "light",
"marginTop":0,
"marginRight": 80,
"dataProvider": [{
"D": "100",
"value": 10
}, {
"D": "200",
"value": 20
}, {
"D": "200",
"value": 30
}, {
"D": "400",
"value": 40
}, {
"D": "500",
"value": 50
}],
"graphs": [{
"id":"g1",
"balloonText": "[[category]]<br><b><span style='font-size:14px;'>[[value]]</span></b>",
"bullet": "round",
"bulletSize": 8,
"lineColor": "#d1655d",
"lineThickness": 2,
"negativeLineColor": "#637bb6",
"type": "smoothedLine",
"valueField": "value"
}],
"chartCursor": { /* required for zoom effect */
"cursorAlpha": 0,
"valueLineEnabled":true,
"valueLineBalloonEnabled":true,
"valueLineAlpha":0.5,
"fullWidth":true
},
/*show x axis values on graph*/
"categoryField": "D",
});
chart.addListener("rendered", zoomChart);
if(chart.zoomChart){
chart.zoomChart();
}
function zoomChart(){
chart.zoomToIndexes(Math.round(chart.dataProvider.length * 0.4), Math.round(chart.dataProvider.length * 0.55));
}
I found a solution. If you want to plot more linegraphs in one single graph. Just add extra id' in "graph": and add extra valueField inside that id. And add needed points in "dataProvider":. Similarly you can do this for more than 2 graphs by adding ids inside "graph":. And save it with .js extension.
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "light",
"marginTop":0,
"marginRight": 80,
"dataProvider": [{
"D": "5",
"value":0.30,
"value1":0.5,
}, {
"D": "10",
"value": 0.29,
"value1":0.27,
}, {
"D": "15",
"value": 0.28,
"value1":0.20,
}, {
"D": "20",
"value": 0.27,
"value1":0.32,
}, {
"D": "25",
"value": 0.26,
"value1":0.25,
}],
"graphs": [{
"id":"g1",
"balloonText": "[[category]]<br><b><span style='font-size:14px;'>[[value]]</span></b>",
"bullet": "round",
"bulletSize": 8,
"lineColor": "#d1655d",
"lineThickness": 2,
"negativeLineColor": "#637bb6",
"type": "smoothedLine",
"title": "redpoint",
"valueField": "value"
}, {
"id":"g2",
"balloonText": "[[category]]<br><b><span style='font-size:14px;> [value]]</span></b>",
"bullet": "round",
"bulletSize": 8,
"lineColor": "#20acd4",
"lineThickness": 2,
"negativeLineColor": "#637bb6",
"type": "smoothedLine",
"title": "bluepoint",
"valueField": "value1"
}],
"chartCursor": { /* required for zoom effect */
"cursorAlpha": 0,
"valueLineEnabled":true,
"valueLineBalloonEnabled":true,
"valueLineAlpha":0.5,
"fullWidth":true
},
/*legend show points value on top*/
"legend": {
"useGraphSettings": true,
"position": "top"
},
/*show x axis values on graph*/
"categoryField": "D",
});
chart.addListener("rendered", zoomChart);/*zoom effect*/
if(chart.zoomChart){
chart.zoomChart();
}
function zoomChart(){
chart.zoomToIndexes(Math.round(chart.dataProvider.length * 0.4), Math.round(chart.dataProvider.length * 0.55));
}
I am looking to render a line chart using Kendo UI. http://demos.telerik.com/kendo-ui/line-charts/remote-data-binding
It expects the json data to be directly an array like in the format (from their example):
[
{
"date": "12/30/2011",
"close": 405,
"volume": 6414369,
"open": 403.51,
"high": 406.28,
"low": 403.49,
"symbol": "2. AAPL"
},
{
"date": "11/30/2011",
"close": 382.2,
"volume": 14464710,
"open": 381.29,
"high": 382.276,
"low": 378.3,
"symbol": "2. AAPL"
}
]
However, I have a URL that returns the data in the following format. Note the extra object 'ranks' at the beginning which has the array:
{
"ranks": [
{
"id": 2,
"rank": 3,
"rankdate": "2015-05-17T00:00:00+0000",
"student": {
"id": 203,
"name": "Student1",
"currentRank": 3,
"LastVerified": "2015-05-17T22:30:00+0000"
}
},
{
"id": 1,
"rank": 4,
"rankdate": "2015-05-16T00:00:00+0000",
"student": {
"id": 203,
"name": "Student1",
"currentRank": 3,
"LastVerified": "2015-05-17T22:30:00+0000"
}
}
]
}
I was wondering if there was a way to have the datasource look inside "ranks" for the array instead of expecting it directly.
Found it. One can customize the schema in Kendo for the datasource using:
schema: {
data: "ranks"
},