示例#1
0
文件: downloads.py 项目: salilb/bokeh
class InstallersModel(VBoxModelForm):
    period = Tuple(Date, Date, default=(start, end))
    installer = Enum("All", *sorted(installers.event.unique()))
    resolution = Enum("daily", "monthly", "yearly", default="monthly")
    platform = Enum("All", *sorted(installers.platform.unique()))
    arch = Enum("All", *sorted(installers.arch.unique()))
    #start = Date(start)
    #end = Date(end)

    input_specs = [
        {
            "widget": DateRangeSlider,
            "name": "period",
            "title": "Period:",
            "value": period.default,
            "bounds": period.default,
            "range": (dict(days=1), None),
        },
        {
            "widget": Select,
            "name": "installer",
            "title": "Installer:",
            "value": installer.default,
            "options": installer.allowed_values,
        },
        {
            "widget": Select,
            "name": "resolution",
            "title": "Resolution:",
            "value": resolution.default,
            "options": resolution.allowed_values,
        },
        {
            "widget": Select,
            "name": "platform",
            "title": "Platform:",
            "value": platform.default,
            "options": platform.allowed_values,
        },
        {
            "widget": Select,
            "name": "arch",
            "title": "Architecture:",
            "value": arch.default,
            "options": arch.allowed_values,
            #}, {
            #    "widget": DatePicker,
            #    "name": "start",
            #    "title": "Start:",
            #    "value": start.default,
            #    "min_date": start.default,
            #}, {
            #    "widget": DatePicker,
            #    "name": "end",
            #    "title": "End:",
            #    "value": end.default,
            #    "max_date": end.default,
            #}]
        }
    ]
示例#2
0
class GlyphRenderer(PlotObject):

    data_source = Instance(DataSource, has_ref=True)
    xdata_range = Instance(DataRange1d, has_ref=True)
    ydata_range = Instance(DataRange1d, has_ref=True)

    # How to intepret the values in the data_source
    units = Enum("screen", "data")

    # Instance of bokeh.glyphs.Glyph; not declaring it explicitly below
    # because of circular imports. The renderers should get moved out
    # into another module...
    glyph = Instance()

    def vm_serialize(self):
        # GlyphRenderers need to serialize their state a little differently,
        # because the internal glyph instance is turned into a glyphspec
        return {
            "id": self._id,
            "data_source": self.data_source,
            "xdata_range": self.xdata_range,
            "ydata_range": self.ydata_range,
            "glyphspec": self.glyph.to_glyphspec()
        }

    def finalize(self, models):
        super(GlyphRenderer, self).finalize(models)
        ## FIXME: we shouldn't have to do this i think..
        if hasattr(self, 'glyphspec'):
            glyphspec = self.glyphspec
            del self.glyphspec
            self.glyph = PlotObject.get_class(glyphspec['type'])(**glyphspec)
        else:
            self.glyph = None
示例#3
0
class LinearAxis(GuideRenderer):
    type = String("linear_axis")
    axis_label = String
    axis_label_standoff = Int
    axis_label_props = Include(TextProps, prefix="axis_label")

    major_label_standoff = Int
    major_label_orientation = Either(Enum("horizontal", "vertical"), Int)
    major_label_props = Include(TextProps, prefix="major_label")

    # Line props
    axis_props = Include(LineProps, prefix="axis")
    tick_props = Include(LineProps, prefix="major_tick")

    major_tick_in = Int
    major_tick_out = Int
示例#4
0
class LineGlyph(XyGlyph):
    """Represents a group of data as a line."""

    width = Int(default=2)
    dash = Enum(DashPattern, default='solid')

    def __init__(self,
                 x=None,
                 y=None,
                 line_color=None,
                 width=None,
                 dash=None,
                 **kwargs):
        kwargs['x'] = x
        kwargs['y'] = y
        if line_color is not None:
            kwargs['line_color'] = line_color
        if width is not None:
            kwargs['width'] = width
        if dash is not None:
            kwargs['dash'] = dash
        super(LineGlyph, self).__init__(**kwargs)
        self.setup()

    def build_source(self):
        if self.x is None:
            x = self.y.index
            data = dict(x_values=x, y_values=self.y)
        elif self.y is None:
            y = self.x.index
            data = dict(x_values=self.x, y_values=y)
        else:
            data = dict(x_values=self.x, y_values=self.y)
        return ColumnDataSource(data)

    def build_renderers(self):
        """Yield a `GlyphRenderer` for the group of data."""
        glyph = Line(x='x_values',
                     y='y_values',
                     line_color=self.line_color,
                     line_alpha=self.line_alpha,
                     line_width=self.width,
                     line_dash=self.dash)
        yield GlyphRenderer(glyph=glyph)
示例#5
0
class Foo(PlotObject):
    """ This is a Foo model. """
    index = Either(Auto, Enum('abc', 'def', 'xzy'), help="doc for index")
    value = Tuple(Float, Float, help="doc for value")
示例#6
0
    def test_Enum(self):
        with self.assertRaises(TypeError):
            prop = Enum()

        with self.assertRaises(TypeError):
            prop = Enum("red", "green", 1)

        with self.assertRaises(TypeError):
            prop = Enum("red", "green", "red")

        prop = Enum("red", "green", "blue")

        self.assertTrue(prop.is_valid(None))
        self.assertFalse(prop.is_valid(False))
        self.assertFalse(prop.is_valid(True))
        self.assertFalse(prop.is_valid(0))
        self.assertFalse(prop.is_valid(1))
        self.assertFalse(prop.is_valid(0.0))
        self.assertFalse(prop.is_valid(1.0))
        self.assertFalse(prop.is_valid(1.0 + 1.0j))
        self.assertFalse(prop.is_valid(""))
        self.assertFalse(prop.is_valid(()))
        self.assertFalse(prop.is_valid([]))
        self.assertFalse(prop.is_valid({}))
        self.assertFalse(prop.is_valid(Foo()))

        self.assertTrue(prop.is_valid("red"))
        self.assertTrue(prop.is_valid("green"))
        self.assertTrue(prop.is_valid("blue"))

        self.assertFalse(prop.is_valid("RED"))
        self.assertFalse(prop.is_valid("GREEN"))
        self.assertFalse(prop.is_valid("BLUE"))

        self.assertFalse(prop.is_valid(" red"))
        self.assertFalse(prop.is_valid(" green"))
        self.assertFalse(prop.is_valid(" blue"))

        from bokeh.enums import LineJoin
        prop = Enum(LineJoin)

        self.assertTrue(prop.is_valid(None))
        self.assertFalse(prop.is_valid(False))
        self.assertFalse(prop.is_valid(True))
        self.assertFalse(prop.is_valid(0))
        self.assertFalse(prop.is_valid(1))
        self.assertFalse(prop.is_valid(0.0))
        self.assertFalse(prop.is_valid(1.0))
        self.assertFalse(prop.is_valid(1.0 + 1.0j))
        self.assertFalse(prop.is_valid(""))
        self.assertFalse(prop.is_valid(()))
        self.assertFalse(prop.is_valid([]))
        self.assertFalse(prop.is_valid({}))
        self.assertFalse(prop.is_valid(Foo()))

        self.assertTrue(prop.is_valid("miter"))
        self.assertTrue(prop.is_valid("round"))
        self.assertTrue(prop.is_valid("bevel"))

        self.assertFalse(prop.is_valid("MITER"))
        self.assertFalse(prop.is_valid("ROUND"))
        self.assertFalse(prop.is_valid("BEVEL"))

        self.assertFalse(prop.is_valid(" miter"))
        self.assertFalse(prop.is_valid(" round"))
        self.assertFalse(prop.is_valid(" bevel"))
示例#7
0
 class Foo(HasProps):
     x = Int(12)
     y = Enum("red", "blue", "green")
     z = String("blah")
示例#8
0
 class Foo(HasProps):
     x = Enum("blue", "red", "green")  # the first item is the default
     y = Enum("small", "medium", "large", default="large")
示例#9
0
    def test_Enum(self):
        with self.assertRaises(TypeError):
            prop = Enum()

        with self.assertRaises(TypeError):
            prop = Enum("red", "green", 1)

        with self.assertRaises(TypeError):
            prop = Enum("red", "green", "red")

        prop = Enum("red", "green", "blue")

        self.assertTrue(prop.is_valid(None))
        self.assertFalse(prop.is_valid(False))
        self.assertFalse(prop.is_valid(True))
        self.assertFalse(prop.is_valid(0))
        self.assertFalse(prop.is_valid(1))
        self.assertFalse(prop.is_valid(0.0))
        self.assertFalse(prop.is_valid(1.0))
        self.assertFalse(prop.is_valid(1.0+1.0j))
        self.assertFalse(prop.is_valid(""))
        self.assertFalse(prop.is_valid(()))
        self.assertFalse(prop.is_valid([]))
        self.assertFalse(prop.is_valid({}))
        self.assertFalse(prop.is_valid(Foo()))

        self.assertTrue(prop.is_valid("red"))
        self.assertTrue(prop.is_valid("green"))
        self.assertTrue(prop.is_valid("blue"))

        self.assertFalse(prop.is_valid("RED"))
        self.assertFalse(prop.is_valid("GREEN"))
        self.assertFalse(prop.is_valid("BLUE"))

        self.assertFalse(prop.is_valid(" red"))
        self.assertFalse(prop.is_valid(" green"))
        self.assertFalse(prop.is_valid(" blue"))

        from bokeh.enums import LineJoin
        prop = Enum(LineJoin)

        self.assertTrue(prop.is_valid(None))
        self.assertFalse(prop.is_valid(False))
        self.assertFalse(prop.is_valid(True))
        self.assertFalse(prop.is_valid(0))
        self.assertFalse(prop.is_valid(1))
        self.assertFalse(prop.is_valid(0.0))
        self.assertFalse(prop.is_valid(1.0))
        self.assertFalse(prop.is_valid(1.0+1.0j))
        self.assertFalse(prop.is_valid(""))
        self.assertFalse(prop.is_valid(()))
        self.assertFalse(prop.is_valid([]))
        self.assertFalse(prop.is_valid({}))
        self.assertFalse(prop.is_valid(Foo()))

        self.assertTrue(prop.is_valid("miter"))
        self.assertTrue(prop.is_valid("round"))
        self.assertTrue(prop.is_valid("bevel"))

        self.assertFalse(prop.is_valid("MITER"))
        self.assertFalse(prop.is_valid("ROUND"))
        self.assertFalse(prop.is_valid("BEVEL"))

        self.assertFalse(prop.is_valid(" miter"))
        self.assertFalse(prop.is_valid(" round"))
        self.assertFalse(prop.is_valid(" bevel"))

        from bokeh.enums import NamedColor
        prop = Enum(NamedColor)

        self.assertTrue(prop.is_valid("red"))
        self.assertTrue(prop.is_valid("Red"))
        self.assertTrue(prop.is_valid("RED"))
示例#10
0
 class Foo(HasProps):
     x = Enum("blue", "red", "green")
     y = Enum("small", "medium", "large", default="tiny")