def create_plot(cls, *, data, tiles_params: Dict, points_params: Dict, labels_params: Dict, reverse_y: bool, show_legend: bool, labels_map_size: bool, corr_value_format: str, threshold) -> PlotSpec: # Adjust options labels_map_size = _OpUtil.adjust_type_color_size( tiles_params, points_params, labels_params, labels_map_size) _OpUtil.adjust_diag(tiles_params, points_params, labels_params, threshold) _OpUtil.flip_type(tiles_params, points_params, labels_params, reverse_y) tooltips = (layer_tooltips().format( field='@..corr..', format=corr_value_format).line('@..corr..')) plot = ggplot(data) if tiles_params is not None: plot += geom_tile(stat='corr', show_legend=show_legend, size=0.0, width=1.002, height=1.002, tooltips=tooltips, sampling='none', **tiles_params) plot += coord_cartesian() else: plot += coord_fixed() if points_params is not None: plot += geom_point(stat='corr', show_legend=show_legend, size_unit='x', mapping=aes(size='..corr_abs..'), tooltips=tooltips, sampling='none', **points_params) if labels_params is not None: m = None if labels_map_size: m = aes(size='..corr_abs..') else: labels_params['size'] = 1 plot += geom_text(stat='corr', show_legend=show_legend, mapping=m, na_text='', label_format=corr_value_format, tooltips=tooltips, size_unit='x', sampling='none', **labels_params) return plot
def as_annotated_data(raw_data: Any, raw_mapping: Any) -> Tuple: data_meta = {} # data data = raw_data if is_data_pub_stream(data): data = {} for col_name in raw_data.col_names: data[col_name] = [] data_meta.update({'pubsub': {'channel_id': raw_data.channel_id, 'col_names': raw_data.col_names}}) # mapping mapping = {} mapping_meta = [] if raw_mapping is not None: for aesthetic, variable in raw_mapping.as_dict().items(): if aesthetic == 'name': # ignore FeatureSpec.name property continue if isinstance(variable, MappingMeta): mapping[aesthetic] = variable.variable mapping_meta.append({ 'aes': aesthetic, 'annotation': variable.annotation, 'parameters': variable.parameters }) else: mapping[aesthetic] = variable if len(mapping_meta) > 0: data_meta.update({'mapping_annotations': mapping_meta}) # series annotations series_meta = [] if is_dict_or_dataframe(data): for column_name, values in data.items(): if isinstance(values, Iterable): not_empty_series = any(True for _ in values) if not_empty_series and all(isinstance(val, datetime) for val in values): series_meta.append({ 'column': column_name, 'type': 'datetime' }) if len(series_meta) > 0: data_meta.update({'series_annotations': series_meta}) return data, aes(**mapping), {'data_meta': data_meta}
def as_annotated_data(raw_data: Any, raw_mapping: dict) -> Tuple: data_meta = {} # data data = raw_data if is_data_pub_stream(data): data = {} for col_name in raw_data.col_names: data[col_name] = [] data_meta.update({ 'pubsub': { 'channel_id': raw_data.channel_id, 'col_names': raw_data.col_names } }) elif is_geo_data_frame(data): data_meta.update(get_geo_data_frame_meta(data)) # mapping mapping = {} mapping_meta = [] if raw_mapping is not None: for aesthetic, variable in raw_mapping.as_dict().items(): if aesthetic == 'name': # ignore FeatureSpec.name property continue if isinstance(variable, MappingMeta): mapping[aesthetic] = variable.variable mapping_meta.append({ 'aes': aesthetic, 'annotation': variable.annotation, 'parameters': variable.parameters }) else: mapping[aesthetic] = variable if len(mapping_meta) > 0: data_meta.update({'mapping_annotations': mapping_meta}) return data, aes(**mapping), {'data_meta': data_meta}