def _build_axes(y): axes = {'xaxis': dict(title=update_label_for_freq(x))} positions = [] for i, y2 in enumerate(y, 0): right = i % 2 == 1 axis_ct = int(i / 2) title = update_label_for_freq(y2) if z is None and agg is not None: title = '{} ({})'.format(title, AGGS[agg]) value = dict(title=title) if i == 0: key = 'yaxis' else: key = 'yaxis{}'.format(i + 1) value = dict_merge( value, dict(overlaying='y', side='right' if right else 'left')) value['anchor'] = 'free' if axis_ct > 0 else 'x' if axis_ct > 0: pos = axis_ct / 20.0 value['position'] = (1 - pos) if right else pos positions.append(value['position']) if y2 in axis_inputs and not (axis_inputs[y2]['min'], axis_inputs[y2]['max']) == ( mins[y2], maxs[y2]): value['range'] = [ axis_inputs[y2]['min'], axis_inputs[y2]['max'] ] if classify_type(dtypes.get(y2)) == 'I': value['tickformat'] = '.0f' axes[key] = value if len(positions): if len(positions) == 1: domain = [positions[0] + 0.05, 1] elif len(positions) == 2: domain = sorted(positions) domain = [domain[0] + 0.05, domain[1] - 0.05] else: lower, upper = divide_chunks(sorted(positions), 2) domain = [lower[-1] + 0.05, upper[0] - 0.05] axes['xaxis']['domain'] = domain if classify_type(dtypes.get(x)) == 'I': axes['xaxis']['tickformat'] = '.0f' if z is not None: axes['zaxis'] = dict( title=z if agg is None else '{} ({})'.format(z, AGGS[agg])) if classify_type(dtypes.get(z)) == 'I': axes['zaxis']['tickformat'] = '.0f' return axes
def cpg_chunker(charts, columns=2): """ Helper function to break a list of charts up into rows of two. If there is only one chart it will only return one row with the chart occupying the full width. :param charts: chart objects :type charts: list of :dash:`dash_core_components.Groph <dash-core-components/graph>` :param columns: how many columns each row of charts should have (default: 2) :type columns: int :return: list of rows by `columns` if more than one chart is input otherwise simply return the chart """ if len(charts) == 1: return charts return [ html.Div([html.Div(c, className='col-md-6') for c in chunk], className='row') for chunk in divide_chunks(charts, columns) ]