Skip to content

Commit

Permalink
rm fixed; add migration; fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ada-x64 committed Feb 28, 2024
1 parent a8ba9b9 commit f575d97
Show file tree
Hide file tree
Showing 19 changed files with 427 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ export class FormatterCache {
let { format } = get_type_config(type);
if (plugin.number_string_format !== undefined) {
format = plugin.number_string_format;
} else if (plugin.fixed !== undefined) {
format.minimumFractionDigits = plugin.fixed;
format.maximumFractionDigits = plugin.fixed;
}

return new FORMATTER_CONS[type]([], format);
Expand All @@ -149,7 +146,6 @@ export class FormatterCache {
get(type, plugin) {
let formatter_key = [
type,
plugin.fixed,
plugin.timeZone,
plugin.dateStyle,
plugin.timeStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default function column_style_opts(type, _group) {
pos_bg_color: this.model._pos_bg_color[0],
neg_bg_color: this.model._neg_bg_color[0],
number_bg_mode: "disabled",
fixed: type === "float" ? 2 : 0,
},
number_string_format: true,
};
Expand Down
6 changes: 3 additions & 3 deletions rust/perspective-viewer/src/less/column-style.less
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
width: 36px;
height: 24px;
text-align: center;
z-index: 1;
}
}

Expand All @@ -185,16 +186,15 @@
opacity: 0.8;
}

&#pos-color-param {
&.pos-color-param {
border-radius: 6px 0 0 6px;
margin: 0 1px 0 0;
}

&#neg-color-param {
&.neg-color-param {
border-radius: 0 6px 6px 0;
margin: 0 0 0 1px;
}

}

::-webkit-color-swatch-wrapper {
Expand Down
12 changes: 12 additions & 0 deletions rust/perspective-viewer/src/less/dom/scrollbar.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
// ┃ This file is part of the Perspective library, distributed under the terms ┃
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

@mixin scrollbar {
&::-webkit-scrollbar-thumb {
border: 0 solid var(--icon--color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use yew::prelude::*;

#[derive(Properties, PartialEq)]
pub struct ColorRangeProps {
pub id: String,
pub pos_color: String,
pub neg_color: String,
pub is_gradient: bool,
Expand Down Expand Up @@ -86,15 +87,15 @@ pub fn color_chooser_component(props: &ColorRangeProps) -> Html {
class="color-selector"
>
<input
id="pos-color-param"
id={format!("{}-pos", props.id)}
style={fg_pos}
class="parameter"
class="parameter pos-color-param"
type="color"
value={gradient.0.to_owned()}
oninput={on_pos_color}
/>
<label
for="pos-color-param"
for={format!("{}-pos", props.id)}
class="color-label"
>
{ "+" }
Expand All @@ -108,15 +109,15 @@ pub fn color_chooser_component(props: &ColorRangeProps) -> Html {
class="color-selector"
>
<input
id="neg-color-param"
id={format!("{}-neg", props.id)}
style={fg_neg}
class="parameter"
class="parameter neg-color-param"
type="color"
value={gradient.1.to_owned()}
oninput={on_neg_color}
/>
<label
for="neg-color-param"
for={format!("{}-neg", props.id)}
class="color-label"
>
{ "-" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ pub fn required_field(props: &RequiredFieldProps) -> Html {
<div
class="section row"
>
<input type="checkbox" disabled=true checked=true />
<input
type="checkbox"
disabled=true
checked=true
id={format!("{}-checkbox", props.label.replace(' ', "-"))}
/>
{ props.children.clone() }
</div>
</fieldset>
Expand Down
91 changes: 13 additions & 78 deletions rust/perspective-viewer/src/rust/components/number_column_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub enum NumberColumnStyleMsg {
Box<NumberColumnStyleConfig>,
Box<NumberColumnStyleDefaultConfig>,
),
FixedChanged(String),
ForeEnabledChanged(bool),
BackEnabledChanged(bool),
PosColorChanged(Side, String),
Expand Down Expand Up @@ -149,18 +148,6 @@ impl Component for NumberColumnStyle {
std::mem::swap(self, &mut new);
true
},
NumberColumnStyleMsg::FixedChanged(fixed) => {
let fixed = match fixed.parse::<u32>() {
Ok(x) if x != self.default_config.fixed => Some(x),
Ok(_) => None,
Err(_) if fixed.is_empty() => Some(0),
Err(_) => None,
};

self.config.fixed = fixed.map(|x| std::cmp::min(15, x));
self.dispatch_config(ctx);
true
},
NumberColumnStyleMsg::ForeEnabledChanged(val) => {
if val {
let color_mode = match self.fg_mode {
Expand Down Expand Up @@ -301,23 +288,6 @@ impl Component for NumberColumnStyle {
}

fn view(&self, ctx: &Context<Self>) -> Html {
// Fixed precision control oninput callback
let fixed_oninput = ctx.link().callback(|event: InputEvent| {
NumberColumnStyleMsg::FixedChanged(
event
.target()
.unwrap()
.unchecked_into::<web_sys::HtmlInputElement>()
.value(),
)
});

let fixed_value = self
.config
.fixed
.unwrap_or(self.default_config.fixed)
.to_string();

// Color enabled/disabled oninput callback
let fg_enabled_oninput = ctx.link().callback(move |event: InputEvent| {
let input = event
Expand Down Expand Up @@ -361,7 +331,7 @@ impl Component for NumberColumnStyle {
<div
class="row inner_section"
>
<ColorRangeSelector ..self.color_props(Fg, false, ctx) />
<ColorRangeSelector ..self.color_props("fg-color", Fg, false, ctx) />
</div>
}
</>
Expand All @@ -374,7 +344,7 @@ impl Component for NumberColumnStyle {
<div
class="row inner_section"
>
<ColorRangeSelector ..self.color_props(Fg, false, ctx) />
<ColorRangeSelector ..self.color_props("bar-color", Fg, false, ctx) />
<NumberInput ..self.max_value_props(Fg, ctx) />
</div>
}
Expand All @@ -388,7 +358,7 @@ impl Component for NumberColumnStyle {
<div
class="row inner_section"
>
<ColorRangeSelector ..self.color_props(Bg,false, ctx) />
<ColorRangeSelector ..self.color_props("bg-color", Bg,false, ctx) />
</div>
}
</>
Expand All @@ -401,7 +371,7 @@ impl Component for NumberColumnStyle {
<div
class="row inner_section"
>
<ColorRangeSelector ..self.color_props(Bg, true, ctx) />
<ColorRangeSelector ..self.color_props("gradient-color", Bg, true, ctx) />
<NumberInput ..self.max_value_props(Bg, ctx) />
</div>
}
Expand All @@ -415,7 +385,7 @@ impl Component for NumberColumnStyle {
<div
class="row inner_section"
>
<ColorRangeSelector ..self.color_props(Bg, true, ctx) />
<ColorRangeSelector ..self.color_props("pulse-color", Bg, true, ctx) />
</div>
}
</>
Expand All @@ -430,34 +400,6 @@ impl Component for NumberColumnStyle {
id="column-style-container"
class="number-column-style-container"
>
<div
class="column-style-label"
>
<label
id="fixed-examples"
class="indent"
>
{ self.make_fixed_text(ctx) }
</label>
</div>
<div
class="row section"
>
<input
type="checkbox"
checked=true
disabled=true
/>
<input
id="fixed-param"
class="parameter"
type="number"
min="0"
step="1"
value={fixed_value}
oninput={fixed_oninput}
/>
</div>
<div
class="column-style-label"
>
Expand Down Expand Up @@ -572,7 +514,13 @@ impl NumberColumnStyle {
.emit(ColumnConfigValueUpdate::DatagridNumberStyle(update));
}

fn color_props(&self, side: Side, is_gradient: bool, ctx: &Context<Self>) -> ColorRangeProps {
fn color_props(
&self,
id: &str,
side: Side,
is_gradient: bool,
ctx: &Context<Self>,
) -> ColorRangeProps {
let on_pos_color = ctx
.link()
.callback(move |x| NumberColumnStyleMsg::PosColorChanged(side, x));
Expand All @@ -581,6 +529,7 @@ impl NumberColumnStyle {
.callback(move |x| NumberColumnStyleMsg::NegColorChanged(side, x));

props!(ColorRangeProps {
id: id.to_string(),
is_gradient,
pos_color: if side == Fg {
&self.pos_fg_color
Expand Down Expand Up @@ -614,20 +563,6 @@ impl NumberColumnStyle {
})
}

/// Human readable precision hint, e.g. "Prec 0.001" for `{fixed: 3}`.
fn make_fixed_text(&self, _ctx: &Context<Self>) -> String {
let fixed = match self.config.fixed {
Some(x) if x > 0 => format!("0.{}1", "0".repeat(x as usize - 1)),
None if self.default_config.fixed > 0 => {
let n = self.default_config.fixed as usize - 1;
format!("0.{}1", "0".repeat(n))
},
Some(_) | None => "1".to_owned(),
};

format!("Prec {}", fixed)
}

fn reset(
config: &NumberColumnStyleConfig,
default_config: &NumberColumnStyleDefaultConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,23 @@ pub struct CustomNumberFormat {
impl CustomNumberFormat {
fn initialize(ctx: &yew::prelude::Context<Self>) -> Self {
let config = ctx.props().restored_config.clone();
let show_frac = config
.minimum_fraction_digits
.or(config.maximum_fraction_digits)
.or(config.rounding_increment)
.is_some();
let show_sig = config
.minimum_significant_digits
.or(config.maximum_significant_digits)
.is_some();
let disable_rounding_increment = show_sig
|| show_frac
|| !matches!(
config.rounding_priority,
Some(RoundingPriority::Auto) | None
);
let disable_rounding_priority = !(show_frac && show_sig);
Self {
show_frac: config
.minimum_fraction_digits
.or(config.maximum_fraction_digits)
.or(config.rounding_increment)
.is_some(),
show_sig: config
.minimum_significant_digits
.or(config.maximum_significant_digits)
.is_some(),
style: config
._style
.as_ref()
Expand All @@ -89,7 +96,11 @@ impl CustomNumberFormat {
})
.unwrap_or_default(),
config,
..Default::default()
show_frac,
show_sig,
disable_rounding_increment,
disable_rounding_priority,
notation: None,
}
}
}
Expand Down Expand Up @@ -245,7 +256,7 @@ impl Component for CustomNumberFormat {
self.config.rounding_priority,
Some(RoundingPriority::Auto) | None
);
self.disable_rounding_priority = self.show_sig || self.show_frac;
self.disable_rounding_priority = !(self.show_frac && self.show_sig);

let filtered_config = self.config.clone().filter_default(
self.show_sig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl CustomNumberFormat {
{ self.rounding_increment(ctx) }
<SelectField<RoundingPriority>
label="Rounding Priority"
disabled={!(self.show_frac && self.show_sig)}
disabled={self.disable_rounding_priority}
current_value={self.config.rounding_priority}
on_change={ctx.link().callback(CustomNumberFormatMsg::RoundingPriority)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ pub struct NumberColumnStyleConfig {
#[serde(skip_serializing_if = "NumberBackgroundMode::is_disabled")]
pub number_bg_mode: NumberBackgroundMode,

#[serde(skip_serializing_if = "Option::is_none")]
pub fixed: Option<u32>,

#[serde(skip_serializing_if = "Option::is_none")]
pub pos_fg_color: Option<String>,

Expand Down Expand Up @@ -165,7 +162,6 @@ derive_wasm_abi!(NumberColumnStyleConfig, FromWasmAbi, IntoWasmAbi);
pub struct NumberColumnStyleDefaultConfig {
pub fg_gradient: f64,
pub bg_gradient: f64,
pub fixed: u32,
pub pos_fg_color: String,
pub neg_fg_color: String,
pub pos_bg_color: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub enum RoundingMode {
Floor,
Expand,
Trunc,
HalfCiel,
HalfCeil,
HalfFloor,
#[default]
HalfExpand,
Expand Down

0 comments on commit f575d97

Please sign in to comment.