Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/application/fact/Chart.js
Show First 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | _redraw: function() { | ||||
g.append('g') | g.append('g') | ||||
.attr('class', 'y axis') | .attr('class', 'y axis') | ||||
.attr('transform', css_function('translate', 0, 0)) | .attr('transform', css_function('translate', 0, 0)) | ||||
.call(yAxis); | .call(yAxis); | ||||
}, | }, | ||||
_newStackedArea: function(g, dataset, x, y, div, curtain) { | _newStackedArea: function(g, dataset, x, y, div, curtain) { | ||||
var ii; | |||||
var to_date = JX.bind(this, this._newDate); | var to_date = JX.bind(this, this._newDate); | ||||
var area = d3.area() | var area = d3.area() | ||||
.x(function(d) { return x(to_date(d.x)); }) | .x(function(d) { return x(to_date(d.x)); }) | ||||
.y0(function(d) { return y(d.y0); }) | .y0(function(d) { return y(d.y0); }) | ||||
.y1(function(d) { return y(d.y1); }); | .y1(function(d) { return y(d.y1); }); | ||||
var line = d3.line() | var line = d3.line() | ||||
.x(function(d) { return x(to_date(d.x)); }) | .x(function(d) { return x(to_date(d.x)); }) | ||||
.y(function(d) { return y(d.y1); }); | .y(function(d) { return y(d.y1); }); | ||||
for (var ii = 0; ii < dataset.data.length; ii++) { | for (ii = 0; ii < dataset.data.length; ii++) { | ||||
var label = new JX.ChartFunctionLabel(dataset.labels[ii]); | var label = new JX.ChartFunctionLabel(dataset.labels[ii]); | ||||
var fill_color = label.getFillColor() || label.getColor(); | var fill_color = label.getFillColor() || label.getColor(); | ||||
g.append('path') | g.append('path') | ||||
.style('fill', fill_color) | .style('fill', fill_color) | ||||
.attr('d', area(dataset.data[ii])); | .attr('d', area(dataset.data[ii])); | ||||
var stroke_color = label.getColor(); | var stroke_color = label.getColor(); | ||||
g.append('path') | g.append('path') | ||||
.attr('class', 'line') | .attr('class', 'line') | ||||
.style('stroke', stroke_color) | .style('stroke', stroke_color) | ||||
.attr('d', line(dataset.data[ii])); | .attr('d', line(dataset.data[ii])); | ||||
curtain.addFunctionLabel(label); | |||||
} | |||||
// Now that we've drawn all the areas and lines, draw the dots. | |||||
for (ii = 0; ii < dataset.data.length; ii++) { | |||||
g.selectAll('dot') | g.selectAll('dot') | ||||
.data(dataset.events[ii]) | .data(dataset.events[ii]) | ||||
.enter() | .enter() | ||||
.append('circle') | .append('circle') | ||||
.attr('class', 'point') | .attr('class', 'point') | ||||
.attr('r', 3) | .attr('r', 3) | ||||
.attr('cx', function(d) { return x(to_date(d.x)); }) | .attr('cx', function(d) { return x(to_date(d.x)); }) | ||||
.attr('cy', function(d) { return y(d.y1); }) | .attr('cy', function(d) { return y(d.y1); }) | ||||
.on('mouseover', function(d) { | .on('mouseover', function(d) { | ||||
var dd = to_date(d.x); | var dd = to_date(d.x); | ||||
var d_y = dd.getFullYear(); | var d_y = dd.getFullYear(); | ||||
// NOTE: Javascript months are zero-based. See PHI1017. | // NOTE: Javascript months are zero-based. See PHI1017. | ||||
var d_m = dd.getMonth() + 1; | var d_m = dd.getMonth() + 1; | ||||
var d_d = dd.getDate(); | var d_d = dd.getDate(); | ||||
var y = parseInt(d.y1); | |||||
var label = d.n + ' Points'; | |||||
var view = | |||||
d_y + '-' + d_m + '-' + d_d + ': ' + y + '<br />' + | |||||
label; | |||||
div | div | ||||
.html(d_y + '-' + d_m + '-' + d_d + ': ' + d.y1) | .html(view) | ||||
.style('opacity', 0.9) | .style('opacity', 0.9) | ||||
.style('left', (d3.event.pageX - 60) + 'px') | .style('left', (d3.event.pageX - 60) + 'px') | ||||
.style('top', (d3.event.pageY - 38) + 'px'); | .style('top', (d3.event.pageY - 38) + 'px'); | ||||
}) | }) | ||||
.on('mouseout', function() { | .on('mouseout', function() { | ||||
div.style('opacity', 0); | div.style('opacity', 0); | ||||
}); | }); | ||||
curtain.addFunctionLabel(label); | |||||
} | } | ||||
}, | }, | ||||
_newDate: function(epoch) { | _newDate: function(epoch) { | ||||
return new Date(epoch * 1000); | return new Date(epoch * 1000); | ||||
}, | }, | ||||
_getCurtain: function() { | _getCurtain: function() { | ||||
if (!this._curtain) { | if (!this._curtain) { | ||||
Show All 19 Lines |