Skip to content

Commit

Permalink
Scatterplot: Fix crash for a single time tick
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Sep 21, 2022
1 parent 1d10fb4 commit e0ce236
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Orange/widgets/visualize/owscatterplotgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,10 @@ def tickValues(self, minVal, maxVal, size):
step = int(np.ceil(float(len(ticks)) / max_steps))
ticks = ticks[::step]

spacing = min(b - a for a, b in zip(ticks[:-1], ticks[1:]))
# In case of a single tick, `default` will inform tickStrings
# about the appropriate scale.
spacing = min((b - a for a, b in zip(ticks[:-1], ticks[1:])),
default=maxVal - minVal)
return [(spacing, ticks)]

def tickStrings(self, values, scale, spacing):
Expand Down
4 changes: 4 additions & 0 deletions Orange/widgets/visualize/tests/test_owscatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,10 @@ def test_time_axis(self):
with self.assertRaises(ValueError):
float(ticks[0])

spacing, ticks = x_axis.tickValues(1581953776, 1582953776, 10)[0]
self.assertEqual(spacing, 1582953776 - 1581953776)
self.assertTrue(not ticks.size or 1581953776 <= ticks[0] <= 1582953776)

def test_clear_plot(self):
self.widget.cb_class_density.setChecked(True)
self.send_signal(self.widget.Inputs.data, self.data)
Expand Down

0 comments on commit e0ce236

Please sign in to comment.