Ejemplo n.º 1
0
def _get_fill_color_transform(table, geometry_column_names):
    column_name, name_parts = _prepare_column_name(
        FILL_COLOR_COLUMN_PATTERN, table.columns)
    if not column_name:
        return
    color_scheme, summary_type = name_parts
    local_property_name = 'fillColor'
    if color_scheme == 'color':
        summarize = _define_summarize_colors(summary_type or 'mean')
        normalize = rgb2hex
    else:
        hex_array = _get_hex_array(color_scheme)
        summarize = _define_summarize_numbers(summary_type or 'sum')
        normalize_number = define_normalize(_get_summary_domain(
            table, geometry_column_names, column_name, summarize), [0, 8.9999])

        def normalize(x):
            index_string = floor(normalize_number(x))
            try:
                index = int(index_string)
            except ValueError:
                index = 0
            return hex_array[index]

    return _define_transform(
        column_name, local_property_name, normalize, summarize)
Ejemplo n.º 2
0
def _get_radius_transform(table, geometry_column_names):
    column_name, name_parts = _prepare_column_name(
        RADIUS_COLUMN_PATTERN, table.columns)
    if not column_name:
        return
    scale, has_range, y_min, y_max, summary_type = name_parts
    local_property_name = 'radius_in_' + scale
    summarize = _define_summarize_numbers(summary_type or 'sum')
    normalize = define_normalize(_get_summary_domain(
        table, geometry_column_names, column_name, summarize,
    ), [float(y_min), float(y_max)]) if has_range else lambda x: x
    return _define_transform(
        column_name, local_property_name, normalize, summarize)