-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chart: add intial support for combined secondary axes
- Loading branch information
Showing
12 changed files
with
241 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Test case that compares a file generated by rust_xlsxwriter with a file | ||
// created by Excel. | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// | ||
// Copyright 2022-2024, John McNamara, [email protected] | ||
|
||
use crate::common; | ||
use rust_xlsxwriter::{ | ||
Chart, ChartAxisLabelPosition, ChartEmptyCells, ChartType, Workbook, XlsxError, | ||
}; | ||
|
||
// Create rust_xlsxwriter file to compare against Excel file. | ||
fn create_new_xlsx_file(filename: &str) -> Result<(), XlsxError> { | ||
let mut workbook = Workbook::new(); | ||
|
||
let worksheet = workbook.add_worksheet(); | ||
|
||
// Add some test data for the chart(s). | ||
worksheet.write_column(0, 0, [2, 7, 3, 6, 2])?; | ||
worksheet.write_column(0, 1, [20, 25, 10, 10, 20])?; | ||
|
||
let mut chart1 = Chart::new(ChartType::Column); | ||
chart1.add_series().set_values(("Sheet1", 0, 0, 4, 0)); | ||
|
||
let mut chart2 = Chart::new(ChartType::Line); | ||
chart2 | ||
.add_series() | ||
.set_values(("Sheet1", 0, 1, 4, 1)) | ||
.set_y2_axis(true); | ||
|
||
chart1.show_empty_cells_as(ChartEmptyCells::Gaps); | ||
|
||
chart1.combine(&chart2); | ||
|
||
chart1 | ||
.x2_axis() | ||
.set_label_position(ChartAxisLabelPosition::NextTo); | ||
|
||
worksheet.insert_chart(8, 4, &chart1)?; | ||
|
||
workbook.save(filename)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_chart_combined04() { | ||
let test_runner = common::TestRunner::new() | ||
.set_name("chart_combined04") | ||
.set_function(create_new_xlsx_file) | ||
.ignore_elements("xl/charts/chart1.xml", "autoZero") | ||
.initialize(); | ||
|
||
test_runner.assert_eq(); | ||
test_runner.cleanup(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Test case that compares a file generated by rust_xlsxwriter with a file | ||
// created by Excel. | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// | ||
// Copyright 2022-2024, John McNamara, [email protected] | ||
|
||
use crate::common; | ||
use rust_xlsxwriter::{ | ||
Chart, ChartAxisCrossing, ChartAxisLabelPosition, ChartEmptyCells, ChartType, Workbook, | ||
XlsxError, | ||
}; | ||
|
||
// Create rust_xlsxwriter file to compare against Excel file. | ||
fn create_new_xlsx_file(filename: &str) -> Result<(), XlsxError> { | ||
let mut workbook = Workbook::new(); | ||
|
||
let worksheet = workbook.add_worksheet(); | ||
|
||
// Add some test data for the chart(s). | ||
worksheet.write_column(0, 0, [2, 7, 3, 6, 2])?; | ||
worksheet.write_column(0, 1, [20, 25, 10, 10, 20])?; | ||
|
||
let mut chart1 = Chart::new(ChartType::Bar); | ||
chart1.set_axis_ids(60914304, 78899072); | ||
chart1.set_axis2_ids(85542016, 85183872); | ||
|
||
chart1.add_series().set_values(("Sheet1", 0, 0, 4, 0)); | ||
|
||
let mut chart2 = Chart::new(ChartType::Line); | ||
chart2 | ||
.add_series() | ||
.set_values(("Sheet1", 0, 1, 4, 1)) | ||
.set_y2_axis(true); | ||
|
||
chart1.show_empty_cells_as(ChartEmptyCells::Gaps); | ||
|
||
chart1.combine(&chart2); | ||
|
||
chart1 | ||
.x2_axis() | ||
.set_crossing(ChartAxisCrossing::Max) | ||
.set_hidden(true) | ||
.set_label_position(ChartAxisLabelPosition::NextTo); | ||
|
||
chart1 | ||
.y2_axis() | ||
.set_crossing(ChartAxisCrossing::Automatic) | ||
.set_hidden(false) | ||
.set_label_position(ChartAxisLabelPosition::NextTo); | ||
|
||
worksheet.insert_chart(8, 4, &chart1)?; | ||
|
||
workbook.save(filename)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_chart_combined05() { | ||
let test_runner = common::TestRunner::new() | ||
.set_name("chart_combined05") | ||
.set_function(create_new_xlsx_file) | ||
.initialize(); | ||
|
||
test_runner.assert_eq(); | ||
test_runner.cleanup(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Test case that compares a file generated by rust_xlsxwriter with a file | ||
// created by Excel. | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// | ||
// Copyright 2022-2024, John McNamara, [email protected] | ||
|
||
use crate::common; | ||
use rust_xlsxwriter::{Chart, ChartType, Workbook, XlsxError}; | ||
|
||
// Create rust_xlsxwriter file to compare against Excel file. | ||
fn create_new_xlsx_file(filename: &str) -> Result<(), XlsxError> { | ||
let mut workbook = Workbook::new(); | ||
|
||
let worksheet = workbook.add_worksheet(); | ||
|
||
// Add some test data for the chart(s). | ||
worksheet.write_column(0, 0, [1, 2, 3, 4, 5])?; | ||
worksheet.write_column(0, 1, [6, 8, 6, 4, 2])?; | ||
|
||
let mut chart = Chart::new(ChartType::Column); | ||
chart.set_axis_ids(45938176, 59715584); | ||
chart.set_axis2_ids(62526208, 59718272); | ||
|
||
chart | ||
.add_series() | ||
.set_values(("Sheet1", 0, 0, 4, 0)) | ||
.set_overlap(12) | ||
.set_gap(51); | ||
|
||
chart | ||
.add_series() | ||
.set_values(("Sheet1", 0, 1, 4, 1)) | ||
.set_overlap(-27) | ||
.set_gap(251) | ||
.set_y2_axis(true); | ||
|
||
worksheet.insert_chart(8, 4, &chart)?; | ||
|
||
workbook.save(filename)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_chart_gap04() { | ||
let test_runner = common::TestRunner::new() | ||
.set_name("chart_gap04") | ||
.set_function(create_new_xlsx_file) | ||
.initialize(); | ||
|
||
test_runner.assert_eq(); | ||
test_runner.cleanup(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters