-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linear constraint-solving module for diagram layout #8
Comments
(Imported. Original comment by byor...@gmail.com on May 16, 2011, 03:45:47 PM UTC) It may be interesting/useful towards this end to be able to construct diagrams over a "free vector space". By the free vector space over v I mean something like data FreeV v = |
Note that #50 may also be relevant. |
An example of the kind of thing we could do, just using the toysolver library: import Diagrams.Prelude
import Diagrams.Backend.Cairo
import Diagrams.Backend.Cairo.CmdLine
import Algorithm.LPSolverHL
import Data.ArithRel
import qualified Data.IntMap as IM
import Data.LA
import Data.Ratio
import Data.Maybe
-- the layout specification
go = let [x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6] = map var [0..11]
in solve
[
-- x1,x2,x3,x4 evenly spaced
x2 ^-^ x1 .==. x3 ^-^ x2
, x3 ^-^ x2 .==. x4 ^-^ x3
-- spacing is 5
, x2 ^-^ x1 .==. constant 5
-- x1,y1 at origin
, x1 .==. constant 0
, y1 .==. constant 0
-- y1,y2,y3,y4 all equal
, y1 .==. y2
, y1 .==. y3
, y1 .==. y4
-- x5,y5 on NNE-SSW line from x2,y2
, y5 ^-^ y2 .==. 2*^x5 ^-^ 2*^x2
-- x5,y5 vertically aligned with x3,y3
, x5 .==. x3
-- x6,y6 on NE-SW diagonal from x2,y2
, y6 ^-^ y2 .==. x6 ^-^ x2
-- x6,y6 vertically aligned with x1,y1
, x6 .==. x1
]
-- this just draws labeled circles at the points determined by the
-- solver
go2 :: Diagram Cairo R2
go2 = let [x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6] =
map fromRational (map snd (IM.toList (fromJust go)))
pairs = [(x1,y1),(x2,y2),(x3,y3),(x4,y4),(x5,y5),(x6,y6)]
in position [ (p2 pair, f n) | (pair,n) <- zip pairs [1..] ]
where f n = circle 1 <> text (show n)
main = defaultMain (go2 # centerXY # pad 1.1 # bg white) |
gridstylesheets.org might have some ideas, its focused on js / css minyou) |
that looks cool, maybe we can do it at hac On Thu, Mar 20, 2014 at 11:33 PM, Carter Tazio Schonwald <
|
I'm now working on this using |
Interesting, is there any similarity to Cassowary? On Sat, Sep 12, 2015 at 5:35 PM Brent Yorgey notifications@github.com
|
I am not familiar with Cassowary, but yes, it seems similar. Differences On Sun, Sep 13, 2015 at 6:22 AM Jeffrey Rosenbluth notifications@github.com
|
(Imported from http://code.google.com/p/diagrams/issues/detail?id=12. Original issue from byor...@gmail.com on January 15, 2011, 01:25:26 AM UTC)
There should be a module in the standard library providing an interface for specifying relative positions of subdiagrams via linear constraints (= equations or possibly even inequalities?), which then solves the constraints and takes care of actually positioning the diagrams as necessary.
The text was updated successfully, but these errors were encountered: