Ejemplo n.º 1
0
def profile_doughnut(values, labels, name, color_palette=False):
    center_text = str(name)

    trace = go.Pie(values=values,
                   labels=labels,
                   hoverinfo="label",
                   hole=0.65,
                   textinfo="none",
                   marker=dict(colors=set_category_colors(labels),
                               line=dict(color=CliqzColors["white"], width=0)))
    data = [trace]
    layout = dict(
        showlegend=False,
        paper_bgcolor=CliqzColors["transparent"],
        plot_bgcolor=CliqzColors["transparent"],
        autosize=True,
        margin=set_margins(l=0, r=0, b=0, t=0, pad=10),

        # Center Text
        annotations=[
            annotation(text=center_text.upper(),
                       x=0.5,
                       y=0.5,
                       background_color=CliqzColors["transparent"],
                       shift_x=0,
                       text_size=30,
                       color="#333")
        ])
    fig = dict(data=data, layout=layout)

    return div_output(fig)
Ejemplo n.º 2
0
def alluvial_plot(sndata):
    data_trace = dict(
        type='sankey',
        domain=dict(x=[0, 1], y=[0, 1]),
        hoverinfo="none",
        orientation="h",
        # valueformat=".0f",
        # valuesuffix="% of pages - present",
        node=dict(pad=10,
                  thickness=30,
                  label=list(
                      map(lambda x: x.replace("_", " ").capitalize(),
                          sndata['node']['label'])),
                  color=sndata['node']['color']),
        link=dict(
            source=sndata['link']['source'],
            target=sndata['link']['target'],
            value=sndata['link']['value'],
            label=sndata['link']['label'],
            color=["#dedede" for _ in range(len(sndata['link']['source']))]))
    layout = dict(
        font=dict(size=12),
        autosize=True,
        margin=set_margins(t=20, l=2, r=2),
    )
    fig = dict(data=[data_trace], layout=layout)
    return div_output(fig)
Ejemplo n.º 3
0
def doughnut_chart(values, labels, name, color_palette=False):
    """
    Doughnut pie chart with text in the middle.

    Args:
        values: (list) - values for the pie chart
        labels: (list) - corresponding to the values
        name:   (str)  - text that goes in the middle of the chart

    Returns: Doughnut pie chart wrapped in a div

    """
    trace = go.Pie(
        values=values,
        labels=labels,
        name=str(name),
        hoverinfo="label+percent",
        hole=0.65,
        pull=0.07,
        sort=not (color_palette),
        textinfo="label",
        textfont=dict(family=CliqzFonts.regular, color=CliqzColors["white"]),
        marker=dict(colors=palette(CliqzColors["blue"], CliqzColors["purple"],
                                   len(labels)) if color_palette else
                    [CliqzColors["blue"], CliqzColors["purple"]],
                    line=dict(color=CliqzColors["white"], width=2)))
    data = [trace]
    layout = dict(showlegend=False,
                  paper_bgcolor=CliqzColors["transparent"],
                  plot_bgcolor=CliqzColors["transparent"],
                  autosize=True,
                  margin=set_margins(),
                  annotations=[
                      annotation(text=str(name).upper(),
                                 x=0.5,
                                 y=0.5,
                                 background_color=CliqzColors["transparent"],
                                 shift_x=0,
                                 text_size=14)
                  ])
    fig = dict(data=data, layout=layout)

    return div_output(fig)
Ejemplo n.º 4
0
def reach(google, facebook, dates):
    """
    Main Page Plot showing the reach of companies that track the most
    Args:
        google:   (list) - values for google
        facebook: (list) - values for facebook
        dates:    (list) - dates

    Returns: Area Plot as div output

    """
    trace_high = scatter(x=dates, y=google, name="Google", color="#3cba54")
    trace_low = scatter(x=dates, y=facebook, name="Facebook", color="#3b5998")
    dangerous = scatter(x=dates,
                        y=[20] * 11,
                        name="Dangerous",
                        color="#FF3232",
                        fill=False,
                        line_style="dot")
    data = [trace_high, trace_low, dangerous]

    layout = go.Layout(
        dict(xaxis=dict(range=['2017-01-01', '2017-01-11']),
             yaxis=dict(title="Percentage of sites where company can track",
                        titlefont=dict(size=12, color="#666666")),
             margin=set_margins(r=90),
             legend=dict(x=0, y=50, orientation="h"),
             annotations=[
                 annotation(text="Facebook",
                            x=dates[-1],
                            y=facebook[-1],
                            background_color="#3b5998"),
                 annotation(text="Google",
                            x=dates[-1],
                            y=google[-1],
                            background_color="#3cba54"),
                 annotation(text="Dangerous",
                            x=dates[-1],
                            y=20,
                            background_color="#FF3232")
             ]))
    fig = dict(data=data, layout=layout)
    return div_output(fig)
Ejemplo n.º 5
0
def overview_reach(companies):
    data = []
    annotations = []
    for c in companies:
        color = random_color()
        ts = [datetime.strptime(t["ts"], "%Y-%m") for t in c["history"]]
        name = c["overview"]["id"].capitalize()
        y = [t['reach'] * 100 for t in c["history"]]
        data.append(scatter(x=ts, y=y, fill=False, name=name, color=color))
        annotations.append(
            overview_label(text=name, x=ts[-1], y=y[-1], color=color))

    layout = go.Layout(
        dict(
            yaxis=dict(title="Percentage of sites where company can track",
                       titlefont=dict(size=12, color="#666666")),
            margin=set_margins(r=90),
            legend=dict(x=0, y=50, orientation="h"),
            # annotations=annotations
        ))
    fig = dict(data=data, layout=layout)
    return div_output(fig)
Ejemplo n.º 6
0
def overview_bars(companies):
    x = []
    y = []
    colors = [CliqzColors["purple"]] * 2 + [CliqzColors["inactive_gray"]] * 8
    for c in companies:
        name = c["name"]
        x.append(round(c["history"][-1]["reach"], 3))
        y.append(name)
    data = [
        go.Bar(x=x[::-1],
               y=y[::-1],
               marker={"color": colors[::-1]},
               orientation='h')
    ]
    layout = go.Layout(
        dict(margin=set_margins(t=30, l=150),
             showlegend=False,
             xaxis=dict(color=CliqzColors["gray_blue"],
                        tickformat="%",
                        anchor="free",
                        position=0)))
    fig = dict(data=data, layout=layout)
    return div_output(fig)
Ejemplo n.º 7
0
def treemap():
    x = 0.
    y = 0.
    width = 100.
    height = 100.

    values = [500, 433, 78, 25, 25, 7]

    normed = squarify.normalize_sizes(values, width, height)
    rects = squarify.squarify(normed, x, y, width, height)

    # Choose colors from http://colorbrewer2.org/ under "Export"
    color_brewer = [
        'rgb(166,206,227)', 'rgb(31,120,180)', 'rgb(178,223,138)',
        'rgb(51,160,44)', 'rgb(251,154,153)', 'rgb(227,26,28)'
    ]
    shapes = []
    annotations = []
    counter = 0

    for r in rects:
        shapes.append(
            dict(type='rect',
                 x0=r['x'],
                 y0=r['y'],
                 x1=r['x'] + r['dx'],
                 y1=r['y'] + r['dy'],
                 line=dict(width=2),
                 fillcolor=color_brewer[counter]))
        annotations.append(
            dict(x=r['x'] + (r['dx'] / 2),
                 y=r['y'] + (r['dy'] / 2),
                 text=values[counter],
                 showarrow=False))
        counter = counter + 1
        if counter >= len(color_brewer):
            counter = 0

    # For hover text
    trace0 = go.Scatter(
        x=[r['x'] + (r['dx'] / 2) for r in rects],
        y=[r['y'] + (r['dy'] / 2) for r in rects],
        text=[str(v) for v in values],
        mode='text',
    )

    layout = dict(height=700,
                  width=700,
                  xaxis=dict(showgrid=False, zeroline=False),
                  yaxis=dict(showgrid=False, zeroline=False),
                  shapes=shapes,
                  annotations=annotations,
                  hovermode='closest')

    # With hovertext
    figure = dict(data=[trace0], layout=layout)

    # Without hovertext
    # figure = dict(data=[Scatter()], layout=layout)

    return div_output(figure)