Skip to content

Commit

Permalink
make reuse of existing tick_interval explicit so tests can pass
Browse files Browse the repository at this point in the history
  • Loading branch information
DaTrader committed Feb 4, 2024
1 parent 47803b5 commit 47afca1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/chart/ohlc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,11 @@ defmodule Contex.OHLC do

x_scale =
x_scale
|> struct(interval_count: interval_count, tick_interval: tick_interval)
|> struct(
interval_count: interval_count,
tick_interval: tick_interval,
use_existing_tick_interval?: true
)
|> TimeScale.domain(min, last_dt)

apply_x_scale(plot, x_scale)
Expand Down
6 changes: 4 additions & 2 deletions lib/chart/scale/time_scale.ex
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ defmodule Contex.TimeScale do
:range,
:interval_count,
:tick_interval,
:use_existing_tick_interval?,
:step,
:custom_tick_formatter,
:display_format
Expand All @@ -105,6 +106,7 @@ defmodule Contex.TimeScale do
%TimeScale{
range: {0.0, 1.0},
interval_count: 11,
use_existing_tick_interval?: false,
step: 1
}
end
Expand Down Expand Up @@ -171,8 +173,8 @@ defmodule Contex.TimeScale do
defp nice(%TimeScale{domain: {min_d, max_d}, interval_count: interval_count} = scale)
when is_number(interval_count) and interval_count > 1 do
tick_interval =
if tick_interval = scale.tick_interval do
tick_interval
if scale.use_existing_tick_interval? do
scale.tick_interval
else
width = Utils.date_diff(max_d, min_d, :millisecond)
unrounded_interval_size = width / (interval_count - 1)
Expand Down

0 comments on commit 47afca1

Please sign in to comment.