mirror of
https://github.com/storytold/gridcraft.git
synced 2026-12-01 10:14:21 -06:00
* PivotTables: Distinct Count as a value summary (#3336) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * Pivot: refuse Distinct Count for calculated fields A calculated field is evaluated on the report totals, so there are no per-record values to count. pivot.addField and pivot.valueSettings now reject the combination. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * PivotTables: do not offer Distinct Count for a calculated field in the field menu Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(xlsx): keep pivot Distinct Count through a save (#3336) SpreadsheetML has no distinct-count subtotal, so a Distinct Count value field is still written as subtotal="count", now with a GridCraft dataField extension that reads back as Distinct Count. A field with Rank as well gets both extensions. The cache of such a PivotTable is written without refreshOnLoad, so Excel opens it showing the computed distinct counts on the sheet; a manual Refresh in Excel recomputes the field as Count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * PivotTables: tell the user on .xlsx export that Distinct Count is read only by GridCraft (#3336) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * PivotTables: disclose a new Distinct Count field on an ordinary Save too (#3336) The notice no longer depends on the save path being new: the document remembers which Distinct Count value fields an .xlsx save already reported. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * i18n: translate the Distinct Count strings in every catalog (#3336) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com> Co-authored-by: skylartaylor <skylartaylor@users.noreply.github.com>
114 lines
4.1 KiB
Rust
114 lines
4.1 KiB
Rust
use super::{Json, PivotDateGroup, PivotFunc, PivotLayout, PivotShowAs, PivotSort, Result, bad, u32_param};
|
|
|
|
pub(super) fn area_param(cmd: &str, v: Option<&str>) -> Result<&'static str> {
|
|
match v.map(str::to_ascii_lowercase) {
|
|
Some(a) if a == "rows" || a == "row" => Ok("rows"),
|
|
Some(a) if a == "columns" || a == "column" || a == "cols" => Ok("columns"),
|
|
Some(a) if a == "values" || a == "value" || a == "data" => Ok("values"),
|
|
Some(a) if a == "filters" || a == "filter" => Ok("filters"),
|
|
Some(a) => Err(bad(cmd, format!("unknown area `{a}` (rows|columns|values|filters)"))),
|
|
None => Err(bad(cmd, "missing `area` (rows|columns|values|filters)")),
|
|
}
|
|
}
|
|
|
|
pub(super) fn func_param(v: Option<&str>) -> Option<PivotFunc> {
|
|
Some(match v?.to_ascii_lowercase().as_str() {
|
|
"sum" => PivotFunc::Sum,
|
|
"count" | "counta" => PivotFunc::Count,
|
|
"average" | "avg" | "mean" => PivotFunc::Average,
|
|
"max" => PivotFunc::Max,
|
|
"min" => PivotFunc::Min,
|
|
"product" => PivotFunc::Product,
|
|
"countnumbers" | "countnums" | "count numbers" => PivotFunc::CountNumbers,
|
|
"distinctcount" | "distinct count" | "distinct" => PivotFunc::DistinctCount,
|
|
"stddev" => PivotFunc::StdDev,
|
|
"stddevp" => PivotFunc::StdDevP,
|
|
"var" => PivotFunc::Var,
|
|
"varp" => PivotFunc::VarP,
|
|
_ => return None,
|
|
})
|
|
}
|
|
|
|
pub(super) fn func_name(f: PivotFunc) -> &'static str {
|
|
match f {
|
|
PivotFunc::Sum => "sum",
|
|
PivotFunc::Count => "count",
|
|
PivotFunc::Average => "average",
|
|
PivotFunc::Max => "max",
|
|
PivotFunc::Min => "min",
|
|
PivotFunc::Product => "product",
|
|
PivotFunc::CountNumbers => "countNumbers",
|
|
PivotFunc::DistinctCount => "distinctCount",
|
|
PivotFunc::StdDev => "stdDev",
|
|
PivotFunc::StdDevP => "stdDevP",
|
|
PivotFunc::Var => "var",
|
|
PivotFunc::VarP => "varP",
|
|
}
|
|
}
|
|
|
|
pub(super) fn show_as_param(v: &str) -> Option<PivotShowAs> {
|
|
Some(match v.to_ascii_lowercase().as_str() {
|
|
"normal" | "none" => PivotShowAs::Normal,
|
|
"percentofgrandtotal" => PivotShowAs::PercentOfGrandTotal,
|
|
"percentofcolumntotal" => PivotShowAs::PercentOfColumnTotal,
|
|
"percentofrowtotal" => PivotShowAs::PercentOfRowTotal,
|
|
"runningtotal" => PivotShowAs::RunningTotal,
|
|
"rank" => PivotShowAs::Rank,
|
|
_ => return None,
|
|
})
|
|
}
|
|
|
|
pub(super) fn show_as_name(v: PivotShowAs) -> &'static str {
|
|
match v {
|
|
PivotShowAs::Normal => "normal",
|
|
PivotShowAs::PercentOfGrandTotal => "percentOfGrandTotal",
|
|
PivotShowAs::PercentOfColumnTotal => "percentOfColumnTotal",
|
|
PivotShowAs::PercentOfRowTotal => "percentOfRowTotal",
|
|
PivotShowAs::RunningTotal => "runningTotal",
|
|
PivotShowAs::Rank => "rank",
|
|
}
|
|
}
|
|
|
|
pub(super) fn layout_name(l: PivotLayout) -> &'static str {
|
|
match l {
|
|
PivotLayout::Compact => "compact",
|
|
PivotLayout::Outline => "outline",
|
|
PivotLayout::Tabular => "tabular",
|
|
}
|
|
}
|
|
|
|
pub(super) fn group_name(g: PivotDateGroup) -> &'static str {
|
|
match g {
|
|
PivotDateGroup::None => "none",
|
|
PivotDateGroup::Years => "years",
|
|
PivotDateGroup::Quarters => "quarters",
|
|
PivotDateGroup::Months => "months",
|
|
PivotDateGroup::Days => "days",
|
|
}
|
|
}
|
|
|
|
pub(super) fn sort_name(o: PivotSort) -> &'static str {
|
|
match o {
|
|
PivotSort::Asc => "asc",
|
|
PivotSort::Desc => "desc",
|
|
PivotSort::None => "none",
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------- field commands
|
|
|
|
pub(super) fn position_param(p: &Json) -> Option<usize> {
|
|
u32_param(p, "position").map(|v| v as usize)
|
|
}
|
|
|
|
pub(super) fn group_param(v: Option<&str>) -> Option<PivotDateGroup> {
|
|
Some(match v?.to_ascii_lowercase().as_str() {
|
|
"years" | "year" => PivotDateGroup::Years,
|
|
"quarters" | "quarter" => PivotDateGroup::Quarters,
|
|
"months" | "month" => PivotDateGroup::Months,
|
|
"days" | "day" => PivotDateGroup::Days,
|
|
"none" | "ungroup" => PivotDateGroup::None,
|
|
_ => return None,
|
|
})
|
|
}
|