Populates a dict with arguments to update trace Parameters ---------- args : dict args to be used for the trace trace_spec : NamedTuple which kind of trace to be used (has constructor, marginal etc. attributes) trace_data : pandas DataFrame data
(args, trace_spec, trace_data, mapping_labels, sizeref)
| 300 | |
| 301 | |
| 302 | def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref): |
| 303 | """Populates a dict with arguments to update trace |
| 304 | |
| 305 | Parameters |
| 306 | ---------- |
| 307 | args : dict |
| 308 | args to be used for the trace |
| 309 | trace_spec : NamedTuple |
| 310 | which kind of trace to be used (has constructor, marginal etc. |
| 311 | attributes) |
| 312 | trace_data : pandas DataFrame |
| 313 | data |
| 314 | mapping_labels : dict |
| 315 | to be used for hovertemplate |
| 316 | sizeref : float |
| 317 | marker sizeref |
| 318 | |
| 319 | Returns |
| 320 | ------- |
| 321 | trace_patch : dict |
| 322 | dict to be used to update trace |
| 323 | fit_results : dict |
| 324 | fit information to be used for trendlines |
| 325 | """ |
| 326 | trace_data: nw.DataFrame |
| 327 | df: nw.DataFrame = args["data_frame"] |
| 328 | |
| 329 | if "line_close" in args and args["line_close"]: |
| 330 | trace_data = nw.concat([trace_data, trace_data.head(1)], how="vertical") |
| 331 | |
| 332 | trace_patch = trace_spec.trace_patch.copy() or {} |
| 333 | fit_results = None |
| 334 | hover_header = "" |
| 335 | for attr_name in trace_spec.attrs: |
| 336 | attr_value = args[attr_name] |
| 337 | attr_label = get_decorated_label(args, attr_value, attr_name) |
| 338 | if attr_name == "dimensions": |
| 339 | dims = [ |
| 340 | (name, trace_data.get_column(name)) |
| 341 | for name in trace_data.columns |
| 342 | if ((not attr_value) or (name in attr_value)) |
| 343 | and (trace_spec.constructor != go.Parcoords or _is_continuous(df, name)) |
| 344 | and ( |
| 345 | trace_spec.constructor != go.Parcats |
| 346 | or (attr_value is not None and name in attr_value) |
| 347 | or nw.to_py_scalar(df.get_column(name).n_unique()) |
| 348 | <= args["dimensions_max_cardinality"] |
| 349 | ) |
| 350 | ] |
| 351 | trace_patch["dimensions"] = [ |
| 352 | dict(label=get_label(args, name), values=column) |
| 353 | for (name, column) in dims |
| 354 | ] |
| 355 | if trace_spec.constructor == go.Splom: |
| 356 | for d in trace_patch["dimensions"]: |
| 357 | d["axis"] = dict(matches=True) |
| 358 | mapping_labels["%{xaxis.title.text}"] = "%{x}" |
| 359 | mapping_labels["%{yaxis.title.text}"] = "%{y}" |
no test coverage detected