Esempio n. 1
0
def add_needle(plot, speed, offset = 0, max_value = 1):
    angle = speed_to_angle(speed, offset, max_value)
    rmax = Ray(x=0, y=0, length=data(0.75), angle=angle, line_color="black", line_width=3)
    rmin = Ray(x=0, y=0, length=data(0.10), angle=angle - pi, line_color="black", line_width=3)
    plot.add_glyph(rmax)
    plot.add_glyph(rmin)
    return rmax, rmin
Esempio n. 2
0
def add_needle(speed: float, units: str) -> None:
    angle = speed_to_angle(speed, units)
    plot.add_glyph(
        Ray(x=0,
            y=0,
            length=data(0.75),
            angle=angle,
            line_color="black",
            line_width=3))
    plot.add_glyph(
        Ray(x=0,
            y=0,
            length=data(0.10),
            angle=angle - pi,
            line_color="black",
            line_width=3))
Esempio n. 3
0
def add_gauge(radius: float, max_value: float, length: float,
              direction: Literal[-1, 1], color: Any, major_step: int,
              minor_step: int) -> None:
    major_angles, minor_angles = [], []

    total_angle = start_angle - end_angle

    major_angle_step = float(major_step) / max_value * total_angle
    minor_angle_step = float(minor_step) / max_value * total_angle

    major_angle = 0

    while major_angle <= total_angle:
        major_angles.append(start_angle - major_angle)
        major_angle += major_angle_step

    minor_angle = 0

    while minor_angle <= total_angle:
        minor_angles.append(start_angle - minor_angle)
        minor_angle += minor_angle_step

    major_labels = [major_step * i for i, _ in enumerate(major_angles)]

    n = major_step / minor_step
    minor_angles = [x for i, x in enumerate(minor_angles) if i % n != 0]

    glyph = Arc(x=0,
                y=0,
                radius=radius,
                start_angle=start_angle,
                end_angle=end_angle,
                direction="clock",
                line_color=color,
                line_width=2)
    plot.add_glyph(glyph)

    rotation = 0 if direction == 1 else -pi

    angles = [angle + rotation for angle in major_angles]
    source = ColumnDataSource(dict(major_angles=major_angles, angle=angles))

    t = PolarTransform(radius=radius, angle="major_angles")
    glyph = Ray(x=expr(t.x),
                y=expr(t.y),
                length=data(length),
                angle="angle",
                line_color=color,
                line_width=2)
    plot.add_glyph(source, glyph)

    angles = [angle + rotation for angle in minor_angles]
    source = ColumnDataSource(dict(minor_angles=minor_angles, angle=angles))

    t = PolarTransform(radius=radius, angle="minor_angles")
    glyph = Ray(x=expr(t.x),
                y=expr(t.y),
                length=data(length / 2),
                angle="angle",
                line_color=color,
                line_width=1)
    plot.add_glyph(source, glyph)

    text_angles = [angle - pi / 2 for angle in major_angles]
    source = ColumnDataSource(
        dict(major_angles=major_angles, angle=text_angles, text=major_labels))

    t = PolarTransform(radius=radius + 2 * length * direction,
                       angle="major_angles")
    glyph = Text(x=expr(t.x),
                 y=expr(t.y),
                 angle="angle",
                 text="text",
                 text_align="center",
                 text_baseline="middle")
    plot.add_glyph(source, glyph)
Esempio n. 4
0
 ("quad",
  Quad(left="x", right="xp01", top="y", bottom="ym01",
       fill_color="#B3DE69")),
 ("quadratic",
  Quadratic(x0="x",
            y0="y",
            x1="xp02",
            y1="y",
            cx="xp01",
            cy="yp01",
            line_color="#4DAF4A",
            line_width=3)),
 ("ray",
  Ray(x="x",
      y="y",
      length=45,
      angle=-0.7,
      line_color="#FB8072",
      line_width=2)),
 ("rect",
  Rect(x="x",
       y="y",
       width=screen(10),
       height=screen(20),
       angle=-0.7,
       fill_color="#CAB2D6")),
 ("segment",
  Segment(x0="x",
          y0="y",
          x1="xm01",
          y1="ym01",
          line_color="#F4A582",
Esempio n. 5
0
def add_gauge(plot, radius, max_value, length, direction, color, major_step, minor_step, offset = 0):
    '''
    draw the gauge in plot area
    :param plot:
    :param radius:
    :param max_value:
    :param length:
    :param direction:
    :param color:
    :param major_step:
    :param minor_step:
    :param offset:
    :return:
    '''

    start_angle = pi + pi / 4
    end_angle = -pi / 4

    major_angles, minor_angles = [], []

    total_angle = start_angle - end_angle

    major_angle_step = float(major_step) / max_value * total_angle
    minor_angle_step = float(minor_step) / max_value * total_angle

    major_angle = 0

    while major_angle <= total_angle:
        major_angles.append(start_angle - major_angle)
        major_angle += major_angle_step

    minor_angle = 0

    while minor_angle <= total_angle:
        minor_angles.append(start_angle - minor_angle)
        minor_angle += minor_angle_step

    major_labels = [major_step * i + offset for i, _ in enumerate(major_angles)]

    n = major_step / minor_step
    minor_angles = [x for i, x in enumerate(minor_angles) if i % n != 0]

    glyph = Arc(x=0, y=0, radius=radius, start_angle=start_angle, end_angle=end_angle, direction="clock",
                line_color=color, line_width=2)
    plot.add_glyph(glyph)

    rotation = 0 if direction == 1 else -pi

    x, y = zip(*[polar_to_cartesian(radius, angle) for angle in major_angles])
    angles = [angle + rotation for angle in major_angles]
    source = ColumnDataSource(dict(x=x, y=y, angle=angles))

    glyph = Ray(x="x", y="y", length=data(length), angle="angle", line_color=color, line_width=2)
    plot.add_glyph(source, glyph)

    x, y = zip(*[polar_to_cartesian(radius, angle) for angle in minor_angles])
    angles = [angle + rotation for angle in minor_angles]
    source = ColumnDataSource(dict(x=x, y=y, angle=angles))

    glyph = Ray(x="x", y="y", length=data(length / 2), angle="angle", line_color=color, line_width=1)
    plot.add_glyph(source, glyph)

    x, y = zip(*[polar_to_cartesian(radius + 2 * length * direction, angle) for angle in major_angles])
    text_angles = [angle - pi / 2 for angle in major_angles]
    source = ColumnDataSource(dict(x=x, y=y, angle=text_angles, text=major_labels))

    glyph = Text(x="x", y="y", angle="angle", text="text", text_align="center", text_baseline="middle")
    plot.add_glyph(source, glyph)
Esempio n. 6
0
N = 9
x = np.linspace(-2, 2, N)
y = x**2
l = x * 5 + 25

source = ColumnDataSource(dict(x=x, y=y, l=l))

plot = Plot(title=None,
            width=300,
            height=300,
            min_border=0,
            toolbar_location=None)

glyph = Ray(x="x",
            y="y",
            length="l",
            angle=-2.0,
            line_color="#fb8072",
            line_width=3)
plot.add_glyph(source, glyph)

xaxis = LinearAxis()
plot.add_layout(xaxis, 'below')

yaxis = LinearAxis()
plot.add_layout(yaxis, 'left')

plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

curdoc().add_root(plot)
Esempio n. 7
0
hover = plot.select(dict(type=HoverTool))

hover.tooltips = [("LH Utilisation", "$x{00.0} %"),
                  ("Cost Per KG", "$y{0.0} Rs.")]
hover.mode = 'vline'

plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)
plot.xaxis.axis_label = 'Net Line-haul Utilisation %'
plot.yaxis.axis_label = 'Cost Per KG'
plot.title.align = "center"

#slope_const = Ray(x=20., y=CONST_REVENUE_PER_KG_CURRENT_AVG, length=100, angle=0.0, line_color='firebrick', line_width=2.5, line_dash='dashed')
slope_down = Ray(x=20.,
                 y=CONST_REVENUE_PER_KG_CURRENT_AVG,
                 length=100,
                 angle=-0.075,
                 line_color='firebrick',
                 line_width=2.5,
                 line_dash='dashed')
#slope_up = Ray(x=20., y=CONST_REVENUE_PER_KG_CURRENT_AVG, length=100, angle=0.075, line_color='firebrick', line_width=3, line_dash='dashed')

citation_const = Label(x=40,
                       y=4.5,
                       x_units='data',
                       y_units='data',
                       text='Breakeven: Cost per KG = Revenue per KG',
                       render_mode='css',
                       border_line_color='black',
                       border_line_alpha=0,
                       background_fill_color='white',
                       background_fill_alpha=1.0)