Skip to content
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

Closed
fryguybob opened this issue Aug 4, 2012 · 8 comments
Closed

Linear constraint-solving module for diagram layout #8

fryguybob opened this issue Aug 4, 2012 · 8 comments

Comments

@fryguybob
Copy link
Member

(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.

@fryguybob
Copy link
Member Author

(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 =
Var String
| Con v
| FreeV v :+: FreeV v
| Scalar v :*: FreeV v

@byorgey
Copy link
Member

byorgey commented Sep 27, 2012

Note that #50 may also be relevant.

@cmears
Copy link
Contributor

cmears commented Apr 12, 2013

An example of the kind of thing we could do, just using the toysolver library:

x

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)

@cartazio
Copy link

gridstylesheets.org might have some ideas, its focused on js / css minyou)

@jeffreyrosenbluth
Copy link
Member

that looks cool, maybe we can do it at hac

On Thu, Mar 20, 2014 at 11:33 PM, Carter Tazio Schonwald <
notifications@github.com> wrote:

gridstylesheets.org might have some ideas, its focused on js / css minyou)

Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-38246658
.

@byorgey byorgey self-assigned this Sep 12, 2015
@byorgey
Copy link
Member

byorgey commented Sep 12, 2015

I'm now working on this using mfsolve for the constraint solving.

@jeffreyrosenbluth
Copy link
Member

Interesting, is there any similarity to Cassowary?
https://en.wikipedia.org/wiki/Cassowary_(software)

On Sat, Sep 12, 2015 at 5:35 PM Brent Yorgey notifications@github.com
wrote:

I'm now working on this using mfsolve for the constraint solving.


Reply to this email directly or view it on GitHub
#8 (comment)
.

@byorgey
Copy link
Member

byorgey commented Sep 14, 2015

I am not familiar with Cassowary, but yes, it seems similar. Differences
that I can see: mfsolve deals with equalities only (no inequalities) and
there is no way to specify constraints as being required or
preferred---every constraint is required. On the other hand, mfsolve is
able to work with non-linear constraints, whereas it seems Cassowary does
not. In any case, I think my approach should scale easily if we switch to
a more powerful constraint-solving engine in the future.

On Sun, Sep 13, 2015 at 6:22 AM Jeffrey Rosenbluth notifications@github.com
wrote:

Interesting, is there any similarity to Cassowary?
https://en.wikipedia.org/wiki/Cassowary_(software)

On Sat, Sep 12, 2015 at 5:35 PM Brent Yorgey notifications@github.com
wrote:

I'm now working on this using mfsolve for the constraint solving.


Reply to this email directly or view it on GitHub
<
https://github.com/diagrams/diagrams-lib/issues/8#issuecomment-139821147>
.


Reply to this email directly or view it on GitHub
#8 (comment)
.

@byorgey byorgey closed this as completed Apr 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants