Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import unittest | ||
|
||
from numpy import alltrue, arange | ||
from enable.compiled_path import CompiledPath | ||
|
||
# Chaco imports | ||
from chaco.api import (ArrayDataSource, ColormappedScatterPlot, DataRange1D, | ||
LinearMapper, PlotGraphicsContext, jet) | ||
|
||
|
||
class TestColormappedScatterplot(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.index = ArrayDataSource(arange(10)) | ||
self.value = ArrayDataSource(arange(10)) | ||
self.color_data = ArrayDataSource(arange(10)) | ||
self.size_data = arange(10) | ||
|
||
self.index_range = DataRange1D() | ||
self.index_range.add(self.index) | ||
self.index_mapper = LinearMapper(range=self.index_range) | ||
|
||
self.value_range = DataRange1D() | ||
self.value_range.add(self.value) | ||
self.value_mapper = LinearMapper(range=self.value_range) | ||
|
||
self.color_range = DataRange1D() | ||
self.color_range.add(self.color_data) | ||
self.color_mapper = jet(self.color_range) | ||
|
||
self.scatterplot = ColormappedScatterPlot( | ||
index=self.index, | ||
value=self.value, | ||
index_mapper=self.index_mapper, | ||
value_mapper=self.value_mapper, | ||
color_data=self.color_data, | ||
marker_size=self.size_data, | ||
color_mapper=self.color_mapper, | ||
) | ||
self.scatterplot.outer_bounds = [50, 50] | ||
self.gc = PlotGraphicsContext((50, 50)) | ||
|
||
def test_scatter_render(self): | ||
# Coverage test to check basic case works | ||
self.gc.render_component(self.scatterplot) | ||
actual = self.gc.bmp_array[:, :, :] | ||
self.assertFalse(alltrue(actual == 255)) | ||
|
||
def test_scatter_circle(self): | ||
# Coverage test to check circles work | ||
self.scatterplot.marker = 'circle' | ||
|
||
self.gc.render_component(self.scatterplot) | ||
actual = self.gc.bmp_array[:, :, :] | ||
self.assertFalse(alltrue(actual == 255)) | ||
|
||
@unittest.expectedFailure | ||
def test_scatter_custom(self): | ||
# Coverage test to check custom markers work | ||
|
||
# build path | ||
path = CompiledPath() | ||
path.move_to(-5, -5) | ||
path.line_to(5, 5) | ||
path.line_to(5, -5) | ||
path.line_to(-5, 5) | ||
path.line_to(-5, -5) | ||
|
||
self.scatterplot.marker = 'custom' | ||
self.scatterplot.custom_symbol = path | ||
|
||
self.gc.render_component(self.scatterplot) | ||
actual = self.gc.bmp_array[:, :, :] | ||
self.assertFalse(alltrue(actual == 255)) | ||
|
||
def test_colormap_updated(self): | ||
# If colormapper updated then we need to redraw """ | ||
self.color_mapper.updated = True | ||
self.assertFalse(self.scatterplot.draw_valid) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |