Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/preview/comitia/0.1.0/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2025 Tobias Heidler <tobias.github@heidler.ovh>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56 changes: 56 additions & 0 deletions packages/preview/comitia/0.1.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# comitia

Use different voting mechanisms in your document. Powered by Rust WASM.

You can analyze a vote turnout by calling `vote(ballots, method, ties_method)` which returns the raw JSON results
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result doesn't seem to be a JSON string anymore

of your ballots or `vote-report(ballots, method, ties_method)` for a more detailled report on the vote.

## Example

First you must import the library and define an *input* for our vote method. This input must be a list
with each element of the list containing the ranked choice(s) for an individual:

```typst
#import "@preview/comitia:0.1.0": *
#let input = (
("Alice", "Charlie"),
("Bob", "Charlie", "Alice"),
("Charlie", "Alice", "Bob"),
("Alice", "Charlie", "Bob"),
("Bob", "Alice", "Charlie"),
("Tim",)
)
```

In our example the first person prefered Alice over Charlie and the last person
only voted for Tim. Please note that an Element that contains only one element
must end with a comma, as shown in `#("Tim",)`.

Then you can either analyze the raw output using the function:

```typst
#vote(input, method: "STV", ties_method: "Random")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't compile, the second argument should be tie-method

```

Or you can have a more sophisticated report on each step performed:

```typst
#vote-report(input, method: "STV", ties_method: "Random")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

```

## Implemented

### Methods

- Plurality
- STV (Single Transferable Vote - for one candidate: Instant-Runoff Voting)

### Tie Breakers

- All
- Random
- Count

### Minimum Number of Candidates

Currently only single (or tie bound multiple) candidates are returned. Multiple voting rounds for more than one candidate are to be implemented in the future.
Binary file added packages/preview/comitia/0.1.0/comitia.wasm
Binary file not shown.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file will be very hard to find, unless someone is browsing this repository. Could you either remove it or link to it from the readme?

Binary file not shown.
176 changes: 176 additions & 0 deletions packages/preview/comitia/0.1.0/examples/example.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#import "@preview/comitia:0.1.0" : vote-report, vote

#set heading(numbering: "1.1")

#show heading.where(level: 4): it =>[
#block(it.body)
]
#show heading.where(level: 5): it =>[
#block(it.body)
]
#show heading.where(level: 6): it =>[
#block(it.body)
]
#set par(justify: true)

#outline(depth: 3)

= Define an Input

First you must define an input for our vote method. This input must be a list
with each element of the list containing the ranked choices for an individual:

```typst
#let input = (
("Alice", "Charlie"),
("Bob", "Charlie", "Alice"),
("Charlie", "Alice", "Bob"),
("Alice", "Charlie", "Bob"),
("Bob", "Alice", "Charlie"),
("Tim",)
)
```

#let input = (
("Alice", "Charlie"),
("Bob", "Charlie", "Alice"),
("Charlie", "Alice", "Bob"),
("Alice", "Charlie", "Bob"),
("Bob", "Alice", "Charlie"),
("Tim",)
)

In our example the first person prefered Alice over Charlie and the last person
only voted for Tim. Please note that an Element that contains only one element
must end with a comma, as shown in #("Tim",).

= Retrieve raw results (`#vote`) <RAW>

To retrieve the raw results simply call

```typst
#vote(input)
```

The results is JSON and is shown here:

#vote(input)

By default vote operates on Plurality (See @Plurality) vote mode and for ties
all candidates are retained (and/or eliminated). For other methods of solving
votes see @Methods and for other tie breaker modes see @Ties.


= Retrieve a detailed result report (`#vote-report`)

To retrieve a report of the raw results simply call

```typst
#vote-report(input)
```

This method takes in the same parameters as `#vote`. For reference see @RAW.

The results are shown in the examples (see @Example-Plurality and @Example-SVT).


= Methods <Methods>

== Plurality <Plurality>

Each ballot selects one candidate. The candidate with the highest number of votes wins. The candidate with the fewest votes is eliminated.

== STV <STV>

Single Transferable Vote is used when multiple seats are to be filled. A quota of votes is calculated. Candidates who reach the quota are elected, and any surplus votes they receive are transferred to remaining candidates according to voter preferences. If no one meets the quota, the candidate with the fewest votes is eliminated and their ballots transferred. The process repeats until all seats are filled.

With only one seat to fill, STV works like Instant-Runoff Voting: voters rank candidates, the least-voted candidate is eliminated each round, and their ballots are transferred to the next preference, until one candidate remains and wins (> 50% of votes).

= Tie Breakers <Ties>

== All

If multiple candidates tie for winning or elimination, all tied candidates share the outcome (all win or all are eliminated).

== Random

If multiple candidates tie, a random selection among the tied candidates determines who wins or is eliminated.

== Count

If multiple candidates tie, the total number of ballots that contain this candidate is summed up. This sum
is used to break the tie.

= Example Reports for Plurality-Voting <Example-Plurality>

== Tie Method: All

```typst
//Call:
#vote-report(input)
```

#vote-report(input)
#pagebreak()

== Tie Method: Random

```typst
//Call:
#vote-report(input, tie-method: "Random")
```

#vote-report(input, tie-method: "Random")
#pagebreak()

== Tie Method: Count

```typst
//Call:
#vote-report(input, tie-method: "Count")
```

#vote-report(input, tie-method: "Count")
#pagebreak()

= Examples Reports for STV-Voting <Example-SVT>

== Tie Method: All

```typst
//Call:
#vote-report(input, method: "STV", tie-method: "All")
```

#vote-report(input, method: "STV", tie-method: "All")
#pagebreak()

== Tie Method: Random

```typst
//Call:
#vote-report(input, method: "STV", tie-method: "Random")
```

#vote-report(input, method: "STV", tie-method: "Random")
#pagebreak()

== Tie Method: Count

```typst
//Call:
#vote-report(input, method: "STV", tie-method: "Count")
```

#vote-report(input, method: "STV", tie-method: "Count")

== Change Header Level

Changes the top header of the report to level 3:

```typst
//Call:
#vote-report(input, method: "STV", tie-method: "All", level-start: 3)
```

#vote-report(input, method: "STV", tie-method: "All", level-start: 3)
Loading