canvas-heatmap
Advanced tools
Comparing version 1.2.8 to 1.2.9
{ | ||
"name": "canvas-heatmap", | ||
"version": "1.2.8", | ||
"version": "1.2.9", | ||
"description": "Interactive heatmap, capable of displaying 1,000,000+ data points using canvas and d3. ", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -12,4 +12,6 @@ import { | ||
zoomIdentity, | ||
range, | ||
zoom as d3zoom, | ||
} from "d3"; | ||
import { contours } from "d3-contour"; | ||
import { | ||
@@ -72,10 +74,10 @@ verifyString, | ||
var nullData; | ||
var prepContours; | ||
if (options.contour) { | ||
contour = options.autoDownsample | ||
? data.map((d) => autoDownSample(d, options.autoDownsample)) | ||
: data; | ||
nullData = replaceNull(data, options.zMax); | ||
prepContours = prepareContours(data, nullData, zDomain, options); | ||
} | ||
if (options.contour && options.autoDownsample) { | ||
contour = data.map((d) => autoDownSample(d, options.autoDownsample)); | ||
} else { | ||
contour = data; | ||
} | ||
@@ -86,3 +88,3 @@ var { zoombox } = addZoom( | ||
contour, | ||
nullData, | ||
prepContours, | ||
div, | ||
@@ -118,6 +120,5 @@ xAxis, | ||
yAxis.ax, | ||
zDomain, | ||
context, | ||
options, | ||
nullData | ||
prepContours | ||
); | ||
@@ -141,2 +142,27 @@ } else { | ||
const prepareContours = (data, nullData, zDomain, options) => { | ||
var thresholds = range( | ||
zDomain[0], | ||
zDomain[1], | ||
(zDomain[1] - zDomain[0]) / options.thresholdStep | ||
); | ||
var baseContour = []; | ||
var mainContour = []; | ||
var nanContour = []; | ||
for (var i = 0; i < data.length; i++) { | ||
let cr = contours() | ||
.size([data[i].z[0].length, data[i].z.length]) | ||
.smooth(false); | ||
let c = contours().size([data[i].z[0].length, data[i].z.length]); | ||
let values = data[i].z.flat(); | ||
let nullValues = nullData[i].z.flat(); | ||
baseContour.push(cr.thresholds(thresholds)(values)[0]); | ||
mainContour.push(c.thresholds(thresholds)(values)); | ||
nanContour.push(cr.thresholds([options.zMax * 10])(nullValues)[0]); | ||
} | ||
return { baseContour, mainContour, nanContour }; | ||
}; | ||
const replaceNull = (data, zMax) => { | ||
@@ -668,3 +694,3 @@ var nullData = JSON.parse(JSON.stringify(data)); | ||
contour, | ||
nullData, | ||
prepContours, | ||
div, | ||
@@ -747,6 +773,5 @@ xAxis, | ||
yAxis.ax, | ||
zDomain, | ||
context, | ||
options, | ||
nullData | ||
prepContours | ||
); | ||
@@ -782,6 +807,5 @@ } else { | ||
yAxis.ax, | ||
zDomain, | ||
context, | ||
options, | ||
nullData | ||
prepContours | ||
); | ||
@@ -816,6 +840,5 @@ } else { | ||
yAxis.ax, | ||
zDomain, | ||
context, | ||
options, | ||
nullData | ||
prepContours | ||
); | ||
@@ -853,6 +876,5 @@ } else { | ||
yAxis.ax, | ||
zDomain, | ||
context, | ||
options, | ||
nullData | ||
prepContours | ||
); | ||
@@ -859,0 +881,0 @@ } else { |
@@ -1,3 +0,1 @@ | ||
import { range } from "d3"; | ||
import { contours } from "d3-contour"; | ||
import { getRGBAColor, indexOfClosest } from "./functions"; | ||
@@ -41,6 +39,5 @@ | ||
scaleY, | ||
zDomain, | ||
context, | ||
options, | ||
nullData | ||
prepContours | ||
) => { | ||
@@ -50,24 +47,9 @@ const colorScale = (v) => { | ||
}; | ||
var thresholds = range( | ||
zDomain[0], | ||
zDomain[1], | ||
(zDomain[1] - zDomain[0]) / options.thresholdStep | ||
); | ||
for (var i = 0; i < data.length; i++) { | ||
let cr = contours() | ||
.size([data[i].z[0].length, data[i].z.length]) | ||
.smooth(false); | ||
let c = contours().size([data[i].z[0].length, data[i].z.length]); | ||
let values = data[i].z.flat(); | ||
let nullValues = nullData[i].z.flat(); | ||
fill(c.thresholds(thresholds)(values)[0], data[i], false); | ||
c.thresholds(thresholds)(values).forEach((contour, index) => { | ||
fill(prepContours.baseContour[i], data[i], false); | ||
prepContours.mainContour[i].forEach((contour, index) => { | ||
if (index !== 0) fill(contour, data[i], false); | ||
}); | ||
fill( | ||
cr.thresholds([options.zMax * 10])(nullValues)[0], | ||
data[i], | ||
[255, 255, 255] | ||
); | ||
fill(prepContours.nanContour[i], data[i], [255, 255, 255]); | ||
} | ||
@@ -74,0 +56,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
904756
7580