Skip to content

Add Custom Scale for Line Plot #32

@GeorgeBerdovskiy

Description

@GeorgeBerdovskiy

Background

As soon as #27 is merged, we'll have a simple working line plot available to use! However, we would like programmers to be able to decide the scale for themselves (for example, whether every "x" should represent one, two, five, and so on).

Goal

Modify the line_plot helper to take an additional configuration argument that states the scale. Assume that it will be formatted like this -

{
    scale: 5 # Every "x" equals five of something
}

If the user doesn't specify a scale, then use use some math to determine the scale yourself. Here's the code that does that -

val_per_x = (largest_value.to_f / 10).ceil()

data.each do |object|
    object[:length] = object[:value].to_f / val_per_x
end

However, this isn't ideal because a line plot should be discrete. If you use this math, some marks will need to be fractional. To get around this, it would be ideal to just scale the "x" marks down. For example, if you need every "x" to be worth two, just scale the mark down by half and keep them worth at one. This way...

  • You won't have fractional marks (which will be difficult to render and confusing for the user), and
  • You will still be able to fit all the data onto the plot

Good luck!

Metadata

Metadata

Assignees

No one assigned

    Labels

    ClaimedSomeone has claimed this issue ✋IntermediateFor more experienced programmers 😎StandaloneDoesn't depend on other issues 💪

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions