예제 #1
0
def make_custom_marker():
    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)
    return path
예제 #2
0
def make_custom_marker():
    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)
    return path
예제 #3
0
    def test_scatter_1d_custom(self):
        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
        gc = PlotGraphicsContext(self.size)
        gc.render_component(self.scatterplot)
        actual = gc.bmp_array[:, :, :]
        self.assertFalse(alltrue(actual == 255))
예제 #4
0
    def test_scatter_1d_custom(self):
        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
        gc = PlotGraphicsContext(self.size)
        gc.render_component(self.scatterplot)
        actual = gc.bmp_array[:, :, :]
        self.assertFalse(alltrue(actual == 255))
예제 #5
0
    def _geojs_filename_changed(self, name):
        data = file(name).read()
        polys = process_raw(data.replace('\r\n', ''))
        # Generate compiled path from the polygons
        paths = []
        for poly in polys:
            path = CompiledPath()
            for p in poly:
                path.lines(p)
            paths.append(path)
        self._paths = paths

        red = np.array([202, 0, 32])/255.
        blue = np.array([5, 113, 176])/255.
        colors = red * np.random.random_integers(0,1,len(paths)).reshape(-1,1)
        colors[np.sum(colors,axis=-1)==0] = blue
        self._colors = colors

        # Store the polygons just in case we need to regenerate the path
        self._polys = polys
        self.request_redraw()
예제 #6
0
    def _geojs_filename_changed(self, name):
        data = file(name).read()
        polys = process_raw(data.replace('\r\n', ''))
        # Generate compiled path from the polygons
        paths = []
        for poly in polys:
            path = CompiledPath()
            for p in poly:
                path.lines(p)
            paths.append(path)
        self._paths = paths

        red = np.array([202, 0, 32]) / 255.
        blue = np.array([5, 113, 176]) / 255.
        colors = red * np.random.random_integers(0, 1, len(paths)).reshape(
            -1, 1)
        colors[np.sum(colors, axis=-1) == 0] = blue
        self._colors = colors

        # Store the polygons just in case we need to regenerate the path
        self._polys = polys
        self.request_redraw()
예제 #7
0
    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)

        size = (50, 50)
        scatterplot = create_scatter_plot(
            data=[range(10), range(10)],
            marker='custom',
            border_visible=False,
        )
        scatterplot.custom_symbol = path
        scatterplot.outer_bounds = list(size)
        gc = PlotGraphicsContext(size)
        gc.render_component(scatterplot)
        actual = gc.bmp_array[:, :, :]
        self.assertFalse(alltrue(actual == 255))
예제 #8
0
파일: lion.py 프로젝트: alexlib/enable
def get_lion():
    """get_lion() -> path_and_color, size, center

        path_and_color: [(path,color), ...]
        size: [width, height]
        center: [x, y]

    Defines a function to return a vector image of a cartoon lion.
    """
    mins = []
    maxs = []
    colors = []
    paths = []
    for line in LION_DATA:
        fields = line.split()
        if len(fields) == 0:
            pass
        elif len(fields) == 1:
            hex_color = fields[0]
            r = int(hex_color[:2], 16) / 255.0
            g = int(hex_color[2:4], 16) / 255.0
            b = int(hex_color[4:6], 16) / 255.0
            colors.append(array((r, g, b, 1.0)))
            paths.append(CompiledPath())
            path = paths[-1]
        else:
            fields = array(fields, "O")
            cmd = fields[::2]
            pts = [array(eval(x), dtype=float) for x in fields[1::2]]
            mins.append(amin(pts, axis=0))
            maxs.append(amax(pts, axis=0))

            path_def = list(zip(cmd, pts))
            for cmd, pt in path_def:
                pt[0] -= 119
                pt[1] -= 190.5
                if cmd == "M":
                    path.move_to(pt[0], pt[1])
                if cmd == "L":
                    path.line_to(pt[0], pt[1])

    min_pt = amin(array(mins), axis=0)
    max_pt = amax(array(maxs), axis=0)

    sz = max_pt - min_pt
    center = min_pt + sz / 2.0
    return list(zip(paths, colors)), sz, center
예제 #9
0
def build_paths(lion_string):
    mins = []
    maxs = []
    colors = []
    paths = []
    lines = lion_string.split('\n')
    for line in lines:
        fields = line.split()
        if len(fields) == 0:
            pass
        elif len(fields) == 1:
            hex_color = fields[0]
            r = int(hex_color[:2], 16) / 255.
            g = int(hex_color[2:4], 16) / 255.
            b = int(hex_color[4:6], 16) / 255.
            colors.append(array((r, g, b, 1.0)))
            paths.append(CompiledPath())
            path = paths[-1]
        else:
            fields = array(fields, 'O')
            cmd = fields[::2]
            pts = [array(eval(x), dtype=float) for x in fields[1::2]]
            mins.append(amin(pts, axis=0))
            maxs.append(amax(pts, axis=0))

            path_def = list(zip(cmd, pts))
            for cmd, pt in path_def:
                pt[0] -= 119
                pt[1] -= 190.5
                if cmd == 'M':
                    path.move_to(pt[0], pt[1])
                if cmd == 'L':
                    path.line_to(pt[0], pt[1])
    min_pt = amin(array(mins), axis=0)
    max_pt = amax(array(maxs), axis=0)

    sz = max_pt - min_pt
    center = min_pt + sz / 2.0
    return list(zip(paths, colors)), sz, center
    def test_scatter_custom(self):
        """ Coverage test to check custom markers work...

        XXX ...which apparently they currently don't. See #232.
        """

        # build path
        path = CompiledPath()
        path.begin_path()
        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))
예제 #11
0
        return self.dataframe.columns[-1]

    def _data_columns_default(self):
        return list(self.dataframe.columns[1:][::-1])


if __name__ == "__main__":
    populations = pandas.read_csv('state_populations.csv')

    from mapping.enable.geojson_overlay import process_raw
    polys = process_raw(file("states.geojs").read().replace('\r\n', ''))
    # generate compiled paths from polys
    paths = []
    coords = numpy.zeros((len(polys), 2))
    for poly, coord in zip(polys, coords):
        path = CompiledPath()
        total = numpy.sum((numpy.sum(p, axis=0) for p in poly), axis=0)
        coord[:] = total / sum(map(len, poly))
        for p in poly:
            path.lines(p - coord)  # recenter on origin
        paths.append(path)

    with enaml.imports():
        from choropleth_view import MapView

    view = MapView(model=Demo(title="State population from 1900 to 2010",
                              index_ds=ArrayDataSource(coords[:, 0]),
                              value_ds=ArrayDataSource(coords[:, 1]),
                              paths=paths,
                              dataframe=populations), )
예제 #12
0
    def test_get_compiled_path(self):
        path = CompiledPath()
        path.begin_path()
        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)

        marker = CustomMarker(path=path)

        # should not fail
        marker.get_compiled_path(np.int64(0))
예제 #13
0
    def test_add_to_path(self):
        path = CompiledPath()
        path.begin_path()
        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)

        marker = CustomMarker(path=path)

        gc = GraphicsContext((50, 50))
        # should not fail
        marker.add_to_path(gc.get_empty_path(), np.int64(0))
예제 #14
0
        return self.dataframe.columns[-1]

    def _data_columns_default(self):
        return list(self.dataframe.columns[1:][::-1])
   

if __name__ == "__main__":
    populations = pandas.read_csv('example/state_populations.csv')

    from mapping.enable.geojson_overlay import process_raw
    polys = process_raw(file("example/states.geojs").read().replace('\r\n',''))
    # generate compiled paths from polys
    paths = []
    coords = numpy.zeros((len(polys), 2))
    for poly, coord in zip(polys, coords):
        path = CompiledPath()
        total = numpy.sum((numpy.sum(p, axis=0) for p in poly), axis=0)
        coord[:] = total/sum(map(len,poly))
        for p in poly:
            path.lines(p - coord) # recenter on origin
        paths.append(path)

    with enaml.imports():
        from choropleth_view import MapView
        
    view = MapView(
        model = Demo(title = "State population from 1900 to 2010",
                     index_ds = ArrayDataSource(coords[:,0]),
                     value_ds = ArrayDataSource(coords[:,1]),
                     paths = paths,
                     dataframe = populations),
    def test_scatter_custom(self):
        """ Coverage test to check custom markers work...

        XXX ...which apparently they currently don't. See #232.
        """

        # build path
        path = CompiledPath()
        path.begin_path()
        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))