Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_readonly(self):
class Readonly(HasProps):
x = Int(12, readonly=True) # with default
y = Int(readonly=True) # without default
z = String("hello")
o = Readonly()
assert o.x == 12
assert o.y == None
assert o.z == 'hello'
# readonly props are still in the list of props
assert 'x' in o.properties()
assert 'y' in o.properties()
assert 'z' in o.properties()
# but they aren't in the dict of props with values
assert 'x' not in o.properties_with_values(include_defaults=True)
assert 'y' not in o.properties_with_values(include_defaults=True)
assert 'z' in o.properties_with_values(include_defaults=True)
assert 'x' not in o.properties_with_values(include_defaults=False)
# Setup
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# General API
#-----------------------------------------------------------------------------
class AnotherModelInTestDocument(Model):
bar = Int(1)
class SomeModelInTestDocument(Model):
foo = Int(2)
child = Instance(Model)
class ModelThatOverridesName(Model):
name = String()
class ModelWithSpecInTestDocument(Model):
foo = DistanceSpec(2)
What kind of scale to use to convert x-coordinates in data space
into x-coordinates in screen space.
""")
y_scale = Instance(Scale, default=lambda: LinearScale(), help="""
What kind of scale to use to convert y-coordinates in data space
into y-coordinates in screen space.
""")
extra_x_ranges = Dict(String, Instance(Range), help="""
Additional named ranges to make available for mapping x-coordinates.
This is useful for adding additional axes.
""")
extra_y_ranges = Dict(String, Instance(Range), help="""
Additional named ranges to make available for mapping y-coordinates.
This is useful for adding additional axes.
""")
hidpi = Bool(default=True, help="""
Whether to use HiDPI mode when available.
""")
title = Instance(Title, default=lambda: Title(text=""), help="""
A title for the plot. Can be a text string or a Title annotation.
""")
title_location = Enum(Location, default="above", help="""
Where the title will be located. Titles on the left or right side
will be rotated.
# class attributes that define the fields (and their types) that can be
# communicated automatically between Python and the browser. Properties
# also support type validation. More information about properties in
# can be found here:
#
# http://bokeh.pydata.org/en/latest/docs/reference/core.html#bokeh-core-properties
# This is a Bokeh ColumnDataSource that can be updated in the Bokeh
# server by Python code
data_source = Instance(ColumnDataSource)
# The vis.js library that we are wrapping expects data for x, y, z, and
# color. The data will actually be stored in the ColumnDataSource, but
# these properties let us specify the *name* of the column that should
# be used for each field.
x = String
y = String
z = String
color = String
options = Dict(String, Any, default=DEFAULTS)
'TextInput',
'TextAreaInput'
)
#-----------------------------------------------------------------------------
# Dev API
#-----------------------------------------------------------------------------
@abstract
class InputWidget(Widget):
''' Abstract base class for input widgets.
'''
title = String(default="", help="""
Widget's label.
""")
@classmethod
def coerce_value(cls, val):
prop_obj = cls.lookup('value')
if isinstance(prop_obj, Float):
return float(val)
elif isinstance(prop_obj, Int):
return int(val)
elif isinstance(prop_obj, String):
return str(val)
else:
return val
#-----------------------------------------------------------------------------
should be `"lat"``.
In order to prevent hard to debug errors, there is no default value for
dimension. Using an un-configured ``MercatorTickFormatter`` will result in
a validation error and a JavaScript console error.
""")
@error(MISSING_MERCATOR_DIMENSION)
def _check_missing_dimension(self):
if self.dimension is None:
return str(self)
class NumeralTickFormatter(TickFormatter):
''' Tick formatter based on a human-readable format string. '''
format = String("0,0", help="""
The number format, as defined in the following tables:
**NUMBERS**:
============ ============== ===============
Number Format String
============ ============== ===============
10000 '0,0.0000' 10,000.0000
10000.23 '0,0' 10,000
10000.23 '+0,0' +10,000
-10000 '0,0.0' -10,000.0
10000.1234 '0.000' 10000.123
10000.1234 '0[.]00000' 10000.12340
-10000 '(0,0.0000)' (10,000.0000)
-0.23 '.00' -.23
-0.23 '(.00)' (.23)
minor_tick_props = Include(ScalarLineProps, help="""
The %s of the minor ticks.
""")
minor_tick_in = Int(default=0, help="""
The distance in pixels that minor ticks should extend into the
main plot area.
""")
minor_tick_out = Int(default=4, help="""
The distance in pixels that major ticks should extend out of the
main plot area.
""")
fixed_location = Either(Float, String, Tuple(String, String), Tuple(String, String, String), default=None, help="""
Set to specify a fixed coordinate location to draw the axis. The direction
of ticks and major labels is determined by the side panel that the axis
belongs to.
.. note::
Axes labels are suppressed when axes are positioned at fixed locations
inside the central plot area.
""")
@abstract
class ContinuousAxis(Axis):
''' A base class for all numeric, non-categorical axes types.
'''
pass
.. warning::
The explicit purpose of this Bokeh Model is to embed *raw JavaScript
code* for a browser to execute. If any part of the code is derived
from untrusted user inputs, then you must take appropriate care to
sanitize the user input prior to passing to Bokeh.
'''
args = Dict(String, AnyRef, help="""
A mapping of names to Python objects. In particular those can be bokeh's models.
These objects are made available to the formatter's code snippet as the values of
named parameters to the callback.
""")
code = String(default="", help="""
A snippet of JavaScript code that reformats a single tick to the desired
format. The variable ``tick`` will contain the unformatted tick value and
can be expected to be present in the code snippet namespace at render time.
Additionally available variables are:
* ``ticks``, an array of all axis ticks as positioned by the ticker,
* ``index``, the position of ``tick`` within ``ticks``, and
* the keys of ``args`` mapping, if any.
Finding yourself needing to cache an expensive ``ticks``-dependent
computation, you can store it on the ``this`` variable.
Example:
.. code-block:: javascript
# This is a Bokeh ColumnDataSource that can be updated in the Bokeh
# server by Python code
data_source = Instance(ColumnDataSource)
# The vis.js library that we are wrapping expects data for x, y, and z.
# The data will actually be stored in the ColumnDataSource, but these
# properties let us specify the *name* of the column that should be
# used for each field.
x = String
y = String
z = String
# color might not be used from vis.js
color = String
# Any of the available vis.js options for Graph3d can be set by changing
# the contents of this dictionary.
options = Dict(String, Any, default=DEFAULTS)
'''
pass
class CustomJSTransform(Transform):
''' Apply a custom defined transform to data.
.. warning::
The explicit purpose of this Bokeh Model is to embed *raw JavaScript
code* for a browser to execute. If any part of the code is derived
from untrusted user inputs, then you must take appropriate care to
sanitize the user input prior to passing to Bokeh.
'''
args = Dict(String, AnyRef, help="""
A mapping of names to Python objects. In particular those can be bokeh's models.
These objects are made available to the transform' code snippet as the values of
named parameters to the callback.
""")
func = String(default="", help="""
A snippet of JavaScript code to transform a single value. The variable
``x`` will contain the untransformed value and can be expected to be
present in the function namespace at render time. The snippet will be
into the body of a function and therefore requires a return statement.
Example:
.. code-block:: javascript
func = '''