def funnel_callback(selected_value, selected_label, group, stacked, data_id): label_value_data, value_options, label_options = label_value_callback( "funnel")(selected_value, selected_label, group, data_id, funnel_stacked=stacked) return ( label_value_data, value_options, label_options, show_style(len(make_list(group)) > 0), )
def input_data( _ts, chart_type, x, y_multi, y_single, z, group, group_val, agg, window, rolling_comp, pathname, query, ): """ dash callback for maintaining chart input state and column-based dropdown options. This will guard against users selecting the same column for multiple axes. """ y_val = make_list(y_single if chart_type in ZAXIS_CHARTS else y_multi) if group_val is not None: group_val = [json.loads(gv) for gv in group_val] inputs = dict( query=query, chart_type=chart_type, x=x, y=y_val, z=z, group=group, group_val=group_val, agg=agg, window=window, rolling_comp=rolling_comp, ) data_id = get_data_id(pathname) options = build_input_options(global_state.get_data(data_id), **inputs) ( x_options, y_multi_options, y_single_options, z_options, group_options, barsort_options, yaxis_options, ) = options show_map = chart_type == "maps" map_style = {} if show_map else {"display": "none"} show_cs = chart_type == "candlestick" cs_style = {} if show_cs else {"display": "none"} show_treemap = chart_type == "treemap" treemap_style = {} if show_treemap else {"display": "none"} standard_style = ({ "display": "none" } if show_map or show_cs or show_treemap else {}) cscale_style = colorscale_input_style(chart_type=chart_type) drilldown_toggle_style = show_style((agg or "raw") != "raw") return ( inputs, x_options, y_single_options, y_multi_options, z_options, group_options, barsort_options, yaxis_options, standard_style, map_style, cs_style, treemap_style, cscale_style, drilldown_toggle_style, lock_zoom_style(chart_type), )
def on_data( _ts1, _ts2, _ts3, _ts4, _ts5, _ts6, _ts7, _ts8, load_clicks, inputs, chart_inputs, yaxis_data, map_data, cs_data, treemap_data, funnel_data, last_chart_inputs, auto_load, prev_load_clicks, ext_aggs, ): """ dash callback controlling the building of dash charts """ all_inputs = dict_merge( inputs, chart_inputs, dict(yaxis=yaxis_data or {}), map_data, cs_data, treemap_data, funnel_data, dict(extended_aggregation=ext_aggs or []) if inputs.get("chart_type") not in NON_EXT_AGGREGATION else {}, ) if not auto_load and load_clicks == prev_load_clicks: raise PreventUpdate if all_inputs == last_chart_inputs: raise PreventUpdate if is_app_root_defined(dash_app.server.config.get("APPLICATION_ROOT")): all_inputs["app_root"] = dash_app.server.config["APPLICATION_ROOT"] charts, range_data, code = build_chart(**all_inputs) agg_disabled = len(ext_aggs) > 0 ext_agg_tt = text("ext_agg_desc") ext_agg_warning = show_style(agg_disabled) if agg_disabled: ext_agg_tt = html.Div([ html.Span(text("ext_agg_desc")), html.Br(), html.Ul([ html.Li( extended_aggregations.build_extended_agg_desc(ext_agg), className="mb-0", ) for ext_agg in ext_aggs ]), ]) final_cols = build_final_cols( make_list(inputs.get("y")), inputs.get("z"), inputs.get("agg"), ext_aggs if inputs.get("chart_type") not in NON_EXT_AGGREGATION else [], ) return ( charts, all_inputs, range_data, "\n".join(make_list(code) + [CHART_EXPORT_CODE]), get_yaxis_type_tabs(final_cols), load_clicks, dict(display="block" if valid_chart(**all_inputs) else "none"), agg_disabled, ext_agg_tt, ext_agg_warning, )
def input_data( _ts, _ts2, chart_type, x, y_multi, y_single, z, group, group_type, group_val, bins_val, bin_type, agg, window, rolling_comp, load, load_type, cleaners, pathname, query, data_id, extended_aggregation, ): """ dash callback for maintaining chart input state and column-based dropdown options. This will guard against users selecting the same column for multiple axes. """ y_val = make_list(y_single if chart_type in ZAXIS_CHARTS else y_multi) data_id = data_id or get_data_id(pathname) if group_val is not None: group_val = [json.loads(gv) for gv in group_val] inputs = dict( data_id=data_id, query=query, chart_type=chart_type, x=x, y=y_val, z=z, group=group, group_type=group_type or "groups", group_val=group_val if group else None, bins_val=bins_val if group else None, bin_type=bin_type or "width", agg=agg or "raw", window=window, rolling_comp=rolling_comp, load=load, load_type=load_type, cleaners=make_list(cleaners), ) options = build_input_options( global_state.get_data(data_id), extended_aggregation=extended_aggregation, **inputs) ( x_options, y_multi_options, y_single_options, z_options, group_options, barsort_options, yaxis_options, ) = options show_map = chart_type == "maps" map_style = {} if show_map else {"display": "none"} show_cs = chart_type == "candlestick" cs_style = {} if show_cs else {"display": "none"} show_treemap = chart_type == "treemap" treemap_style = {} if show_treemap else {"display": "none"} show_funnel = chart_type == "funnel" funnel_style = {} if show_funnel else {"display": "none"} standard_style = ({ "display": "none" } if show_map or show_cs or show_treemap or show_funnel else {}) cscale_style = colorscale_input_style(chart_type=chart_type) drilldown_toggle_style = show_style((agg or "raw") != "raw") return ( inputs, x_options, y_single_options, y_multi_options, z_options, group_options, barsort_options, yaxis_options, standard_style, map_style, cs_style, treemap_style, funnel_style, cscale_style, drilldown_toggle_style, lock_zoom_style(chart_type), show_style(chart_type not in NON_EXT_AGGREGATION and len(y_val)), "({} Selected)".format(len(inputs["cleaners"])) if len(inputs["cleaners"]) else "", )
def build_body(ext_aggs): col_inputs = [html.Div(id="extended-agg-errors")] for i in INPUT_IDS: ext_agg = ext_aggs[i - 1] if len(ext_aggs) >= i else {} col_inputs.append( html.Div( [ html.Span( "{}.".format(i), className="col-auto pr-0 mt-auto mb-auto ext-agg-id", ), build_input( text("Col"), dcc.Dropdown( id="col-dropdown-{}".format(i), placeholder=text("Select"), style=dict(width="inherit"), value=ext_agg.get("col"), ), className="col-md-3", ), build_input( text("Agg"), dcc.Dropdown( id="agg-dropdown-{}".format(i), options=[ build_option(v, text(AGGS[v])) for v in [ "count", "nunique", "sum", "mean", "rolling", "corr", "first", "last", # "drop_duplicates", "median", "min", "max", "std", "var", "mad", "prod", "pctsum", "pctct", ] ], placeholder=text("Select"), style=dict(width="inherit"), value=ext_agg.get("agg"), ), className="col-md-3", ), html.Div( [ build_input( text("Window"), dcc.Input( id="window-input-{}".format(i), type="number", placeholder=text("Enter Days"), className="form-control text-center", style={"lineHeight": "inherit"}, value=ext_agg.get("window"), ), className="col-md-6", ), build_input( text("Computation"), dcc.Dropdown( id="rolling-comp-dropdown-{}".format(i), options=[ build_option("corr", text("Correlation")), build_option("count", text("Count")), build_option("cov", text("Covariance")), build_option("kurt", text("Kurtosis")), build_option("max", text("Maximum")), build_option("mean", text("Mean")), build_option("median", text("Median")), build_option("min", text("Minimum")), build_option("skew", text("Skew")), build_option( "std", text("Standard Deviation"), ), build_option("sum", text("Sum")), build_option("var", text("Variance")), ], placeholder=text("Select"), style=dict(width="inherit"), value=ext_agg.get("rolling_comp"), ), className="col-md-6 pl-0", ), ], id="rolling-inputs-{}".format(i), style=show_style(ext_agg.get("agg") == "rolling", display_style="inherit"), className="col-md-6 row p-0", ), ], className="row pb-3", )) return html.Div(col_inputs, id="extended-agg-body")
def toggle_rolling_style(agg): return show_style(agg == "rolling", display_style="inherit")