Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit before trying to bundle update to latest rails
- Loading branch information
Showing
15 changed files
with
3,575 additions
and
1,623 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Prognoz Export</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
|
||
<script type="text/javascript" src="/javascripts/d3.v2.js"></script> | ||
<script type="text/javascript" src="/javascripts/dat.gui.min.js"></script> | ||
|
||
|
||
|
||
<h1><%= @series.name %></h1> | ||
<div id= "chart_div"> | ||
<svg></svg> | ||
</div> | ||
|
||
<script type="text/javascript"> | ||
|
||
var gui = new dat.GUI(); | ||
|
||
var dat_gui_ranges = { | ||
w : [0, 800], | ||
h : [0, 1200], | ||
udaman_width :[0,20], | ||
aremos_width :[0,20], | ||
|
||
} | ||
|
||
//put all hard coded values in this object | ||
var params = { | ||
scale: 1.7, | ||
w: 555, | ||
h: 280, | ||
t_margin: 20, | ||
r_margin: 20, | ||
b_margin: 85, | ||
l_margin: 50, | ||
|
||
// bar_width: 50, | ||
tick_length: 7, | ||
|
||
x_axis_color: "gray", | ||
x_axis_fontcolor: "gray", | ||
x_axis_fontsize: 10, | ||
x_axis_font_rotation: 320, | ||
|
||
y_axis_color: "gray", | ||
y_axis_fontcolor: "gray", | ||
y_axis_fontsize: 10, | ||
|
||
udaman_color: "#227893", | ||
aremos_color: "#D84506", | ||
aremos_width:1.5, | ||
udaman_width:1.5, | ||
// fill_opacity: 0.2, | ||
// point_size :2.5, | ||
//just to store for redraw | ||
viz_data: [], | ||
}; | ||
|
||
function left_boundary() { return params.l_margin; } | ||
function right_boundary() { return params.w * params.scale - params.r_margin; } | ||
function top_boundary() { return params.t_margin; } | ||
function bottom_boundary() { return params.h * params.scale - params.b_margin; } | ||
|
||
|
||
function init_viz_element(svg, elem_with_class, data) { | ||
var elem_parts = elem_with_class.split("."); | ||
var elem = elem_parts[0]; | ||
var elem_class = elem_parts[1]; | ||
|
||
var viz_element = svg.selectAll(elem_with_class).data(data); | ||
viz_element.enter().append(elem).attr("class", elem_class); | ||
viz_element.exit().remove(); | ||
|
||
return viz_element; | ||
} | ||
|
||
function draw() { | ||
var data = [ | ||
<% @comp.sort.each do |date_string, val| %> | ||
{date: "<%=date_string %>", aremos: <%= val[:aremos].nil? ? "null" : val[:aremos] %>, udaman: <%= val[:udaman].nil? ? "null" : val[:udaman] %>}, | ||
<%end%> | ||
] | ||
//store things for next draw iteration | ||
params.viz_data = data; | ||
|
||
var max_y_val = d3.max(data, function(row) {return row.aremos > row.udaman ? row.aremos : row.udaman });// 30000; // replace with actual value from data | ||
var min_y_val = d3.min(data, function(row) {return row.aremos < row.udaman ? row.aremos : row.udaman });// 30000; // replace with actual value from data | ||
|
||
//preparing SVG Area | ||
var svg = d3.selectAll("svg"); | ||
svg. | ||
attr("height", function(d,i) {return params.h * params.scale}). | ||
attr("width", function(d) {return params.w * params.scale}). | ||
attr("fill", 'green') | ||
.data([data]); | ||
|
||
var headers = data.map(function(elem) { return elem.date }); | ||
//var categories = headers.slice(1); //alert(categories.toSource()); | ||
var first_year = d3.min(data, function(row) {return row[headers[0]]}); | ||
var last_year = d3.max(data, function(row) {return row[headers[0]]}); | ||
|
||
var x = d3.scale.ordinal().domain(headers).rangePoints([left_boundary(), right_boundary() ]); | ||
var y = d3.scale.linear().domain([min_y_val, max_y_val]).range([bottom_boundary(), top_boundary() ]); | ||
|
||
|
||
var line = init_viz_element(svg, "path.line_aremos", function(d) { return [d]; }) | ||
.attr("d", d3.svg.line() | ||
.x(function(d) { return x(d.date); }) | ||
.y(function(d) { return d.aremos === null ? y(min_y_val) : y(d.aremos); }) | ||
) | ||
.attr("stroke", params.aremos_color) | ||
.attr("fill", "none") | ||
.attr("stroke-dasharray", "10,5") | ||
.attr("stroke-width", params.aremos_width); | ||
|
||
var line = init_viz_element(svg, "path.line_udaman", function(d) { return [d]; }) | ||
.attr("d", d3.svg.line() | ||
.x(function(d) { return x(d.date); }) | ||
.y(function(d) { return d.udaman === null ? y(min_y_val) : y(d.udaman); }) | ||
) | ||
.attr("stroke", params.udaman_color) | ||
.attr("stroke-width",params.udaman_width) | ||
.attr("fill", "none"); | ||
|
||
|
||
//------ x Axis ------------------------------------------------------------------- | ||
var xaxis = init_viz_element(svg, "line.xaxis", ["dummy_data"]) | ||
.attr("y1", bottom_boundary()) | ||
.attr("y2", bottom_boundary()) | ||
.attr("x1", function(d) {return left_boundary()}) | ||
.attr("x2", function(d) {return right_boundary()}) | ||
.attr("stroke", params.x_axis_color); | ||
|
||
var xticks = init_viz_element(svg, "line.xtick", headers) | ||
.attr("y1", bottom_boundary()) | ||
.attr("y2", bottom_boundary() + params.tick_length ) | ||
.attr("x1", function(d) {return x(d)}) | ||
.attr("x2", function(d) {return x(d)}) | ||
.attr("stroke", params.x_axis_color); | ||
|
||
var xtick_labels = init_viz_element(svg, "text.xtick_label", headers) | ||
.attr("x", function(d) { return x(d)}) | ||
.attr("y", bottom_boundary()) | ||
.attr("fill", params.x_axis_fontcolor) | ||
.attr("font-size", params.x_axis_fontsize+"px") | ||
.attr("transform", function(d) {return "rotate("+params.x_axis_font_rotation +" "+ (x(d)+params.tick_length*4).toString() + "," + bottom_boundary() + ")"; }) | ||
.attr("text-anchor", "end") | ||
.text(function(d) {return d; }); | ||
|
||
//------ x Axis End ------------------------------------------------------------------- | ||
|
||
|
||
//------ y Axis ------------------------------------------------------------------- | ||
var yaxis = init_viz_element(svg, "line.yaxis", ["dummy_data"]) | ||
.attr("x1", left_boundary()) | ||
.attr("x2", left_boundary()) | ||
.attr("y1", function(d) {return top_boundary()}) | ||
.attr("y2", function(d) {return bottom_boundary()}) | ||
.attr("stroke", params.y_axis_color); | ||
|
||
var yticks = init_viz_element(svg, "line.ytick", y.ticks(10)) | ||
.attr("y1", function(d) {return y(d)}) | ||
.attr("y2", function(d) {return y(d)}) | ||
.attr("x1", left_boundary() - params.tick_length) | ||
.attr("x2", left_boundary() ) | ||
.attr("stroke", params.y_axis_color); | ||
|
||
var ytick_labels = init_viz_element(svg, "text.ytick_label", y.ticks(10)) | ||
.attr("y", function(d) { return y(d) + (params.y_axis_fontsize / 3.5)}) | ||
.attr("x", left_boundary() - params.tick_length * 1.5) | ||
.attr("fill", params.y_axis_fontcolor) | ||
.attr("font-size", params.y_axis_fontsize+"px") | ||
.attr("text-anchor", "end") | ||
.text(function(d) {return d; }); | ||
|
||
//------ y Axis End ------------------------------------------------------------------- | ||
|
||
} | ||
|
||
|
||
//all dat.gui changes should trigger a redraw | ||
// generate the dat.gui control for any numerical ranges | ||
d3.entries(dat_gui_ranges).forEach(function(elem) { | ||
var attr = elem.key; | ||
var range = elem.value; | ||
gui.add(params, attr, range[0], range[1]).onChange(draw); | ||
} ); | ||
|
||
gui.addColor(params, 'udaman_color').onChange(draw); | ||
gui.addColor(params, 'aremos_color').onChange(draw); | ||
|
||
//add color or custom controls here | ||
|
||
draw(); | ||
</script> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.