bijection / g9 Goto Github PK
View Code? Open in Web Editor NEWAutomatically Interactive Graphics ๐ผโจ๐ฏ
Home Page: http://omrelli.ug/g9/gallery
License: MIT License
Automatically Interactive Graphics ๐ผโจ๐ฏ
Home Page: http://omrelli.ug/g9/gallery
License: MIT License
I'll take the example code from "using Max and Min to limit a point's range of motion" as a starting point:
var initial = {
x1: -100,
x2: 0,
x3: 100,
}
function render(data, ctx){
var m = Math.max(Math.min(data.x2, data.x3 - 20), data.x1 + 20)
ctx.point(m,0, {affects: ['x2']})
ctx.point(data.x2,20, {affects: ['x2']})
ctx.point(data.x1,0, {fill: 'red'})
ctx.point(data.x3,0, {fill: 'red'})
}
When I drag point x1 or x3, there's nothing stopping me from dragging one point beyond the other.
That can be fixed by repeating the trick used for x2:
var mMin = Math.min(data.x1, data.x3 - 40)
var mMax = Math.max(data.x1 + 40, data.x3)
var m = Math.max(Math.min(data.x2, mMax - 20), mMin + 20)
ctx.point(m,0, {affects: ['x2']})
ctx.point(data.x2,20, {affects: ['x2']})
ctx.point(mMin,0, { affects: ['x1'], fill: 'red'})
ctx.point(mMax,0, { affects: ['x3'], fill: 'red'})
Now x1
and x3
can't get closer than 40 pixels and stop when dragged into each other. Great! But then I thought: well, what would be really cool is if x1
and x3
would push each other when dragged into each other. Is there a way to do this?
The problem, as I see it, is that in order for this to work, the values of x1
and x3
would have to be mutually dependent on each other: if I drag x1
into x3
, then the value x3
should depend on x1
, but if I drag x3
into x1
, the value of x1
should depend on x3
. And for that to work I need to know which of the points is being dragged, but I don't see a way to check for that in the documentation. But maybe there's another trick and I just don't properly think in terms of constraint based programming yet?
Hi there,
I really love the g9.js demos! I think they convey how gradients work in such a nice and intuitive manner.
Just for fun I was playing with the idea of running a Torch-like library in the browser. I ported over most of the g9 code to python and ran it with AD (as opposed to finite-differences) -> https://srush.github.io/g9py/ . Not sure why this is better, but it might let you run models with tons of parameters. Let me know if this is okay.
Cheers!
Sasha
Hi,
When I do an 'insertInto' call, the SVG which is created has its viewbox automatically set to some drawing size and offset. If I am rendering into a fixed size Div tag, how to I ensure that the resulting drawing is not arbitrarily re-scaled?
Thanks,
Forrest
Hi all, thanks for this awesome library! May I ask what the license is for using it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.