Example #1
0
def test_monthlychart_set_min_max_by_index():
    """Test the set_minimum_by_index amd set_maximum_by_index methods."""
    header = Header(Temperature(), 'C', AnalysisPeriod())
    values = [i for i in range(12)]
    date_t = list(range(1, 13))
    data_coll = MonthlyCollection(header, values, date_t)
    header2 = Header(RelativeHumidity(), '%', AnalysisPeriod())
    values2 = [i for i in range(10, 70, 5)]
    data_coll2 = MonthlyCollection(header2, values2, date_t)
    l_par = LegendParameters(min=-20, max=40)
    l_par.decimal_count = 0

    month_chart = MonthlyChart([data_coll, data_coll2], legend_parameters=l_par)

    assert month_chart.y_axis_labels1[0] == '-20'
    assert month_chart.y_axis_labels1[-1] == '40'

    month_chart.set_minimum_by_index(0, 1)
    assert month_chart.y_axis_labels2[0] == '0'
    month_chart.set_maximum_by_index(100, 1)
    assert month_chart.y_axis_labels2[-1] == '100'
    z_val_tol = z_val + tolerance
    _base_pt_ = to_point2d(_base_pt_) if _base_pt_ is not None else Point2D()
    _x_dim_ = _x_dim_ if _x_dim_ is not None else 10.0 / conversion_to_meters()
    _y_dim_ = _y_dim_ if _y_dim_ is not None else 40.0 / conversion_to_meters()
    stack_ = stack_ if stack_ is not None else False
    percentile_ = percentile_ if percentile_ is not None else 34.0
    lpar = legend_par_[0] if len(legend_par_) != 0 else None

    # create the monthly chart object and get the main pieces of geometry
    month_chart = MonthlyChart(_data, lpar, _base_pt_, _x_dim_, _y_dim_,
                               stack_, percentile_)
    if len(legend_par_) > 1:
        if legend_par_[1].min is not None:
            month_chart.set_minimum_by_index(legend_par_[1].min, 1)
        if legend_par_[1].max is not None:
            month_chart.set_maximum_by_index(legend_par_[1].max, 1)

    #  get the main pieces of geometry
    d_meshes = month_chart.data_meshes
    if d_meshes is not None:
        data_mesh = [from_mesh2d(msh, z_val_tol) for msh in d_meshes]
    d_lines = month_chart.data_polylines
    if d_lines is not None:
        data_lines = [from_polyline2d(lin, z_val_tol) for lin in d_lines]
    borders = [from_polyline2d(month_chart.chart_border, z_val)] + \
            [from_linesegment2d(line, z_val) for line in month_chart.y_axis_lines] + \
            [from_linesegment2d(line, z_val_tol) for line in month_chart.month_lines]
    legend = legend_objects(month_chart.legend)

    # process all of the text-related outputs
    title_txt = month_chart.title_text if global_title_ is None else global_title_