def add_chart_title(fig: go.Figure, title: str, elevate_line: int = 1,
    title_margin: int = 40, font_size: int = 12, **kwargs) -> None:

    y_line = 0.98 + (elevate_line * 0.04)
    y_annotation = y_line

    fig.add_annotation(
        text=title,
        font={'size': font_size},
        align='left',
        yanchor='bottom',
        xref='paper', x=0.5, yref='paper', y=y_annotation,
        showarrow=False,
        **kwargs
    )

    fig.add_shape(
        type='line',
        xref='paper', x0=0, x1=1,
        yref='paper', y0=y_line, y1=y_line,
        line=dict(
            width=1
        )
    )

    if title_margin:
        fig.update_layout(
            dict(
                margin={'t': title_margin + (elevate_line * 30)},
            )
        )
Example #2
0
    def add_textbox(fig: go.Figure,
                    text: str,
                    position: Union[str, Tuple[float, float]],
                    fontsize=10) -> None:
        """
        Adds <text> to figure in a text box.
        Args:
            fig (): Figure to add text box to
            text (): Text to add
            position (): Absolute position on figure to add to (e.g. (0.5,0.9) for center top, or 'CT' for center top, or 'T' for center top)

        Returns:
            None: Modifies figure passed in
        """
        if isinstance(position, str):
            position = get_position_from_string(position)
        text = text.replace('\n', '<br>')
        fig.add_annotation(text=text,
                           xref='paper',
                           yref='paper',
                           x=position[0],
                           y=position[1],
                           showarrow=False,
                           bordercolor='#111111',
                           borderpad=3,
                           borderwidth=1,
                           opacity=0.8,
                           bgcolor='#F5F5F5',
                           font=dict(size=fontsize))
Example #3
0
    def _add_tier_annotations(fig: go.Figure) -> go.Figure:
        """Adds tier annotations to the figure."""
        fig.add_traces([
            go.Scatter(x=[x_, x_],
                       y=[-2, 40],
                       line_color="gray",
                       line_dash="dash") for x_ in [1.5, 1, 0.5]
        ])

        annos = [
            (1.75, 10, "S TIER"),
            (1.25, 10, "A TIER"),
            (0.75, 10, "B TIER"),
            (0.25, 10, "C TIER"),
        ]
        for anno in annos:
            annotation = dict(
                x=anno[0],
                y=anno[1],
                text="<b>%s</b>" % anno[2],
                showarrow=
                True,  # with True there is no arrow, but text is centered
                xanchor="left",
                yanchor="middle",
                borderpad=0,
                font=dict(color="black", size=50, family="MonacoRegular"),
                opacity=0.7,
                textangle=90,
            )
            fig.add_annotation(annotation)
        return fig
def add_chart_annotation(fig: go.Figure, text: str) -> None:
    fig.add_annotation(text=text,
        xanchor='left', yanchor='bottom',
        xref='paper', x=0, yref='paper', y=1,
        font=dict(
            color='grey',
            size=8
        ),
        showarrow=False
    )
def add_chart_bottom_annotation(fig: go.Figure, text: str,
    y_position: float = 0, x_position: float = 0) -> None:

    fig.add_annotation(text=text,
        xanchor='left', yanchor='top',
        xref='paper', x=x_position, yref='paper', y=-y_position,
        font=dict(
            color='grey',
            size=8
        ),
        showarrow=False
    )
Example #6
0
def annotate(
    fig: go.Figure,
    font_size: int,
    at: Point,
    xanchor: Literal['left', 'center', 'right'],
    yanchor: Literal['top', 'middle', 'bottom'],
    y_adjust: Optional[
        float],  # additional normalised offet of text relative to plot
    text: str,
    textangle: int = 0,
) -> None:
    """Add an annotation to supplied figure, with supplied arguments in addition to some default settings."""
    fig.add_annotation(xref='paper',
                       yref='paper',
                       showarrow=False,
                       font=dict(size=font_size),
                       x=at[0],
                       y=at[1] + (0 if y_adjust is None else y_adjust),
                       xanchor=xanchor,
                       yanchor=yanchor,
                       text=text,
                       textangle=textangle)
Example #7
0
def annotate_weekly_figure(fig: go.Figure) -> go.Figure:
    """Annotates weekly figure with seasonal labels."""
    # add season timeline labels
    fig.add_annotation(
        dict(
            x=1,
            y=1,
            yref="paper",
            xanchor="left",
            yanchor="top",
            text="BFA S4",
            showarrow=True,
        )
    )
    fig.add_annotation(
        dict(
            x=39,
            y=1,
            yref="paper",
            xanchor="center",
            yanchor="top",
            text="BFA Post-patch",
            showarrow=True,
        )
    )
    fig.add_annotation(
        dict(
            x=47,
            y=1,
            yref="paper",
            xanchor="left",
            yanchor="top",
            text="SL S1",
            showarrow=True,
        )
    )
    fig.add_annotation(
        dict(
            x=77,
            y=1,
            yref="paper",
            xanchor="left",
            yanchor="top",
            text="SL S2",
            showarrow=True,
        )
    )
    return fig
Example #8
0
def _annotate_scatter(fig: go.Figure, current_cnt_df: pd.DataFrame) -> None:
    """
    Helper function to annotate Issues and PRs on scatter plot.
    Legend is not shown so need annotations to see which line
    pertains to Issues and which line pertains to PRs.
    """
    x_loc = pd.to_datetime(current_cnt_df.iloc[0].name, format="%Y-%m-%d")

    fig.add_annotation(
        x=x_loc,
        y=current_cnt_df.iloc[0].issues_closed,
        text="Issues",
        row=1,
        col=1,
    )

    fig.add_annotation(
        x=x_loc,
        y=current_cnt_df.iloc[0].prs_closed,
        text="Pull Requests",
        row=1,
        col=1,
    )

    fig.add_annotation(
        x=x_loc,
        y=current_cnt_df.iloc[0].issues_open,
        text="Issues",
        row=2,
        col=1,
    )

    fig.add_annotation(
        x=x_loc,
        y=current_cnt_df.iloc[0].prs_open,
        text="Pull Requests",
        row=2,
        col=1,
    )