Last active
August 29, 2015 14:19
-
-
Save mbaba/b8add1aeec936f57fd9d to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script> | |
<link rel="stylesheet" type="text/css" href="main.css"> | |
<title>Workplace Violence</title> | |
</head> | |
<body> | |
<div id="wrapper"> | |
<div class="text"> | |
<h1>Workplace Violence</h1> | |
</div> | |
<div class="text"> | |
<p> | |
The European Survey of Enterprises on New and Emerging Risks (ESENER) asks managers and workers" health and safety representatives about how health and safety risks are managed at their workplace, with a particular focus on the newer "psychosocial risks", such as work-related stress, violence and harassment. Data is drawn from 36,000 interviews carried out in 31 countries. Survey was cunducted in 2009. | |
</p> | |
<p> | |
Charts are showing correlation between percentage of answers <b>"Major concern"</b> to question "For each of the following issues, please tell me whether it is of major concern, some concern or no concern at all in your establishment."<br /><br /><b>Issues:</b> Work related stress, Violence or threat of violence, Bullying or harassment. | |
</p> | |
<p> | |
Data source: <a href="https://osha.europa.eu/sub/esener/en/" target="_blank">European Agency for Safety and Health at Work</a> | |
</p> | |
</div> | |
<script type="text/javascript"> | |
var tooltip = d3.select("body") | |
.append("div") | |
.attr("class", "tooltip"); | |
var w = 750; | |
var h = 600; | |
var padding = [20, 30, 45, 50]; | |
var xScale = d3.scale.linear() | |
.range([ padding[3], w - padding[1] - padding[3] ]) | |
.domain([0, 80]); | |
var yScale = d3.scale.linear() | |
.range([ padding[0], h - padding[2] ]) | |
.domain([70, 0]); | |
var xScaleRight = d3.scale.linear() | |
.range([ padding[3], w - padding[1] - padding[3] ]) | |
.domain([80, 0]); | |
var yScaleRight = d3.scale.linear() | |
.range([ padding[0], h - padding[2] ]) | |
.domain([70, 0]); | |
var xAxis = d3.svg.axis() | |
.scale(xScale) | |
.orient("bottom") | |
.ticks(10) | |
.tickFormat(function(d) { | |
return d + "%"; | |
}); | |
var yAxis = d3.svg.axis() | |
.scale(yScale) | |
.orient("left") | |
.ticks(10) | |
.tickFormat(function(d) { | |
return d + "%"; | |
}); | |
var xAxisRight = d3.svg.axis() | |
.scale(xScaleRight) | |
.orient("bottom") | |
.ticks(10) | |
.tickFormat(function(d) { | |
return d + "%"; | |
}); | |
var yAxisRight = d3.svg.axis() | |
.scale(yScaleRight) | |
.orient("right") | |
.ticks(10) | |
.tickFormat(function(d) { | |
return d + "%"; | |
}); | |
d3.select("div", "#wrapper") | |
.append("div") | |
.attr("id", "col-left1"); | |
d3.select("div", "#wrapper") | |
.append("div") | |
.attr("id", "col-right1"); | |
var svg = d3.select("#col-left1") | |
.append("svg") | |
.attr("width", w) | |
.attr("height", h); | |
var svg2 = d3.select("#col-right1") | |
.append("svg") | |
.attr("width", w) | |
.attr("height", h); | |
svg.append("text") | |
.text("Violence") | |
.attr("transform", "translate(10, " + h/2+ ") rotate(270)") | |
.attr("text-anchor", "middle") | |
.attr("class", "y label") | |
svg.append("text") | |
.text("Bullying & Harassment") | |
.attr("x", w/2) | |
.attr("y", h - 10) | |
.attr("text-anchor", "middle") | |
.attr("class", "x label") | |
svg2.append("text") | |
.text("Violence") | |
.attr("transform", "translate(" + (w - padding[1]) + " , " + h/2 + ") rotate(90)") | |
.attr("text-anchor", "middle") | |
.attr("class", "y label") | |
svg2.append("text") | |
.text("Work Related Stress") | |
.attr("x", w/2) | |
.attr("y", h - 10) | |
.attr("text-anchor", "middle") | |
.attr("class", "x label") | |
//violence + bullying_harassment | |
d3.csv("psychosocial_risk_major_concerns.csv", function(data) { | |
console.log(data); | |
var circles = svg.selectAll("circle") | |
.data(data) | |
.enter() | |
.append("circle"); | |
circles.attr("cx", padding[3]) | |
.attr("cy", h - padding[2]) | |
.attr("r", 0.1) | |
circles.sort(function(a, b) { | |
return d3.ascending(+a.bullying_harassment, +b.bullying_harassment); | |
}) | |
.transition() | |
.delay(function(d, i) { | |
return i * 25; | |
}) | |
.duration(750) | |
.attr("cx", function(d) { | |
return xScale(d.bullying_harassment); | |
}) | |
.attr("cy", function(d) { | |
return yScale(d.violence); | |
}) | |
.attr("r", 5); | |
circles.on("mouseover", function(d) { | |
d3.select(this) | |
.classed("hover", true) | |
.transition() | |
.attr("r", 8) | |
tooltip = d3.select(".tooltip"); | |
tooltip.html('<span class="country">' + d.country + '</span>' + '<br />' + 'Violence - ' + d.violence + '%' + '<br />' + 'Bullying & Harassment - ' + d.bullying_harassment + '%') | |
.style("top", d3.event.pageY - 12 + "px") | |
.style("opacity", 0.9) | |
}) | |
circles.on("mouseout", function() { | |
d3.select(this) | |
.classed("hover", false) | |
.transition() | |
.attr("r", 5) | |
tooltip.style("opacity", 0) | |
}) | |
circles.on("mousemove", function (d) { | |
var tool_width = d3.select(".tooltip").node().getBoundingClientRect().width; | |
if(d3.event.pageX > (w - tool_width)) { | |
tooltip.style("left", d3.event.pageX - tool_width - 12 + "px") | |
} else { | |
tooltip.style("left", d3.event.pageX + 12 + "px") | |
} | |
}) | |
svg.append("g") | |
.attr("class", "x axis") | |
.attr("transform", "translate(0," + (h - padding[2]) + ")") | |
.call(xAxis); | |
svg.append("g") | |
.attr("class", "y axis") | |
.attr("transform", "translate(" + (padding[3]) + ",0)") | |
.call(yAxis); | |
//violence + work_related_stress | |
var circles2 = svg2.selectAll("circle") | |
.data(data) | |
.enter() | |
.append("circle"); | |
circles2.attr("cx", w- padding[1]) | |
.attr("cy", h - padding[2]) | |
.attr("r", 0.1); | |
circles2.sort(function(a, b) { | |
return d3.ascending(+a.work_related_stress, +b.work_related_stress); | |
}) | |
.transition() | |
.delay(function(d, i) { | |
return i * 25; | |
}) | |
.duration(750) | |
.attr("cx", function(d) { | |
return xScaleRight(d.work_related_stress); | |
}) | |
.attr("cy", function(d) { | |
return yScaleRight(d.violence); | |
}) | |
.attr("r", 5); | |
circles2.on("mouseover", function(d) { | |
d3.select(this) | |
.classed("hover", true) | |
.transition() | |
.attr("r", 8) | |
tooltip = d3.select(".tooltip"); | |
tooltip.html('<span class="country">' + d.country + '</span>' + '<br />' + 'Violence - ' + d.violence + '%' + '<br />' + 'Work Related Stress - ' + d.work_related_stress + '%') | |
.style("top", d3.event.pageY - 12 + "px") | |
.style("opacity", 0.9) | |
}) | |
circles2.on("mouseout", function() { | |
d3.select(this) | |
.classed("hover", false) | |
.transition() | |
.attr("r", 5) | |
tooltip.style("opacity", 0) | |
}) | |
circles2.on("mousemove", function (d) { | |
var tool_width = d3.select(".tooltip").node().getBoundingClientRect().width; | |
if(d3.event.pageX > (w - tool_width)) { | |
tooltip.style("left", d3.event.pageX - tool_width - 12 + "px") | |
} else { | |
tooltip.style("left", d3.event.pageX + 12 + "px") | |
} | |
}) | |
svg2.append("g") | |
.attr("class", "x axis") | |
.attr("transform", "translate(0," + (h - padding[2]) + ")") | |
.call(xAxisRight); | |
svg2.append("g") | |
.attr("class", "y axis") | |
.attr("transform", "translate(" + (w - padding[3] - padding[1]) + ",0)") | |
.call(yAxisRight); | |
}); | |
</script> | |
</div> | |
</body> | |
</html> |
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
body { | |
background-color: #d2d0cc; | |
font-family: Helvetica, Arial, sans-serif; | |
font-size: 16px; | |
} | |
h1 { | |
font-size: 28px; | |
font-weight: bold; | |
font-variant: small-caps; | |
text-align: center; | |
line-height: 14px; | |
color: dimgrey; | |
} | |
a { | |
text-decoration: none; | |
} | |
a:link, a:visited { | |
color: dimgrey; | |
border-bottom: 2px dotted dimgrey; | |
} | |
a:hover { | |
color: #ffc04c; | |
border-bottom: 2px dotted #ffc04c; | |
} | |
.chart-title { | |
font-size: 20px; | |
font-weight: bold; | |
font-variant: small-caps; | |
letter-spacing: 2px; | |
padding-top: 5px; | |
padding-bottom: 5px; | |
text-align: center; | |
color: dimgrey; | |
} | |
.text { | |
padding: 1px 1%; | |
margin-left: 1%; | |
margin-right: 1%; | |
margin-bottom: 25px; | |
background-color: #ededeb; | |
} | |
.axis path, .axis line { | |
fill: none; | |
stroke: dimgrey; | |
shape-rendering: crispEdges; | |
} | |
.axis text, .label { | |
font-family: Helvetica, Arial, sans-serif; | |
font-size: 11px; | |
fill: dimgrey; | |
} | |
.label { | |
font-family: Helvetica, Arial, sans-serif; | |
font-size: 12px; | |
font-weight: bold; | |
letter-spacing: 2px; | |
fill: dimgrey; | |
} | |
#wrapper { | |
width: 85%; | |
height: 100%; | |
margin: 0 auto; | |
position: relative; | |
} | |
#col-left1, #col-left2, #col-left3, #col-left4, #col-left5, #col-right1, #col-right2, #col-right3, #col-right4, #col-right5 { | |
margin-bottom: 25px; | |
padding-left: 1%; | |
padding-bottom: 1%; | |
width: 47%; | |
background-color: #ededeb; | |
} | |
#col-left1, #col-left2, #col-left3, #col-left4, #col-left5 { | |
float: left; | |
margin-left: 1%; | |
} | |
#col-right1, #col-right2, #col-right3, #col-right4, #col-right5 { | |
float: right; | |
margin-right: 1% | |
} | |
#container { | |
float: left; | |
width: 96%; | |
padding: 1px 1%; | |
margin-left: 1%; | |
margin-right: 1%; | |
margin-bottom: 25px; | |
background-color: #ededeb; | |
text-align: center; | |
} | |
svg { | |
fill: #ff7b00; | |
} | |
/*ToolTip*/ | |
.tooltip { | |
padding: 3px; | |
background-color: #d2d0cc; | |
border-radius: 4px; | |
position: absolute; | |
font-size: 11px; | |
line-height: 14px; | |
opacity: 0; | |
} | |
.country { | |
font-weight: bold; | |
font-size: 11px; | |
} | |
.hover { | |
cursor: crosshair; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment