/
LineChart.js
84 lines (76 loc) · 2.36 KB
/
LineChart.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
$jit.LineChart = new Class({
Implements: [Layouts.Scatter, Loader, Extras],
initialize: function(config) {
var opt = {
legendX: '',
legendY: '',
animate: false,
nodeOffsetWidth: 0,
nodeOffsetHeight: 0,
showNodeNames: false,
colors: ["#416D9C", "#70A35E", "#EBB056", "#C74243", "#83548B", "#909291", "#557EAA"],
Node: {
overridable: true,
color: 'rgba(0, 0, 0, 0)',
type: 'square'
},
Edge: {
overridable:true,
type:'line',
},
Label: {
textAlign: 'center',
textBaseline: 'middle'
}
};
var opts = Options("Canvas", "Margin", "Node", "Edge", "Fx", "Tips", "NodeStyles",
"Events", "Navigation", "Controller", "Label");
this.controller = this.config = $.merge(opts, opt, config);
this.delegate = new $jit.Scatter(this.config);
this.canvas = this.delegate.canvas;
},
refresh: function() {
this.delegate.refresh();
},
/*
Method: loadJSON
Loads JSON data into the visualization.
Parameters:
json - The JSON data format. This format is described in <http://blog.thejit.org/2010/04/24/new-javascript-infovis-toolkit-visualizations/#json-data-format>.
Example:
(start code js)
var lineChart = new $jit.LineChart(options);
lineChart.loadJSON(json);
(end code)
*/
loadJSON: function(json) {
var newJSON = [],
config = this.config,
color = $.splat(json.color || this.colors),
delegate = this.delegate,
that = this;
for(var i=0, values=json.values, l=json.values.length; i<l; i++) {
var label = values[i].label,
valArray = $.splat(values[i].values);
for(var j in valArray) {
var adjacencies_ = ((j%2!=0) ? [label+(parseInt(j)-1), label+(parseInt(j)+1)] : []),
// used to eliminate the last bug adjacency
adjacencies = ((j!=valArray.length-1) ? adjacencies_ : [label+(parseInt(j)-1)]);
newJSON.push({
"id": label+j,
"name": 'event'+i+j,
"adjacencies": adjacencies,
"data": {
"$color":"#674fde",
"$dim":5,
"$x":i*j,
"$y":valArray[j]
}
});
}
}
delegate.loadJSON(newJSON);
delegate.refresh();
}
});
var LineChart = $jit.LineChart;