{"id":15882509,"url":"https://github.com/another-guy/use-d3","last_synced_at":"2026-01-16T00:23:36.559Z","repository":{"id":40765629,"uuid":"270270563","full_name":"another-guy/use-d3","owner":"another-guy","description":"React hooks for D3.js data visualization library.","archived":false,"fork":false,"pushed_at":"2023-01-06T08:12:11.000Z","size":1041,"stargazers_count":0,"open_issues_count":12,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-28T14:03:18.375Z","etag":null,"topics":["d3","d3js","d3js-hook","d3js-hooks","data-visualization","data-viz","react","react-hook","react-hooks","reactjs"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/another-guy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":"FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"ko_fi":"anotherguy","patreon":"another_guy","custom":["https://www.paypal.me/IgorSoloydenko"]}},"created_at":"2020-06-07T10:28:26.000Z","updated_at":"2020-06-08T04:01:57.000Z","dependencies_parsed_at":"2023-02-05T16:45:41.204Z","dependency_job_id":null,"html_url":"https://github.com/another-guy/use-d3","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/another-guy/use-d3","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/another-guy%2Fuse-d3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/another-guy%2Fuse-d3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/another-guy%2Fuse-d3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/another-guy%2Fuse-d3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/another-guy","download_url":"https://codeload.github.com/another-guy/use-d3/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/another-guy%2Fuse-d3/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28474501,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T00:15:39.755Z","status":"ssl_error","status_checked_at":"2026-01-16T00:15:32.174Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["d3","d3js","d3js-hook","d3js-hooks","data-visualization","data-viz","react","react-hook","react-hooks","reactjs"],"created_at":"2024-10-06T04:04:08.979Z","updated_at":"2026-01-16T00:23:36.545Z","avatar_url":"https://github.com/another-guy.png","language":"TypeScript","funding_links":["https://ko-fi.com/anotherguy","https://patreon.com/another_guy","https://www.paypal.me/IgorSoloydenko"],"categories":[],"sub_categories":[],"readme":"# `use-d3`\n\nReact hooks for D3.js data visualization library.\n\nPlease make sure to follow our [Code of Conduct](./CODE_OF_CONDUCT.md). \n\nCode of `use-d3` and the package are distributed under [MIT License](./LICENSE) terms.\n\n\n## Installation\n\n| yarn              | npm                         |\n| ----------------- | --------------------------- |\n| `yarn add use-d3` | `npm install --save use-d3` |\n\n## Usage\n\n### `useSelectionWithData` hook\n\nRenders static or dynamic data by mapping data points into SVG DOM elements.\n\n#### Parameters\n\n* `svgRef` — ref object corresponding to the SVG-container.\n* `svgTag` — valid SVG tag to render for each data point.\n* `cssClassName` — CSS class to apply to each generated SVG tag. **IMPORTANT:** this class has to be unique among all calls of any `use-d3` hooks!\n* `data` — array with the data points to map into svg tags.\n* `plotImplementation` — code that consumes the generated D3 selection and assigns new attributes to each generated SVG tag.\n\n#### Example\n\n```tsx\nimport { useSelectionWithData } from 'use-d3';\n\nexport const TestComponent: React.FC\u003c{}\u003e = props =\u003e {\n  const svgRef: React.RefObject\u003cSVGSVGElement\u003e = useRef(null);\n  const data = [1, 4, 9, 16, 25];\n\n  useSelectionWithData(\n    svgRef,\n    'text',\n    'data-point',\n    data,\n    selection =\u003e selection\n      .attr('x', d =\u003e 0)\n      .attr('y', (d, i) =\u003e 15 * (i + 1))\n      .attr('width', d =\u003e d * 10)\n      .attr('height', 10)\n      .attr('fill', 'red'),\n      // [ data.length ]  \u003c-- Any additional dependencies besides `data`\n      //                      whose changes should result in an update/re-render.\n  );\n\n  return (\u003csvg ref={svgRef} viewBox=\"0 0 -100 100\" width=\"350\" height=\"100\" /\u003e);\n};\n```\n\nRendered result DOM.\n\n```html\n\u003csvg viewBox=\"0 0 -100 100\" width=\"350\" height=\"100\"\u003e\n  \u003crect class=\"data-point\" x=\"0\" y=\"15\" width=\"10\" height=\"10\" fill=\"red\" /\u003e\n  \u003crect class=\"data-point\" x=\"0\" y=\"30\" width=\"40\" height=\"10\" fill=\"red\" /\u003e\n  \u003crect class=\"data-point\" x=\"0\" y=\"45\" width=\"90\" height=\"10\" fill=\"red\" /\u003e\n  \u003crect class=\"data-point\" x=\"0\" y=\"60\" width=\"160\" height=\"10\" fill=\"red\" /\u003e\n  \u003crect class=\"data-point\" x=\"0\" y=\"75\" width=\"250\" height=\"10\" fill=\"red\" /\u003e\n\u003c/svg\u003e\n```\n\nAppearance of the rendered HTML.\n\n![use-selection-with-data](docs/use-selection-with-data.png)\n\n### `useSelectionWithoutData` hook\n\nConsumes a D3 selection exactly once without implicitly generating any SVG DOM elements.\n\nThis is useful in scenarios like creation of unique reusable definitions which don't depend on any data.\n\n#### Parameters\n\n* `svgRef` — ref object corresponding to the SVG-container.\n* `plotImplementation` — code that consumes the generated D3 selection.\n\n#### Example\n\n```tsx\nimport { useSelectionWithoutData } from 'use-d3';\n\nexport const TestComponent: React.FC\u003c{}\u003e = props =\u003e {\n  const svgRef: React.RefObject\u003cSVGSVGElement\u003e = useRef(null);\n  useSelectionWithoutData(\n    svgRef,\n    svg =\u003e {\n      const defs = select(svg).append('defs');\n      defs\n        .append('pattern')\n        .attr('id', 'HashLine')\n        .attr('width', '3')\n        .attr('height', '3')\n        .attr('patternUnits', 'userSpaceOnUse')\n        .attr('patternTransform', 'rotate(37)')\n        .append('rect')\n        .attr('width', '1.5')\n        .attr('height', '3')\n        .attr('transform', 'translate(0,0)')\n        .attr('fill', 'silver');\n    }\n  );\n  return (\u003csvg ref={svgRef} viewBox=\"0 0 -100 100\" width=\"350\" height=\"100\" /\u003e);\n};\n```\n\nRendered result DOM.\n\n```html\n\u003csvg viewBox=\"0 0 -100 100\" width=\"350\" height=\"100\"\u003e\n  \u003cdefs\u003e\n    \u003cpattern id=\"HashLine\" width=\"3\" height=\"3\" patternUnits=\"userSpaceOnUse\" patternTransform=\"rotate(37)\"\u003e\n      \u003crect width=\"1.5\" height=\"3\" transform=\"translate(0,0)\" fill=\"silver\" /\u003e\n    \u003c/pattern\u003e\n  \u003c/defs\u003e\n\u003c/svg\u003e\n```\n\nWhen the pattern is used in a `\u003crect\u003e` tag like this\n\n```html\n\u003crect x=\"0\" y=\"0\" width=\"100\" height=\"100\" fill=\"url(#HashLine)\" /\u003e\n```\n\nthe result rectangle appears shaded.\n\n![use-selection-without-data](./docs/use-selection-without-data.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanother-guy%2Fuse-d3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanother-guy%2Fuse-d3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanother-guy%2Fuse-d3/lists"}