def CreateGauge(percentage, scaleInfo):
    gaugeFig = Plot(x_range=Range1d(start=-1.25, end=1.25), y_range=Range1d(start=-1.25, end=1.25), plot_width=250, plot_height=250)
    gaugeFig.title.text = "Scale " + str(scaleInfo.Num) + ": " + scaleInfo.Name
    gaugeFig.title.align = 'center'
    gaugeFig.toolbar_location = None

    gaugeFig.border_fill_color = "#101010"
    gaugeFig.background_fill_color = "#101010"
    gaugeFig.title.text_color = "white"
    gaugeFig.outline_line_color = None

    glyph = AnnularWedge(x=0, y=0, inner_radius=.7, outer_radius=1, start_angle=math.pi / 2 - (2 * math.pi),
                         end_angle=math.pi / 2, fill_color="#444444", name="back")
    glyph2 = AnnularWedge(x=0, y=0, inner_radius=.7, outer_radius=1, start_angle=math.pi / 2 - (2 * math.pi * percentage),
                          end_angle=math.pi / 2, fill_color=gaugeColors[(scaleInfo.Num - 1) % len(gaugeColors)], name="front")
    PercentageText = Label(text_align='center', text=str(round((percentage * scaleInfo.MaxCapacity), 1)),text_color = 'white',
                           text_font_size="35px")
    lowerText = Label(text_align='center', y=-0.25, text=scaleInfo.Units, text_color='white')
    lowerText2 = Label(text_align='center', y=-0.48, text="Of " + str(scaleInfo.MaxCapacity), text_color='white')
    gaugeFig.add_glyph(glyph)
    gaugeFig.add_glyph(glyph2)
    gaugeFig.add_layout(PercentageText)
    gaugeFig.add_layout(lowerText)
    gaugeFig.add_layout(lowerText2)

    return gaugeFig
Ejemplo n.º 2
0
def test_AnnularWedge() -> None:
    glyph = AnnularWedge()
    assert glyph.x == field("x")
    assert glyph.y == field("y")
    assert glyph.inner_radius == field("inner_radius")
    assert glyph.outer_radius == field("outer_radius")
    assert glyph.start_angle == field("start_angle")
    assert glyph.end_angle == field("end_angle")
    assert glyph.direction == "anticlock"
    check_line_properties(glyph)
    check_fill_properties(glyph)
    check_hatch_properties(glyph)
    check_properties_existence(glyph, [
        "x",
        "y",
        "inner_radius",
        "inner_radius_units",
        "outer_radius",
        "outer_radius_units",
        "start_angle",
        "start_angle_units",
        "end_angle",
        "end_angle_units",
        "direction",
    ], LINE, FILL, HATCH, GLYPH)
Ejemplo n.º 3
0
def sunburst(node):
    if node.children:
        count = 0
        n_old = None
        for n in node.children:
            if not n.seen:
                if count == 0:
                    n.right_bound = n.parent.right_bound
                    for p in node.children:
                        p.range = (p.leaves_subtree /
                                   p.parent.leaves_subtree) * p.parent.range
                else:
                    n.right_bound = n_old.left_bound
                n.left_bound = n.right_bound + n.range
                glyph = AnnularWedge(x=10,
                                     y=10,
                                     inner_radius=(n.level * n.width),
                                     outer_radius=((n.level * n.width) +
                                                   n.width),
                                     start_angle=n.right_bound,
                                     end_angle=n.left_bound,
                                     fill_color=n.color,
                                     line_color='#ffffff',
                                     line_width=1,
                                     fill_alpha=0.7)
                plot.add_glyph(source, glyph)
                n_old = n
                count += 1
                sunburst(n)
            n.seen = True
Ejemplo n.º 4
0
def plot(classPercentages, curdoc, rating=4.8):
    """Function to generate donut plot. Input format of the plot 
    
    :param classPercentages: Dictionary representing class and percentage 
    :param rating: rating to be displayed.
    :returns: returns a donut figure and list of annular wedges.
    :rtype: bokeh.plotting.figure, bokeh.models.glyphs.AnnularWedge

    """
    global annularWedgesList
    donutPlot = figure(width=400, height=350, x_range=(-1.5,3), y_range=(-1,1), title="Average Rating")
    donutPlot.xgrid.grid_line_color = None
    donutPlot.ygrid.grid_line_color = None
    donutPlot.axis.visible = None
    donutPlot.axis.visible = None
    donutPlot.toolbar.logo = None
    donutPlot.toolbar_location = None
    donutPlot.legend.location=(0, -8)
    classes = list(classPercentages.keys())
    classes.sort()
    colors = {"negative":"#B22222", "neutral":"yellow",  "positive":"green"}


    annularWedgesList = []
    start_angle = 0
    for Class in classes:
        if classPercentages[Class] == 0:
            continue
        
        end_angle = (classPercentages[Class]*360)/100.0
        annularWedgesList.append(AnnularWedge(x=0, y=0, inner_radius=1, outer_radius=0.5,
                                            start_angle=radians(start_angle), end_angle=radians(start_angle + end_angle-2),
                                            fill_color=colors[Class],fill_alpha=0.6,line_width=1,
                                            line_alpha=0.3, line_color=colors[Class]))
        
        donutPlot.annular_wedge(x=[0], y=[0], inner_radius=0, outer_radius=0.0,
                                start_angle=radians(start_angle), end_angle=radians(start_angle + end_angle-2),
                                color=colors[Class], alpha=0.5,line_width=1,line_alpha=0, line_color=colors[Class],
                                legend="class "+Class+" - "+str(classPercentages[Class])+"%")
        
        start_angle = end_angle+start_angle

    for annularWedge in annularWedgesList:
        donutPlot.add_glyph(annularWedge)

    donutPlot.wedge(x=[0], y=[0], radius=0.48, start_angle=radians(0), end_angle=radians(360), 
                    color="orange", alpha=1, direction="clock")

    donutPlot.text(x=[0], y=[0], text=[str(rating)],text_baseline="middle",
                 text_align="center", text_font_size="30pt", alpha=1, text_color="black")
    
 
    curdoc.add_periodic_callback(update_donut, 10)
 
    return (donutPlot, annularWedgesList)
Ejemplo n.º 5
0
def sunburst_root(root):
    root.range = np.pi * 2
    root.right_bound = 0
    glyph = AnnularWedge(x=10,
                         y=10,
                         inner_radius=0,
                         outer_radius=root.width,
                         start_angle=root.right_bound,
                         end_angle=np.pi * 2,
                         fill_color=root.color,
                         line_alpha=0,
                         fill_alpha=0.7)
    plot.add_glyph(source, glyph)
    sunburst(root)
Ejemplo n.º 6
0
def test_AnnularWedge():
    glyph = AnnularWedge()
    assert glyph.x == "x"
    assert glyph.y == "y"
    assert glyph.inner_radius == None
    assert glyph.outer_radius == None
    assert glyph.start_angle == "start_angle"
    assert glyph.end_angle == "end_angle"
    assert glyph.direction == "clock"
    yield check_fill, glyph
    yield check_line, glyph
    yield check_props, glyph, [
        "x", "y", "inner_radius", "outer_radius", "start_angle", "end_angle",
        "direction"
    ], FILL, LINE
Ejemplo n.º 7
0
    def yield_renderers(self):

        aw = AnnularWedge(x=0,
                          y=0,
                          inner_radius='inners',
                          outer_radius='outers',
                          start_angle='start',
                          end_angle='end',
                          fill_color='color',
                          fill_alpha=0.8,
                          line_color=self.line_color)

        yield GlyphRenderer(data_source=self.chart_data, glyph=aw)

        txt = Text(x="x",
                   y="y",
                   text="text",
                   angle="text_angle",
                   text_align="center",
                   text_baseline="middle",
                   text_font_size=self.text_font_size)

        yield GlyphRenderer(data_source=self.text_data, glyph=txt)
Ejemplo n.º 8
0
def test_AnnularWedge():
    glyph = AnnularWedge()
    assert glyph.x is None
    assert glyph.y is None
    assert glyph.inner_radius is None
    assert glyph.outer_radius is None
    assert glyph.start_angle is None
    assert glyph.end_angle is None
    assert glyph.direction == "anticlock"
    check_fill_properties(glyph)
    check_line_properties(glyph)
    check_properties_existence(glyph, [
        "x",
        "y",
        "inner_radius",
        "inner_radius_units",
        "outer_radius",
        "outer_radius_units",
        "start_angle",
        "start_angle_units",
        "end_angle",
        "end_angle_units",
        "direction",
    ], FILL, LINE, GLYPH)
Ejemplo n.º 9
0
def test_AnnularWedge():
    glyph = AnnularWedge()
    assert glyph.x is None
    assert glyph.y is None
    assert glyph.inner_radius is None
    assert glyph.outer_radius is None
    assert glyph.start_angle is None
    assert glyph.end_angle is None
    assert glyph.direction == "anticlock"
    yield check_fill, glyph
    yield check_line, glyph
    yield (check_props, glyph, [
        "x",
        "y",
        "inner_radius",
        "inner_radius_units",
        "outer_radius",
        "outer_radius_units",
        "start_angle",
        "start_angle_units",
        "end_angle",
        "end_angle_units",
        "direction",
    ], FILL, LINE)
Ejemplo n.º 10
0
ydr = DataRange1d()

plot = Plot(title=None,
            x_range=xdr,
            y_range=ydr,
            plot_width=300,
            plot_height=300,
            h_symmetry=False,
            v_symmetry=False,
            min_border=0,
            toolbar_location=None)

glyph = AnnularWedge(x="x",
                     y="y",
                     inner_radius=.2,
                     outer_radius="r",
                     start_angle=0.6,
                     end_angle=4.1,
                     fill_color="#8888ee")
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)
Ejemplo n.º 11
0
first = True

for browser, start_angle, end_angle in zip(browsers, start_angles, end_angles):
    versions = df[(df.Browser == browser) & (df.Share >= 0.5)]
    angles = versions.Share.map(radians).cumsum() + start_angle
    end = angles.tolist() + [end_angle]
    start = [start_angle] + end[:-1]
    base_color = colors[browser]
    fill = [ base_color.lighten(i*0.05) for i in range(len(versions) + 1) ]
    text = [ number if share >= 1 else "" for number, share in zip(versions.VersionNumber, versions.Share) ]
    x, y = polar_to_cartesian(1.25, start, end)

    source = ColumnDataSource(dict(start=start, end=end, fill=fill))
    glyph = AnnularWedge(x=0, y=0,
        inner_radius=1, outer_radius=1.5, start_angle="start", end_angle="end",
        line_color="white", line_width=2, fill_color="fill")
    plot.add_glyph(source, glyph)


    text_angle = [(start[i]+end[i])/2 for i in range(len(start))]
    text_angle = [angle + pi if pi/2 < angle < 3*pi/2 else angle for angle in text_angle]

    if first and text:
        text.insert(0, '(version)')
        offset = pi / 48
        text_angle.insert(0, text_angle[0] - offset)
        start.insert(0, start[0] - offset)
        end.insert(0, end[0] - offset)
        x, y = polar_to_cartesian(1.25, start, end)
        first = False
Ejemplo n.º 12
0
    ))

xdr = DataRange1d()
ydr = DataRange1d()


def screen(value):
    return dict(value=value, units="screen")


glyphs = [
    ("annular_wedge",
     AnnularWedge(x="x",
                  y="y",
                  inner_radius=screen(10),
                  outer_radius=screen(20),
                  start_angle=0.6,
                  end_angle=4.1,
                  fill_color="#8888ee")),
    ("annulus",
     Annulus(x="x",
             y="y",
             inner_radius=screen(10),
             outer_radius=screen(20),
             fill_color="#7FC97F")),
    ("arc",
     Arc(x="x",
         y="y",
         radius=screen(20),
         start_angle=0.6,
         end_angle=4.1,
Ejemplo n.º 13
0
def generate_single_pie(df, time_str, color_dict, colors):

    xdr = Range1d(start=-2, end=2)
    ydr = Range1d(start=-2, end=2)
    xoffset = .45
    title = "Percent of Drive Models in use" + time_str
    #plot = Plot(title=title, x_range=xdr, y_range=ydr, plot_width=700, plot_height=600,tools=['hover'])

    plot = figure(title=title,
                  x_range=xdr,
                  y_range=ydr,
                  plot_width=700,
                  plot_height=600,
                  tools=['hover,wheel_zoom,save'])
    hover = plot.select(dict(type=HoverTool))
    # = plot.select(dict(type=HoverTool))
    hover.tooltips = [("Model ", "@model"), ("Failure Rate ", "@failure_rate")]
    hover.mode = 'mouse'

    plot.xaxis.visible = False
    plot.yaxis.visible = False
    plot.grid.grid_line_alpha = 0
    #plot.outline = None
    plot.outline_line_width = 0
    plot.ygrid.grid_line_color = None
    plot.toolbar.logo = None
    plot.outline_line_width = 0
    plot.outline_line_color = "white"
    aggregated = df.groupby("manufacturer").agg(sum)
    selected = aggregated[aggregated.percent_total >= 2].copy()
    selected.loc["Other"] = aggregated[aggregated.percent_total < 2].sum()
    browsers = selected.index.tolist()
    radians = lambda x: 2 * pi * (x / 100)
    angles = selected.percent_total.map(radians).cumsum()
    end_angles = angles.tolist()
    start_angles = [0] + end_angles[:-1]

    browsers_source = ColumnDataSource(
        dict(start=start_angles,
             end=end_angles,
             colors=[colors[browser] for browser in browsers],
             model=browsers,
             failure_rate=[f for f in selected["failure_rate"]]))

    glyph = Wedge(x=xoffset,
                  y=0,
                  radius=.8,
                  line_color="white",
                  line_width=2,
                  start_angle="start",
                  end_angle="end",
                  fill_color="colors")
    plot.add_glyph(browsers_source, glyph)

    def polar_to_cartesian(r, start_angles, end_angles):
        cartesian = lambda r, alpha: (r * cos(alpha), r * sin(alpha))
        points = []

        for start, end in zip(start_angles, end_angles):
            points.append(cartesian(r, (end + start) / 2))

        return zip(*points)

    show_wedge_percent = 1.0
    show_label_percent = 1.0
    n = 0
    for manufac, start_angle, end_angle in zip(browsers, start_angles,
                                               end_angles):
        manufac_models = df[(df.manufacturer == manufac) & (
            df.percent_total > show_wedge_percent)]  #if it has gt than
        other_manufac_models = df[(df.manufacturer == manufac)
                                  & (df.percent_total <= show_wedge_percent)]
        other_manufac_models.model = "Other"
        manufac_models = manufac_models.append(other_manufac_models)
        manufac_models = manufac_models.reset_index().groupby("model").sum()
        manufac_models["model"] = manufac_models.index
        manufac_models = manufac_models[manufac_models.percent_total >
                                        show_wedge_percent]  #if it has gt than
        angles = manufac_models.percent_total.map(
            radians).cumsum() + start_angle
        end = angles.tolist() + [end_angle]
        start = [start_angle] + end[:-1]
        base_color = colors[manufac]
        fill = [
            color_dict[model_key] if model_key in color_dict else 'grey'
            for model_key in manufac_models.model
        ]
        text = [
            modnumber if share >= show_label_percent else " " for modnumber,
            share in zip(manufac_models.model, manufac_models.percent_total)
        ]
        x = np.zeros(len(manufac_models)) - 1.93
        y = [1.7 - .23 * h - .23 * n for h in range(len(manufac_models))]
        n += len(manufac_models)
        source = ColumnDataSource(
            dict(start=start,
                 end=end,
                 fill=fill,
                 model=text,
                 failure_rate=manufac_models.failure_rate))
        glyph = AnnularWedge(x=xoffset,
                             y=0,
                             inner_radius=.8,
                             outer_radius=1.4,
                             start_angle="start",
                             end_angle="end",
                             line_color="white",
                             line_width=2,
                             fill_color="fill")
        plot.add_glyph(source, glyph)

        text_source = ColumnDataSource(dict(text=text, x=x, y=y, fill=fill))
        labels = LabelSet(x='x', y='y', text='text', text_color= "white", level='glyph', source=text_source, \
            render_mode='canvas', background_fill_color="fill", border_line_color="fill", border_line_width=8)
        plot.add_layout(labels)
    x, y = polar_to_cartesian(1.7, start_angles, end_angles)

    selected = selected[selected['percent_total'] > 3.5]
    text = ["%.02f%%" % value for value in selected.percent_total]
    x, y = polar_to_cartesian(0.6, start_angles, end_angles)
    x = [i + xoffset - .02 for i in x]
    text_source = ColumnDataSource(dict(text=text, x=x, y=y))
    glyph = Text(x="x",
                 y="y",
                 text="text",
                 text_align="center",
                 text_baseline="middle",
                 text_color="white")
    plot.add_glyph(text_source, glyph)
    return plot
source = ColumnDataSource(dict(type=type_list,
                               start_location=start_locations,
                               end_location=end_locations,
                               strand=strand_values,
                               locus_tag=locus_tags,
                               start_angle=end_angles,
                               end_angle=start_angles,
                               wedge_inner_radius=wedge_inner_radii,
                               wedge_outer_radius=wedge_outer_radii))

annular_wedge = AnnularWedge(x=0, y=0,
                             inner_radius='wedge_inner_radius',  # For the inner_radius, use the values in the column
                                                                 # called 'wedge_inner_radius'
                             outer_radius='wedge_outer_radius',  # Likewise for the outer radius...
                             line_color='white',
                             fill_color='green',
                             start_angle='start_angle',          # ...and start and end angles
                             end_angle='end_angle',
                             direction='anticlock')

features = plot.add_glyph(source, annular_wedge)  # Add all the wedges to the plot

# Add track
arc = Arc(x=0, y=0,
          radius=track_mid_radius,
          start_angle=0,
          end_angle=2*pi,
          direction='clock',
          line_width=2,
          line_color="black")