====== Charts ======
* [[tq:work:charts:urls|URLs]]
===== TQshow =====
==== First version ====
Piran, 30. October, 2016
For visualization of temporal quantities I decided to adapt some bar-chart solution based on D3.js.
A current version is available on the file ''barChart.html'':
TQchart
It expects on the file ''barData.js'' data about a selected temporal quantity:
var barData = [[1970, 1984, 0], [1984, 1985, 0.5], [1985, 1989, 1.0], [1989, 1990, 1.5],
[1990, 1992, 2.4444], [1992, 1994, 3.8333], [1994, 1995, 5.2778], [1995, 1996, 5.7222],
[1996, 2000, 7.0972], [2000, 2001, 7.5417], [2001, 2003, 8.0417], [2003, 2004, 8.5417],
[2004, 2007, 9.4306], [2007, 2009, 9.4714]];
var TQmax = 17;
var Tmin = 1970;
var Tmax = 2009;
var width = 600;
var height = 250;
var title = "DOREIAN_P";
For a visualization of a given temporal quantity in Python the function ''TQshow'' (included in ''GraphNew.py'') can be used:
def TQshow(tq,TQmax,Tmin,Tmax,w,h,tit):
TQ = [ list(q) for q in tq ]
js = open('barData.js','w')
js.write('var barData = '+str(TQ)+';\n')
js.write('var TQmax = '+str(TQmax)+';\n')
js.write('var Tmin = '+str(Tmin)+';\n')
js.write('var Tmax = '+str(Tmax)+';\n')
js.write('var width = '+str(w)+';\n')
js.write('var height = '+str(h)+';\n')
js.write('var title = "'+tit+'";\n')
js.close()
# https://pymotw.com/3/webbrowser/
# import webbrowser
# b = webbrowser.get('google-chrome')
# b = webbrowser.get('mozilla')
b = webbrowser.get('windows-default')
b.open('c:/users/batagelj/work/python/graph/chart/barChart.html')
It writes the data about a selected temporal quentity on the file ''barData.js'' and applies a web browser on
the file ''barChart.html'':
>>> TQmax = 17; Tmin = 1970; Tmax = 2009; width = 600; height = 250;
>>> tit = "BORGATTI_S"
>>> tq = [(1970, 1988, 0), (1988, 1989, 0.5), (1989, 1990, 1.4444), (1990, 1991, 3.3333),
(1991, 1992, 4.2778), (1992, 1993, 5.2778), (1993, 1994, 6.2778), (1994, 1996, 7.7778),
(1996, 1997, 8.2778), (1997, 1998, 9.2222), (1998, 1999, 9.5972), (1999, 2001, 11.0972),
(2001, 2002, 11.9167), (2002, 2003, 12.3611), (2003, 2005, 14.1111),
(2005, 2006, 15.1111), (2006, 2007, 16.0556), (2007, 2009, 16.9204)]
>>> TQshow(tq,TQmax,Tmin,Tmax,width,height,tit)
In the browser's window we get the bar-chart of a given temporal quantity. To obtain a picture we can either capture the screen and crop it (Irfanview), or use the Chrome browser and entering ''More Tools / Developer tools'' select the SVG element, copy it into a text file, and saving it as a SVG picture.
{{tq:pics:borgatti.png}}
{{tq:pics:everett.png}}
{{tq:pics:doreian.png}}
{{tq:pics:workers.png}}
[[http://vladowiki.fmf.uni-lj.si/lib/exe/fetch.php?media=tq:pics:borgatti.svg|Borgatti.svg]]
==== To do ====
- correct dimensions in the SVG tag
- add color of bars into barData.js
- labels on x axis
- add position of the title into barData.js
==== Second version ====
An improved version of the temporal quentities charts is given in ''TQchart.html''
TQ chart
The content of the file ''barData.js'' is extended with some additional parameters
var barData = [[1, 2, 27], [10, 11, 11], [14, 15, 27], [16, 17, 11], [17, 18, 17],
[18, 19, 12], [22, 23, 17], [25, 26, 11], [27, 28, 18], [28, 29, 16], [29, 30, 53],
[30, 31, 56], [31, 32, 51], [32, 33, 30], [33, 34, 17], [34, 35, 71], [35, 36, 76],
[36, 37, 53], [37, 38, 11], [38, 39, 23], [39, 40, 54], [40, 41, 13], [41, 42, 174],
[42, 43, 25], [43, 44, 20], [45, 46, 15], [46, 47, 25]]
var Tmin = 1;
var Tmax = 47;
var Width = 900;
var Height = 250;
var TQmax = 180;
var Title = 'Workers';
var Rfill = 'orange';
var xLab = 70;
var yLab = 40;
Here is an SVG picture produced by ''TQchart.html''
==== Co-authorship in SN5 ====
''multiply.py'': introduction of options ''edge'' and ''double'' in procedures ''TQtwo2oneCols'' and ''TQtwo2oneRows''.
gdir = 'c:/users/batagelj/work/python/graph/graph'
# wdir = 'c:/users/batagelj/work/python/graph/JSON/test'
wdir = 'c:/users/batagelj/work/python/graph/JSON/SN5'
cdir = 'c:/users/batagelj/work/python/graph/chart'
import sys, os, datetime, json
sys.path = [gdir]+sys.path; os.chdir(wdir)
import TQ
from GraphNew import Graph
# file = 'C:/Users/batagelj/work/Python/graph/JSON/test/WAtestInst.json'
file = 'C:/Users/batagelj/work/Python/graph/JSON/SN5/WAcInst.json'
# file = 'C:/Users/batagelj/work/Python/graph/JSON/SN5/WAcCum.json'
# file = 'C:/Users/batagelj/work/Python/graph/JSON/Gisela/papInst.json'
t1 = datetime.datetime.now()
print("started: ",t1.ctime(),"\n")
G = Graph.loadNetJSON(file)
t2 = datetime.datetime.now()
print("\nloaded: ",t2.ctime(),"\ntime used: ", t2-t1)
# T = G.transpose()
# Co = Graph.TQmultiply(T,G,True)
# CR = G.TQtwo2oneRows()
CC = G.TQtwo2oneCols()
t3 = datetime.datetime.now()
print("\ncomputed: ",t3.ctime(),"\ntime used: ", t3-t2)
ia = { v[3]['lab']: k for k,v in CC._nodes.items() }
# iw = { v[3]['lab']: k for k,v in CR._nodes.items() }
# CC._links[(ia['BORGATTI_S'],ia['EVERETT_M'])][4]['tq']
# CC._links[(ia['IDI/B'],ia['HCL/B'])][4]['tq']
# len(CC)
# CC._links[(ia['BORGATTI_S'],ia['EVERETT_M'])][4]['tq']
# CC._links[(ia['BORGATTI_S'],ia['BORGATTI_S'])][4]['tq']
# TQmax = 17; Tmin = 1970; Tmax = 2009; w = 600; h = 250; tit = 'BORGATTI_S'
# TQshow(BB,cdir,TQmax,Tmin,Tmax,w,h,tit,fill='orange')
======= RESTART: C:\Users\batagelj\work\Python\graph\graph\multiply.py =======
started: Sun Nov 20 00:26:51 2016
loaded: Sun Nov 20 00:26:51 2016
time used: 0:00:00.425024
computed: Sun Nov 20 00:26:52 2016
time used: 0:00:01.165066
>>> BB = CC._links[(ia['BORGATTI_S'],ia['BORGATTI_S'])][4]['tq']
>>> BE = CC._links[(ia['BORGATTI_S'],ia['EVERETT_M'])][4]['tq']
>>> BB
[(1988, 1990, 2), (1990, 1991, 4), (1991, 1992, 2), (1992, 1993, 4), (1993, 1994, 2),
(1994, 1995, 3), (1996, 1997, 1), (1997, 1998, 2), (1998, 1999, 1), (1999, 2000, 3),
(2001, 2002, 2), (2002, 2003, 1), (2003, 2004, 4), (2005, 2006, 3), (2006, 2007, 2),
(2007, 2008, 3)]
>>> BE
[(1988, 1989, 1), (1989, 1990, 2), (1990, 1991, 4), (1991, 1992, 1), (1992, 1995, 2),
(1996, 1998, 1), (1999, 2000, 3), (2003, 2004, 1), (2005, 2007, 1)]
>>> TQmax = 8; Tmin = 1970; Tmax = 2009; w = 600; h = 120; tit = 'BORGATTI_S'
>>> Graph.TQshow(BB,cdir,TQmax,Tmin,Tmax,w,h,tit,fill='orange')
>>> tit = 'BORGATTI_S - EVERETT_M'
>>> Graph.TQshow(BE,cdir,TQmax,Tmin,Tmax,w,h,tit,fill='orange')
>>> NN = CC._links[(ia['NEWMAN_M'],ia['NEWMAN_M'])][4]['tq']
>>> NN
[(1999, 2000, 2), (2000, 2001, 4), (2001, 2002, 7), (2002, 2003, 8), (2003, 2004, 7),
(2004, 2005, 11), (2005, 2006, 7), (2006, 2007, 11), (2007, 2008, 3)]
>>> tit = 'NEWMAN_M'; TQmax = 12; h = 150
>>> Graph.TQshow(NN,cdir,TQmax,Tmin,Tmax,w,h,tit,fill='orange')