Example #1
0
def classical_gear(module, large_teeth, small_teeth):
    xdr = Range1d(start=-300, end=150)
    ydr = Range1d(start=-100, end=100)

    source = ColumnDataSource(data=dict(dummy=[0]))
    plot = Plot(
        title=None,
        x_range=xdr, y_range=ydr,
        plot_width=800, plot_height=800
    )
    plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())

    radius = pitch_radius(module, large_teeth)
    angle = 0
    glyph = Gear(
        x=-radius, y=0,
        module=module, teeth=large_teeth, angle=angle,
        fill_color=fill_color[0], line_color=line_color
    )
    plot.add_glyph(source, glyph)

    radius = pitch_radius(module, small_teeth)
    angle = half_tooth(small_teeth)
    glyph = Gear(
        x=radius, y=0,
        module=module, teeth=small_teeth, angle=angle,
        fill_color=fill_color[1], line_color=line_color
    )
    plot.add_glyph(source, glyph)

    return plot
Example #2
0
class TestGear(unittest.TestCase):

    def setUp(self):
        from bokeh.glyphs import Gear
        self.test_gear = Gear()

    def test_expected_properties(self):
        expected_properties = set(['x', 'y', 'angle', 'module', 'teeth', 'pressure_angle', 'shaft_size', 'internal'])
        actual_properties = get_prop_set(type(self.test_gear))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_gear.x, 'x')
        self.assertEqual(self.test_gear.y, 'y')
        self.assertEqual(self.test_gear.angle, 0)
        self.assertEqual(self.test_gear.module, 'module')
        self.assertEqual(self.test_gear.teeth, 'teeth')
        self.assertEqual(self.test_gear.pressure_angle, 20)
        self.assertEqual(self.test_gear.shaft_size, 0.3)
        self.assertEqual(self.test_gear.internal,  False)
        self.assertEqual(self.test_gear.__view_model__, 'gear')

    def test_to_glyphspec(self):
        self.maxDiff = None
        expected = dict(GENERIC_GLYPH_DICT)
        expected['type'] = 'gear'
        expected.update({
            'angle':            {'units': 'data', 'value': 0},
            'module':           {'units': 'data', 'field': 'module'},
            'teeth':            {'units': 'data', 'field': 'teeth'},
            'pressure_angle':   {'units': 'data', 'value': 20},
            'shaft_size':       {'units': 'data', 'value': 0.3},
            'internal':         {'units': 'data', 'value': False}
        })
        self.assertEqual(self.test_gear.to_glyphspec(), expected)
        self.test_gear.x = 50
        self.test_gear.y = 51
        self.test_gear.angle = 52
        self.test_gear.module = 53
        self.test_gear.teeth = 54
        self.test_gear.pressure_angle = 55
        self.test_gear.shaft_size = 56
        self.test_gear.internal = True
        expected.update({
            'x':                {'units': 'data', 'value': 50},
            'y':                {'units': 'data', 'value': 51},
            'angle':            {'units': 'data', 'value': 52},
            'module':           {'units': 'data', 'value': 53},
            'teeth':            {'units': 'data', 'value': 54},
            'pressure_angle':   {'units': 'data', 'value': 55},
            'shaft_size':       {'units': 'data', 'value': 56},
            'internal':         {'units': 'data', 'value': True}
        })
        self.assertEqual(self.test_gear.to_glyphspec(), expected)
Example #3
0
def sample_gear():
    xdr = Range1d(start=-30, end=30)
    ydr = Range1d(start=-30, end=30)

    source = ColumnDataSource(data=dict(dummy=[0]))
    plot = Plot(title=None,
                data_sources=[source],
                x_range=xdr,
                y_range=ydr,
                width=800,
                height=800)
    plot.tools.extend(
        [PanTool(plot=plot),
         WheelZoomTool(plot=plot),
         ResetTool(plot=plot)])

    glyph = Gear(x=0,
                 y=0,
                 module=5,
                 teeth=8,
                 angle=0,
                 shaft_size=0.2,
                 fill_color=fill_color[2],
                 line_color=line_color)
    renderer = Glyph(data_source=source,
                     xdata_range=xdr,
                     ydata_range=ydr,
                     glyph=glyph)
    plot.renderers.append(renderer)

    return plot
Example #4
0
def classical_gear(module, large_teeth, small_teeth):
    xdr = Range1d(start=-300, end=150)
    ydr = Range1d(start=-100, end=100)

    source = ColumnDataSource(data=dict(dummy=[0]))
    plot = Plot(title=None,
                data_sources=[source],
                x_range=xdr,
                y_range=ydr,
                width=800,
                height=800)
    plot.tools.extend(
        [PanTool(plot=plot),
         WheelZoomTool(plot=plot),
         ResetTool(plot=plot)])

    radius = pitch_radius(module, large_teeth)
    angle = 0
    glyph = Gear(x=-radius,
                 y=0,
                 module=module,
                 teeth=large_teeth,
                 angle=angle,
                 fill_color=fill_color[0],
                 line_color=line_color)
    renderer = Glyph(data_source=source,
                     xdata_range=xdr,
                     ydata_range=ydr,
                     glyph=glyph)
    plot.renderers.append(renderer)

    radius = pitch_radius(module, small_teeth)
    angle = half_tooth(small_teeth)
    glyph = Gear(x=radius,
                 y=0,
                 module=module,
                 teeth=small_teeth,
                 angle=angle,
                 fill_color=fill_color[1],
                 line_color=line_color)
    renderer = Glyph(data_source=source,
                     xdata_range=xdr,
                     ydata_range=ydr,
                     glyph=glyph)
    plot.renderers.append(renderer)

    return plot
Example #5
0
def epicyclic_gear(module, sun_teeth, planet_teeth):
    xdr = Range1d(start=-150, end=150)
    ydr = Range1d(start=-150, end=150)

    source = ColumnDataSource(data=dict(dummy=[0]))
    plot = Plot(
        title=None,
        x_range=xdr, y_range=ydr,
        plot_width=800, plot_height=800
    )
    plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())

    annulus_teeth = sun_teeth + 2*planet_teeth

    glyph = Gear(
        x=0, y=0,
        module=module, teeth=annulus_teeth, angle=0,
        fill_color=fill_color[0], line_color=line_color, internal=True
    )
    plot.add_glyph(source, glyph)

    glyph = Gear(
        x=0, y=0,
        module=module, teeth=sun_teeth, angle=0,
        fill_color=fill_color[2], line_color=line_color
    )
    plot.add_glyph(source, glyph)

    sun_radius = pitch_radius(module, sun_teeth)
    planet_radius = pitch_radius(module, planet_teeth)

    radius = sun_radius + planet_radius
    angle = half_tooth(planet_teeth)

    for i, j in [(+1, 0), (0, +1), (-1, 0), (0, -1)]:
        glyph = Gear(
            x=radius*i, y=radius*j,
            module=module, teeth=planet_teeth, angle=angle,
            fill_color=fill_color[1], line_color=line_color
        )
        plot.add_glyph(source, glyph)

    return plot
Example #6
0
def sample_gear():
    xdr = Range1d(start=-30, end=30)
    ydr = Range1d(start=-30, end=30)

    source = ColumnDataSource(data=dict(dummy=[0]))
    plot = Plot(title=None, x_range=xdr, y_range=ydr, plot_width=800, plot_height=800)
    plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())

    glyph = Gear(x=0, y=0, module=5, teeth=8, angle=0, shaft_size=0.2, fill_color=fill_color[2], line_color=line_color)
    plot.add_glyph(source, glyph)

    return plot
Example #7
0
def test_Gear():
    glyph = Gear()
    assert glyph.x == "x"
    assert glyph.y == "y"
    assert glyph.angle == 0
    assert glyph.module == "module"
    assert glyph.teeth == "teeth"
    assert glyph.pressure_angle == 20
    assert glyph.shaft_size == 0.3
    assert glyph.internal == False
    yield check_fill, glyph
    yield check_line, glyph
    yield check_props, glyph, [
        "x", "y", "angle", "module", "teeth", "pressure_angle", "shaft_size",
        "internal"
    ], FILL, LINE
Example #8
0
 def setUp(self):
     from bokeh.glyphs import Gear
     self.test_gear = Gear()
Example #9
0
def epicyclic_gear(module, sun_teeth, planet_teeth):
    xdr = Range1d(start=-150, end=150)
    ydr = Range1d(start=-150, end=150)

    source = ColumnDataSource(data=dict(dummy=[0]))
    plot = Plot(title=None,
                data_sources=[source],
                x_range=xdr,
                y_range=ydr,
                width=800,
                height=800)
    plot.tools.extend(
        [PanTool(plot=plot),
         WheelZoomTool(plot=plot),
         ResetTool(plot=plot)])

    annulus_teeth = sun_teeth + 2 * planet_teeth

    glyph = Gear(x=0,
                 y=0,
                 module=module,
                 teeth=annulus_teeth,
                 angle=0,
                 fill_color=fill_color[0],
                 line_color=line_color,
                 internal=True)
    renderer = Glyph(data_source=source,
                     xdata_range=xdr,
                     ydata_range=ydr,
                     glyph=glyph)
    plot.renderers.append(renderer)

    glyph = Gear(x=0,
                 y=0,
                 module=module,
                 teeth=sun_teeth,
                 angle=0,
                 fill_color=fill_color[2],
                 line_color=line_color)
    renderer = Glyph(data_source=source,
                     xdata_range=xdr,
                     ydata_range=ydr,
                     glyph=glyph)
    plot.renderers.append(renderer)

    sun_radius = pitch_radius(module, sun_teeth)
    planet_radius = pitch_radius(module, planet_teeth)

    radius = sun_radius + planet_radius
    angle = half_tooth(planet_teeth)

    for i, j in [(+1, 0), (0, +1), (-1, 0), (0, -1)]:
        glyph = Gear(x=radius * i,
                     y=radius * j,
                     module=module,
                     teeth=planet_teeth,
                     angle=angle,
                     fill_color=fill_color[1],
                     line_color=line_color)
        renderer = Glyph(data_source=source,
                         xdata_range=xdr,
                         ydata_range=ydr,
                         glyph=glyph)
        plot.renderers.append(renderer)

    return plot