""" Goldilocks Range / Dual-Thumb Slider Layout Generates a dual-thumb range slider for selecting a min-max range. Uses custom div-based handles (not native range inputs) for reliable cross-browser rendering. Research basis: - Pavlick & Kwiatkowski (2019) "Inherent Disagreements in Human Textual Inferences" TACL - Jurgens (2013) "Embracing Ambiguity: A Comparison of Annotation Methodologies for Crowdsourcing Word Sense Labels" NAACL """ import logging from potato.ai.ai_help_wrapper import get_ai_wrapper from .identifier_utils import ( safe_generate_layout, generate_element_identifier, generate_validation_attribute, escape_html_content, generate_layout_attributes, ) logger = logging.getLogger(__name__) DEFAULT_MIN = 0 DEFAULT_MAX = 100 DEFAULT_STEP = 1 def generate_range_slider_layout(annotation_scheme): """ Generate HTML for a dual-thumb range slider interface. Args: annotation_scheme (dict): Configuration including: - name: Schema identifier - description: Display description - min_value: Minimum value (default 0) - max_value: Maximum value (default 100) - step: Step size (default 1) - left_label: Label for left end - right_label: Label for right end - show_values: Show numeric values (default true) Returns: tuple: (html_string, key_bindings) """ return safe_generate_layout(annotation_scheme, _generate_range_slider_layout_internal) def _generate_range_slider_layout_internal(annotation_scheme): schema_name = annotation_scheme["name"] safe_schema = escape_html_content(schema_name) description = annotation_scheme["description"] min_val = annotation_scheme.get("min_value", DEFAULT_MIN) max_val = annotation_scheme.get("max_value", DEFAULT_MAX) step = annotation_scheme.get("step", DEFAULT_STEP) left_label = annotation_scheme.get("left_label", "") right_label = annotation_scheme.get("right_label", "") show_values = annotation_scheme.get("show_values", True) layout_attrs = generate_layout_attributes(annotation_scheme) validation = generate_validation_attribute(annotation_scheme) # Default initial range: 25th to 75th percentile range_span = max_val - min_val init_low = min_val + range_span // 4 init_high = max_val - range_span // 4 id_low = generate_element_identifier(schema_name, "range_low", "range") id_high = generate_element_identifier(schema_name, "range_high", "range") html = f"""
{get_ai_wrapper()}
{escape_html_content(description)}
""" if left_label or right_label: html += f"""
{escape_html_content(left_label)} {escape_html_content(right_label)}
""" html += f"""
""" if show_values: html += f"""
{init_low} {init_high}
""" html += f"""
""" key_bindings = [] logger.info(f"Generated range_slider layout for {schema_name}") return html, key_bindings