Comments (2)
Hi @Nate-Wessel, thanks for reaching out!
That's great feedback, and I'm glad the force plugin does what you're looking for. 👍
You're right that it is a bit verbose for the common use case of setting a fully enclosed rectangular bounding box. However the syntax was made like that to allow the flexibility of setting surfaces in other scenarios, like having diagonal lines, non-rectangular shapes and even for cases when the surfaces are not necessarily enclosed, like in the quad-pong example.
At the end, it's prob easy enough to do a function that converts one syntax into the other, for the simple bounding case, like:
const bbox2Surfaces = ([[x1, y1], [x2, y2]]) => [
{ from: { x: x1, y: y1 }, to: { x: x2, y: y1 } },
{ from: { x: x2, y: y1 }, to: { x: x2, y: y2 } },
{ from: { x: x2, y: y2 }, to: { x: x1, y: y2 } },
{ from: { x: x1, y: y2 }, to: { x: x1, y: y1 } }
];
We could maybe simplify the syntax of each line from { from: {x1,y1}, to: {x2,y2}}
to something like [[x1,y1],[x2,y2]]
. But it's normally so easy to get lost in these nested arrays and I think spelling out the fields can prevent some bugs from creeping, and help with troubleshooting. Once again you can also easily do a structures transformation helper method. We could make the lib accept both, but that may add a bit of confusion, I don't know.
Oh, and for the simple case of keeping nodes within a bounding box, there may be an easier force for that: d3-force-limit, with also an easier input syntax for coords. 😄
There's an example here: https://observablehq.com/@vasturiano/d3-force-limit
from d3-force-surface.
Thanks for the reply @vasturiano!
I did eventually find my way over to d3-force-limit which was actually more what I was looking for for this particular application. More succinct and also works great!
One thing I might suggest for this lib is looking into the GeoJSON spec. I could see this handling simple lines, polylines, polygons, multipolygons and even geometry collections pretty well if the shapes were simple enough. And there are lots of tools already for working with geometry data in those formats. The coordinates would just have to be in screen pixels rather than geographic coordinates.
from d3-force-surface.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-force-surface.