{"id":15760523,"url":"https://github.com/caldwellc/d3-brush-tooltip","last_synced_at":"2026-01-18T22:33:05.840Z","repository":{"id":249272009,"uuid":"831014500","full_name":"caldwellc/d3-brush-tooltip","owner":"caldwellc","description":"Tooltip to display when hovering over a d3 brush selection","archived":false,"fork":false,"pushed_at":"2024-08-06T11:35:18.000Z","size":72,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-26T15:44:58.945Z","etag":null,"topics":["brush","d3","d3-js","d3js","popover","tooltip","tooltips"],"latest_commit_sha":null,"homepage":"https://caldwellc.github.io/d3-brush-tooltip/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/caldwellc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-19T13:13:24.000Z","updated_at":"2024-08-06T11:34:48.000Z","dependencies_parsed_at":"2024-10-25T13:55:13.660Z","dependency_job_id":null,"html_url":"https://github.com/caldwellc/d3-brush-tooltip","commit_stats":null,"previous_names":["caldwellc/d3-brush-tooltip"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/caldwellc/d3-brush-tooltip","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caldwellc%2Fd3-brush-tooltip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caldwellc%2Fd3-brush-tooltip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caldwellc%2Fd3-brush-tooltip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caldwellc%2Fd3-brush-tooltip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caldwellc","download_url":"https://codeload.github.com/caldwellc/d3-brush-tooltip/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caldwellc%2Fd3-brush-tooltip/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28552785,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T20:59:07.572Z","status":"ssl_error","status_checked_at":"2026-01-18T20:59:02.799Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["brush","d3","d3-js","d3js","popover","tooltip","tooltips"],"created_at":"2024-10-04T10:58:32.957Z","updated_at":"2026-01-18T22:33:05.819Z","avatar_url":"https://github.com/caldwellc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# d3-brush-tooltip\n\nLibrary for adding a tooltip to a [d3 brush](https://github.com/d3/d3-brush).\n\n[![npm version](https://badge.fury.io/js/d3-brush-tooltip.svg)](https://badge.fury.io/js/d3-brush-tooltip)\n\n\n# Example\n[See it in action here](https://caldwellc.github.io/d3-brush-tooltip/)\n\n![Tooltip Example](https://github.com/caldwellc/d3-brush-tooltip/blob/main/tooltip-example.jpg?raw=true)\n\n# add to d3 brush in browser\n\nAdding the tooltip to a d3 brush requires importing the library and providing a bit of css. Below you will find a sample html file and sample style for the label, which allows for it to be positioned alongside the cursor.\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/d3@7\"\u003e\u003c/script\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/d3-brush-tooltip@1.0.1\"\u003e\u003c/script\u003e\n\u003clink rel=\"stylesheet\" href=\"css/style.css\"\u003e\n\u003chtml\u003e\n    \u003cbody\u003e\n        \u003cdiv id=\"chart-div\"\u003e\n            \u003cdiv id=\"tooltip\" class=\"tooltip-default\"/\u003e\n        \u003c/div\u003e\n        \u003cscript\u003e\n            // create chart\n            let width = 600;\n            let height = 400;\n\n            const margin = { top: 10, right: 30, bottom: 30, left: 40 };\n            width = width - margin.left - margin.right,\n            height = height - margin.top - margin.bottom;\n\n            // append the svg object to the body of the page\n            var svg = d3.select(\"#chart-div\")\n                .append(\"svg\")\n                .attr(\"width\", width + margin.left + margin.right)\n                .attr(\"height\", height + margin.top + margin.bottom)\n                .append(\"g\")\n                .attr(\"transform\",\n                    \"translate(\" + margin.left + \",\" + margin.top + \")\");\n\n            const maxX = 1000;\n\n            // add x axis\n            const x = d3.scaleLinear()\n                .domain([0, maxX])\n                .range([0, width]);\n\n            svg.append(\"g\")\n                .attr(\"transform\", \"translate(0,\" + height + \")\")\n                .call(d3.axisBottom(x));\n\n            // generate random data\n            const data = [];\n            for (let i = 0; i \u003c 1000; i++) {\n              data.push(Math.random() * maxX);\n            }\n\n            // create bins\n            const bin = d3.bin()\n                .domain(x.domain())\n                .thresholds(x.ticks(20));\n\n            const bins = bin(data);\n\n            // add y axis\n            const y = d3.scaleLinear()\n                .domain([0, d3.max(bins, function (d) { return d.length; })])\n                .range([height, 0]);\n\n            svg.append(\"g\")\n                .call(d3.axisLeft(y));\n\n            // append the bar rectangles to the svg element\n            svg.selectAll(\"rect\")\n                .data(bins)\n                .enter()\n                .append(\"rect\")\n                .attr(\"x\", 1)\n                .attr(\"transform\", function (d) { return \"translate(\" + x(d.x0) + \",\" + y(d.length) + \")\"; })\n                .attr(\"width\", function (d) { return Math.max(0, x(d.x1) - x(d.x0) - 1); })\n                .attr(\"height\", function (d) { return height - y(d.length); })\n                .style(\"fill\", \"#69b3a2\")\n\n            // add a brush container to the chart\n            const brushContainer = svg.append(\"g\");\n\n            // create the brush\n            const brush = d3.brushX().extent([[0, 0], [width, height]]);\n            brushContainer.call(brush);\n\n            // move brush to the initial position\n            const initialSelection = [x(100), x(200)];\n            brushContainer.call(brush.move, initialSelection);\n\n            const tooltipId = \"#tooltip\";\n\n            // function that takes a selection and provides the count of records within those bounds\n            function getTooltipText(selection) {\n                if (selection) {\n                    const min = Math.round(x.invert(selection[0]));\n                    const max = Math.round(x.invert(selection[1]));\n                    const count = data.filter(value =\u003e value \u003e= min \u0026\u0026 value \u003c= max).length;\n                    return `${min} - ${max}: ${count} records`;\n                } else {\n                    return null;\n                }\n            }\n\n            // add tooltip to the brush\n            window.d3BrushTooltip.addTooltipToBrush(tooltipId, brush, brushContainer, (brushEvent) =\u003e {\n                const selection = brushEvent.selection;\n                return getTooltipText(selection);\n            }, getTooltipText(initialSelection));\n        \u003c/script\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\n```css\n.tooltip-default {\n    opacity: 1;\n    background-color: white;\n    border: solid 1px black;\n    padding: 4px;\n    border-radius: 4px;\n    white-space: nowrap;\n    pointer-events: none;\n    display: none;\n    z-index: 2;\n    user-select: none;\n    position: fixed;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaldwellc%2Fd3-brush-tooltip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaldwellc%2Fd3-brush-tooltip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaldwellc%2Fd3-brush-tooltip/lists"}