//! Tests for Chart helper module
//!
//! Extracted from src/widget/data/chart/

use revue::layout::Rect;
use revue::render::Buffer;
use revue::style::Color;
use revue::widget::data::chart::{chart, line_chart, Chart};
use revue::widget::data::chart::scatter_chart::{scatter_chart, ScatterSeries};
use revue::widget::data::chart::types::{ChartType, LineStyle, Series};
use revue::widget::data::chart::chart_common::{Axis, AxisFormat, LegendPosition, Marker};
use revue::widget::RenderContext;
use revue::widget::View;

// ==================== Builder Pattern Tests ====================

#[test]
fn test_chart_new() {
    let chart = Chart::new();
    // Verify chart can be created and renders without panic
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_default() {
    let chart = Chart::default();
    // Verify default chart renders without panic
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_title() {
    let chart = Chart::new().title("Test Chart");
    // Verify title doesn't cause rendering errors
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_title_str() {
    let chart = Chart::new().title(String::from("Owned Title"));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_series_single() {
    let series = Series::new("Data 1").data(vec![(1.0, 2.0), (2.0, 3.0)]);
    let chart = Chart::new().series(series);
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_series_multiple() {
    let series1 = Series::new("Data 1").data(vec![(1.0, 2.0), (2.0, 3.0)]);
    let series2 = Series::new("Data 2").data(vec![(1.0, 1.5), (2.0, 2.5)]);
    let chart = Chart::new().series(series1).series(series2);
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_series_vec() {
    let series_vec = vec![
        Series::new("Data 1").data(vec![(1.0, 2.0)]),
        Series::new("Data 2").data(vec![(1.0, 3.0)]),
        Series::new("Data 3").data(vec![(1.0, 4.0)]),
    ];
    let chart = Chart::new().series_vec(series_vec);
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_series_vec_empty() {
    let chart = Chart::new().series_vec(vec![]);
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_series_combined() {
    let series1 = Series::new("Data 1").data(vec![(1.0, 2.0)]);
    let series_vec = vec![
        Series::new("Data 2").data(vec![(1.0, 3.0)]),
        Series::new("Data 3").data(vec![(1.0, 4.0)]),
    ];
    let chart = Chart::new().series(series1).series_vec(series_vec);
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_x_axis() {
    let axis = Axis::new().bounds(0.0, 100.0);
    let chart = Chart::new().x_axis(axis);
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_y_axis() {
    let axis = Axis::new().bounds(-10.0, 10.0);
    let chart = Chart::new().y_axis(axis);
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_legend_top_left() {
    let chart = Chart::new()
        .legend(LegendPosition::TopLeft)
        .series(Series::new("Data").data(vec![(1.0, 2.0)]));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_legend_top_right() {
    let chart = Chart::new()
        .legend(LegendPosition::TopRight)
        .series(Series::new("Data").data(vec![(1.0, 2.0)]));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_legend_bottom_left() {
    let chart = Chart::new()
        .legend(LegendPosition::BottomLeft)
        .series(Series::new("Data").data(vec![(1.0, 2.0)]));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_legend_bottom_right() {
    let chart = Chart::new()
        .legend(LegendPosition::BottomRight)
        .series(Series::new("Data").data(vec![(1.0, 2.0)]));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_no_legend() {
    let chart = Chart::new()
        .no_legend()
        .series(Series::new("Data").data(vec![(1.0, 2.0)]));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_bg_color() {
    let chart = Chart::new().bg(Color::BLUE);
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_bg_color_rgb() {
    let chart = Chart::new().bg(Color::rgb(255, 0, 0));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_border_color() {
    let chart = Chart::new().border(Color::GREEN);
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_border_color_rgb() {
    let chart = Chart::new().border(Color::rgb(128, 128, 128));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_braille_mode() {
    let chart = Chart::new()
        .braille()
        .series(Series::new("Data").data(vec![(1.0, 2.0)]));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_builder_chain() {
    let series = Series::new("Test Data").data(vec![(1.0, 2.0), (2.0, 4.0), (3.0, 6.0)]);
    let chart = Chart::new()
        .title("Builder Test")
        .series(series)
        .x_axis(Axis::new().bounds(0.0, 5.0))
        .y_axis(Axis::new().bounds(0.0, 10.0))
        .legend(LegendPosition::TopLeft)
        .bg(Color::BLACK)
        .border(Color::WHITE);

    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

// ==================== Helper Function Tests ====================

#[test]
fn test_chart_helper() {
    let my_chart = chart();
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    my_chart.render(&mut ctx);
}

#[test]
fn test_line_chart_helper() {
    let chart = line_chart(&[2.0, 4.0]);
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_line_chart_helper_empty() {
    let chart = line_chart(&[]);
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_line_chart_helper_single_point() {
    let chart = line_chart(&[10.0]);
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_scatter_plot_helper() {
    let chart = scatter_chart().series(ScatterSeries::new("Data").points(&[
        (1.0, 2.0),
        (3.0, 4.0),
        (5.0, 6.0),
    ]));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_scatter_plot_helper_empty() {
    let chart = scatter_chart();
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

// ==================== Edge Cases Tests ====================

#[test]
fn test_chart_with_nan_values() {
    let chart = Chart::new().series(Series::new("Data").data(vec![
        (1.0, 2.0),
        (f64::NAN, 3.0),
        (3.0, f64::NAN),
        (4.0, 5.0),
    ]));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

// Note: Infinite values cause overflow in bounds calculation - this is a known bug
// #[test]
// fn test_chart_with_infinite_values() {
//     let chart = Chart::new().series(
//         Series::new("Data").data(vec![
//             (1.0, 2.0),
//             (f64::INFINITY, 3.0),
//             (3.0, f64::NEG_INFINITY),
//             (4.0, 5.0),
//         ]),
//     );
//     let mut buffer = Buffer::new(40, 20);
//     let area = Rect::new(0, 0, 40, 20);
//     let mut ctx = RenderContext::new(&mut buffer, area);
//     chart.render(&mut ctx);
// }

#[test]
fn test_chart_single_point() {
    let chart = Chart::new().series(Series::new("Data").data(vec![(5.0, 10.0)]));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_identical_values() {
    let chart =
        Chart::new().series(Series::new("Data").data(vec![(1.0, 5.0), (2.0, 5.0), (3.0, 5.0)]));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_negative_values() {
    let chart =
        Chart::new().series(Series::new("Data").data(vec![(-5.0, -3.0), (-2.0, -1.0), (0.0, 0.0)]));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_large_values() {
    let chart =
        Chart::new().series(Series::new("Data").data(vec![(1000.0, 2000.0), (3000.0, 4000.0)]));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_small_values() {
    let chart = Chart::new().series(Series::new("Data").data(vec![(0.001, 0.002), (0.003, 0.004)]));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_axis_bounds_override() {
    let chart = Chart::new()
        .series(Series::new("Data").data(vec![(5.0, 10.0)]))
        .x_axis(Axis::new().bounds(0.0, 20.0))
        .y_axis(Axis::new().bounds(0.0, 30.0));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

// ==================== Chart Type Tests ====================

#[test]
fn test_chart_line_type() {
    let chart = Chart::new().series(
        Series::new("Line")
            .data(vec![(1.0, 2.0), (2.0, 4.0)])
            .chart_type(ChartType::Line),
    );
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_scatter_type() {
    let chart = Chart::new().series(
        Series::new("Scatter")
            .data(vec![(1.0, 2.0), (2.0, 4.0)])
            .chart_type(ChartType::Scatter),
    );
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_area_type() {
    let chart = Chart::new().series(
        Series::new("Area")
            .data(vec![(1.0, 2.0), (2.0, 4.0)])
            .chart_type(ChartType::Area),
    );
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_step_after_type() {
    let chart = Chart::new().series(
        Series::new("Step")
            .data(vec![(1.0, 2.0), (2.0, 4.0)])
            .chart_type(ChartType::StepAfter),
    );
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_step_before_type() {
    let chart = Chart::new().series(
        Series::new("Step")
            .data(vec![(1.0, 2.0), (2.0, 4.0)])
            .chart_type(ChartType::StepBefore),
    );
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

// ==================== Line Style Tests ====================

#[test]
fn test_chart_line_solid() {
    let chart = Chart::new().series(
        Series::new("Solid")
            .data(vec![(1.0, 2.0), (2.0, 4.0)])
            .line_style(LineStyle::Solid),
    );
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_line_dashed() {
    let chart = Chart::new().series(
        Series::new("Dashed")
            .data(vec![(1.0, 2.0), (2.0, 4.0)])
            .line_style(LineStyle::Dashed),
    );
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_line_dotted() {
    let chart = Chart::new().series(
        Series::new("Dotted")
            .data(vec![(1.0, 2.0), (2.0, 4.0)])
            .line_style(LineStyle::Dotted),
    );
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_line_none() {
    let chart = Chart::new().series(
        Series::new("None")
            .data(vec![(1.0, 2.0), (2.0, 4.0)])
            .line_style(LineStyle::None),
    );
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

// ==================== Marker Tests ====================

#[test]
fn test_chart_marker_dot() {
    let chart = Chart::new().series(
        Series::new("Dot")
            .data(vec![(1.0, 2.0)])
            .marker(Marker::Dot),
    );
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_marker_circle() {
    let chart = Chart::new().series(
        Series::new("Circle")
            .data(vec![(1.0, 2.0)])
            .marker(Marker::Circle),
    );
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_marker_star() {
    let chart = Chart::new().series(
        Series::new("Star")
            .data(vec![(1.0, 2.0)])
            .marker(Marker::Star),
    );
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_marker_none() {
    let chart = Chart::new().series(
        Series::new("NoMarker")
            .data(vec![(1.0, 2.0)])
            .marker(Marker::None),
    );
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

// ==================== Multiple Series Tests ====================

#[test]
fn test_chart_multiple_series_same_data() {
    let chart = Chart::new()
        .series(
            Series::new("Series 1")
                .data(vec![(1.0, 2.0), (2.0, 4.0)])
                .color(Color::RED),
        )
        .series(
            Series::new("Series 2")
                .data(vec![(1.0, 3.0), (2.0, 5.0)])
                .color(Color::BLUE),
        );
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_multiple_series_different_types() {
    let chart = Chart::new()
        .series(
            Series::new("Line")
                .data(vec![(1.0, 2.0), (2.0, 4.0)])
                .chart_type(ChartType::Line),
        )
        .series(
            Series::new("Scatter")
                .data(vec![(1.0, 3.0), (2.0, 5.0)])
                .chart_type(ChartType::Scatter),
        );
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_three_series() {
    let chart = Chart::new()
        .series(Series::new("A").data(vec![(1.0, 2.0)]))
        .series(Series::new("B").data(vec![(1.0, 3.0)]))
        .series(Series::new("C").data(vec![(1.0, 4.0)]));
    let mut buffer = Buffer::new(40, 20);
    let area = Rect::new(0, 0, 40, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

// ==================== Size Tests ====================

#[test]
fn test_chart_small_area() {
    let chart = Chart::new().series(Series::new("Data").data(vec![(1.0, 2.0)]));
    let mut buffer = Buffer::new(10, 5);
    let area = Rect::new(0, 0, 10, 5);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_large_area() {
    let chart = Chart::new().series(Series::new("Data").data(vec![(1.0, 2.0)]));
    let mut buffer = Buffer::new(200, 100);
    let area = Rect::new(0, 0, 200, 100);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_wide_area() {
    let chart = Chart::new().series(Series::new("Data").data(vec![(1.0, 2.0)]));
    let mut buffer = Buffer::new(100, 20);
    let area = Rect::new(0, 0, 100, 20);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_tall_area() {
    let chart = Chart::new().series(Series::new("Data").data(vec![(1.0, 2.0)]));
    let mut buffer = Buffer::new(40, 80);
    let area = Rect::new(0, 0, 40, 80);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

// ==================== Complex Scenarios ====================

#[test]
fn test_chart_full_featured() {
    let chart = Chart::new()
        .title("Full Featured Chart")
        .series(
            Series::new("Temperature")
                .data(vec![
                    (1.0, 20.0),
                    (2.0, 22.0),
                    (3.0, 25.0),
                    (4.0, 23.0),
                    (5.0, 21.0),
                ])
                .color(Color::RED)
                .line_style(LineStyle::Solid)
                .marker(Marker::Circle),
        )
        .series(
            Series::new("Humidity")
                .data(vec![
                    (1.0, 60.0),
                    (2.0, 65.0),
                    (3.0, 70.0),
                    (4.0, 68.0),
                    (5.0, 62.0),
                ])
                .color(Color::BLUE)
                .line_style(LineStyle::Dashed)
                .marker(Marker::Dot),
        )
        .x_axis(Axis::new().bounds(0.0, 6.0))
        .y_axis(Axis::new().bounds(0.0, 100.0))
        .legend(LegendPosition::TopRight)
        .bg(Color::BLACK)
        .border(Color::WHITE);

    let mut buffer = Buffer::new(80, 40);
    let area = Rect::new(0, 0, 80, 40);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}

#[test]
fn test_chart_complex_scenario() {
    // Empty series
    let chart = Chart::new()
        .title("Complex Test")
        .series(Series::new("Empty").data(vec![]))
        .series(Series::new("With NaN").data(vec![(1.0, 2.0), (f64::NAN, 3.0), (3.0, 4.0)]))
        .series(Series::new("Normal").data(vec![(1.0, 5.0), (2.0, 6.0), (3.0, 7.0)]));

    let mut buffer = Buffer::new(60, 30);
    let area = Rect::new(0, 0, 60, 30);
    let mut ctx = RenderContext::new(&mut buffer, area);
    chart.render(&mut ctx);
}
