Skip to content

Instantly share code, notes, and snippets.

@tslumley
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tslumley/9d6265ad35cc9b0f125b to your computer and use it in GitHub Desktop.
Save tslumley/9d6265ad35cc9b0f125b to your computer and use it in GitHub Desktop.
Electorate candidate donations, all parties, 2014

Election donations, New Zealand, 2014.

Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<head>
All parties
</head>
<body>
<h3>Donations to electorate candidates, 2014</h3>
<p>Area is proportional to money, with the same scale across all maps. The inset map is the Māori electorates</p>
<p>Click for full-size versions with mouseover electorate names</p>
<h3>All parties</h3>
<a href="http://bl.ocks.org/tslumley/raw/9d6265ad35cc9b0f125b/allparties.svg"><img src="allparties.svg" type="image/svg+xml" height="300px"></a>
<h3>Shaded by margin of victory</h3>
<a href="http://bl.ocks.org/tslumley/raw/9d6265ad35cc9b0f125b/margins.svg"><img src="margins.svg" type="image/svg+xml" height="300px"></a>
<h3>Parties</h3>
<p>National</p> <a href="http://bl.ocks.org/tslumley/raw/9d6265ad35cc9b0f125b/national.svg"><img src="national.svg" type="image/svg+xml" height="300px"></a>
<p>Labour</p>
<a href="http://bl.ocks.org/tslumley/raw/9d6265ad35cc9b0f125b/labour.svg"><img src="labour.svg" type="image/svg+xml" height="300px"></a>
<p>Green Party</p>
<a href="http://bl.ocks.org/tslumley/raw/9d6265ad35cc9b0f125b/greens.svg"><img src="greens.svg" type="image/svg+xml" height="300px"></a>
<p>New Zealand First</p>
<a href="http://bl.ocks.org/tslumley/raw/9d6265ad35cc9b0f125b/nzfirst.svg"><img src="nzfirst.svg" type="image/svg+xml" height="300px"></a>
<p>ACT</p>
<a href="http://bl.ocks.org/tslumley/raw/9d6265ad35cc9b0f125b/act.svg"><img src="act.svg" type="image/svg+xml" height="300px"></a>
<p>Conservative Party</p>
<a href="http://bl.ocks.org/tslumley/raw/9d6265ad35cc9b0f125b/conservative.svg"><img src="conservative.svg" type="image/svg+xml" height="300px"></a>
<p>Internet Mana Party</p>
<a href="http://bl.ocks.org/tslumley/raw/9d6265ad35cc9b0f125b/imp.svg"><img src="imp.svg" type="image/svg+xml" height="300px"></a>
<p>Data from NZ Herald, layout from <a href="http://hindsight.clerestories.com/2014/01/06/chris-mcdowall-hexagonal-maps/">Chris McDowall</a>
modified by <a href="https://a3995c31ebd7ea534f2bb73d7af5d1ab1163a570.googledrive.com/host/0B-6BcF0gNMHCWjBYMm9jSmxlMTg/">David Friggens</a></p>
</body>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
var showTooltip = function(evt, label) {
// Getting rid of any existing tooltips
hideTooltip();
var svgNS = "http://www.w3.org/2000/svg";
var target = evt.currentTarget;
// Create new text node, rect and text for the tooltip
var content = document.createTextNode(label);
var text = document.createElementNS(svgNS, "text");
text.setAttribute("id", "tooltipText");
// Resetting some style attributes
text.setAttribute("font-size", "16px");
text.setAttribute("fill", "black");
text.setAttribute("stroke-width", "0");
text.appendChild(content);
var rect = document.createElementNS(svgNS, "rect");
rect.setAttribute("id", "tooltipRect");
// Add rect and text to the bottom of the document.
// This is because SVG has a rendering order.
// We want the tooltip to be on top, therefore inserting last.
var wrappingGroup = document.getElementsByTagName("g")[0];
wrappingGroup.appendChild(rect);
wrappingGroup.appendChild(text);
// Transforming the mouse location to the SVG coordinate system
// Snippet lifted from: http://tech.groups.yahoo.com/group/svg-developers/message/52701
var m = target.getScreenCTM();
var p = document.documentElement.createSVGPoint();
p.x = evt.clientX;
p.y = evt.clientY;
p = p.matrixTransform(m.inverse());
// Determine position for tooltip based on location of
// element that mouse is over
// AND size of text label
// Currently the tooltip is offset by (-3, 0)
var tooltipx = p.x - text.getBBox().width/2;
var tooltiplabx = tooltipx + 5;
var tooltipy = p.y + 0;
var tooltiplaby = tooltipy + 5;
// Position tooltip rect and text
text.setAttribute("transform",
"translate(" + tooltiplabx + ", " + tooltiplaby + ") " +
"scale(1, -1)");
rect.setAttribute("x", tooltipx);
rect.setAttribute("y", tooltipy);
rect.setAttribute("width", text.getBBox().width + 10);
rect.setAttribute("height", text.getBBox().height + 5);
rect.setAttribute("stroke", "white");
rect.setAttribute("fill", "white");
};
var hideTooltip = function() {
// Remove tooltip text and rect
var text = document.getElementById("tooltipText");
var rect = document.getElementById("tooltipRect");
if (text && rect) {
text.parentNode.removeChild(text);
rect.parentNode.removeChild(rect);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment