mirror of
https://github.com/nushell/nushell.git
synced 2025-02-23 14:01:14 +01:00
make histogram sorted (#7267)
# Description Closes: #7208 After this pr, histogram will output by count descending # User-Facing Changes _(List of all changes that impact the user experience here. This helps us keep track of breaking changes.)_ # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
parent
380c216d77
commit
d28624796c
@ -249,25 +249,33 @@ fn histogram_impl(
|
|||||||
let percentage = format!("{:.2}%", quantile * 100_f64);
|
let percentage = format!("{:.2}%", quantile * 100_f64);
|
||||||
let freq = "*".repeat((MAX_FREQ_COUNT * quantile).floor() as usize);
|
let freq = "*".repeat((MAX_FREQ_COUNT * quantile).floor() as usize);
|
||||||
|
|
||||||
result.push(Value::Record {
|
result.push((
|
||||||
cols: result_cols.clone(),
|
count, // attach count first for easily sorting.
|
||||||
vals: vec![
|
Value::Record {
|
||||||
val.into_value(),
|
cols: result_cols.clone(),
|
||||||
Value::Int { val: count, span },
|
vals: vec![
|
||||||
Value::Float {
|
val.into_value(),
|
||||||
val: quantile,
|
Value::Int { val: count, span },
|
||||||
span,
|
Value::Float {
|
||||||
},
|
val: quantile,
|
||||||
Value::String {
|
span,
|
||||||
val: percentage,
|
},
|
||||||
span,
|
Value::String {
|
||||||
},
|
val: percentage,
|
||||||
Value::String { val: freq, span },
|
span,
|
||||||
],
|
},
|
||||||
span,
|
Value::String { val: freq, span },
|
||||||
});
|
],
|
||||||
|
span,
|
||||||
|
},
|
||||||
|
));
|
||||||
}
|
}
|
||||||
Value::List { vals: result, span }.into_pipeline_data()
|
result.sort_by(|a, b| b.0.cmp(&a.0));
|
||||||
|
Value::List {
|
||||||
|
vals: result.into_iter().map(|x| x.1).collect(),
|
||||||
|
span,
|
||||||
|
}
|
||||||
|
.into_pipeline_data()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
Reference in New Issue
Block a user