Exemplo n.º 1
0
    def get_circle_canvas_from_color(color, radius=__radius, stroke_width=1.0, stroke_color=avg.Color("c0c0c0"),
                                     fake_opacity=1.0):
        if color is None:
            raise ValueError("CanvasManager.get_circle_canvas_from_color: color for canvas cannot be None.")
        if isinstance(color, str):
            color = avg.Color(color)
        if not isinstance(color, avg.Color):
            raise ValueError("CanvasManager.get_circle_canvas_from_color: color for canvas must be type avg.Color.")

        # TODO: Fix the problem with the wrong stroke color string.
        canvas_id = "circle_%d-%d-%d_%d_%s_%d" % (color.r, color.g, color.b, stroke_width, "c0c0c0", fake_opacity)

        # check if color in already existing canvases
        if canvas_id in CanvasManager.__circle_canvases:
            return "canvas:%s" % canvas_id  # CanvasManager.__circle_canvases[color]

        # create canvas and add to circle canvases
        size = avg.Point2D(CanvasManager.__radius, CanvasManager.__radius) * 2 + (2, 2)
        canvas = player.createCanvas(id=canvas_id, autorender=False, multisamplesamples=8, size=size)
        if fake_opacity != 1.0:
            avg.CircleNode(
                pos=(size / 2) + (1, 1),
                r=CanvasManager.__radius,
                strokewidth=0.0,
                fillopacity=1.0,
                fillcolor='fff',
                parent=canvas.getRootNode()
            )
        avg.CircleNode(
                pos=(size / 2) + (1, 1),
                r=CanvasManager.__radius,
                color=stroke_color,
                strokewidth=stroke_width,
                fillopacity=fake_opacity,
                fillcolor=color,
                parent=canvas.getRootNode()
        )
        canvas.render()
        CanvasManager.__circle_canvases.append(canvas_id)
        return "canvas:%s" % canvas_id
Exemplo n.º 2
0
 def setColor():
     node.color = "FFFF00"
     self.assertEqual(node.color, "FFFF00")
     node.color = avg.Color(255, 255, 0)
     node.color = (255, 255, 0)
Exemplo n.º 3
0
    def testColor(self):
        col = avg.Color("0080FF")
        self.assertEqual(col, avg.Color(0, 128, 255))
        self.assertEqual(col, avg.Color((0, 128, 255)))
        self.assertEqual(col, (0, 128, 255))
        self.assertEqual(col, "0080FF")
        self.assertEqual(col.r, 0)
        self.assertEqual(col.g, 128)
        self.assertEqual(col.b, 255)
        self.assertEqual(avg.Color("FF6600"), avg.Color("F60"))
        col = avg.Color.mix(avg.Color("FF0000"), avg.Color("0000FF"), 1)
        self.assertEqual(col, avg.Color("FF0000"))
        col = avg.Color.mix(avg.Color("FF0000"), avg.Color("0000FF"), 0)
        self.assertEqual(col, avg.Color("0000FF"))
        col = avg.Color.fromLch(60, 74, 126)
        self.assertEqual(col, "5CA20D")
        self.assertRaises(avg.Exception, lambda: avg.Color("1234567"))
        self.assertRaises(avg.Exception, lambda: avg.Color("xxx"))
        self.assertRaises(avg.Exception, lambda: avg.Color("xxxxxx"))

        # Test mixing when saturation==0
        col = avg.Color.mix(avg.Color("FFFFFF"), avg.Color("FF0000"), 0.5)
        self.assertEqual(col, avg.Color("FF9E81"))
        self.assertEqual(str(col), "FF9E81")
Exemplo n.º 4
0
    def __on_selection_of_data_objects_in_view(self, sender,
                                               selection_data_holder,
                                               selection_set_id,
                                               selection_diff):
        """
        Called when a selection on a node in a grid element div were made.
        Sets the color and the state of all visviews in the application.

        :type sender: Node
        :param selection_data_holder: The selection data holder for the vis.
        :type selection_data_holder: SelectionDataHolder
        :param selection_set_id: The id of the changed selection.
        :type selection_set_id: str
        :param selection_diff: The diff of the previous selection and the new one.
        :type selection_diff: list
        """
        removed = len(
            selection_data_holder.check_if_selection_in_set(
                selection_diff)) == 0
        selection_color = avg.Color(
            SelectionColorMapper.get_next_selection_color(selection_set_id))
        if removed and len(
                selection_data_holder.get_selection_set(
                    selection_set_id)) == 0:
            SelectionColorMapper.remove_selection_id(selection_set_id)

        color = defaults.ITEM_COLOR if removed else selection_color  # DataDefaults.COLOR_SELECTED
        opacity = defaults.ITEM_OPACITY if removed else defaults.ITEM_OPACITY_SELECTED
        state = DataSelectionState.Nothing if removed else DataSelectionState.Selected

        # Set the color and for the new selected/deselected data objects of a chart.
        if isinstance(sender, ChartBase):
            data_object_ids = sender.find_data_objects(
                data_objects=sender.data_objects,
                values_to_check=selection_diff,
                key=selection_set_id.split('|')[0]).keys()
            extra_colors = self.__get_original_color_for_data_objects(
                selection_data_holder=selection_data_holder,
                changed_data_object_ids=data_object_ids,
                vis_view_data_objects=sender.data_objects,
                vis_view=sender) if removed else {}

            sender.change_color_for_data_objects(data_object_ids,
                                                 color=color,
                                                 opacity=opacity)
            # Set the color of those that are already selected new.
            for data_object_id, other_color in extra_colors.iteritems():
                sender.change_color_for_data_objects(
                    [data_object_id],
                    color=other_color,
                    opacity=defaults.ITEM_OPACITY_SELECTED)
            sender.change_selection_state_for_data_objects(data_object_ids,
                                                           state=state)
        elif isinstance(sender, MapVisView):
            point_views = sender.find_map_point_views(
                point_views=sender.point_views,
                values_to_check=selection_diff,
                key=selection_set_id.split('|')[0])
            sender.change_state_for_points(point_views,
                                           state=state,
                                           highlight_color=color)

        # Search all views that have the same data key as the sender.
        vis_views_to_notify = []
        for grid_element_div in self.__multi_view_node.grid_element_divs.itervalues(
        ):
            for vis_view in grid_element_div.child_nodes:
                if sender is vis_view:
                    continue
                if selection_set_id.split(
                        '|')[0] in vis_view.data_keys_for_selection:
                    vis_views_to_notify.append(vis_view)

        # Set the new selection for all the other vis views that have the same key to represent.
        for vis_view in vis_views_to_notify:
            selection_set = selection_data_holder.get_selection_set(
                selection_set_id)
            changed_object_set = vis_view.change_data_selection(
                selection_set_id=selection_set_id,
                selection_set=selection_set,
                selection_diff=selection_diff,
                addition=not removed,
                update_colors=False)

            in_vis_removed = len(
                vis_view.selection_data_holder.check_if_selection_in_set(
                    selection_diff)) == 0
            state = DataSelectionState.Nothing if in_vis_removed else DataSelectionState.Selected
            opacity = defaults.ITEM_OPACITY if in_vis_removed else defaults.ITEM_OPACITY_SELECTED
            color = defaults.ITEM_COLOR if in_vis_removed else selection_color  # DataDefaults.COLOR_SELECTED

            if isinstance(vis_view, ChartBase):
                extra_colors = self.__get_original_color_for_data_objects(
                    selection_data_holder=vis_view.selection_data_holder,
                    changed_data_object_ids=changed_object_set,
                    vis_view_data_objects=vis_view.data_objects,
                    vis_view=vis_view) if in_vis_removed else {}

                vis_view.change_color_for_data_objects(changed_object_set,
                                                       color=color,
                                                       opacity=opacity)
                # Set the color and the state of those that are already selected new.
                for data_object_id, other_color in extra_colors.iteritems():
                    vis_view.change_color_for_data_objects(
                        [data_object_id],
                        color=other_color,
                        opacity=defaults.ITEM_OPACITY_SELECTED)
                    vis_view.change_selection_state_for_data_objects(
                        [data_object_id], state=DataSelectionState.Selected)
                vis_view.change_selection_state_for_data_objects(
                    changed_object_set, state=state)
            elif isinstance(vis_view, MapVisView):
                vis_view.change_state_for_points(changed_object_set,
                                                 state=state,
                                                 highlight_color=color)