Example #1
0
def tracker_reach_ts(ts1, ts2, t):
    """
    Timeseries area plot for two time-series
    Args:
        ts1: timeseries 1
        ts2: timeseries 2
        t: x-axis (time)

    Returns: hmtl output of an interactive timeseries plot

    """
    trace0 = scatter(x=t,
                     y=ts1,
                     name="Domain Reach",
                     color=cliqz_colors["purple"])
    trace1 = scatter(x=t, y=ts2, name="Page Reach", color=cliqz_colors["blue"])
    layout = go.Layout(margin=set_margins(t=30), height=300)

    # makes sure that whichever is smallest
    # will be on top (displaying color correctly)
    if mean(ts1) > mean(ts2):
        data = [trace0, trace1]
    else:
        data = [trace1, trace0]
    fig = dict(data=data, layout=layout)
    return div_output(fig)
Example #2
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)