$(function () {
/**
* This plugin extends Highcharts in two ways:
* - Use HTML5 canvas instead of SVG for rendering of the heatmap squares. Canvas
* outperforms SVG when it comes to thousands of single shapes.
* - Add a K-D-tree to find the nearest point on mouse move. Since we no longer have SVG shapes
* to capture mouseovers, we need another way of detecting hover points for the tooltip.
*/
(function (H) {
var wrap = H.wrap,
seriesTypes = H.seriesTypes;
/**
* Recursively builds a K-D-tree
*/
function KDTree(points, depth) {
var axis, median, length = points && points.length;
if (length) {
// alternate between the axis
axis = ['plotX', 'plotY'][depth % 2];
// sort point array
points.sort(function(a, b) {
return a[axis] - b[axis];
});
median = Math.floor(length / 2);
// build and return node
return {
point: points[median],
left: KDTree(points.slice(0, median), depth + 1),
right: KDTree(points.slice(median + 1), depth + 1)
};
}
}
/**
* Recursively searches for the nearest neighbour using the given K-D-tree
*/
function nearest(search, tree, depth) {
var point = tree.point,
axis = ['plotX', 'plotY'][depth % 2],
tdist,
sideA,
sideB,
ret = point,
nPoint1,
nPoint2;
// Get distance
point.dist = Math.pow(search.plotX - point.plotX, 2) +
Math.pow(search.plotY - point.plotY, 2);
// Pick side based on distance to splitting point
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.