diff --git a/Project.toml b/Project.toml index 98e784c..b75f688 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "HasseDiagrams" uuid = "eda30fb7-e799-4e1d-8790-5b2716643197" authors = ["Ed Scheinerman "] -version = "0.0.2" +version = "0.1.0" [deps] Posets = "9a158a65-591e-4f68-ac4f-9ffef2fc51f2" @@ -9,7 +9,6 @@ SimpleDrawing = "d78a06e8-ae74-583c-9a07-0d6572347000" Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" LayeredLayouts = "f4a74d36-062a-4d48-97cd-1356bad1de4e" - Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/README.md b/README.md index c39c3e8..4a7bc93 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # HasseDiagrams -Drawings of [Posets](https://github.com/scheinerman/Posets.jl) (partially ordered sets). +[Hasse diagrams](https://en.wikipedia.org/wiki/Hasse_diagram) are +drawings of [Posets](https://github.com/scheinerman/Posets.jl) (partially ordered sets). ## Basic Usage @@ -16,7 +17,7 @@ Hasse diagram of a {8, 19} Int64 poset julia> draw(h) ``` -Note that `h` contains a copy of `p`, so subsequent changes to `p` are not reflected in `h`. +> Note that `h` contains a copy of `p`, so subsequent changes to `p` are not reflected in `h`. ## Creating a Layout @@ -25,7 +26,7 @@ When a Hasse diagram is created, it is given a default layout. Hasse diagrams ca * `set_xy!(h, method)` uses the function `method` to compute the layout. The function acts on the posets held inside `h`. The list of available layout methods is in the next section. * `set_xy!(h, xy)` uses the dictionary `xy` to site the vertices. Vertex `v` is placed at `xy[v]`. If `v` is not a key of `xy`, then its location is unchanged. -### Scaling +#### Scaling The function `scale!(p,μ)` multiplies all coordinates in the embedding by `μ`. It is likely more useful just to multiply the `x`- or `y`-coordinates; diff --git a/docs/build/.documenter-siteinfo.json b/docs/build/.documenter-siteinfo.json index 6d1d2b5..a1c3648 100644 --- a/docs/build/.documenter-siteinfo.json +++ b/docs/build/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.10.5","generation_timestamp":"2024-09-03T17:15:22","documenter_version":"1.6.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.10.5","generation_timestamp":"2024-09-04T11:38:28","documenter_version":"1.6.0"}} \ No newline at end of file diff --git a/docs/build/index.html b/docs/build/index.html index 3ac2237..c763e1e 100644 --- a/docs/build/index.html +++ b/docs/build/index.html @@ -1,5 +1,5 @@ -HasseDiagrams · HasseDiagrams

HasseDiagrams

Drawings of Posets (partially ordered sets).

Basic Usage

To create a Hasse diagram for a Poset and draw it on the screen, do this:

julia> using Posets, HasseDiagrams
+HasseDiagrams · HasseDiagrams

HasseDiagrams

Hasse diagrams are drawings of Posets (partially ordered sets).

Basic Usage

To create a Hasse diagram for a Poset and draw it on the screen, do this:

julia> using Posets, HasseDiagrams
 
 julia> p = subset_lattice(3)
 {8, 19} Int64 poset
@@ -7,7 +7,7 @@
 julia> h = HasseDiagram(p)
 Hasse diagram of a {8, 19} Int64 poset
 
-julia> draw(h)

Note that h contains a copy of p, so subsequent changes to p are not reflected in h.

Creating a Layout

When a Hasse diagram is created, it is given a default layout. Hasse diagrams can be given an alternative layout with the function set_xy!. There are two forms:

  • set_xy!(h, method) uses the function method to compute the layout. The function acts on the posets held inside h. The list of available layout methods is in the next section.
  • set_xy!(h, xy) uses the dictionary xy to site the vertices. Vertex v is placed at xy[v]. If v is not a key of xy, then its location is unchanged.

Scaling

The function scale!(p,μ) multiplies all coordinates in the embedding by μ. It is likely more useful just to multiply the x- or y-coordinates; to do so, use scalex! or scaley!, respecitvely.

Layout Methods

  • basic_layout places vertices vertically based on their rank and, within each rank, the horizontal placement is evenly spaced.
  • dim2_layout is a decent layout function that is applicable to posets whose dimension is at most two. Reasonbly quick. If the poset has dimension greater than two, a reasonable alternative is presented.
  • layered_layout is a Sugiyaqma style layout from the LayeredLayouts module. Can be slow.

Sample Results

Results for a randomly generated two-dimensional poset:

Properties

Font size

  • Use set_font_size!(h, sz) to set labels to be sz points. Use 0 to hide labels. Default is FONT_SIZE = 10.
  • Use get_font_size(h) to determine the current font size for h.

Node radius

  • Use set_radius!(h, r) to set the size of the circles that represent the elements of the poset. Default is RADIUS = 12.
  • Use get_radius(h) to determine the current radius.

Fill color

  • Use set_fill_color!(h, c) to set the fill color for the circles to c. Default is FILL_COLOR = :white. All circles are filled with the same color.
  • Use get_fill_color(h) to determine the current color.

Example

Here is an example for drawing (small) subset lattices with sensible labels. Here is the function to produce the picture:

using Posets, HasseDiagrams, SimpleDrawing, ShowSet
+julia> draw(h)

Note that h contains a copy of p, so subsequent changes to p are not reflected in h.

Creating a Layout

When a Hasse diagram is created, it is given a default layout. Hasse diagrams can be given an alternative layout with the function set_xy!. There are two forms:

  • set_xy!(h, method) uses the function method to compute the layout. The function acts on the posets held inside h. The list of available layout methods is in the next section.
  • set_xy!(h, xy) uses the dictionary xy to site the vertices. Vertex v is placed at xy[v]. If v is not a key of xy, then its location is unchanged.

Scaling

The function scale!(p,μ) multiplies all coordinates in the embedding by μ. It is likely more useful just to multiply the x- or y-coordinates; to do so, use scalex! or scaley!, respecitvely.

Layout Methods

  • basic_layout places vertices vertically based on their rank and, within each rank, the horizontal placement is evenly spaced.
  • dim2_layout is a decent layout function that is applicable to posets whose dimension is at most two. Reasonbly quick. If the poset has dimension greater than two, a reasonable alternative is presented.
  • layered_layout is a Sugiyaqma style layout from the LayeredLayouts module. Can be slow.

Sample Results

Results for a randomly generated two-dimensional poset:

Properties

Font size

  • Use set_font_size!(h, sz) to set labels to be sz points. Use 0 to hide labels. Default is FONT_SIZE = 10.
  • Use get_font_size(h) to determine the current font size for h.

Node radius

  • Use set_radius!(h, r) to set the size of the circles that represent the elements of the poset. Default is RADIUS = 12.
  • Use get_radius(h) to determine the current radius.

Fill color

  • Use set_fill_color!(h, c) to set the fill color for the circles to c. Default is FILL_COLOR = :white. All circles are filled with the same color.
  • Use get_fill_color(h) to determine the current color.

Example

Here is an example for drawing (small) subset lattices with sensible labels. Here is the function to produce the picture:

using Posets, HasseDiagrams, SimpleDrawing, ShowSet
 
 function draw_bool(k)
     p = subset_lattice(k)
@@ -23,4 +23,4 @@
     set_xy!(h, layered_layout)
     draw(h)
     expand_canvas()  # from SimpleDrawing
-end

Here is the result of draw_bool(4):

+end

Here is the result of draw_bool(4):

diff --git a/docs/build/objects.inv b/docs/build/objects.inv index f8ce6ec..7d7c414 100644 Binary files a/docs/build/objects.inv and b/docs/build/objects.inv differ diff --git a/docs/build/search_index.js b/docs/build/search_index.js index 51196d6..5bd48d5 100644 --- a/docs/build/search_index.js +++ b/docs/build/search_index.js @@ -1,3 +1,3 @@ var documenterSearchIndex = {"docs": -[{"location":"#HasseDiagrams","page":"HasseDiagrams","title":"HasseDiagrams","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"Drawings of Posets (partially ordered sets).","category":"page"},{"location":"#Basic-Usage","page":"HasseDiagrams","title":"Basic Usage","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"To create a Hasse diagram for a Poset and draw it on the screen, do this:","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"julia> using Posets, HasseDiagrams\n\njulia> p = subset_lattice(3)\n{8, 19} Int64 poset\n\njulia> h = HasseDiagram(p)\nHasse diagram of a {8, 19} Int64 poset\n\njulia> draw(h)","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"Note that h contains a copy of p, so subsequent changes to p are not reflected in h.","category":"page"},{"location":"#Creating-a-Layout","page":"HasseDiagrams","title":"Creating a Layout","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"When a Hasse diagram is created, it is given a default layout. Hasse diagrams can be given an alternative layout with the function set_xy!. There are two forms:","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"set_xy!(h, method) uses the function method to compute the layout. The function acts on the posets held inside h. The list of available layout methods is in the next section. \nset_xy!(h, xy) uses the dictionary xy to site the vertices. Vertex v is placed at xy[v]. If v is not a key of xy, then its location is unchanged.","category":"page"},{"location":"#Scaling","page":"HasseDiagrams","title":"Scaling","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"The function scale!(p,μ) multiplies all coordinates in the embedding by μ. It is likely more useful just to multiply the x- or y-coordinates; to do so, use scalex! or scaley!, respecitvely. ","category":"page"},{"location":"#Layout-Methods","page":"HasseDiagrams","title":"Layout Methods","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"basic_layout places vertices vertically based on their rank and, within each rank, the horizontal placement is evenly spaced.\ndim2_layout is a decent layout function that is applicable to posets whose dimension is at most two. Reasonbly quick. If the poset has dimension greater than two, a reasonable alternative is presented. \nlayered_layout is a Sugiyaqma style layout from the LayeredLayouts module. Can be slow. ","category":"page"},{"location":"#Sample-Results","page":"HasseDiagrams","title":"Sample Results","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"Results for a randomly generated two-dimensional poset:","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"(Image: )","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"(Image: )","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"(Image: )","category":"page"},{"location":"#Properties","page":"HasseDiagrams","title":"Properties","text":"","category":"section"},{"location":"#Font-size","page":"HasseDiagrams","title":"Font size","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"Use set_font_size!(h, sz) to set labels to be sz points. Use 0 to hide labels. Default is FONT_SIZE = 10.\nUse get_font_size(h) to determine the current font size for h. ","category":"page"},{"location":"#Node-radius","page":"HasseDiagrams","title":"Node radius","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"Use set_radius!(h, r) to set the size of the circles that represent the elements of the poset. Default is RADIUS = 12.\nUse get_radius(h) to determine the current radius.","category":"page"},{"location":"#Fill-color","page":"HasseDiagrams","title":"Fill color","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"Use set_fill_color!(h, c) to set the fill color for the circles to c. Default is FILL_COLOR = :white. All circles are filled with the same color. \nUse get_fill_color(h) to determine the current color. ","category":"page"},{"location":"#Example","page":"HasseDiagrams","title":"Example","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"Here is an example for drawing (small) subset lattices with sensible labels. Here is the function to produce the picture:","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"using Posets, HasseDiagrams, SimpleDrawing, ShowSet\n\nfunction draw_bool(k)\n p = subset_lattice(k)\n h = HasseDiagram(p)\n labs = Dict{Int,String}()\n for v in 1:nv(p)\n labs[v] = string(subset_decode(v))\n end\n set_labels!(h, labs)\n set_font_size!(h, 8)\n set_radius!(h, 30)\n set_fill_color!(h, :lightblue)\n set_xy!(h, layered_layout)\n draw(h)\n expand_canvas() # from SimpleDrawing\nend","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"Here is the result of draw_bool(4):","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"(Image: )","category":"page"}] +[{"location":"#HasseDiagrams","page":"HasseDiagrams","title":"HasseDiagrams","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"Hasse diagrams are drawings of Posets (partially ordered sets).","category":"page"},{"location":"#Basic-Usage","page":"HasseDiagrams","title":"Basic Usage","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"To create a Hasse diagram for a Poset and draw it on the screen, do this:","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"julia> using Posets, HasseDiagrams\n\njulia> p = subset_lattice(3)\n{8, 19} Int64 poset\n\njulia> h = HasseDiagram(p)\nHasse diagram of a {8, 19} Int64 poset\n\njulia> draw(h)","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"Note that h contains a copy of p, so subsequent changes to p are not reflected in h.","category":"page"},{"location":"#Creating-a-Layout","page":"HasseDiagrams","title":"Creating a Layout","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"When a Hasse diagram is created, it is given a default layout. Hasse diagrams can be given an alternative layout with the function set_xy!. There are two forms:","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"set_xy!(h, method) uses the function method to compute the layout. The function acts on the posets held inside h. The list of available layout methods is in the next section. \nset_xy!(h, xy) uses the dictionary xy to site the vertices. Vertex v is placed at xy[v]. If v is not a key of xy, then its location is unchanged.","category":"page"},{"location":"#Scaling","page":"HasseDiagrams","title":"Scaling","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"The function scale!(p,μ) multiplies all coordinates in the embedding by μ. It is likely more useful just to multiply the x- or y-coordinates; to do so, use scalex! or scaley!, respecitvely. ","category":"page"},{"location":"#Layout-Methods","page":"HasseDiagrams","title":"Layout Methods","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"basic_layout places vertices vertically based on their rank and, within each rank, the horizontal placement is evenly spaced.\ndim2_layout is a decent layout function that is applicable to posets whose dimension is at most two. Reasonbly quick. If the poset has dimension greater than two, a reasonable alternative is presented. \nlayered_layout is a Sugiyaqma style layout from the LayeredLayouts module. Can be slow. ","category":"page"},{"location":"#Sample-Results","page":"HasseDiagrams","title":"Sample Results","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"Results for a randomly generated two-dimensional poset:","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"(Image: )","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"(Image: )","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"(Image: )","category":"page"},{"location":"#Properties","page":"HasseDiagrams","title":"Properties","text":"","category":"section"},{"location":"#Font-size","page":"HasseDiagrams","title":"Font size","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"Use set_font_size!(h, sz) to set labels to be sz points. Use 0 to hide labels. Default is FONT_SIZE = 10.\nUse get_font_size(h) to determine the current font size for h. ","category":"page"},{"location":"#Node-radius","page":"HasseDiagrams","title":"Node radius","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"Use set_radius!(h, r) to set the size of the circles that represent the elements of the poset. Default is RADIUS = 12.\nUse get_radius(h) to determine the current radius.","category":"page"},{"location":"#Fill-color","page":"HasseDiagrams","title":"Fill color","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"Use set_fill_color!(h, c) to set the fill color for the circles to c. Default is FILL_COLOR = :white. All circles are filled with the same color. \nUse get_fill_color(h) to determine the current color. ","category":"page"},{"location":"#Example","page":"HasseDiagrams","title":"Example","text":"","category":"section"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"Here is an example for drawing (small) subset lattices with sensible labels. Here is the function to produce the picture:","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"using Posets, HasseDiagrams, SimpleDrawing, ShowSet\n\nfunction draw_bool(k)\n p = subset_lattice(k)\n h = HasseDiagram(p)\n labs = Dict{Int,String}()\n for v in 1:nv(p)\n labs[v] = string(subset_decode(v))\n end\n set_labels!(h, labs)\n set_font_size!(h, 8)\n set_radius!(h, 30)\n set_fill_color!(h, :lightblue)\n set_xy!(h, layered_layout)\n draw(h)\n expand_canvas() # from SimpleDrawing\nend","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"Here is the result of draw_bool(4):","category":"page"},{"location":"","page":"HasseDiagrams","title":"HasseDiagrams","text":"(Image: )","category":"page"}] } diff --git a/docs/src/index.md b/docs/src/index.md index c39c3e8..4a7bc93 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -1,6 +1,7 @@ # HasseDiagrams -Drawings of [Posets](https://github.com/scheinerman/Posets.jl) (partially ordered sets). +[Hasse diagrams](https://en.wikipedia.org/wiki/Hasse_diagram) are +drawings of [Posets](https://github.com/scheinerman/Posets.jl) (partially ordered sets). ## Basic Usage @@ -16,7 +17,7 @@ Hasse diagram of a {8, 19} Int64 poset julia> draw(h) ``` -Note that `h` contains a copy of `p`, so subsequent changes to `p` are not reflected in `h`. +> Note that `h` contains a copy of `p`, so subsequent changes to `p` are not reflected in `h`. ## Creating a Layout @@ -25,7 +26,7 @@ When a Hasse diagram is created, it is given a default layout. Hasse diagrams ca * `set_xy!(h, method)` uses the function `method` to compute the layout. The function acts on the posets held inside `h`. The list of available layout methods is in the next section. * `set_xy!(h, xy)` uses the dictionary `xy` to site the vertices. Vertex `v` is placed at `xy[v]`. If `v` is not a key of `xy`, then its location is unchanged. -### Scaling +#### Scaling The function `scale!(p,μ)` multiplies all coordinates in the embedding by `μ`. It is likely more useful just to multiply the `x`- or `y`-coordinates; diff --git a/test/runtests.jl b/test/runtests.jl index 31a2bae..e356757 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,11 @@ using Test using Posets, HasseDiagrams -@test true + +p = chain(1) / (chain(2) + chain(1)) / chain(2) +h = HasseDiagram(p) +set_xy!(h, layered_layout) +coords = values(get_xy(h)) +ys = [ v[2] for v in coords ] + +@test maximum(ys) == height(p) \ No newline at end of file