How to use the @nivo/core.getRelativeCursor function in @nivo/core

To help you get started, we’ve selected a few @nivo/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github plouc / nivo / packages / treemap / src / TreeMapCanvas.js View on Github external
handleClick = event => {
        const { isInteractive, nodes, margin, onClick } = this.props

        if (!isInteractive) return

        const [x, y] = getRelativeCursor(this.surface, event)

        const node = findNodeUnderCursor(nodes, margin, x, y)
        if (node !== undefined) onClick(node, event)
    }
github plouc / nivo / packages / geo / src / ChoroplethCanvas.js View on Github external
const getFeatureFromMouseEvent = (event, el, features, projection) => {
    const [x, y] = getRelativeCursor(el, event)

    return features.find(f => geoContains(f, projection.invert([x, y])))
}
github plouc / nivo / packages / swarmplot / src / SwarmPlotCanvas.js View on Github external
event => {
                const [x, y] = getRelativeCursor(canvasEl.current, event)
                if (!isCursorInRect(margin.left, margin.top, innerWidth, innerHeight, x, y))
                    return null

                const nodeIndex = delaunay.find(x - margin.left, y - margin.top)
                return nodes[nodeIndex]
            },
            [canvasEl, margin, innerWidth, innerHeight, delaunay]
github plouc / nivo / packages / scatterplot / src / ScatterPlotCanvas.js View on Github external
event => {
            const [x, y] = getRelativeCursor(canvasEl.current, event)
            if (!isCursorInRect(margin.left, margin.top, innerWidth, innerHeight, x, y)) return null

            const nodeIndex = delaunay.find(x - margin.left, y - margin.top)
            return nodes[nodeIndex]
        },
        [canvasEl, margin, innerWidth, innerHeight, delaunay]
github plouc / nivo / packages / voronoi / src / Mesh.js View on Github external
event => {
            const [x, y] = getRelativeCursor(elementRef.current, event)
            const index = delaunay.find(x, y)

            return [index, index !== undefined ? nodes[index] : null]
        },
        [delaunay]
github plouc / nivo / packages / nivo-waffle / src / WaffleCanvas.js View on Github external
handleMouseHover = (showTooltip, hideTooltip) => event => {
        const {
            isInteractive,
            margin,
            theme,
            cells,
            cellSize,
            origin,
            tooltipFormat,
            tooltip,
        } = this.props

        if (!isInteractive || !cells) return

        const [x, y] = getRelativeCursor(this.surface, event)
        const cell = findCellUnderCursor(cells, cellSize, origin, margin, x, y)

        if (cell !== undefined && cell.data) {
            showTooltip(
                ,
                event
            )
github plouc / nivo / packages / pie / src / PieCanvasRenderer.js View on Github external
getArcFromMouse = event => {
        const [x, y] = getRelativeCursor(this.surface, event)
        const { centerX, centerY, margin, radius, innerRadius, arcs } = this.props

        return getHoveredArc(
            margin.left + centerX,
            margin.top + centerY,
            radius,
            innerRadius,
            arcs,
            x,
            y
        )
    }
github plouc / nivo / packages / heatmap / src / HeatMapCanvas.js View on Github external
handleMouseHover = (showTooltip, hideTooltip, event) => {
        if (!this.nodes) return

        const [x, y] = getRelativeCursor(this.surface, event)

        const { margin, offsetX, offsetY, theme, setCurrentNode, tooltip } = this.props
        const node = this.nodes.find(node =>
            isCursorInRect(
                node.x + margin.left + offsetX - node.width / 2,
                node.y + margin.top + offsetY - node.height / 2,
                node.width,
                node.height,
                x,
                y
            )
        )

        if (node !== undefined) {
            setCurrentNode(node)
            showTooltip(, event)
github plouc / nivo / packages / nivo-treemap / src / TreeMapCanvas.js View on Github external
handleClick = event => {
        const { isInteractive, nodes, margin, onClick } = this.props

        if (!isInteractive) return

        const [x, y] = getRelativeCursor(this.surface, event)

        const node = findNodeUnderCursor(nodes, margin, x, y)
        if (node !== undefined) onClick(node, event)
    }
github plouc / nivo / packages / geo / src / GeoMapCanvas.js View on Github external
const getFeatureFromMouseEvent = (event, el, features, projection) => {
    const [x, y] = getRelativeCursor(el, event)

    return features.find(f => geoContains(f, projection.invert([x, y])))
}