From d2ceffc7bdd29a83ea1f3236d96e36aea0cffb36 Mon Sep 17 00:00:00 2001 From: Neil Kistner Date: Fri, 3 Jul 2020 08:52:33 -0500 Subject: [PATCH] fix(scatterplot): fix canvas missing annotations layer (#1043) Close #1042 --- packages/scatterplot/src/ScatterPlotCanvas.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/scatterplot/src/ScatterPlotCanvas.js b/packages/scatterplot/src/ScatterPlotCanvas.js index 0bb444666..ea1b5e853 100644 --- a/packages/scatterplot/src/ScatterPlotCanvas.js +++ b/packages/scatterplot/src/ScatterPlotCanvas.js @@ -14,12 +14,13 @@ import { getRelativeCursor, isCursorInRect, } from '@nivo/core' +import { renderAnnotationsToCanvas } from '@nivo/annotations' import { renderAxesToCanvas, renderGridLinesToCanvas } from '@nivo/axes' import { renderLegendToCanvas } from '@nivo/legends' import { useTooltip } from '@nivo/tooltip' import { useVoronoiMesh, renderVoronoiToCanvas, renderVoronoiCellToCanvas } from '@nivo/voronoi' import { ScatterPlotCanvasPropTypes, ScatterPlotCanvasDefaultProps } from './props' -import { useScatterPlot } from './hooks' +import { useScatterPlot, useScatterPlotAnnotations } from './hooks' const ScatterPlotCanvas = props => { const { @@ -50,6 +51,8 @@ const ScatterPlotCanvas = props => { axisBottom, axisLeft, + annotations, + isInteractive, debugMesh, onMouseEnter, @@ -83,6 +86,8 @@ const ScatterPlotCanvas = props => { colors, }) + const boundAnnotations = useScatterPlotAnnotations(nodes, annotations) + const { delaunay, voronoi } = useVoronoiMesh({ points: nodes, width: innerWidth, @@ -139,6 +144,8 @@ const ScatterPlotCanvas = props => { axis: 'y', values: gridYValues, }) + } else if (layer === 'annotations') { + renderAnnotationsToCanvas(ctx, { annotations: boundAnnotations, theme }) } else if (layer === 'axes') { renderAxesToCanvas(ctx, { xScale,