{"id":13990019,"url":"https://github.com/Olical/d3-react","last_synced_at":"2025-07-22T11:32:39.187Z","repository":{"id":66128235,"uuid":"41478173","full_name":"Olical/d3-react","owner":"Olical","description":"Render React elements with D3","archived":false,"fork":false,"pushed_at":"2016-06-08T10:23:24.000Z","size":12,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-16T16:20:04.625Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://lab.oli.me.uk/d3-to-react/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Olical.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-08-27T09:35:17.000Z","updated_at":"2019-08-18T16:50:35.000Z","dependencies_parsed_at":"2023-02-21T20:30:45.810Z","dependency_job_id":null,"html_url":"https://github.com/Olical/d3-react","commit_stats":{"total_commits":16,"total_committers":2,"mean_commits":8.0,"dds":0.375,"last_synced_commit":"58296dd04cb2853e5299ef28237b0e73bc2d14f6"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Olical%2Fd3-react","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Olical%2Fd3-react/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Olical%2Fd3-react/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Olical%2Fd3-react/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Olical","download_url":"https://codeload.github.com/Olical/d3-react/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227089500,"owners_count":17729476,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-08-09T13:02:16.802Z","updated_at":"2024-11-29T09:30:42.851Z","avatar_url":"https://github.com/Olical.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# d3-react [![npm version](https://badge.fury.io/js/d3-react.svg)](http://badge.fury.io/js/d3-react) [![Build Status](https://travis-ci.org/Olical/d3-react.svg?branch=master)](https://travis-ci.org/Olical/d3-react) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)\n\n# WARNING: Deprecated in favour of [react-faux-dom][], my other (better) approach to using D3 with React.\n\nRender [React][] elements with [D3][] declaratively and without state, as it should be.\n\n## Usage\n\nThis plugin essentially allows you to use D3 as your React render function without letting D3 mutate any existing DOM. You build the entire result from scratch on each render and then let React reconcile the DOM / SVG. Here's a simple chart built with the plugin.\n\n```javascript\nvar Graph = React.createClass({\n  propTypes: {\n    data: React.PropTypes.arrayOf(React.PropTypes.number)\n  },\n  render: function () {\n    var chart = d3.select(document.createElement('div'))\n\n    chart\n      .selectAll('.bar')\n      .data(this.props.data)\n      .enter().append('div')\n      .prop({\n        className: 'bar',\n        key: function (d, i) {\n          return i\n        },\n        style: function (d, i) {\n          return {\n            width: d * 10\n          }\n        }\n      })\n      .text(function (d) {\n        return d\n      })\n\n    return chart.toReact()\n  }\n})\n\nvar data = [4, 8, 15, 16, 23, 42]\n\nReact.render(\n  React.createElement(Graph, {data: data}),\n  document.getElementById('mount-chart')\n)\n```\n\nAs you can see, I'm using `prop` in place of `attr` and `toReact` at the end to build the React DOM. I'm also specifying a key so React knows which element is which. `prop` works just like `attr` so you can give it an object, key/value or key/function.\n\nThis script depends upon D3 and React, so make sure they're available within your application. It's wrapped in a [UMD][], so you should be able to use it with most module systems. You may need to configure your build tool to not include multiple versions of React and D3 in your final script bundle.\n\n## Why?\n\nThis was born from trying to use these two excellent tools together, but not liking how the existing bridges were executed ([react-d3-wrap][], for example). The wrap approach works, but I'd much rather declare my view and let React work out what to render.\n\nThis repository is a polished version of my [experiment][d3-lab]. The main drawback is that you can't use some normal D3 features, such as animations or anything else that mutates the DOM after it's rendered. You can however now write modular React components and animate the elements they produce. It's a trade off, you're sacrificing parts of D3 for simplicity and a more React-like approach.\n\nThe main driving factor was to make building great React / D3 things at [Qubit][] easier. Qubit is awesome.\n\n## Development\n\n```bash\n# Fetch the dependencies\nmake bootstrap\n\n# Test\nmake test\n\n# Test continually\nmake test-watch\n```\n\n## Author\n\n[Oliver Caldwell][author-site] ([@OliverCaldwell][author-twitter])\n\n## Unlicenced\n\nFind the full [unlicense][] in the `UNLICENSE` file, but here's a snippet.\n\n\u003eThis is free and unencumbered software released into the public domain.\n\u003e\n\u003eAnyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.\n\nDo what you want. Learn as much as you can. Unlicense more software.\n\n[unlicense]: http://unlicense.org/\n[author-site]: http://oli.me.uk/\n[author-twitter]: https://twitter.com/OliverCaldwell\n[d3]: http://d3js.org/\n[react]: http://facebook.github.io/react/\n[d3-lab]: http://lab.oli.me.uk/d3-to-react/\n[react-d3-wrap]: https://www.npmjs.com/package/react-d3-wrap\n[qubit]: http://www.qubit.com/\n[umd]: https://github.com/umdjs/umd\n[react-faux-dom]: https://github.com/Olical/react-faux-dom\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOlical%2Fd3-react","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FOlical%2Fd3-react","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOlical%2Fd3-react/lists"}