DevactionUI.Chart.Geometry (devaction_ui v0.2.3)

Copy Markdown View Source

The arithmetic of the charts, with no markup: where a value sits on an axis, the path of a line, an area, a column with a rounded top and a slice of a ring. Every function is pure, so the charts can be drawn on the server and tested without a browser.

Summary

Functions

The path of a ring slice between two radii, from angle a to b (degrees from the top, clockwise).

The path of the area under a line, closed down to baseline.

A column from baseline up to top, width wide, with the top corners rounded by radius.

A number as the least text that says it: 12, 12.5.

The path of a line through {x, y} points.

A round number at or above value, to end an axis on, that four grid lines divide without a mess: 1, 1.2, 1.6, 2, 2.4, 3, 4, 5, 6, 8 or 10 times a power of ten.

The point at angle degrees from the top, clockwise, on a circle.

A number rounded to two decimals, so paths stay short.

The y of value on an axis from 0 to max drawn between bottom and top.

Moves labels apart: ys are positions, the result keeps the order and leaves gap between neighbours.

The slices of a ring from values: {start, stop} angles in degrees, from the top, clockwise, each one shortened by gap degrees so the slices do not touch. A value of 0 has no slice.

count positions from left to right; one position is the middle.

count + 1 evenly spaced values from 0 to max, for the grid lines.

Functions

arc_path(cx, cy, outer, inner, a, b)

@spec arc_path(number(), number(), number(), number(), number(), number()) ::
  String.t()

The path of a ring slice between two radii, from angle a to b (degrees from the top, clockwise).

area_path(points, baseline)

@spec area_path([{number(), number()}], number()) :: String.t()

The path of the area under a line, closed down to baseline.

column_path(x, top, baseline, width, radius)

@spec column_path(number(), number(), number(), number(), number()) :: String.t()

A column from baseline up to top, width wide, with the top corners rounded by radius.

fmt(value)

@spec fmt(number()) :: String.t()

A number as the least text that says it: 12, 12.5.

line_path(list)

@spec line_path([{number(), number()}]) :: String.t()

The path of a line through {x, y} points.

nice_max(value)

@spec nice_max(number()) :: number()

A round number at or above value, to end an axis on, that four grid lines divide without a mess: 1, 1.2, 1.6, 2, 2.4, 3, 4, 5, 6, 8 or 10 times a power of ten.

point(cx, cy, radius, angle)

@spec point(number(), number(), number(), number()) :: {float(), float()}

The point at angle degrees from the top, clockwise, on a circle.

round_to(value)

@spec round_to(number()) :: float() | integer()

A number rounded to two decimals, so paths stay short.

scale(value, max, bottom, top)

@spec scale(number(), number(), number(), number()) :: float()

The y of value on an axis from 0 to max drawn between bottom and top.

separate(ys, gap)

@spec separate([number()], number()) :: [number()]

Moves labels apart: ys are positions, the result keeps the order and leaves gap between neighbours.

slices(values, gap)

@spec slices([number()], number()) :: [{float(), float()} | nil]

The slices of a ring from values: {start, stop} angles in degrees, from the top, clockwise, each one shortened by gap degrees so the slices do not touch. A value of 0 has no slice.

spread(count, left, right)

@spec spread(pos_integer(), number(), number()) :: [float()]

count positions from left to right; one position is the middle.

ticks(max, count)

@spec ticks(number(), pos_integer()) :: [number()]

count + 1 evenly spaced values from 0 to max, for the grid lines.