예제 #1
0
    def test_restrict(self, bokeh_model_page) -> None:
        """Test effect of 'restrict=False' with explicit JS callback"""
        text_input = AutocompleteInput(css_classes=["foo"], completions = ["aAaBbb", "aAaBbB"], restrict=False)
        text_input.js_on_change('value', CustomJS(code=RECORD("value", "cb_obj.value")))

        page = bokeh_model_page(text_input)

        el = page.driver.find_element_by_css_selector('.foo input')
        text = "not in completions"
        enter_text_in_element(page.driver, el, text, click=1, enter=True)

        results = page.results
        assert results['value'] == text
        assert page.has_no_console_errors()
예제 #2
0
def set_tbl_logic(source: ColumnDataSource, choices: AutocompleteInput, patchsources: Dict[str, Tuple],
                  countytable_cds: ColumnDataSource, rtplot: Figure, plots: List[Dict], ms_plot: Figure) -> None:
    someargs = dict(source=source, rtplot=rtplot, rtxaxis=rtplot.xaxis[0], rtyaxis=rtplot.yaxis[0],
                    ms_plot=ms_plot, ms_plot_xaxis=ms_plot.xaxis[0], ms_plot_yaxis0=ms_plot.yaxis[0],
                    choices=choices, countytable_cds=countytable_cds, patchsources=patchsources)
    someargs['xaxes'], someargs['yaxes'], someargs['plots'] = [], [], []
    for p in plots:
        someargs['xaxes'].append(p['plot'].xaxis[0])
        someargs['yaxes'].append(p['plot'].yaxis[0])
        someargs['plots'].append(p['plot'])
    tblcallback = CustomJS(args=someargs, code=constants.tblcallback_code)
    countytable_cds.selected.js_on_change('indices', tblcallback)
    # set additional callback on autocompeleteinput linking table row selected
    someargs = dict(source=source, choices=choices, countytable_cds=countytable_cds)
    inputtbl_callback = CustomJS(args=someargs, code=constants.autocomplete_in_tbl_code)
    choices.js_on_change('value', inputtbl_callback)
예제 #3
0
def build_autocomplete_grph_driver(rtplot: Figure, plots: List, ms_plot: Figure, patchsources: Dict[str, Tuple],
                                   source: ColumnDataSource, default_county: str,
                                   counties: pd.Index) -> Tuple[CDSView, AutocompleteInput]:
    choices = AutocompleteInput(completions=counties.tolist(), case_sensitive=False, value=default_county,
                                   title='Search for county or select from table:', name="county_input", width_policy='fit',
                                   css_classes=['autocomplete_input'], min_width=250, align="start")
    someargs = dict(source=source, rtplot=rtplot, rtxaxis=rtplot.xaxis[0], rtyaxis=rtplot.yaxis[0],
                    ms_plot=ms_plot, ms_plot_xaxis=ms_plot.xaxis[0], ms_plot_yaxis0=ms_plot.yaxis[0],
                    plots=plots, choices=choices, patchsources=patchsources)
    someargs['xaxes'], someargs['yaxes'], someargs['plots'] = [], [], []
    for p in plots:
        someargs['xaxes'].append(p['plot'].xaxis[0])
        someargs['yaxes'].append(p['plot'].yaxis[0])
        someargs['plots'].append(p['plot'])

    callback = CustomJS(args=someargs, code=constants.autocomplete_input_code)
    choices.js_on_change('value', callback)
    js_filter = CustomJSFilter(args=dict(choices=choices), code=constants.cdsview_jsfilter_code)
    view = CDSView(source=source, filters=[js_filter])
    return view, choices
예제 #4
0
    case_sensitive=False)
autocomplete_input_trh_20 = AutocompleteInput(
    placeholder="Enter value Threshold 20 no case sensitive ...",
    completions=completions,
    fuzzy_threshold=20,
    case_sensitive=False)
autocomplete_input_trh_5_sens = AutocompleteInput(
    placeholder="Enter value Threshold 5 sensitive ...",
    completions=completions,
    fuzzy_threshold=5,
    case_sensitive=True)
autocomplete_input_trh_20_sens = AutocompleteInput(
    placeholder="Enter value Threshold 20 sensitive ...",
    completions=completions,
    fuzzy_threshold=20,
    case_sensitive=True)
autocomplete_input_trh_5.js_on_change(
    "value",
    CustomJS(code="""
    console.log('text_input: value=' + this.value, this.toString())
"""),
)

curdoc().add_root(
    column(autocomplete_input_trh_5,
           autocomplete_input_trh_20,
           autocomplete_input_trh_5_sens,
           autocomplete_input_trh_20_sens,
           width=800))
curdoc().title = "Autocomplete Fuzzy"
예제 #5
0
def run_make_table(creds):
    if creds.get('env') == 'dev':
        csvs_file_location = './dev_csv'
    else:
        csvs_file_location = 's3://graycannon.com/csvs'

    df = pd.read_csv('{}/country_table.csv'.format(csvs_file_location))
    df2 = pd.read_csv('{}/locale_table.csv'.format(csvs_file_location))
    base = pd.read_csv('{}/base.csv'.format(csvs_file_location))

    df['charts_page'] = './chart_pages/country_' + df['country_region'] + '.html'
    df2['charts_page'] = './chart_pages/locale_' + df2['locale'] + '.html'

    original_source1 = ColumnDataSource(data=df)
    source1 = ColumnDataSource(data=df)
    original_source2 = ColumnDataSource(data=df2)
    source2 = ColumnDataSource(data=df2)

    button = Button(label="Download", button_type="success", width_policy="max")
    button.js_on_click(CustomJS(args=dict(source=source1),
                                code=open(join(dirname(__file__), "download.js")).read()))

    button2 = Button(label="Download", button_type="success", width_policy="max")
    button2.js_on_click(CustomJS(args=dict(source=source2),
                                code=open(join(dirname(__file__), "download.js")).read()))

    columns = [
        TableColumn(field="country_region", title="Country/Region"),
        TableColumn(field="current_day", title="Confirmed Cases To {}".format(base['day'].max()), formatter=NumberFormatter(format="0,0")),
        TableColumn(field="new_cases", title="New Cases Current Day", formatter=NumberFormatter(format="0,0")),
        TableColumn(field="peak_new", title="Peak New Cases", formatter=NumberFormatter(format="0,0")),
        TableColumn(field="since_peak_new", title="Days Since Peak", formatter=NumberFormatter(format="0,0")),
        TableColumn(field="growth_rate", title="Daily Growth Rate", formatter=NumberFormatter(format="0,0.00")),
        TableColumn(field="growth_factor", title="Daily Growth Factor", formatter=NumberFormatter(format="0,0.00")),
        TableColumn(field="growth_rate_week", title="Weekly Growth Rate", formatter=NumberFormatter(format="0,0.00")),
        TableColumn(field="growth_factor_week", title="Weekly Growth Factor", formatter=NumberFormatter(format="0,0.00")),
        TableColumn(field="charts_page", title="Link to Charts", formatter=HTMLTemplateFormatter(template='<a href="<%= charts_page%>" target="_blank"><%= country_region %> Charts</a>'))
    ]

    columns2 = columns.copy()
    columns2[0] = TableColumn(field="locale", title="Province/State")
    columns2[9] = TableColumn(field="charts_page", title="Link to Charts", formatter=HTMLTemplateFormatter(template='<a href="<%= charts_page%>" target="_blank"><%= locale %> Charts</a>'))

    data_table = DataTable(source=source1, columns=columns, width=1700, index_position=None)
    data_table2 = DataTable(source=source2, columns=columns2, width=1700, index_position=None)
    reset_button = Button(label="Reset Table", button_type="success", width_policy="min", height_policy="max")
    reset_button2 = Button(label="Reset Table", button_type="success", width_policy="min", height_policy="max")

    country_list = df['country_region'].unique().tolist()
    country_list_lower = [x.lower() for x in country_list]
    country_options = country_list + country_list_lower
    country_search = AutocompleteInput(title="Country:", completions=country_options)

    locale_list = df2['locale'].unique().tolist()
    locale_list_lower = [x.lower() for x in locale_list]
    locale_options = locale_list + locale_list_lower
    locale_search = AutocompleteInput(title="Province/State:", completions=locale_options)

    search_js = """
        var data = source.data;
        var originalData = orig.data;
        var f = cb_obj.value;
        for (var key in data) {
            data[key] = [];
            for (var i = 0; i < originalData[breakdown].length; ++i) {
                if (originalData[breakdown][i].toLowerCase() === f.toLowerCase()) {
                    data[key].push(originalData[key][i]);
                }
            }
        }
        console.log('originalData', originalData);
        console.log('data', data);
        source.change.emit();
    """

    reset_js = """
        console.log('click');
        search.value = '';
        source.data = JSON.parse(JSON.stringify(orig.data));
        source.change.emit();
    """

    callback = CustomJS(args=dict(source=source1, orig=original_source1, breakdown='country_region', target_object=data_table), code=search_js)
    reset_callback = CustomJS(args=dict(source=source1, orig=original_source1, search=country_search, target_object=data_table), code=reset_js)
    country_search.js_on_change('value', callback)
    reset_button.js_on_click(reset_callback)

    callback2 = CustomJS(args=dict(source=source2, orig=original_source2, breakdown='locale', target_object=data_table), code=search_js)
    reset_callback2 = CustomJS(args=dict(source=source2, orig=original_source2, search=locale_search, target_object=data_table), code=reset_js)
    locale_search.js_on_change('value', callback2)
    reset_button2.js_on_click(reset_callback2)

    page_layout = layout(
        [country_search, reset_button],
        [data_table],
        [button],
        [locale_search, reset_button2],
        [data_table2],
        [button2]
    )

    object_key = 'covid_tables.html'
    filename = '/tmp/{}'.format(object_key)
    output_file(filename, title='Covid Data Tables')

    save(page_layout)
    write_html_to_s3(filename, object_key, creds)
    os.remove(filename)