-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKey.js
More file actions
executable file
·56 lines (48 loc) · 1.52 KB
/
Key.js
File metadata and controls
executable file
·56 lines (48 loc) · 1.52 KB
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
var Icon = require('app/components/visualization/Icon.js').Icon;
var Label = require('app/components/visualization/Label.js').Label;
var d3 = require('app/components/d3js.js');
var Key = function (index, shape, x, y, isChartLegendEnabled = false, width = 0) {
this.id = shape.geometry.type + index
this.height = 15
this.width = width
this.x = x
this.y = y
this.spacing = 10
this.icon = new Icon(this.id, shape, this.height, this.x, this.y)
this.label = new Label(this.id, shape.properties.name, this.height, this.x, this.y, width)
this.legendSpacing = 0
this.isChartLegendEnabled = isChartLegendEnabled
this.display = function (graph, legend_spacing = this.spacing) {
if(shape.properties.name){
this.legendSpacing = legend_spacing
this.icon.draw(graph)
this.label.addOffset(this.icon.width + this.spacing, 0)
this.label.draw(graph)
this.width = this.icon.width + this.spacing + this.label.width + this.legendSpacing
}
}
this.addOffset = function (x, y) {
this.x += x
this.y += y
this.icon.addOffset(x, y)
this.label.addOffset(x, y)
}
this.setX = function (x) {
this.x = x
this.icon.setX(x)
this.label.setX(x)
}
this.setY = function (y) {
this.offset = y
this.icon.setY(y)
this.label.setY(y)
}
this.remove = function (graphId) {
if (this.isChartLegendEnabled) {
d3.selectAll("#chart" + graphId + " #" + this.id).remove()
} else {
d3.selectAll("#" + graphId + " #" + this.id).remove()
}
}
}
exports.Key = Key