conjur-asset-ui 1.4.2 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +8 -3
- data/CHANGELOG.md +10 -0
- data/Makefile +19 -0
- data/README.md +0 -3
- data/Rakefile +22 -17
- data/TODO.md +0 -23
- data/app/.csscomb.json +304 -0
- data/app/.eslintignore +3 -0
- data/app/.eslintrc +265 -0
- data/app/config/preprocessor.js +19 -0
- data/app/config/webpack.js +124 -0
- data/app/gulpfile.js +96 -0
- data/app/package.json +86 -0
- data/app/src/actions.js +550 -0
- data/app/src/app.js +83 -0
- data/app/src/clients/audit.js +34 -0
- data/app/src/clients/auth.js +24 -0
- data/app/src/clients/generic.js +52 -0
- data/app/src/clients/graph.js +7 -0
- data/app/src/clients/layer_members.js +18 -0
- data/app/src/clients/list.js +31 -0
- data/app/src/clients/members.js +20 -0
- data/app/src/clients/request.js +531 -0
- data/app/src/clients/search.js +5 -0
- data/app/src/components/app/__tests__/app-test.js +22 -0
- data/app/src/components/app/app.js +36 -0
- data/app/src/components/app/wrapper.js +17 -0
- data/app/src/components/audit/__tests__/table_header-test.js +22 -0
- data/app/src/components/audit/box.js +9 -0
- data/app/src/components/audit/constants.js +5 -0
- data/app/src/components/audit/entry.js +105 -0
- data/app/src/components/audit/fields_mixin.js +11 -0
- data/app/src/components/audit/humanize_event.js +213 -0
- data/app/src/components/audit/table.js +64 -0
- data/app/src/components/audit/table_header.js +37 -0
- data/app/src/components/audit/timestamp.js +28 -0
- data/app/src/components/auth/login.js +177 -0
- data/app/src/components/auth/login.less +71 -0
- data/app/src/components/auth/logout.js +42 -0
- data/app/src/components/auth/logout.less +21 -0
- data/app/src/components/chart/chart.js +540 -0
- data/app/src/components/chart/chart_helper_mixin.js +78 -0
- data/app/src/components/custom/list.js +3 -0
- data/app/src/components/custom/view.js +81 -0
- data/app/src/components/dashboard/activity.js +144 -0
- data/app/src/components/dashboard/dashboard.js +46 -0
- data/app/src/components/flash/flash.js +98 -0
- data/app/src/components/flash/flash.less +3 -0
- data/app/src/components/generic/__tests__/time-test.js +42 -0
- data/app/src/components/generic/annotations.js +39 -0
- data/app/src/components/generic/breadcrumbs.js +57 -0
- data/app/src/components/generic/foldable_audit_section.js +204 -0
- data/app/src/components/generic/list.js +141 -0
- data/app/src/components/generic/list_factory.js +41 -0
- data/app/src/components/generic/resource_link.js +64 -0
- data/app/src/components/generic/role_link.js +66 -0
- data/app/src/components/generic/tab_mixin.js +146 -0
- data/app/src/components/generic/time.js +32 -0
- data/app/src/components/graph/__tests__/collapse-test.js +133 -0
- data/app/src/components/graph/__tests__/edges-from-vertices-test.js +48 -0
- data/app/src/components/graph/__tests__/new-vertex-set-test.js +16 -0
- data/app/src/components/graph/__tests__/next-id-test.js +27 -0
- data/app/src/components/graph/__tests__/role-kind-from-id-test.js +24 -0
- data/app/src/components/graph/__tests__/vertices-from-edges-test.js +72 -0
- data/app/src/components/graph/graph.js +449 -0
- data/app/src/components/graph/graph.less +39 -0
- data/app/src/components/graph/helpers.js +368 -0
- data/app/src/components/group/list.js +3 -0
- data/app/src/components/group/view.js +153 -0
- data/app/src/components/host/activity.js +111 -0
- data/app/src/components/host/details.js +28 -0
- data/app/src/components/host/executors.js +77 -0
- data/app/src/components/host/host_link.js +18 -0
- data/app/src/components/host/list.js +3 -0
- data/app/src/components/host/updaters.js +77 -0
- data/app/src/components/host/view.js +145 -0
- data/app/src/components/layer/list.js +3 -0
- data/app/src/components/layer/view.js +197 -0
- data/app/src/components/navbar/__tests__/navbar-test.js +21 -0
- data/app/src/components/navbar/nav_search_form.js +40 -0
- data/app/src/components/navbar/navbar.js +96 -0
- data/app/src/components/notfound/notfound.js +35 -0
- data/app/src/components/notfound/notfound.less +21 -0
- data/app/src/components/owned_resources/owned_resources.js +84 -0
- data/app/src/components/owned_resources/owned_resources_box.js +101 -0
- data/app/src/components/permissions/permissions.js +138 -0
- data/app/src/components/permissions/permissions_table.js +101 -0
- data/app/src/components/policy/list.js +3 -0
- data/app/src/components/policy/view.js +107 -0
- data/app/src/components/refresh/refresh.js +29 -0
- data/app/src/components/refresh/refresh.less +15 -0
- data/app/src/components/search/group.js +43 -0
- data/app/src/components/search/group_heading.js +50 -0
- data/app/src/components/search/group_title.js +37 -0
- data/app/src/components/search/result_item.js +55 -0
- data/app/src/components/search/search.js +118 -0
- data/app/src/components/user/activity.js +112 -0
- data/app/src/components/user/details.js +30 -0
- data/app/src/components/user/list.js +3 -0
- data/app/src/components/user/pubkeys.js +118 -0
- data/app/src/components/user/pubkeys.less +56 -0
- data/app/src/components/user/view.js +143 -0
- data/app/src/components/variable/activity.js +101 -0
- data/app/src/components/variable/details.js +46 -0
- data/app/src/components/variable/fetchers.js +77 -0
- data/app/src/components/variable/list.js +3 -0
- data/app/src/components/variable/updaters.js +77 -0
- data/app/src/components/variable/view.js +115 -0
- data/app/src/constants.js +36 -0
- data/{public → app/src}/images/conjur-logo.svg +0 -0
- data/{public → app/src}/images/icon-client-pc.svg +0 -0
- data/{public → app/src}/images/icon-environment.png +0 -0
- data/{public → app/src}/images/icon-person.svg +0 -0
- data/{public → app/src}/images/icon-policy.png +0 -0
- data/{public → app/src}/images/icon-resource.png +0 -0
- data/{public → app/src}/images/icon-service-dots.svg +0 -0
- data/{public → app/src}/images/icon-variable.png +0 -0
- data/app/src/pages/index.html +27 -0
- data/app/src/routes.js +64 -0
- data/app/src/stores/app_store.js +35 -0
- data/app/src/stores/audit_store.js +143 -0
- data/app/src/stores/graph_store.js +51 -0
- data/app/src/stores/group_store.js +104 -0
- data/app/src/stores/host_store.js +111 -0
- data/app/src/stores/layer_store.js +115 -0
- data/app/src/stores/policy_store.js +88 -0
- data/app/src/stores/resources_store.js +115 -0
- data/app/src/stores/route_store.js +21 -0
- data/app/src/stores/search_store.js +77 -0
- data/app/src/stores/user_store.js +109 -0
- data/app/src/stores/variable_store.js +93 -0
- data/app/src/styles/bootstrap.less +54 -0
- data/{public/css → app/src/styles}/styles.less +26 -82
- data/app/src/utils.js +38 -0
- data/app/src/vendor/pace.js +2 -0
- data/conjur-asset-ui.gemspec +3 -4
- data/docker/assets-build/Dockerfile +12 -0
- data/docker/conjur-ui/Dockerfile +33 -0
- data/docker/conjur-ui/README.md +38 -0
- data/docker/conjur-ui/mime.types +90 -0
- data/docker/conjur-ui/nginx.conf +110 -0
- data/docker/conjur-ui/start.py +72 -0
- data/docker/conjur-ui/start.sh +18 -0
- data/docker/conjur-ui/test.env +8 -0
- data/lib/conjur-asset-ui-version.rb +1 -1
- data/lib/conjur/command/ui.rb +10 -2
- data/lib/conjur/webserver/home.rb +3 -3
- data/lib/conjur/webserver/login.rb +1 -1
- data/lib/conjur/webserver/server.rb +16 -4
- data/public/js/views/roleGraph.js +91 -0
- metadata +167 -105
- data/.jshintrc +0 -41
- data/bower.json +0 -98
- data/gulpfile.js +0 -139
- data/package.json +0 -47
- data/preprocessor.js +0 -7
- data/public/_client_libs.html +0 -9
- data/public/index.html.erb +0 -63
- data/public/js/init.js +0 -196
- data/public/js/lib/pace.js +0 -2
- data/public/js/lib/sorted-set.no-require.js +0 -1145
- data/public/js/lib/sorted-set.no-require.js.txt +0 -6
- data/public/js/models/groupRecord.js +0 -72
- data/public/js/models/hostRecord.js +0 -60
- data/public/js/models/layerRecord.js +0 -79
- data/public/js/models/namespace.js +0 -12
- data/public/js/models/policyList.js +0 -16
- data/public/js/models/policyRecord.js +0 -54
- data/public/js/models/record.js +0 -117
- data/public/js/models/resourceList.js +0 -87
- data/public/js/models/userList.js +0 -25
- data/public/js/models/userRecord.js +0 -75
- data/public/js/models/variableList.js +0 -27
- data/public/js/models/variableRecord.js +0 -77
- data/public/js/routers.js +0 -242
- data/public/js/views/annotations.js +0 -47
- data/public/js/views/audit.js +0 -369
- data/public/js/views/breadcrumbs.js +0 -62
- data/public/js/views/chart.js +0 -617
- data/public/js/views/dashboard.js +0 -146
- data/public/js/views/generic.js +0 -122
- data/public/js/views/group.js +0 -109
- data/public/js/views/groups.js +0 -26
- data/public/js/views/host.js +0 -200
- data/public/js/views/hosts.js +0 -26
- data/public/js/views/layer.js +0 -146
- data/public/js/views/layers.js +0 -26
- data/public/js/views/mixins/search.js +0 -22
- data/public/js/views/mixins/tabs.js +0 -154
- data/public/js/views/namespaces.js +0 -40
- data/public/js/views/navSearch.js +0 -36
- data/public/js/views/owned.js +0 -184
- data/public/js/views/permissions.js +0 -254
- data/public/js/views/policies.js +0 -26
- data/public/js/views/policy.js +0 -70
- data/public/js/views/resource.js +0 -59
- data/public/js/views/role.js +0 -63
- data/public/js/views/searchResults.js +0 -212
- data/public/js/views/sections.js +0 -226
- data/public/js/views/time.js +0 -39
- data/public/js/views/user.js +0 -297
- data/public/js/views/users.js +0 -26
- data/public/js/views/variable.js +0 -310
- data/public/js/views/variables.js +0 -26
- data/spec/javascripts/helpers/.gitkeep +0 -0
- data/spec/javascripts/support/jasmine.yml +0 -112
- data/spec/javascripts/support/jasmine_helper.rb +0 -22
- data/spec/javascripts/support/run.html.erb +0 -23
- data/spec/javascripts/views/AuditSpec.js +0 -22
- data/spec/javascripts/views/AuditSpec.ls +0 -18
@@ -0,0 +1,540 @@
|
|
1
|
+
var React = require('react'),
|
2
|
+
d3 = require('d3');
|
3
|
+
|
4
|
+
import {merge} from 'lodash';
|
5
|
+
|
6
|
+
var bisector = d3.bisector(function(d) {
|
7
|
+
return d.date;
|
8
|
+
}).left;
|
9
|
+
|
10
|
+
var oneDay = 86400000;
|
11
|
+
|
12
|
+
function _translate(x, y) {
|
13
|
+
return 'translate(' + x + ',' + y + ')';
|
14
|
+
}
|
15
|
+
|
16
|
+
export default React.createClass({
|
17
|
+
displayName: 'Chart',
|
18
|
+
|
19
|
+
getInitialState() {
|
20
|
+
return {ready: false};
|
21
|
+
},
|
22
|
+
|
23
|
+
getDefaultProps() {
|
24
|
+
return {
|
25
|
+
defaultOptions: {
|
26
|
+
legend: {},
|
27
|
+
axis: {
|
28
|
+
x: {
|
29
|
+
label: 'X axis'
|
30
|
+
},
|
31
|
+
y: {
|
32
|
+
label: 'Y axis'
|
33
|
+
}
|
34
|
+
},
|
35
|
+
margin: {
|
36
|
+
top: 20,
|
37
|
+
right: 145,
|
38
|
+
bottom: 30,
|
39
|
+
left: 50
|
40
|
+
}
|
41
|
+
}
|
42
|
+
};
|
43
|
+
},
|
44
|
+
|
45
|
+
el: null,
|
46
|
+
svg: null,
|
47
|
+
|
48
|
+
componentDidMount() {
|
49
|
+
// should be better way to do this
|
50
|
+
this.el = this.getDOMNode();
|
51
|
+
this.svg = {};
|
52
|
+
|
53
|
+
this._calculateInitialState(this.props);
|
54
|
+
},
|
55
|
+
|
56
|
+
componentWillReceiveProps(nextProps) {
|
57
|
+
this._calculateInitialState(nextProps);
|
58
|
+
},
|
59
|
+
|
60
|
+
componentDidUpdate() {
|
61
|
+
if (this.state.ready === false) {
|
62
|
+
return;
|
63
|
+
}
|
64
|
+
|
65
|
+
if (typeof this.svg.svg === 'undefined') {
|
66
|
+
this._create();
|
67
|
+
}
|
68
|
+
|
69
|
+
this._update();
|
70
|
+
|
71
|
+
return;
|
72
|
+
},
|
73
|
+
|
74
|
+
componentWillUnmount() {
|
75
|
+
this.el = null;
|
76
|
+
this.svg = null;
|
77
|
+
},
|
78
|
+
|
79
|
+
render() {
|
80
|
+
return (
|
81
|
+
<div className="b-chart"></div>
|
82
|
+
);
|
83
|
+
},
|
84
|
+
|
85
|
+
_getHeight(top, bottom) {
|
86
|
+
var height;
|
87
|
+
|
88
|
+
if (this.el.offsetHeight) {
|
89
|
+
height = this.el.offsetHeight;
|
90
|
+
} else if (this.el.style.pixelHeight) {
|
91
|
+
height = this.el.style.pixelHeight;
|
92
|
+
}
|
93
|
+
|
94
|
+
height = window.parseFloat(height) -
|
95
|
+
top - bottom;
|
96
|
+
|
97
|
+
return height;
|
98
|
+
},
|
99
|
+
|
100
|
+
_getWidth(left, right) {
|
101
|
+
var width;
|
102
|
+
|
103
|
+
if (this.el.offsetWidth) {
|
104
|
+
width = this.el.offsetWidth;
|
105
|
+
} else if (this.el.style.pixelWidth) {
|
106
|
+
width = this.el.style.pixelWidth;
|
107
|
+
}
|
108
|
+
|
109
|
+
width = window.parseFloat(width) -
|
110
|
+
left - right;
|
111
|
+
|
112
|
+
return width;
|
113
|
+
},
|
114
|
+
|
115
|
+
_create() {
|
116
|
+
var svg = d3.select(this.el)
|
117
|
+
.append('svg')
|
118
|
+
.attr('class', 'd3-line-chart')
|
119
|
+
.attr('width', this.state.fullWidth)
|
120
|
+
.attr('height', this.state.fullHeight)
|
121
|
+
.append('g')
|
122
|
+
.attr('class', 'd3-line-chart__inner')
|
123
|
+
.attr('transform', _translate(this.state.margin.left, this.state.margin.top));
|
124
|
+
|
125
|
+
this.svg.svg = svg;
|
126
|
+
|
127
|
+
this.svg.axis = svg.append('g')
|
128
|
+
.attr('class', 'd3-axis');
|
129
|
+
|
130
|
+
this.svg.axis.append('g')
|
131
|
+
.attr('class', 'd3-axis__x');
|
132
|
+
|
133
|
+
this.svg.axis.append('g')
|
134
|
+
.attr('class', 'd3-axis__y');
|
135
|
+
|
136
|
+
this.svg.legend = svg.append('g')
|
137
|
+
.attr('class', 'd3-legend');
|
138
|
+
|
139
|
+
this.svg.graph = svg.append('g')
|
140
|
+
.attr('class', 'd3-graph');
|
141
|
+
|
142
|
+
this.svg.focus = this.svg.graph.append('g')
|
143
|
+
.attr('class', 'd3-graph__focus');
|
144
|
+
},
|
145
|
+
|
146
|
+
_update() {
|
147
|
+
this._drawAxisX();
|
148
|
+
this._drawAxisY();
|
149
|
+
this._drawLegend();
|
150
|
+
this._drawLine();
|
151
|
+
this._drawFocus();
|
152
|
+
},
|
153
|
+
|
154
|
+
_calculateInitialState(props) {
|
155
|
+
var options = merge({}, props.options,
|
156
|
+
props.defaultOptions);
|
157
|
+
|
158
|
+
var width = this._getWidth(options.margin.left,
|
159
|
+
options.margin.right),
|
160
|
+
height = this._getHeight(options.margin.top,
|
161
|
+
options.margin.bottom),
|
162
|
+
fullWidth = (
|
163
|
+
width +
|
164
|
+
options.margin.left +
|
165
|
+
options.margin.right
|
166
|
+
),
|
167
|
+
fullHeight = (
|
168
|
+
height +
|
169
|
+
options.margin.top +
|
170
|
+
options.margin.bottom
|
171
|
+
);
|
172
|
+
|
173
|
+
var color = d3.scale.category10();
|
174
|
+
|
175
|
+
color.domain(d3.keys(options.legend)
|
176
|
+
.filter(function(key) {
|
177
|
+
return key !== 'date';
|
178
|
+
}));
|
179
|
+
|
180
|
+
var data = color.domain().map(function(name) {
|
181
|
+
return {
|
182
|
+
name: name,
|
183
|
+
values: props.data.map(function(d) {
|
184
|
+
return {date: d.date, value: +d[name]};
|
185
|
+
})
|
186
|
+
};
|
187
|
+
});
|
188
|
+
|
189
|
+
var xExtent = d3.extent(props.data, function(d) {
|
190
|
+
return d.date;
|
191
|
+
});
|
192
|
+
|
193
|
+
var currentDate = (new Date()).getTime();
|
194
|
+
|
195
|
+
var xMin = xExtent[0] || new Date(currentDate - oneDay),
|
196
|
+
xMax = xExtent[1] || new Date(currentDate);
|
197
|
+
|
198
|
+
var yMin = d3.min(data, function(c) {
|
199
|
+
return d3.min(c.values, function(v) {
|
200
|
+
return v.value;
|
201
|
+
});
|
202
|
+
}) || 0;
|
203
|
+
|
204
|
+
if (yMin < 1) {
|
205
|
+
yMin = 0;
|
206
|
+
}
|
207
|
+
|
208
|
+
var yMax = d3.max(data, function(c) {
|
209
|
+
return d3.max(c.values, function(v) {
|
210
|
+
return v.value;
|
211
|
+
});
|
212
|
+
}) || 4;
|
213
|
+
|
214
|
+
yMax += 1;
|
215
|
+
|
216
|
+
if (yMax < 5) {
|
217
|
+
yMax = 5;
|
218
|
+
}
|
219
|
+
|
220
|
+
var x = this._getScaleX('time')
|
221
|
+
.range([0, width])
|
222
|
+
.domain([xMin, xMax]),
|
223
|
+
|
224
|
+
y = this._getScaleX('linear')
|
225
|
+
.range([height, 0])
|
226
|
+
.domain([yMin, yMax]),
|
227
|
+
|
228
|
+
legendScale = d3.scale.ordinal()
|
229
|
+
.domain([])
|
230
|
+
.range([0, 20, 40, 60, 80, 100, 120, 140]),
|
231
|
+
|
232
|
+
scales = {x: x, y: y, yMax: yMax, legend: legendScale};
|
233
|
+
|
234
|
+
var line = this._getLine(scales);
|
235
|
+
|
236
|
+
this.setState({
|
237
|
+
ready: true,
|
238
|
+
legend: options.legend,
|
239
|
+
axis: options.axis,
|
240
|
+
margin: options.margin,
|
241
|
+
width: width,
|
242
|
+
height: height,
|
243
|
+
fullWidth: fullWidth,
|
244
|
+
fullHeight: fullHeight,
|
245
|
+
color: color,
|
246
|
+
scales: scales,
|
247
|
+
lineStencil: line,
|
248
|
+
data: data
|
249
|
+
});
|
250
|
+
},
|
251
|
+
|
252
|
+
_getScaleX(type) {
|
253
|
+
if (type === 'linear') {
|
254
|
+
return d3.scale.linear();
|
255
|
+
} else if (type === 'time') {
|
256
|
+
return d3.time.scale();
|
257
|
+
}
|
258
|
+
|
259
|
+
return null;
|
260
|
+
},
|
261
|
+
|
262
|
+
_getLine(scales) {
|
263
|
+
return d3.svg.line()
|
264
|
+
.x(function(d) {
|
265
|
+
return scales.x(d.date);
|
266
|
+
})
|
267
|
+
.y(function(d) {
|
268
|
+
return scales.y(d.value);
|
269
|
+
});
|
270
|
+
},
|
271
|
+
|
272
|
+
_drawAxisX() {
|
273
|
+
var xAxis = d3.svg.axis()
|
274
|
+
.scale(this.state.scales.x)
|
275
|
+
.orient('bottom');
|
276
|
+
|
277
|
+
this.svg.axis.select('.d3-axis__x')
|
278
|
+
.attr('transform', _translate(0, this.state.height))
|
279
|
+
.call(xAxis);
|
280
|
+
},
|
281
|
+
|
282
|
+
_drawAxisY() {
|
283
|
+
var yAxis = d3.svg.axis()
|
284
|
+
.scale(this.state.scales.y)
|
285
|
+
.orient('left')
|
286
|
+
.ticks(this.state.scales.yMax > 10 ? 10 : this.state.scales.yMax)
|
287
|
+
.tickFormat(d3.format('d'))
|
288
|
+
.tickSubdivide(0);
|
289
|
+
|
290
|
+
var axis = this.svg.axis.select('.d3-axis__y')
|
291
|
+
.call(yAxis);
|
292
|
+
|
293
|
+
if (typeof this.state.yAxisLabel === 'string') {
|
294
|
+
this._drawAxisLabel(axis, this.state.yAxisLabel, true);
|
295
|
+
}
|
296
|
+
},
|
297
|
+
|
298
|
+
_drawAxisLabel(axis, text, rotate) {
|
299
|
+
var label = axis.append('text');
|
300
|
+
|
301
|
+
if (typeof rotate === 'boolean' && rotate === true) {
|
302
|
+
label.attr('transform', 'rotate(-90)')
|
303
|
+
.attr('y', 0 - this.state.margin.left)
|
304
|
+
.attr('x', 0 - (this.state.height / 2))
|
305
|
+
.attr('dy', '1em')
|
306
|
+
.style('text-anchor', 'middle')
|
307
|
+
.text(text);
|
308
|
+
} else {
|
309
|
+
label.attr('transform',
|
310
|
+
_translate(this.state.width / 2,
|
311
|
+
this.state.height + this.state.margin.bottom))
|
312
|
+
.style('text-anchor', 'middle')
|
313
|
+
.text(text);
|
314
|
+
}
|
315
|
+
},
|
316
|
+
|
317
|
+
_drawLegend() {
|
318
|
+
var self = this,
|
319
|
+
legend,
|
320
|
+
enter;
|
321
|
+
|
322
|
+
legend = this.svg.legend
|
323
|
+
.selectAll('.d3-legend__item')
|
324
|
+
.data(d3.keys(this.state.legend));
|
325
|
+
|
326
|
+
enter = legend
|
327
|
+
.enter()
|
328
|
+
.append('g')
|
329
|
+
.style('opacity', 0.9)
|
330
|
+
.attr('class', 'd3-legend__item')
|
331
|
+
.attr('data-graph-line-id', function(d) {
|
332
|
+
return 'd3-legend__item--' + d;
|
333
|
+
})
|
334
|
+
.on('mouseover', function(d) {
|
335
|
+
self._handleLegendMouseover(this, d);
|
336
|
+
})
|
337
|
+
.on('mouseout', function(d) {
|
338
|
+
self._handleLegendMouseout(this, d);
|
339
|
+
})
|
340
|
+
.on('click', function(d) {
|
341
|
+
self._handleLegendClick(this, d);
|
342
|
+
});
|
343
|
+
|
344
|
+
enter.append('circle')
|
345
|
+
.attr('cx', this.state.width + 30)
|
346
|
+
.attr('cy', function(d, i) {
|
347
|
+
return self.state.scales.legend(i) - 3.1;
|
348
|
+
})
|
349
|
+
.attr('r', 5.5)
|
350
|
+
.style('fill', function(d) {
|
351
|
+
return self.state.color(d);
|
352
|
+
});
|
353
|
+
|
354
|
+
enter.append('text')
|
355
|
+
.attr('x', this.state.width + 40)
|
356
|
+
.attr('y', function(d, i) {
|
357
|
+
return self.state.scales.legend(i);
|
358
|
+
})
|
359
|
+
.text(function(d) {
|
360
|
+
return self.state.legend[d];
|
361
|
+
});
|
362
|
+
},
|
363
|
+
|
364
|
+
_handleLegendMouseover(that) {
|
365
|
+
var opacity = parseFloat(that.style.opacity);
|
366
|
+
|
367
|
+
if (opacity >= 0.9) {
|
368
|
+
d3.select(that)
|
369
|
+
.style('opacity', 1);
|
370
|
+
} else {
|
371
|
+
d3.select(that)
|
372
|
+
.style('opacity', 0.5);
|
373
|
+
}
|
374
|
+
},
|
375
|
+
|
376
|
+
_handleLegendMouseout(that) {
|
377
|
+
var opacity = parseFloat(that.style.opacity);
|
378
|
+
|
379
|
+
if (opacity >= 0.9) {
|
380
|
+
d3.select(that)
|
381
|
+
.style('opacity', 0.9);
|
382
|
+
} else {
|
383
|
+
d3.select(that)
|
384
|
+
.style('opacity', 0.2);
|
385
|
+
}
|
386
|
+
},
|
387
|
+
|
388
|
+
_handleLegendClick(that) {
|
389
|
+
var line = document.getElementById(that.getAttribute('data-graph-line-id'));
|
390
|
+
|
391
|
+
if (line === null) {
|
392
|
+
return;
|
393
|
+
}
|
394
|
+
|
395
|
+
if (line.style.opacity !== '0') {
|
396
|
+
d3.select(line).transition()
|
397
|
+
.duration(500)
|
398
|
+
.style('opacity', 0);
|
399
|
+
|
400
|
+
d3.select(that).transition()
|
401
|
+
.duration(500)
|
402
|
+
.style('opacity', 0.2);
|
403
|
+
} else {
|
404
|
+
d3.select(line).transition()
|
405
|
+
.duration(500)
|
406
|
+
.style('opacity', 1);
|
407
|
+
|
408
|
+
d3.select(that).transition()
|
409
|
+
.duration(500)
|
410
|
+
.style('opacity', 0.9);
|
411
|
+
}
|
412
|
+
},
|
413
|
+
|
414
|
+
_drawLine() {
|
415
|
+
var self = this,
|
416
|
+
line;
|
417
|
+
|
418
|
+
this.svg.graph.selectAll('.d3-graph__line')
|
419
|
+
.remove();
|
420
|
+
|
421
|
+
line = this.svg.graph.selectAll('.d3-graph__line')
|
422
|
+
.data(this.state.data)
|
423
|
+
.enter()
|
424
|
+
.append('g')
|
425
|
+
.attr('class', 'd3-graph__line')
|
426
|
+
.attr('id', function(d) {
|
427
|
+
return 'd3-legend__item--' + d.name;
|
428
|
+
});
|
429
|
+
|
430
|
+
line.append('path')
|
431
|
+
.attr('class', 'line')
|
432
|
+
.attr('d', function(d) {
|
433
|
+
return self.state.lineStencil(d.values);
|
434
|
+
})
|
435
|
+
.style('stroke', function(d) {
|
436
|
+
return self.state.color(d.name);
|
437
|
+
});
|
438
|
+
},
|
439
|
+
|
440
|
+
_drawFocus() {
|
441
|
+
var self = this;
|
442
|
+
|
443
|
+
var circle = this.svg.focus.selectAll('.d3-graph__focus-circle')
|
444
|
+
.data(this.state.data)
|
445
|
+
.enter()
|
446
|
+
.append('g')
|
447
|
+
.attr('class', 'd3-graph__focus-circle')
|
448
|
+
.attr('id', function(d) {
|
449
|
+
return 'd3-graph__focus-circle--' + d.name;
|
450
|
+
})
|
451
|
+
.style('display', 'none');
|
452
|
+
|
453
|
+
circle.append('circle')
|
454
|
+
.attr('r', 4.5);
|
455
|
+
|
456
|
+
circle.append('text')
|
457
|
+
.attr('x', 9)
|
458
|
+
.attr('dy', '.35em');
|
459
|
+
|
460
|
+
this.svg.focus.selectAll('.d3-graph__focus-line')
|
461
|
+
.data([1])
|
462
|
+
.enter()
|
463
|
+
.append('line')
|
464
|
+
.attr('class', 'd3-graph__focus-line')
|
465
|
+
.attr('x1', 0)
|
466
|
+
.attr('y1', 0)
|
467
|
+
.attr('x2', 0)
|
468
|
+
.attr('y2', this.state.height)
|
469
|
+
.style('display', 'none')
|
470
|
+
.style('stroke', 'gray')
|
471
|
+
.style('stroke-width', 0.5)
|
472
|
+
.style('stroke-dasharray', '5,10');
|
473
|
+
|
474
|
+
this.svg.graph.selectAll('.d3-graph__overlay')
|
475
|
+
.data([1])
|
476
|
+
.enter()
|
477
|
+
.append('rect')
|
478
|
+
.attr('class', 'd3-graph__overlay')
|
479
|
+
.attr('width', this.state.width)
|
480
|
+
.attr('height', this.state.height)
|
481
|
+
.on('mouseover', function() {
|
482
|
+
self.svg.focus.selectAll('.d3-graph__focus-line')
|
483
|
+
.style('display', null);
|
484
|
+
})
|
485
|
+
.on('mouseout', function() {
|
486
|
+
self.svg.focus.selectAll('.d3-graph__focus-line')
|
487
|
+
.style('display', 'none');
|
488
|
+
|
489
|
+
self.svg.focus.selectAll('.d3-graph__focus-circle')
|
490
|
+
.style('display', 'none');
|
491
|
+
})
|
492
|
+
.on('mousemove', function() {
|
493
|
+
self._handleFocusMousemove(this);
|
494
|
+
});
|
495
|
+
},
|
496
|
+
|
497
|
+
_handleFocusMousemove(overlay) {
|
498
|
+
var self = this,
|
499
|
+
mouse = d3.mouse(overlay)[0],
|
500
|
+
x0 = this.state.scales.x.invert(mouse);
|
501
|
+
|
502
|
+
var bisectData = function(data) {
|
503
|
+
var i = bisector(data.values, x0, 1),
|
504
|
+
d0 = data.values[i - 1],
|
505
|
+
d1 = data.values[i],
|
506
|
+
ret = {name: data.name, data: {value: []}};
|
507
|
+
|
508
|
+
if (typeof d0 === 'object' || typeof d1 === 'object') {
|
509
|
+
var d = x0 - d0.date > d1.date - x0 ? d1 : d0;
|
510
|
+
|
511
|
+
ret.data = d;
|
512
|
+
}
|
513
|
+
|
514
|
+
return ret;
|
515
|
+
};
|
516
|
+
|
517
|
+
this.svg.focus.selectAll('.d3-graph__focus-line')
|
518
|
+
.attr('transform', _translate(this.state.scales.x(x0), 0));
|
519
|
+
|
520
|
+
this.state.data.map(function(e) {
|
521
|
+
return bisectData(e);
|
522
|
+
}).map(function(d) {
|
523
|
+
var circle = document.getElementById('d3-graph__focus-circle--' + d.name),
|
524
|
+
line = document.getElementById('d3-legend__item--' + d.name);
|
525
|
+
|
526
|
+
if (d.data.value > 0 && line.style.opacity !== '0') {
|
527
|
+
d3.select(circle)
|
528
|
+
.style('display', null)
|
529
|
+
.attr('transform',
|
530
|
+
_translate(self.state.scales.x(d.data.date),
|
531
|
+
self.state.scales.y(d.data.value)))
|
532
|
+
|
533
|
+
.select('text').text(d3.format(',.2f')(d.data.value));
|
534
|
+
} else {
|
535
|
+
d3.select(circle)
|
536
|
+
.style('display', 'none');
|
537
|
+
}
|
538
|
+
});
|
539
|
+
}
|
540
|
+
});
|