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
34 changes: 15 additions & 19 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ jobs:
at: .
- <<: *install_hex_rebar

# - run:
# name: Start Chrome Driver
# command: /usr/local/bin/chromedriver
# background: true
- run:
name: mix test
command: mix coveralls.html
Expand Down Expand Up @@ -148,7 +144,7 @@ jobs:
- << parameters.project_name >>/priv/plts

- run:
command: mix dialyzer --halt-exit-status
command: mix dialyzer
working_directory: ~/project/<< parameters.project_name >>
no_output_timeout: 20m

Expand Down Expand Up @@ -219,13 +215,13 @@ workflows:
filters:
tags:
only: /v.*/
# - dialyzer:
# project_name: uncharted
# name: uncharted_dialyzer
# requires:
# - uncharted_credo
# - uncharted_test
# - uncharted_check_formatted
- dialyzer:
project_name: uncharted
name: uncharted_dialyzer
requires:
- uncharted_credo
- uncharted_test
- uncharted_check_formatted

- check-formatted:
project_name: uncharted_phoenix
Expand All @@ -251,10 +247,10 @@ workflows:
filters:
tags:
only: /v.*/
# - dialyzer:
# project_name: uncharted_phoenix
# name: uncharted_phoenix_dialyzer
# requires:
# - uncharted_phoenix_credo
# - uncharted_phoenix_test
# - uncharted_phoenix_check_formatted
- dialyzer:
project_name: uncharted_phoenix
name: uncharted_phoenix_dialyzer
requires:
- uncharted_phoenix_credo
- uncharted_phoenix_test
- uncharted_phoenix_check_formatted
3 changes: 3 additions & 0 deletions run_ci_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/sh

cd uncharted && MIX_ENV=test mix do format --check-formatted, test, credo --strict && cd ../uncharted_phoenix && MIX_ENV=test mix do format --check-formatted, test, credo --strict
3 changes: 3 additions & 0 deletions run_dialyzer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/sh

cd uncharted && mix dialyzer && cd ../uncharted_phoenix && mix dialyzer
6 changes: 4 additions & 2 deletions uncharted/lib/uncharted.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ defmodule Uncharted do
is a union type
"""
@type dataset ::
Uncharted.ColumnChart.Dataset.t()
Uncharted.BarChart.Dataset.t()
| Uncharted.ColumnChart.Dataset.t()
| Uncharted.LineChart.Dataset.t()
| Uncharted.PieChart.Dataset.t()
| Uncharted.PolarChart.Dataset.t()
| Uncharted.ProgressChart.Dataset.t()
| Uncharted.BarChart.Dataset.t()
@type gen_chart :: %{
title: String.t(),
colors: %{color_name() => String.t() | Uncharted.Gradient.t()},
Expand Down
18 changes: 10 additions & 8 deletions uncharted/lib/uncharted/axes/magnitude_axis.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ defmodule Uncharted.Axes.MagnitudeAxis do
@moduledoc """
Exposes a struct representing configuration for an axis that has values that increase in a particular direction
"""
defstruct [:min, :max, :step, :label, grid_lines: &__MODULE__.default_grid_lines_fun/2]
defstruct [:min, :max, :step, :label, :units, grid_lines: &__MODULE__.default_grid_lines_fun/2]
@type min :: number()
@type max :: number()
@type step :: integer()
@type num_steps :: integer()
@type units :: atom()

@typedoc """
A function that takes a tuple with a minimum and maximum value that
represents the min and max of a grid axis and a step value. This function
is used to determine the spacial offsets of the labels on the axis and the
gridlines of the chart.
"""
@type grid_lines_func :: ({min, max}, step -> list(Float.t()))
@type grid_lines_func :: ({min, max}, num_steps() -> list(float()))
@type t() :: %__MODULE__{
min: number(),
max: number(),
units: units(),
step: integer(),
label: String.t() | nil,
grid_lines: grid_lines_func
Expand All @@ -30,10 +32,10 @@ defmodule Uncharted.Axes.MagnitudeAxis do
when you create a `Uncharted.Axes.MagnitudeAxis` struct, this
implementation will be provided used.
"""
@spec default_grid_lines_fun({min, max}, step) :: list(Float.t())
def default_grid_lines_fun({min, max}, step) do
min..max
|> Enum.take_every(div(max - min, step))
|> Enum.drop(1)
@spec default_grid_lines_fun({min, max}, num_steps()) :: list(float())
def default_grid_lines_fun({min, max}, num_steps) do
step_size = (max - min) / (num_steps * 1.0)

Enum.map(0..num_steps, fn step -> step * step_size end)
end
end
13 changes: 13 additions & 0 deletions uncharted/lib/uncharted/axes/polar_axes.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule Uncharted.Axes.PolarAxes do
@moduledoc """
A struct for representing a polar coordinate system's axes
"""

defstruct [:r, :t, show_gridlines: true]

@type t() :: %__MODULE__{
r: Uncharted.Axes.MagnitudeAxis.t(),
t: Uncharted.Axes.MagnitudeAxis.t(),
show_gridlines: boolean()
}
end
10 changes: 5 additions & 5 deletions uncharted/lib/uncharted/bar_chart/bar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ defmodule Uncharted.BarChart.Bar do
defstruct [:height, :offset, :label, :bar_height, :bar_offset, :bar_width, :fill_color]

@type t() :: %__MODULE__{
height: Float.t(),
offset: Float.t(),
height: float(),
offset: float(),
label: String.t(),
bar_height: Float.t(),
bar_offset: Float.t(),
bar_width: Float.t(),
bar_height: float(),
bar_offset: float(),
bar_width: float(),
fill_color: atom()
}
end
2 changes: 1 addition & 1 deletion uncharted/lib/uncharted/bar_chart/dataset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Uncharted.BarChart.Dataset do
defstruct [:axes, :data]

@type t() :: %__MODULE__{
axes: Uncharted.BaseAxes.t(),
axes: Uncharted.Axes.BaseAxes.t(),
data: list(Uncharted.BaseDatum.t())
}
end
2 changes: 1 addition & 1 deletion uncharted/lib/uncharted/base_chart.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Uncharted.BaseChart do

@type t() :: %__MODULE__{
title: String.t(),
colors: %{color_name() => String.t() | Gradient.t()},
colors: %{color_name() => String.t() | Uncharted.Gradient.t()},
dataset: Uncharted.dataset()
}

Expand Down
10 changes: 5 additions & 5 deletions uncharted/lib/uncharted/column_chart/column.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ defmodule Uncharted.ColumnChart.Column do
defstruct [:width, :offset, :label, :bar_width, :bar_offset, :column_height, :fill_color]

@type t() :: %__MODULE__{
width: Float.t(),
offset: Float.t(),
width: float(),
offset: float(),
label: String.t(),
bar_width: Float.t(),
bar_offset: Float.t(),
column_height: Float.t(),
bar_width: float(),
bar_offset: float(),
column_height: float(),
fill_color: atom()
}
end
2 changes: 1 addition & 1 deletion uncharted/lib/uncharted/column_chart/dataset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Uncharted.ColumnChart.Dataset do
defstruct [:axes, :data]

@type t() :: %__MODULE__{
axes: Uncharted.BaseAxes.t(),
axes: Uncharted.Axes.BaseAxes.t(),
data: list(Uncharted.BaseDatum.t())
}
end
2 changes: 1 addition & 1 deletion uncharted/lib/uncharted/line_chart/base_chart_impl.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defimpl Uncharted.LineChart, for: Uncharted.BaseChart do
alias Uncharted.BaseChart
alias Uncharted.ColumnChart.Dataset
alias Uncharted.LineChart.Dataset
alias Uncharted.LineChart.{Line, Point}

def points(%BaseChart{dataset: nil}), do: []
Expand Down
11 changes: 11 additions & 0 deletions uncharted/lib/uncharted/line_chart/dataset.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule Uncharted.LineChart.Dataset do
@moduledoc """
Struct representing a dataset for a basic column chart.
"""
defstruct [:axes, :data]

@type t() :: %__MODULE__{
axes: Uncharted.Axes.XYAxes.t(),
data: list(Uncharted.BaseDatum.t())
}
end
4 changes: 2 additions & 2 deletions uncharted/lib/uncharted/line_chart/line_chart.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defprotocol Uncharted.LineChart do
@spec points(Uncharted.chart() | Uncharted.ColumnChart.Dataset.t()) ::
@spec points(Uncharted.chart() | Uncharted.LineChart.Dataset.t()) ::
list(Uncharted.LineChart.Point.t())
def points(chart)

@spec lines(Uncharted.chart() | Uncharted.ColumnChart.Dataset.t()) ::
@spec lines(Uncharted.chart() | Uncharted.LineChart.Dataset.t()) ::
list(Uncharted.LineChart.Line.t())
def lines(chart)
end
4 changes: 2 additions & 2 deletions uncharted/lib/uncharted/line_chart/point.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Uncharted.LineChart.Point do
@type t :: %__MODULE__{
label: String.t(),
fill_color: atom(),
x_offset: Float.t(),
y_offset: Float.t()
x_offset: float(),
y_offset: float()
}
end
2 changes: 1 addition & 1 deletion uncharted/lib/uncharted/pie_chart/pie_slice.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Uncharted.PieChart.PieSlice do

@type t() :: %__MODULE__{
label: String.t(),
percentage: Float.t(),
percentage: float(),
fill_color: atom()
}
end
22 changes: 22 additions & 0 deletions uncharted/lib/uncharted/polar_chart/base_chart_impl.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defimpl Uncharted.PolarChart, for: Uncharted.BaseChart do
alias Uncharted.BaseChart
alias Uncharted.PolarChart.Dataset
alias Uncharted.PolarChart.Point

def points(%BaseChart{dataset: nil}), do: []
def points(%BaseChart{dataset: dataset}), do: points(dataset)
def points(%Dataset{data: []}), do: []

def points(%Dataset{
data: data
}) do
data
|> Enum.map(fn datum ->
%Point{
label: datum.name,
r: Enum.at(datum.values, 0),
t: Enum.at(datum.values, 1)
}
end)
end
end
11 changes: 11 additions & 0 deletions uncharted/lib/uncharted/polar_chart/dataset.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule Uncharted.PolarChart.Dataset do
@moduledoc """
Struct representing a dataset for a basic polar chart.
"""
defstruct [:axes, :data]

@type t() :: %__MODULE__{
axes: Uncharted.Axes.PolarAxes.t(),
data: list(Uncharted.BaseDatum.t())
}
end
13 changes: 13 additions & 0 deletions uncharted/lib/uncharted/polar_chart/point.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule Uncharted.PolarChart.Point do
@moduledoc """
A struct representing a Point on a polar r, t coordinate chart
"""

defstruct [:label, :r, :t]

@type t :: %__MODULE__{
label: String.t(),
r: float(),
t: float()
}
end
5 changes: 5 additions & 0 deletions uncharted/lib/uncharted/polar_chart/polar_chart.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defprotocol Uncharted.PolarChart do
@spec points(Uncharted.chart() | Uncharted.PolarChart.Dataset.t()) ::
list(Uncharted.PolarChart.Point.t())
def points(chart)
end
2 changes: 1 addition & 1 deletion uncharted/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Uncharted.MixProject do
compilers: Mix.compilers(),
dialyzer: [
plt_add_apps: ~w(ex_unit mix)a,
plt_add_deps: :transitive,
plt_add_deps: :app_tree,
plt_file: {:no_warn, "priv/plts/dialyzer.plt"}
# ignore_warnings: "../.dialyzer-ignore.exs"
],
Expand Down
2 changes: 1 addition & 1 deletion uncharted/test/uncharted/line_chart_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Uncharted.LineChartTest do
alias Uncharted.{BaseChart, BaseDatum, LineChart}
alias Uncharted.Axes.{MagnitudeAxis, XYAxes}
alias Uncharted.ColumnChart.Dataset
alias Uncharted.LineChart.Dataset
alias Uncharted.LineChart.Line
use ExUnit.Case

Expand Down
49 changes: 49 additions & 0 deletions uncharted/test/uncharted/polar_chart_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
defmodule Uncharted.PolarChartTest do
alias Uncharted.{BaseChart, BaseDatum, PolarChart}
alias Uncharted.Axes.{MagnitudeAxis, PolarAxes}
alias Uncharted.PolarChart.Dataset
alias Uncharted.PolarChart.Line
use ExUnit.Case

@radial_axis %MagnitudeAxis{min: 0, max: 12.0}
@angular_axis %MagnitudeAxis{min: 0, max: 2.0, units: :radians, step: 4}
@axes %PolarAxes{r: @radial_axis, t: @angular_axis}
@data [
%BaseDatum{name: "Point One", values: [1, 1.3]},
%BaseDatum{name: "Point Two", values: [5, 1.0]},
%BaseDatum{name: "Point Three", values: [6, 0.5]},
%BaseDatum{name: "Point Four", values: [8, 1.8]},
%BaseDatum{name: "Point Five", values: [10, 0.3]}
]
@dataset %Dataset{data: @data, axes: @axes}
@chart %BaseChart{title: "title", dataset: @dataset}

describe "points/1" do
test "returns the number of points that make up the dataset" do
assert length(PolarChart.points(@chart)) == length(@data)
end

test "returns point labels" do
points = Enum.map(PolarChart.points(@chart), & &1.label)
labels = Enum.map(@data, & &1.name)

assert points
|> Enum.zip(labels)
|> Enum.all?(fn {actual, expected} -> actual == expected end)
end

test "assigns point r (radial distance) value as first element in datum.values" do
r_values = Enum.map(PolarChart.points(@chart), & &1.r)
expected_r_values = [1, 5, 6, 8, 10]

assert r_values == expected_r_values
end

test "assigns point t (angular distance) value as first element in datum.values" do
t_values = Enum.map(PolarChart.points(@chart), & &1.t)
expected_t_values = [1.3, 1.0, 0.5, 1.8, 0.3]

assert t_values == expected_t_values
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<g id="<%= svg_id(@chart, "radial_circles") %>" class="columns__lines">
<%= for radius <- @grid_lines do %>
<circle class="counter__ring" cx="0" cy="0" r="<%= radius %>" fill="transparent" stroke="#BBBBBB" stroke-width="0.1"></circle>
<% end %>
</g>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<g id="<%= svg_id(@chart, "lines") %>" class="columns__lines">
<%= for %Line{start: %{x_offset: x1, y_offset: y1}, end: %{x_offset: x2, y_offset: y2}} <- angular_to_cartesian_gridlines(@grid_lines, @chart.dataset.axes.r.max) do %>
<line x1="<%= x1 %>" y1="<%= y1 %>" x2="<%= x2 %>" y2="<%= y2 %>" stroke="#efefef" stroke-width="0.2px" stroke-linecap="round" />
<% end %>
</g>
Loading