Skip to content

Commit

Permalink
Adjust point sample process.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdunkerley committed Aug 23, 2022
1 parent 30c1555 commit 6473ad1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,40 +158,25 @@ type Extreme min_x max_x min_y max_y
## PRIVATE
limit_data limit data = case limit of
Nothing -> data
_ -> if (data.length <= limit) then data else
b = Vector.new_builder limit

_ -> if ((data.length <= limit) || (data.length == 0)) then data else
x datum = (datum.get "x").unwrap
y datum = (datum.get "y").unwrap

check_max_y min now = case min of
Extreme min_x max_x min_y Nothing -> Extreme min_x max_x min_y now
Extreme min_x max_x min_y max_y -> if y max_y < y now then @Tail_Call check_max_y (Extreme min_x max_x min_y now) max_y else
b.append now
min

check_min_y min now = case min of
Extreme min_x max_x Nothing max_y -> Extreme min_x max_x now max_y
Extreme min_x max_x min_y max_y -> if y min_y > y now then @Tail_Call check_min_y (Extreme min_x max_x now max_y) min_y else
check_max_y min now

check_max_x min now = case min of
Extreme min_x Nothing min_y max_y -> Extreme min_x now min_y max_y
Extreme min_x max_x min_y max_y -> if x max_x < x now then @Tail_Call check_max_x (Extreme min_x now min_y max_y) max_x else
check_min_y min now

check_min_x min now = case min of
Extreme Nothing max_x min_y max_y -> Extreme now max_x min_y max_y
Extreme min_x max_x min_y max_y -> if x min_x > x now then @Tail_Call check_min_x (Extreme now max_x min_y max_y) min_x else
check_max_x min now
update_extreme current idx point =
new_min_x = if x current.min_x.second > x point then [idx, point] else current.min_x
new_min_y = if y current.min_y.second > y point then [idx, point] else current.min_y
new_max_x = if x current.max_x.second < x point then [idx, point] else current.max_x
new_max_y = if y current.max_y.second < y point then [idx, point] else current.max_y
Extreme new_min_x new_max_x new_min_y new_max_y

extreme = case data.fold (Extreme Nothing Nothing Nothing Nothing) check_min_x of
Extreme min_x max_x min_y max_y -> [min_x, max_x, min_y, max_y].filter case _ of
Nothing -> False
_ -> True
first = [0, data.first]
bounds = case data.fold_with_index (Extreme first first first first) update_extreme of
Extreme min_x max_x min_y max_y -> [min_x, max_x, min_y, max_y]
_ -> []
extreme = Map.from_vector bounds . values

if limit <= extreme.length then extreme.take (First limit) else
extreme + b.to_vector.take (Sample limit-extreme.length)
extreme + data.take (Sample (limit - extreme.length))

## PRIVATE
json_from_table : Table -> [Int]|Nothing -> Int|Nothing -> Json
Expand Down
4 changes: 3 additions & 1 deletion test/Visualization_Tests/src/Scatter_Plot_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ spec =
json.fields.keys.should_equal ['axis','data']
data = (json.fields.get 'data') . unwrap
data.length . should_equal 10
(data.take (First 4)).to_text . should_equal "[[['x', 0], ['y', 225]], [['x', 29], ['y', 196]], [['x', 15], ['y', 0]], [['x', 1], ['y', 196]]]"
(data.take (First 3)).to_text . should_equal '[[[\'x\', 0], [\'y\', 225]], [[\'x\', 15], [\'y\', 0]], [[\'x\', 29], [\'y\', 196]]]'

Test.specify "filter the elements" <|
vector = [0,10,20,30]
Expand All @@ -141,3 +141,5 @@ spec =
Test.specify "using indices for x if given a range" <|
value = 2.up_to 5
expect value no_labels '[{"x":0,"y":2},{"x":1,"y":3},{"x":2,"y":4}]'

main = Test.Suite.run_main spec

0 comments on commit 6473ad1

Please sign in to comment.