class MeasureControl(Control): _view_name = Unicode('LeafletMeasureControlView').tag(sync=True) _model_name = Unicode('LeafletMeasureControlModel').tag(sync=True) _length_units = ['feet', 'meters', 'miles', 'kilometers'] _area_units = ['acres', 'hectares', 'sqfeet', 'sqmeters', 'sqmiles'] _custom_units_dict = {} _custom_units = Dict().tag(sync=True) primary_length_unit = Enum( values=_length_units, default_value='feet', help="""Possible values are feet, meters, miles, kilometers or any user defined unit""").tag(sync=True, o=True) secondary_length_unit = Enum( values=_length_units, default_value=None, allow_none=True, help="""Possible values are feet, meters, miles, kilometers or any user defined unit""").tag(sync=True, o=True) primary_area_unit = Enum( values=_area_units, default_value='acres', help="""Possible values are acres, hectares, sqfeet, sqmeters, sqmiles or any user defined unit""").tag(sync=True, o=True) secondary_area_unit = Enum( values=_area_units, default_value=None, allow_none=True, help="""Possible values are acres, hectares, sqfeet, sqmeters, sqmiles or any user defined unit""").tag(sync=True, o=True) active_color = Color('#ABE67E').tag(sync=True, o=True) completed_color = Color('#C8F2BE').tag(sync=True, o=True) popup_options = Dict({ 'className': 'leaflet-measure-resultpopup', 'autoPanPadding': [10, 10] }).tag(sync=True, o=True) capture_z_index = Int(10000).tag(sync=True, o=True) def add_length_unit(self, name, factor, decimals=0): self._length_units.append(name) self._add_unit(name, factor, decimals) def add_area_unit(self, name, factor, decimals=0): self._area_units.append(name) self._add_unit(name, factor, decimals) def _add_unit(self, name, factor, decimals): self._custom_units_dict[name] = { 'factor': factor, 'display': name, 'decimals': decimals } self._custom_units = dict(**self._custom_units_dict)
class PhongMaterial(BasicMaterial): _view_name = Unicode('PhongMaterialView').tag(sync=True) _model_name = Unicode('PhongMaterialModel').tag(sync=True) emissive = Color('black').tag(sync=True) specular = Color('darkgray').tag(sync=True) shininess = CFloat(30).tag(sync=True) reflectivity = CFloat(1.0).tag(sync=True) refractionRatio = CFloat(0.98).tag(sync=True) combine = Enum(Operations, 'MultiplyOperation').tag(sync=True)
class Boxplot(Mark): """Boxplot marks. Attributes ---------- stroke: Color or None stroke color of the marker color: Color fill color of the box opacities: list of floats (default: []) Opacities for the markers of the boxplot. Defaults to 1 when the list is too short, or the element of the list is set to None. outlier-color: color color for the outlier Data Attributes _y_default: numpy.ndarray default 2 dimensional value for y x: numpy.ndarray abscissas of the data points (1d array) y: numpy.ndarray Sample data points (2d array) """ # Mark decoration icon = 'fa-birthday-cake' name = 'Boxplot chart' # Scaled attributes x = NdArray().tag(sync=True, scaled=True, rtype='Number', min_dim=1, max_dim=1, atype='bqplot.Axis') # Second dimension must contain OHLC data, otherwise the behavior is # undefined. y = NdArray().tag(sync=True, scaled=True, rtype='Number', min_dim=1, max_dim=2, atype='bqplot.Axis') # Other attributes scales_metadata = Dict({ 'x': {'orientation': 'horizontal', 'dimension': 'x'}, 'y': {'orientation': 'vertical', 'dimension': 'y'} }).tag(sync=True) stroke = Color(None, allow_none=True).tag(sync=True, display_name='Stroke color') box_fill_color = Color('dodgerblue', sync=True, display_name='Fill color for the box') outlier_fill_color = Color('gray').tag(sync=True, display_name='Outlier fill color') opacities = List(trait=Float(1.0, min=0, max=1, allow_none=True)).tag(sync=True, display_name='Opacities') _view_name = Unicode('Boxplot').tag(sync=True) _model_name = Unicode('BoxplotModel').tag(sync=True)
class TextRenderer(CellRenderer): _model_name = Unicode("TextRendererModel").tag(sync=True) _view_name = Unicode("TextRendererView").tag(sync=True) text_value = Union( (Unicode(), Instance(VegaExpr), Instance(Scale)), allow_none=True, default_value=None, ).tag(sync=True, **widget_serialization) text_wrap = Bool(default_value=False).tag(sync=True, **widget_serialization) text_elide_direction = Enum(values=["right", "left"], default_value="right").tag( sync=True, **widget_serialization) font = Union( (Unicode(), Instance(VegaExpr), Instance(Scale)), default_value="12px sans-serif", ).tag(sync=True, **widget_serialization) text_color = Union( (Color(), Instance(VegaExpr), Instance(ColorScale)), default_value=Expr("default_value"), ).tag(sync=True, **widget_serialization) background_color = Union( (Color(), Instance(VegaExpr), Instance(ColorScale)), default_value=Expr("default_value"), ).tag(sync=True, **widget_serialization) vertical_alignment = Union( ( Enum(values=["top", "center", "bottom"]), Instance(VegaExpr), Instance(Scale), ), default_value="center", ).tag(sync=True, **widget_serialization) horizontal_alignment = Union( ( Enum(values=["left", "center", "right"]), Instance(VegaExpr), Instance(Scale), ), default_value="left", ).tag(sync=True, **widget_serialization) format = Union((Unicode(), Instance(VegaExpr)), allow_none=True, default_value=None).tag(sync=True, **widget_serialization) format_type = Enum(values=["number", "time"], default_value="number").tag(sync=True) missing = Unicode("").tag(sync=True)
class BasicMaterial(Material): _view_name = Unicode('BasicMaterialView').tag(sync=True) _model_name = Unicode('BasicMaterialModel').tag(sync=True) color = Color('white').tag(sync=True) wireframe = Bool().tag(sync=True) wireframeLinewidth = CFloat(1.0).tag(sync=True) wireframeLinecap = Unicode('round').tag(sync=True) wireframeLinejoin = Unicode('round').tag(sync=True) shading = Enum(['SmoothShading', 'FlatShading', 'NoShading'], 'SmoothShading').tag(sync=True) vertexColors = Enum(['NoColors', 'FaceColors', 'VertexColors'], 'NoColors').tag(sync=True) fog = Bool().tag(sync=True) map = Instance(Texture, allow_none=True).tag(sync=True, **widget_serialization) lightMap = Instance(Texture, allow_none=True).tag(sync=True, **widget_serialization) specularMap = Instance(Texture, allow_none=True).tag(sync=True, **widget_serialization) envMap = Instance(Texture, allow_none=True).tag(sync=True, **widget_serialization) skinning = Bool().tag(sync=True) morphTargets = Bool().tag(sync=True)
class BarRenderer(TextRenderer): _model_name = Unicode("BarRendererModel").tag(sync=True) _view_name = Unicode("BarRendererView").tag(sync=True) bar_value = Union((Float(), Instance(VegaExpr), Instance(Scale)), default_value=0.0).tag(sync=True, **widget_serialization) bar_color = Union( (Color(), Instance(VegaExpr), Instance(ColorScale)), default_value="#4682b4", ).tag(sync=True, **widget_serialization) orientation = Union( (Unicode(), Instance(VegaExpr), Instance(Scale)), default_value="horizontal", ).tag(sync=True, **widget_serialization) bar_vertical_alignment = Union( ( Enum(values=["top", "center", "bottom"]), Instance(VegaExpr), Instance(Scale), ), default_value="bottom", ).tag(sync=True, **widget_serialization) bar_horizontal_alignment = Union( ( Enum(values=["left", "center", "right"]), Instance(VegaExpr), Instance(Scale), ), default_value="left", ).tag(sync=True, **widget_serialization) show_text = Union((Bool(), Instance(VegaExpr)), default_value=True).tag(sync=True, **widget_serialization)
class baseCanvasModel(DOMWidget): """TODO: Add docstring here """ _model_name = Unicode('baseCanvasModel').tag(sync=True) _model_module = Unicode(module_name).tag(sync=True) _model_module_version = Unicode(module_version).tag(sync=True) _view_name = Unicode('baseCanvasView').tag(sync=True) _view_module = Unicode(module_name).tag(sync=True) _view_module_version = Unicode(module_version).tag(sync=True) value = Unicode('Hello World').tag(sync=True) classColor = Color('red').tag(sync=True) erasing = Bool(True).tag(sync=True) # underlying info for labels - this handles the syncing to ts # _labels = Bytes(default_value=None, allow_none=True, read_only=True).tag(sync=True, **labels_serialization) # yikes = # data = DataUnion( # np.zeros([10, 10, 4], dtype=np.uint8), # dtype='uint8', shape_constraint=shape_constraints(None, None, 4), # 2D RGBA # ).tag(sync=True, **data_union_serialization) def __init__(self, **kwargs): super().__init__(**kwargs) self.on_msg(self.handle_msg) width = CInt(700).tag(sync=True) height = CInt(700).tag(sync=True) def set_image(self, arr): """ Set the image to be segmented arr : numpy array Shape (WxHx1) or (WxHx3) TODO: transparency here? I removed the transparency enabling code on the typescript side to make things simpler with the class canvas """ image_metadata, image_buffer = binary_image(arr) command = {'name': 'image', 'metadata': image_metadata} self.send(command, (image_buffer, )) def gogogo(self): command = {'name': 'gogogo'} self.send(command, []) def beep(self): command = {'name': 'beep'} self.send(command, []) def gimme(self): command = {'name': 'gimme'} self.send(command, []) def handle_msg(self, widget, content, buffers): # print('widget:', widget) # print(content) # self.gogogo() self.yikes(content['start'])
class Scene(_GanyDOMWidgetBase): """A 3-D Scene widget.""" _view_name = Unicode('SceneView').tag(sync=True) _model_name = Unicode('SceneModel').tag(sync=True) children = List(Instance(Block)).tag(sync=True, **widget_serialization) background_color = Color('white').tag(sync=True) background_opacity = CFloat(1.).tag(sync=True) camera_position = Union((Tuple(trait=CFloat, minlen=3, maxlen=3), ), allow_none=True, default_value=None).tag(sync=True) camera_target = Union((Tuple(trait=CFloat, minlen=3, maxlen=3), ), allow_none=True, default_value=None).tag(sync=True) camera_up = Tuple(trait=CFloat, minlen=3, maxlen=3, default_value=(0, 1, 0)).tag(sync=True) def __init__(self, children=[], **kwargs): """Construct a Scene.""" super(Scene, self).__init__(children=children, **kwargs)
class Path(VectorLayer): _view_name = Unicode('LeafletPathView').tag(sync=True) _model_name = Unicode('LeafletPathModel').tag(sync=True) stroke = Bool(True).tag(sync=True, o=True) color = Color('#0033FF').tag(sync=True, o=True) weight = Int(5).tag(sync=True, o=True) fill = Bool(True).tag(sync=True, o=True) fill_color = Color('#0033FF').tag(sync=True, o=True) fill_opacity = Float(0.2).tag(sync=True, o=True) dash_array = Unicode().tag(sync=True, o=True) line_cap = Unicode().tag(sync=True, o=True) line_join = Unicode().tag(sync=True, o=True) clickable = Bool(True).tag(sync=True, o=True) pointer_events = Unicode().tag(sync=True, o=True) class_name = Unicode().tag(sync=True, o=True)
def CSSColor(default_value): """Create a color trait. Temporary workaround to allow both hsl(h,s,l) syntax and linking to the standard color picker widget. """ return Union([Color(default_value), Unicode()])
class BrushSelector(TwoDSelector): """Brush interval selector interaction. This 2-D selector interaction enables the user to select a rectangular region using the brushing action of the mouse. A mouse-down marks the starting point of the interval. The drag after the mouse down selects the rectangle of interest and a mouse-up signifies the end point of the interval. Once an interval is drawn, the selector can be moved to a new interval by dragging the selector to the new interval. A double click at the same point without moving the mouse will result in the entire interval being selected. Attributes ---------- selected: numpy.ndarray Two element array containing the start and end of the interval selected in terms of the scales of the selector. This is a read-only attribute. This attribute changes while the selection is being made with the ``BrushIntervalSelector``. brushing: bool (default: False) boolean attribute to indicate if the selector is being dragged. It is True when the selector is being moved and False when it is not. This attribute can be used to trigger computationally intensive code which should be run only on the interval selection being completed as opposed to code which should be run whenever selected is changing. color: Color or None (default: None) Color of the rectangle representing the brush selector. """ clear = Bool().tag(sync=True) brushing = Bool().tag(sync=True) selected = List().tag(sync=True) color = Color(None, allow_none=True).tag(sync=True) def __init__(self, **kwargs): # Stores information regarding the scales. The date scaled values have # to be converted into dateobjects because they are transmitted as # strings. try: self.read_json_x = kwargs.get('x_scale').domain_class.from_json except AttributeError: self.read_json_x = None try: self.read_json_y = kwargs.get('y_scale').domain_class.from_json except AttributeError: self.read_json_y = None super(BrushSelector, self).__init__(**kwargs) def _selected_changed(self, name, selected): if (len(self.selected) == 2): if (self.read_json_x is not None): self.selected[0][0] = self.read_json_x(self.selected[0][0]) self.selected[1][0] = self.read_json_x(self.selected[1][0]) if (self.read_json_y is not None): self.selected[0][1] = self.read_json_y(self.selected[0][1]) self.selected[1][1] = self.read_json_y(self.selected[1][1]) _view_name = Unicode('BrushSelector').tag(sync=True) _model_name = Unicode('BrushSelectorModel').tag(sync=True)
class IndexSelector(OneDSelector): """Index selector interaction. This 1-D selector interaction uses the mouse x-cooridnate to select the corresponding point in terms of the selector scale. Index Selector has two modes: 1. default mode: The mouse controls the x-position of the selector. 2. frozen mode: In this mode, the selector is frozen at a point and does not respond to mouse events. A single click switches between the two modes. Attributes ---------- selected: numpy.ndarray A single element array containing the point corresponding the x-position of the mouse. This attribute is updated as you move the mouse along the x-direction on the figure. color: Color or None (default: None) Color of the line representing the index selector. line_width: nonnegative integer (default: 0) Width of the line represetning the index selector. """ selected = NdArray().tag(sync=True) line_width = Int(2).tag(sync=True) color = Color(None, allow_none=True).tag(sync=True) _view_name = Unicode('IndexSelector').tag(sync=True) _model_name = Unicode('IndexSelectorModel').tag(sync=True)
class LassoSelector(TwoDSelector): """Lasso selector interaction. This 2-D selector enables the user to select multiple sets of data points by drawing lassos on the figure. Lasso Selector is currently supported only for Lines and Scatter marks. A mouse-down starts drawing the lasso and after the mouse-up the lasso is closed and the `selected` attribute of each mark gets updated with the data in the lasso. A lasso which doesn't encompass any mark data will be automatically deleted. The user can select (de-select) by clicking on lassos and can delete them (and their associated data) by pressing the 'Delete' button. Attributes ---------- marks: List of marks which are instances of {Lines, Scatter} (default: []) List of marks on which lasso selector will be applied. color: Color (default: None) Color of the lasso. """ color = Color(None, allow_none=True).tag(sync=True) _view_name = Unicode('LassoSelector').tag(sync=True) _model_name = Unicode('LassoSelectorModel').tag(sync=True)
class BrushSelector(TwoDSelector): """Brush interval selector interaction. This 2-D selector interaction enables the user to select a rectangular region using the brushing action of the mouse. A mouse-down marks the starting point of the interval. The drag after the mouse down selects the rectangle of interest and a mouse-up signifies the end point of the interval. Once an interval is drawn, the selector can be moved to a new interval by dragging the selector to the new interval. A double click at the same point without moving the mouse will result in the entire interval being selected. Attributes ---------- selected_x: numpy.ndarray Two element array containing the start and end of the interval selected in terms of the x_scale of the selector. This attribute changes while the selection is being made with the ``BrushSelector``. selected_y: numpy.ndarray Two element array containing the start and end of the interval selected in terms of the y_scale of the selector. This attribute changes while the selection is being made with the ``BrushSelector``. selected_x: list Readonly 2x2 array containing the coordinates [[selected_x[0], selected_y[0]], [selected_x[1], selected_y[1]]] brushing: bool (default: False) boolean attribute to indicate if the selector is being dragged. It is True when the selector is being moved and False when it is not. This attribute can be used to trigger computationally intensive code which should be run only on the interval selection being completed as opposed to code which should be run whenever selected is changing. color: Color or None (default: None) Color of the rectangle representing the brush selector. """ clear = Bool().tag(sync=True) brushing = Bool().tag(sync=True) selected_x = Array(None, allow_none=True).tag(sync=True, **array_serialization) selected_y = Array(None, allow_none=True).tag(sync=True, **array_serialization) color = Color(None, allow_none=True).tag(sync=True) # This is for backward compatibility @property def selected(self): if self.selected_x is None or len(self.selected_x) == 0: return [] else: return [[self.selected_x[0], self.selected_y[0]], [self.selected_x[1], self.selected_y[1]]] _view_name = Unicode('BrushSelector').tag(sync=True) _model_name = Unicode('BrushSelectorModel').tag(sync=True)
class AntPath(VectorLayer): _view_name = Unicode('LeafletAntPathView').tag(sync=True) _model_name = Unicode('LeafletAntPathModel').tag(sync=True) locations = List().tag(sync=True) # Options use = Enum(values=['polyline', 'polygon', 'rectangle', 'circle'], default_value='polyline').tag(sync=True, o=True) delay = Int(400).tag(sync=True, o=True) weight = Int(5).tag(sync=True, o=True) dash_array = List([10, 20]).tag(sync=True, o=True) color = Color('#0000FF').tag(sync=True, o=True) pulse_color = Color('#FFFFFF').tag(sync=True, o=True) paused = Bool(False).tag(sync=True, o=True) reverse = Bool(False).tag(sync=True, o=True) hardware_accelerated = Bool(False).tag(sync=True, o=True) radius = Int(10).tag(sync=True, o=True)
class ColorsInput(TagsInputBase): """ List of color tags """ _model_name = Unicode('ColorsInputModel').tag(sync=True) _view_name = Unicode('ColorsInputView').tag(sync=True) value = List(Color(), help='List of color tags').tag(sync=True)
class Path(VectorLayer): _view_name = Unicode('LeafletPathView').tag(sync=True) _model_name = Unicode('LeafletPathModel').tag(sync=True) # Options stroke = Bool(True).tag(sync=True, o=True) color = Color('#0033FF').tag(sync=True, o=True) weight = Int(5).tag(sync=True, o=True) fill = Bool(True).tag(sync=True, o=True) fill_color = Color('#0033FF').tag(sync=True, o=True) fill_opacity = Float(0.2).tag(sync=True, o=True) dash_array = Unicode(allow_none=True, default_value=None).tag(sync=True, o=True) line_cap = Unicode('round').tag(sync=True, o=True) line_join = Unicode('round').tag(sync=True, o=True) pointer_events = Unicode('').tag(sync=True, o=True) class_name = Unicode('').tag(sync=True, o=True) opacity = Float(1.0, min=0.0, max=1.0).tag(sync=True, o=True)
class LambertMaterial(BasicMaterial): _view_name = Unicode('LambertMaterialView').tag(sync=True) _model_name = Unicode('LambertMaterialModel').tag(sync=True) emissive = Color('black').tag(sync=True) reflectivity = CFloat(1.0).tag(sync=True) refractionRatio = CFloat(0.98).tag(sync=True) combine = Enum(Operations, 'MultiplyOperation').tag(sync=True)
class TextTexture(Texture): _view_name = Unicode('TextTextureView').tag(sync=True) _model_name = Unicode('TextTextureModel').tag(sync=True) fontFace = Unicode('Arial').tag(sync=True) size = CInt(12).tag(sync=True) color = Color('black').tag(sync=True) string = Unicode(sync=True) squareTexture = Bool(True).tag(sync=True)
class ParticleSystemMaterial(Material): _view_name = Unicode('ParticleSystemMaterialView').tag(sync=True) _model_name = Unicode('ParticleSystemMaterialModel').tag(sync=True) color = Color('yellow').tag(sync=True) map = Instance(Texture, allow_none=True).tag(sync=True, **widget_serialization) size = CFloat(1.0).tag(sync=True) sizeAttenuation = Bool().tag(sync=True) vertexColors = Bool().tag(sync=True) fog = Bool().tag(sync=True)
class LineBasicMaterial(_LineMaterial): _view_name = Unicode('LineBasicMaterialView').tag(sync=True) _model_name = Unicode('LineBasicMaterialModel').tag(sync=True) color = Color('white').tag(sync=True) linewidth = CFloat(1.0).tag(sync=True) linecap = Unicode('round').tag(sync=True) linejoin = Unicode('round').tag(sync=True) fog = Bool().tag(sync=True) vertexColors = Enum(['NoColors', 'FaceColors', 'VertexColors'], 'NoColors').tag(sync=True)
class AwesomeIcon(UILayer): _view_name = Unicode('LeafletAwesomeIconView').tag(sync=True) _model_name = Unicode('LeafletAwesomeIconModel').tag(sync=True) name = Unicode('home').tag(sync=True) marker_color = Enum( values=['white', 'red', 'darkred', 'lightred', 'orange', 'beige', 'green', 'darkgreen', 'lightgreen', 'blue', 'darkblue', 'lightblue', 'purple', 'darkpurple', 'pink', 'cadetblue', 'white', 'gray', 'lightgray', 'black'], default_value='blue' ).tag(sync=True) icon_color = Color('white').tag(sync=True) spin = Bool(False).tag(sync=True)
class LineDashedMaterial(_LineMaterial): _view_name = Unicode('LineDashedMaterialView').tag(sync=True) _model_name = Unicode('LineDashedMaterialModel').tag(sync=True) color = Color('white').tag(sync=True) linewidth = CFloat(1.0).tag(sync=True) scale = CFloat(1.0).tag(sync=True) dashSize = CFloat(3.0).tag(sync=True) gapSize = CFloat(1.0).tag(sync=True) vertexColors = Enum(['NoColors', 'FaceColors', 'VertexColors'], 'NoColors').tag(sync=True) fog = Bool().tag(sync=True)
class Scene(DOMWidget): """A 3-D Scene widget.""" _view_name = Unicode('SceneView').tag(sync=True) _model_name = Unicode('SceneModel').tag(sync=True) _view_module = Unicode('odysis').tag(sync=True) _model_module = Unicode('odysis').tag(sync=True) _view_module_version = Unicode(odysis_version).tag(sync=True) _model_module_version = Unicode(odysis_version).tag(sync=True) datablocks = List(Instance(DataBlock)).tag(sync=True, **widget_serialization) background_color = Color('#fff').tag(sync=True)
class Grid(PluginBlock): _view_name = Unicode('GridView').tag(sync=True) _model_name = Unicode('GridModel').tag(sync=True) axis = Enum(('x', 'y', 'z'), default_value='x').tag(sync=True) color = Color('black').tag(sync=True) step = Float().tag(sync=True) width = Float().tag(sync=True) def interact(self): if not self.initialized_widgets: self._init_grid_widgets() self.initialized_widgets = True return HBox( self._interact() + (VBox((self.axis_wid, self.color_wid, self.step_wid, self.width_wid)), ) ) def __init__(self, *args, **kwargs): super(Grid, self).__init__(*args, **kwargs) self.initialized_widgets = False self.axis_wid = None self.color_wid = None self.step_wid = None self.width_wid = None def _init_grid_widgets(self): self.axis_wid = ToggleButtons( description='Axis', options=['x', 'y', 'z'], value=self.axis ) self.color_wid = ColorPicker( concise=True, description='Color', value=self.color ) self.step_wid = FloatText( description='Step', value=self.step ) self.width_wid = FloatText( description='Width', value=self.width ) link((self.axis_wid, 'value'), (self, 'axis')) link((self.color_wid, 'value'), (self, 'color')) link((self.step_wid, 'value'), (self, 'step')) link((self.width_wid, 'value'), (self, 'width'))
class SpriteMaterial(Material): _view_name = Unicode('SpriteMaterialView').tag(sync=True) _model_name = Unicode('SpriteMaterialModel').tag(sync=True) map = Instance(Texture, allow_none=True).tag(sync=True, **widget_serialization) uvScale = List(CFloat).tag(sync=True) sizeAttenuation = Bool().tag(sync=True) color = Color('white').tag(sync=True) uvOffset = List(CFloat).tag(sync=True) fog = Bool().tag(sync=True) useScreenCoordinates = Bool().tag(sync=True) scaleByViewport = Bool().tag(sync=True) alignment = List(CFloat).tag(sync=True)
class Choropleth(GeoJSON): geo_data = Dict() choro_data = Dict() value_min = Float(None, allow_none=True) value_max = Float(None, allow_none=True) colormap = Instance(ColorMap) border_color = Color('black') @observe('choro_data') def _update_bounds(self, change): self.value_min = min(self.choro_data.items(), key=lambda x: x[1])[1] self.value_max = max(self.choro_data.items(), key=lambda x: x[1])[1] @observe('value_min', 'value_max', 'geo_data', 'choro_data', 'colormap', 'border_color') def _update_data(self, change): self.data = self._get_data() @default('colormap') def _default_colormap(self): return linear.OrRd_06 def _get_data(self): if not self.geo_data: return {} if self.value_min is None: self.value_min = min(self.choro_data.items(), key=lambda x: x[1])[1] if self.value_max is None: self.value_max = max(self.choro_data.items(), key=lambda x: x[1])[1] colormap = self.colormap.scale(self.value_min, self.value_max) color_dict = { key: colormap(self.choro_data[key]) for key in self.choro_data.keys() } data = copy.deepcopy(self.geo_data) for feature in data['features']: feature['properties']['style'] = dict( fillColor=color_dict[feature['id']], color=self.border_color, weight=0.9) return data def __init__(self, **kwargs): super(Choropleth, self).__init__(**kwargs) self.data = self._get_data()
class Scene(_GanyDOMWidgetBase): """A 3-D Scene widget.""" _view_name = Unicode('SceneView').tag(sync=True) _model_name = Unicode('SceneModel').tag(sync=True) children = List(Instance(Block)).tag(sync=True, **widget_serialization) background_color = Color('white').tag(sync=True) background_opacity = CFloat(1.).tag(sync=True) def __init__(self, children=[], **kwargs): """Construct a Scene.""" super(Scene, self).__init__(children=children, **kwargs)
class FlexLine(Mark): """Flexible Lines mark. In the case of the FlexLines mark, scales for 'x' and 'y' MUST be provided. Scales for the color and width data attributes are optional. In the case where another data attribute than 'x' or 'y' is provided but the corresponding scale is missing, the data attribute is ignored. Attributes ---------- name: string (class-level attributes) user-friendly name of the mark colors: list of colors (default: CATEGORY10) List of colors for the Lines stroke_width: float (default: 1.5) Default stroke width of the Lines Data Attributes x: numpy.ndarray (default: []) abscissas of the data points (1d array) y: numpy.ndarray (default: []) ordinates of the data points (1d array) color: numpy.ndarray or None (default: []) Array controlling the color of the data points width: numpy.ndarray or None (default: []) Array controlling the widths of the Lines. """ # Mark decoration icon = 'fa-line-chart' name = 'Flexible lines' # Scaled attributes x = NdArray().tag(sync=True, min_dim=1, max_dim=1, scaled=True, rtype='Number', atype='bqplot.Axis') y = NdArray().tag(sync=True, min_dim=1, max_dim=1, scaled=True, rtype='Number', atype='bqplot.Axis') color = NdArray(None, allow_none=True).tag(sync=True, scaled=True, rtype='Color', atype='bqplot.ColorAxis') width = NdArray(None, allow_none=True).tag(sync=True, scaled=True, rtype='Number') # Other attributes scales_metadata = Dict({ 'x': {'orientation': 'horizontal', 'dimension': 'x'}, 'y': {'orientation': 'vertical', 'dimension': 'y'}, 'color': {'dimension': 'color'} }).tag(sync=True) stroke_width = Float(1.5).tag(sync=True, display_name='Stroke width') colors = List(trait=Color(default_value=None, allow_none=True), default_value=CATEGORY10).tag(sync=True) _view_name = Unicode('FlexLine').tag(sync=True) _model_name = Unicode('FlexLineModel').tag(sync=True)
class Renderer(DOMWidget): _view_module = Unicode('jupyter-threejs').tag(sync=True) _model_module = Unicode('jupyter-threejs').tag(sync=True) _view_name = Unicode('RendererView').tag(sync=True) _model_name = Unicode('RendererModel').tag(sync=True) width = Unicode('600').tag(sync=True) # TODO: stop relying on deprecated DOMWidget attribute height = Unicode('400').tag(sync=True) renderer_type = Enum(['webgl', 'canvas', 'auto'], 'auto').tag(sync=True) scene = Instance(Scene).tag(sync=True, **widget_serialization) camera = Instance(Camera).tag(sync=True, **widget_serialization) controls = List(Instance(Controls)).tag(sync=True, **widget_serialization) effect = Instance(Effect, allow_none=True).tag(sync=True, **widget_serialization) background = Color('black', allow_none=True).tag(sync=True) backgroud_opacity = Float(min=0.0, max=1.0).tag(sync=True)