Example #1
0
def state_token(state):
    """Returns a formatted string with HTML for a given State"""
    color = State.color(state)
    fg_color = State.color_fg(state)
    return Markup("""
        <span class="label" style="color:{fg_color}; background-color:{color};"
            title="Current State: {state}">{state}</span>
        """).format(color=color, state=state, fg_color=fg_color)
def render_dag(dag: DAG, tis: Optional[List[TaskInstance]] = None) -> graphviz.Digraph:
    """
    Renders the DAG object to the DOT object.

    If an task instance list is passed, the nodes will be painted according to task statuses.

    :param dag: DAG that will be rendered.
    :type dag: airflow.models.dag.DAG
    :param tis: List of task instances
    :type tis: Optional[List[TaskInstance]]
    :return: Graphviz object
    :rtype: graphviz.Digraph
    """
    dot = graphviz.Digraph(
        dag.dag_id,
        graph_attr={
            "rankdir": dag.orientation if dag.orientation else "LR",
            "labelloc": "t",
            "label": dag.dag_id,
        },
    )
    states_by_task_id = None
    if tis is not None:
        states_by_task_id = {ti.task_id: ti.state for ti in tis}
    for task in dag.tasks:
        node_attrs = {
            "shape": "rectangle",
            "style": "filled,rounded",
        }
        if states_by_task_id is None:
            node_attrs.update(
                {
                    "color": _refine_color(task.ui_fgcolor),
                    "fillcolor": _refine_color(task.ui_color),
                }
            )
        else:
            state = states_by_task_id.get(task.task_id, State.NONE)
            node_attrs.update(
                {
                    "color": State.color_fg(state),
                    "fillcolor": State.color(state),
                }
            )
        dot.node(
            task.task_id,
            _attributes=node_attrs,
        )
        for downstream_task_id in task.downstream_task_ids:
            dot.edge(task.task_id, downstream_task_id)
    return dot
Example #3
0
def _draw_task(task: BaseOperator, parent_graph: graphviz.Digraph,
               states_by_task_id: Optional[Dict[Any, Any]]) -> None:
    """Draw a single task on the given parent_graph"""
    if states_by_task_id:
        state = states_by_task_id.get(task.task_id, State.NONE)
        color = State.color_fg(state)
        fill_color = State.color(state)
    else:
        color = task.ui_fgcolor
        fill_color = task.ui_color

    parent_graph.node(
        task.task_id,
        _attributes={
            "label": task.label,
            "shape": "rectangle",
            "style": "filled,rounded",
            "color": _refine_color(color),
            "fillcolor": _refine_color(fill_color),
        },
    )
Example #4
0
def state_token(state):
    color = State.color(state)
    return Markup('<span class="label" style="background-color:{color};">'
                  '{state}</span>').format(color=color, state=state)
Example #5
0
def state_token(state):
    """Returns a formatted string with HTML for a given State"""
    color = State.color(state)
    return Markup('<span class="label" style="background-color:{color};">'
                  '{state}</span>').format(color=color, state=state)
Example #6
0
def state_token(state):
    color = State.color(state)
    return Markup(
        '<span class="label" style="background-color:{color};">'
        '{state}</span>').format(color=color, state=state)
Example #7
0
def state_f(v, c, m, p):
    state = m.state
    color = State.color(m.state)
    return Markup('<span class="label" style="background-color:{color};">'
                  '{state}</span>').format(**locals())