Exemple #1
0
    def __init__(self, *args, **kwargs):
        """Create a Vega Grouped Bar Chart"""

        if 'grouped' not in kwargs:
            kwargs['grouped'] = True

        super(GroupedBar, self).__init__(*args, **kwargs)

        del self.data['stats']

        del self.scales['y'].type
        self.scales['y'].domain.field = 'data.val'
        self.scales['y'].domain.data = 'table'
        self.scales['x'].padding = 0.2

        del self.marks[0].from_.transform[1]
        self.marks[0].from_.transform[0].keys[0] = 'data.idx'
        enter_props = PropertySet(x=ValueRef(scale='x', field="key"),
                                  width=ValueRef(scale='x', band=True))
        self.marks[0].properties = MarkProperties(enter=enter_props)
        self.marks[0].scales = KeyedList()
        self.marks[0].scales['pos'] = Scale(name='pos', type='ordinal',
                                            range='width',
                                            domain=DataRef(field='data.group'))

        self.marks[0].marks[0].properties.enter.width.scale = 'pos'
        self.marks[0].marks[0].properties.enter.y.field = 'data.val'
        self.marks[0].marks[0].properties.enter.x.field = 'data.group'
        self.marks[0].marks[0].properties.enter.x.scale = 'pos'

        del self.marks[0].marks[0].properties.enter.y2.field
        self.marks[0].marks[0].properties.enter.y2.value = 0
Exemple #2
0
    def __init__(self, *args, **kwargs):
        """Initialize a Visualization

        In addition to setting any attributes, this sets the data, marks,
        scales, and axes properties to empty KeyedLists if they aren't
        defined by the arguments.
        """
        super(Visualization, self).__init__(*args, **kwargs)
        for attrib in ('data', 'scales'):
            if not getattr(self, attrib):
                setattr(self, attrib, KeyedList(attr_name='name'))
        # The axes get keyed by "type" instead of name.
        if not self.axes:
            self.axes = KeyedList(attr_name='type')
        # Marks and Legends don't get keyed.
        if not self.marks:
            self.marks = []
        if not self.legends:
            self.legends = []