示例#1
0
def __get_position_scales(metrics, chart_height, chart_width, concat_chart):
    """Computes the scales for x and y encodings to be used in the metric bubble chart."""

    position_scales = dict()

    # METRICS VALUES SCALE
    x_range = get_chart_size_range(chart_width, Metric_Chart.padding_x)
    x_domain = [0, 1]
    position_scales["x"] = alt.Scale(domain=x_domain, range=x_range)

    # METRICS LABELS SCALE
    y_range = get_chart_size_range(chart_height, Metric_Chart.padding_y)
    y_domain = [metric.upper() for metric in metrics]
    position_scales["y"] = alt.Scale(domain=y_domain, range=y_range)

    return position_scales
示例#2
0
def __get_position_scales(chart_height, chart_width):
    """Computes the scales for x and y encodings to be used in the xy metrics chart."""

    position_scales = dict()

    # X-Y RANGES (based on chart dimensions)
    x_range = get_chart_size_range(chart_width, XY_Chart.padding_x)
    y_range = get_chart_size_range(chart_height, XY_Chart.padding_y)
    y_range.reverse()

    # METRICS SCALES
    metric_domain = [0, 1]
    position_scales["x"] = alt.Scale(domain=metric_domain, range=x_range)
    position_scales["y"] = alt.Scale(domain=metric_domain, range=y_range)

    return position_scales
示例#3
0
def __get_position_scales(plot_table, metrics, fairness_threshold,
                          chart_height, chart_width):
    """Computes the scales for x and y encodings to be used in the disparity bubble chart."""

    position_scales = dict()

    # DISPARITIES SCALE
    # RANGE
    x_range = get_chart_size_range(chart_width, Disparity_Chart.padding_x)

    # DOMAIN
    # Get max absolute disparity
    scaled_disparities_col_names = [
        f"{metric}_disparity_scaled" for metric in metrics
    ]

    def max_column(x):
        return max(x.min(), x.max(), key=abs)

    max_disparities = plot_table[scaled_disparities_col_names].apply(
        max_column, axis=1)
    abs_max_disparity = abs(max_column(max_disparities))

    # If fairness_threshold is defined, get max between threshold and max absolute disparity
    if fairness_threshold is not None:
        x_domain_limit = math.ceil(max(abs_max_disparity, fairness_threshold))
    else:
        x_domain_limit = math.ceil(abs_max_disparity)

    x_domain = [-x_domain_limit, x_domain_limit]
    position_scales["x"] = alt.Scale(domain=x_domain, range=x_range)

    # METRICS SCALE
    y_range = get_chart_size_range(chart_height, Disparity_Chart.padding_y)
    if chart_height < 300:
        y_range[0] = 30
    y_domain = [metric.upper() for metric in metrics]
    position_scales["y"] = alt.Scale(domain=y_domain, range=y_range)

    return position_scales