Improve Discrete Axis Specification - #71
Merged
Merged
Conversation
slemus9
force-pushed
the
issue-70-discrete-axis
branch
from
March 28, 2026 00:54
6ff9b51 to
1ebba03
Compare
slemus9
force-pushed
the
issue-70-discrete-axis
branch
from
March 28, 2026 00:57
1ebba03 to
5233fd0
Compare
slemus9
marked this pull request as ready for review
March 28, 2026 18:36
slemus9
commented
Mar 28, 2026
slemus9
commented
Mar 28, 2026
slemus9
commented
Mar 28, 2026
dabd
reviewed
Apr 10, 2026
dabd
approved these changes
Apr 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Fixes #70
Currently, a user can specify Categorical/Discrete axis for a LineChart. However, in order to so, the user has to take care of the mapping between the categories and their actual numeric values on the axis. For example:
Here the user needs to take into account the following mapping when building the chart:
"Mon" -> 1.0, "Tue" -> 2.0, "Wed" -> 3.0, "Thu" -> 4.0, "Fri" -> 5.0. This is error-prone and allows for values that shouldn't be valid; for instance, the user is allowed to map a discrete category into a decimal position on the axis.A more user-friendly specification would be a direct map from the String categories to the co-domain values like this:
Here the user doesn't have to worry about the specific numeric position of each category, as we can infer those and compute them behind the scenes
The goal of this PR is to constrain the specification of the LineChart so that it prevents us from building some invalid permutations between axis and line series, as well as to simplify the DSL and expose more user-friendly functions to build Discrete charts
Design
In order to allow Discrete String categories in the LineChart specification, we have to open up the LineSeries type so that it can receive different type of values for the Domain and Codomain of the plot. The main change proposed by this PR is to index the LineChart type by the Domain and Codomain types:
However, we can not allow any type to act as the Domain/Codomain, we also need to constrain it to the types that we can effectively process; in this case, we will only allow
StringsandDoubles(for now). To implement this restriction we define the following ADTDomainrepresents all the valid types that can be given as the Domain or Codomain to a Line Chart. Each case of the ADT has an objecteqobject that will help us pattern-match on the Domain when we are in the scope of a generic function. For example:We can now constraint the DSL by requiring an implicit evidence showing that the given Type is a valid Domain type:
Finally, we can write some generic functions that will map the line series data points to the actual numeric values in accordance to the Axis specification:
Note that the
Axisis also indexed by the type of the Domain. This will make sure that we can not construct Axis that are not coherent with the type of the Line SeriesFor example, the following expression won't compile:
DSL changes
We modify the DSL so that the user doesn't need to specify the
Axis.CategoryScale. We will infer the positions of the Discrete categories based on the order of the line series sequences that the user created.We assume that the categories that we should display in the axis are the unique labels from the sequence of categories, and we show them in the order that they first appear. For example, If we receive the following labels:
The order in which we show them in the axis is:
Since the user can specify multiple line series, we traverse all the series in the same order that the user wrote, and we yield a single axis specification. For example, if the user created the following sequence of series:
The order in which we display the categories in the x-axis is:
The user can still manually build a
Axis.CategoryScaleto specify the order in which the labels should appear on the axisResult
Fully inferred categorical axis
Constraining the values of the categorical axis
In this example, the plot will only show the categories that belong to the Axis.CategoryScale sequence
Specifying the order of the categories in the axis
in this example, we swap the order between categories "c3" and "c4"