示例#1
0
    def _process(self, p, element, ranges={}):
        # Creates a unified Dataset.data attribute
        # to draw the data from
        if isinstance(element.data, np.ndarray):
            if 'dataframe' in Dataset.datatype:
                el_data = element.table('dataframe')
            else:
                el_data = element.table('dictionary')
        else:
            el_data = element.data

        # Get dimensions to plot against each other
        dims = [
            d for d in element.dimensions() if _is_number(element.range(d)[0])
        ]
        permuted_dims = [(d1, d2) for d1 in dims for d2 in dims[::-1]]

        data = {}
        for d1, d2 in permuted_dims:
            if d1 == d2:
                if p.diagonal_type is Histogram:
                    bin_range = ranges.get(d1.name, element.range(d1))
                    el = element.hist(
                        dimension=d1.name, bin_range=bin_range,
                        adjoin=False)(norm=dict(axiswise=True, framewise=True))
                else:
                    values = element.dimension_values(d1)
                    el = p.diagonal_type(values, vdims=[d1])
            else:
                el = p.chart_type(el_data,
                                  kdims=[d1],
                                  vdims=[d2],
                                  datatype=['dataframe', 'dictionary'])
            data[(d1.name, d2.name)] = el
        return data
示例#2
0
    def _process(self, p, element, ranges={}):
        # Creates a unified Columns.data attribute
        # to draw the data from
        if isinstance(element.data, np.ndarray):
            if 'dataframe' in Columns.datatype:
                el_data = element.table('dataframe')
            else:
                el_data = element.table('ndelement')
        el_data = element.data

        # Get dimensions to plot against each other
        dims = [d for d in element.dimensions()
                if _is_number(element.range(d)[0])]
        permuted_dims = [(d1, d2) for d1 in dims
                         for d2 in dims[::-1]]

        data = {}
        for d1, d2 in permuted_dims:
            if d1 == d2:
                if p.diagonal_type is Histogram:
                    bin_range = ranges.get(d1.name, element.range(d1))
                    el = element.hist(dimension=d1.name,
                                      bin_range=bin_range,
                                      adjoin=False)
                else:
                    values = element.dimension_values(d1)
                    el = p.diagonal_type(values, kdims=[d1])
            else:
                el = p.chart_type(el_data, kdims=[d1],
                                  vdims=[d2])
            data[(d1.name, d2.name)] = el
        return data
示例#3
0
def ObjectSelector(pobj):
    """
    Determines param.ObjectSelector widget depending on whether all values
    are numeric.
    """
    options = list(pobj.objects.values()) if isinstance(pobj.objects, dict) else pobj.objects
    if options and all(param._is_number(o) for o in options):
        return DiscreteSlider
    else:
        return Select
示例#4
0
    def _process(self, p, element, ranges={}):
        # Creates a unified Dataset.data attribute
        # to draw the data from
        if isinstance(element.data, np.ndarray):
            if 'dataframe' in Dataset.datatype:
                el_data = element.table('dataframe')
            else:
                el_data = element.table('dictionary')
        else:
            el_data = element.data

        # Get dimensions to plot against each other
        types = (str, basestring, np.str_, np.object_) + datetime_types
        dims = [
            d for d in element.dimensions() if _is_number(element.range(d)[0])
            and not issubclass(element.get_dimension_type(d), types)
        ]
        permuted_dims = [(d1, d2) for d1 in dims for d2 in dims[::-1]]

        # Convert Histogram type to operation to avoid one case in the if below.
        if p.diagonal_type is Histogram:
            p.diagonal_type = None
            p.diagonal_operation = histogram

        data = {}
        for d1, d2 in permuted_dims:
            if d1 == d2:
                if p.diagonal_type is not None:
                    if p.diagonal_type._auto_indexable_1d:
                        el = p.diagonal_type(
                            el_data,
                            kdims=[d1],
                            vdims=[d2],
                            datatype=['dataframe', 'dictionary'])
                    else:
                        values = element.dimension_values(d1)
                        el = p.diagonal_type(values, kdims=[d1])
                elif p.diagonal_operation is histogram or isinstance(
                        p.diagonal_operation, histogram):
                    bin_range = ranges.get(d1.name, element.range(d1))
                    el = p.diagonal_operation(element,
                                              dimension=d1.name,
                                              bin_range=bin_range)
                else:
                    el = p.diagonal_operation(element, dimension=d1.name)
            else:
                kdims, vdims = ([d1, d2],
                                []) if len(p.chart_type.kdims) == 2 else (d1,
                                                                          d2)
                el = p.chart_type(el_data,
                                  kdims=kdims,
                                  vdims=vdims,
                                  datatype=['dataframe', 'dictionary'])
            data[(d1.name, d2.name)] = el
        return data
示例#5
0
文件: interact.py 项目: yuttie/panel
 def widget_from_iterable(o, name):
     """Make widgets from an iterable. This should not be done for
     a string or tuple."""
     # Select expects a dict or list, so we convert an arbitrary
     # iterable to either of those.
     values = list(o.values()) if isinstance(o, Mapping) else list(o)
     widget_type = DiscreteSlider if all(param._is_number(v) for v in values) else Select
     if isinstance(o, (list, dict)):
         return widget_type(options=o, name=name)
     elif isinstance(o, Mapping):
         return widget_type(options=list(o.items()), name=name)
     else:
         return widget_type(options=list(o), name=name)
示例#6
0
    def _process(self, p, element, ranges={}):
        # Creates a unified Dataset.data attribute
        # to draw the data from
        if isinstance(element.data, np.ndarray):
            if 'dataframe' in Dataset.datatype:
                el_data = element.table('dataframe')
            else:
                el_data = element.table('dictionary')
        else:
            el_data = element.data

        # Get dimensions to plot against each other
        dims = [
            d for d in element.dimensions() if _is_number(element.range(d)[0])
        ]
        permuted_dims = [(d1, d2) for d1 in dims for d2 in dims[::-1]]

        # Convert Histogram type to operation to avoid one case in the if below.
        if p.diagonal_type is Histogram:
            p.diagonal_type = None
            p.diagonal_operation = histogram

        data = {}
        for d1, d2 in permuted_dims:
            if d1 == d2:
                if p.diagonal_type is not None:
                    if p.diagonal_type._auto_indexable_1d:
                        el = p.diagonal_type(
                            el_data,
                            kdims=[d1],
                            vdims=[d2],
                            datatype=['dataframe', 'dictionary'])
                    else:
                        values = element.dimension_values(d1)
                        el = p.diagonal_type(values, vdims=[d1])
                elif p.diagonal_operation is histogram or isinstance(
                        p.diagonal_operation, histogram):
                    bin_range = ranges.get(d1.name, element.range(d1))
                    opts = dict(axiswise=True, framewise=True)
                    el = p.diagonal_operation(element,
                                              dimension=d1.name,
                                              bin_range=bin_range)(norm=opts)
                else:
                    el = p.diagonal_operation(element, dimension=d1.name)
            else:
                el = p.chart_type(el_data,
                                  kdims=[d1],
                                  vdims=[d2],
                                  datatype=['dataframe', 'dictionary'])
            data[(d1.name, d2.name)] = el
        return data
示例#7
0
    def _process(self, p, element, ranges={}):
        # Creates a unified Dataset.data attribute
        # to draw the data from
        if isinstance(element.data, np.ndarray):
            if 'dataframe' in Dataset.datatype:
                el_data = element.table('dataframe')
            else:
                el_data = element.table('dictionary')
        else:
            el_data = element.data

        # Get dimensions to plot against each other
        types = (str, basestring, np.str_, np.object_)+datetime_types
        dims = [d for d in element.dimensions()
                if _is_number(element.range(d)[0]) and
                not issubclass(element.get_dimension_type(d), types)]
        permuted_dims = [(d1, d2) for d1 in dims
                         for d2 in dims[::-1]]

        # Convert Histogram type to operation to avoid one case in the if below.
        if p.diagonal_type is Histogram:
            p.diagonal_type = None
            p.diagonal_operation = histogram

        data = {}
        for d1, d2 in permuted_dims:
            if d1 == d2:
                if p.diagonal_type is not None:
                    if p.diagonal_type._auto_indexable_1d:
                        el = p.diagonal_type(el_data, kdims=[d1], vdims=[d2],
                                             datatype=['dataframe', 'dictionary'])
                    else:
                        values = element.dimension_values(d1)
                        el = p.diagonal_type(values, kdims=[d1])
                elif p.diagonal_operation is histogram or isinstance(p.diagonal_operation, histogram):
                    bin_range = ranges.get(d1.name, element.range(d1))
                    el = p.diagonal_operation(element, dimension=d1.name, bin_range=bin_range)
                else:
                    el = p.diagonal_operation(element, dimension=d1.name)
            else:
                kdims, vdims = ([d1, d2], []) if len(p.chart_type.kdims) == 2 else (d1, d2)
                el = p.chart_type(el_data, kdims=kdims, vdims=vdims,
                                  datatype=['dataframe', 'dictionary'])
            data[(d1.name, d2.name)] = el
        return data