ElyTable: the chart search uses its own sheet, scans the sheet as a last resort, and fails cleanly with no room (R2.10)
This commit is contained in:
5 files changed
+71
-25
No files matched your search
@@ -336,7 +336,13 @@ fn undoing_a_new_kind_brings_the_whole_chart_back() {
|
||||
|
||||
/// A sheet of ones filling each `(columns, rows)` block.
|
||||
fn blocks(filled: &[(std::ops::RangeInclusive<usize>, std::ops::RangeInclusive<usize>)]) -> String {
|
||||
let rows: String = (1..=60)
|
||||
sheet(&rows_of(filled))
|
||||
}
|
||||
|
||||
/// Rows of ones filling each `(columns, rows)` block.
|
||||
fn rows_of(filled: &[(std::ops::RangeInclusive<usize>, std::ops::RangeInclusive<usize>)]) -> String {
|
||||
let height = filled.iter().map(|(_, rows)| *rows.end()).max().unwrap_or(0);
|
||||
(1..=height)
|
||||
.map(|r| {
|
||||
let cells: String = (0..20)
|
||||
.map(|c| match filled.iter().any(|(cols, rows)| cols.contains(&c) && rows.contains(&r)) {
|
||||
@@ -346,12 +352,11 @@ fn blocks(filled: &[(std::ops::RangeInclusive<usize>, std::ops::RangeInclusive<u
|
||||
.collect();
|
||||
format!("<table:table-row>{cells}</table:table-row>")
|
||||
})
|
||||
.collect();
|
||||
sheet(&rows)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Charts `source` and checks it clears each data block.
|
||||
fn charted(sheet: &str, visible: (i32, i32, i32, i32), source: &str, data: &[(&str, &str)]) {
|
||||
fn charted(sheet: &str, visible: (i32, i32, i32, i32), (source, stand): (&str, &str), data: &[(&str, &str)]) {
|
||||
let (_dir, mut worker, doc) = open_book(sheet);
|
||||
doc.visible_area(&mut worker, visible, (256, 3840)).expect("the area");
|
||||
let mut seen = poll_until(&mut worker, &doc, &Events::default(), SETTLE, |_| false);
|
||||
@@ -363,7 +368,7 @@ fn charted(sheet: &str, visible: (i32, i32, i32, i32), source: &str, data: &[(&s
|
||||
};
|
||||
let spans: Vec<_> = data.iter().map(|(from, to)| (cell(&mut worker, from), cell(&mut worker, to))).collect();
|
||||
let all = written(&mut worker, &doc, source);
|
||||
worker.run(&doc, "cell.goto", &["A1"]).expect("A1");
|
||||
worker.run(&doc, "cell.goto", &[stand]).expect("where the chart goes");
|
||||
worker.run(&doc, "chart.insert", &[&all, "false", &Look { kind: "column".into(), ..Look::default() }.to_json()]).expect("inserts");
|
||||
let framed = poll_until(&mut worker, &doc, &seen, SETTLE, |now| now.graphic.is_some());
|
||||
let (x, y, w, h) = framed.graphic.expect("the chart is selected");
|
||||
@@ -375,12 +380,18 @@ fn charted(sheet: &str, visible: (i32, i32, i32, i32), source: &str, data: &[(&s
|
||||
|
||||
/// A sheet body as flat XML.
|
||||
fn sheet(rows: &str) -> String {
|
||||
sheets(&[("S", rows)])
|
||||
}
|
||||
|
||||
/// Named sheets as one flat XML book.
|
||||
fn sheets(tables: &[(&str, &str)]) -> String {
|
||||
let tables: String = tables.iter().map(|(name, rows)| format!(r#"<table:table table:name="{name}">{rows}</table:table>"#)).collect();
|
||||
format!(
|
||||
r#"<?xml version="1.0" encoding="UTF-8"?>
|
||||
<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
|
||||
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
|
||||
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.spreadsheet">
|
||||
<office:body><office:spreadsheet><table:table table:name="S">{rows}</table:table></office:spreadsheet></office:body>
|
||||
<office:body><office:spreadsheet>{tables}</office:spreadsheet></office:body>
|
||||
</office:document>"#
|
||||
)
|
||||
}
|
||||
@@ -393,19 +404,28 @@ fn a_new_chart_lands_beside_its_data() {
|
||||
return;
|
||||
}
|
||||
// Its own data, a neighbour past two empty columns.
|
||||
charted(&blocks(&[(0..=2, 1..=5), (5..=15, 1..=20)]), (0, 0, 15000, 10000), "A1:C5", &[("A1", "C5"), ("F1", "P20")]);
|
||||
charted(&blocks(&[(0..=2, 1..=5), (5..=15, 1..=20)]), (0, 0, 15000, 10000), ("A1:C5", "A1"), &[("A1", "C5"), ("F1", "P20")]);
|
||||
// Data wider and taller than the view.
|
||||
charted(&blocks(&[(0..=15, 1..=50)]), (0, 0, 15000, 10000), "A1:P50", &[("A1", "P50")]);
|
||||
charted(&blocks(&[(0..=15, 1..=50)]), (0, 0, 15000, 10000), ("A1:P50", "A1"), &[("A1", "P50")]);
|
||||
// A view narrower than the chart.
|
||||
charted(&blocks(&[(0..=2, 1..=5)]), (0, 0, 6000, 3500), "A1:C5", &[("A1", "C5")]);
|
||||
charted(&blocks(&[(0..=2, 1..=5)]), (0, 0, 6000, 3500), ("A1:C5", "A1"), &[("A1", "C5")]);
|
||||
// A merged block beside the data is taken, not free.
|
||||
let merged = format!(
|
||||
r#"<table:table-row>{ONE}{ONE}{ONE}<table:table-cell table:number-columns-spanned="13" table:number-rows-spanned="20"><text:p>MERGED</text:p></table:table-cell></table:table-row><table:table-row table:number-rows-repeated="4">{ONE}{ONE}{ONE}</table:table-row>"#
|
||||
);
|
||||
charted(&sheet(&merged), (0, 0, 15000, 10000), "A1:C5", &[("A1", "C5"), ("D1", "D1")]);
|
||||
charted(&sheet(&merged), (0, 0, 15000, 10000), ("A1:C5", "A1"), &[("A1", "C5"), ("D1", "D1")]);
|
||||
// Data in the last cells: left or above.
|
||||
let corner = format!(
|
||||
r#"<table:table-row table:number-rows-repeated="1048574"><table:table-cell table:number-columns-repeated="16384"/></table:table-row><table:table-row table:number-rows-repeated="2"><table:table-cell table:number-columns-repeated="16382"/>{ONE}{ONE}</table:table-row>"#
|
||||
);
|
||||
charted(&sheet(&corner), (0, 0, 15000, 10000), "XFC1048575:XFD1048576", &[("XFC1048575", "XFD1048576")]);
|
||||
let corner = |above: usize| {
|
||||
let empty = 1048574 - above;
|
||||
format!(
|
||||
r#"<table:table-row table:number-rows-repeated="{empty}"><table:table-cell table:number-columns-repeated="16384"/></table:table-row><table:table-row table:number-rows-repeated="2"><table:table-cell table:number-columns-repeated="16382"/>{ONE}{ONE}</table:table-row>"#
|
||||
)
|
||||
};
|
||||
charted(&sheet(&corner(0)), (0, 0, 15000, 10000), ("XFC1048575:XFD1048576", "A1"), &[("XFC1048575", "XFD1048576")]);
|
||||
// Corner data, a block at A1: room elsewhere.
|
||||
let full = format!("{}{}", rows_of(&[(0..=15, 1..=20)]), corner(20));
|
||||
charted(&sheet(&full), (0, 0, 15000, 10000), ("XFC1048575:XFD1048576", "A1"), &[("A1", "P20"), ("XFC1048575", "XFD1048576")]);
|
||||
// Data on S, chart on T: T's cells stay clear.
|
||||
let two = sheets(&[("S", &rows_of(&[(0..=2, 1..=5)])), ("T", &rows_of(&[(0..=15, 1..=20)]))]);
|
||||
charted(&two, (0, 0, 15000, 10000), ("S!A1:C5", "T!A1"), &[("T!A1", "T!P20")]);
|
||||
}
|
||||
Reference in new issue
Block a user