Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2857157
Initial implementation of color architecture. RBG fully implmented
etfrogers Feb 14, 2025
203b8ce
Implement variable index color -requires new plot architecture
etfrogers Feb 16, 2025
9be2ab0
Implement no-show option in inverse_api example
etfrogers Feb 16, 2025
01b0be1
Finish architecture updates for generate_data/new_plot
etfrogers Feb 16, 2025
b3ed312
Tidy macro formatting
etfrogers Feb 16, 2025
bf72c4b
Improve and simplify architecture for more consistency
etfrogers Feb 18, 2025
e07682a
Add XY Error Bars plot type
etfrogers Feb 22, 2025
e99e055
Convert BorderColor to new color style
etfrogers Feb 22, 2025
75f6e97
Improve internal color API, and add more Into<Color> options
etfrogers Feb 22, 2025
889e55d
Add box error bars plots
etfrogers Feb 22, 2025
ff99e95
Finish first color example and put in a loop
etfrogers Feb 23, 2025
c5b0046
Add VariablePaletteColor with example
etfrogers Feb 23, 2025
d120097
Fix parentheses in from_argb
etfrogers Feb 24, 2025
adcd232
Add VariableARGBColor example
etfrogers Feb 24, 2025
91c20df
Add SavedColorMap implementation and example
etfrogers Feb 24, 2025
235163a
Move variable color example to separate file
etfrogers Feb 24, 2025
14a05b2
Rename colors to reduce redundancy and add more documentation
etfrogers Feb 24, 2025
9be4064
Complete color example and modify common code to allow transpareny to…
etfrogers Feb 24, 2025
eca6c4f
Conform to nightly formatting rules
etfrogers Feb 24, 2025
3d1f213
Add TextColor functions
etfrogers Feb 25, 2025
102dd89
Add documentation to convenience functions
etfrogers Feb 25, 2025
da45b28
Improve documentation
etfrogers Feb 25, 2025
f75f748
Implement palette fixed colors
etfrogers Feb 25, 2025
359b403
Fix clippy suggestions
etfrogers Feb 25, 2025
76029b4
FIx sample code in docs
etfrogers Mar 3, 2025
f2612e9
Improve color docs
etfrogers Mar 16, 2025
d407f42
Remove (hacky) convenience functions in favour of clear explicit .int…
etfrogers Mar 16, 2025
0af1a96
Improve clarity of color_name function
etfrogers Mar 17, 2025
211709b
Remove unused IntoColor trait
etfrogers Mar 17, 2025
bac4a12
Change background color command for backward compatability
etfrogers Mar 17, 2025
fc85364
Use wildcard for clarity in ColorType::data
etfrogers Mar 17, 2025
ab7eb96
Convert fallible ColorType conversions to TryFrom and remove float co…
etfrogers Mar 17, 2025
4a4ff15
Convert chars().count() to simpler len(), as string must be ASCII
etfrogers Mar 18, 2025
1487349
Simplify string creation in command()
etfrogers Mar 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions gnuplot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ path = "examples/box_xy_error.rs"

[[example]]

name = "color"
path = "examples/color.rs"

[[example]]

name = "variable_color"
path = "examples/variable_color.rs"

[[example]]

name = "lines_3d"
path = "examples/lines_3d.rs"

Expand Down
2 changes: 1 addition & 1 deletion gnuplot/examples/box_and_whisker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn example(c: Common)
[0.5f32, 0.25, 0.125].iter(),
&[
WhiskerBars(0.5),
Color("blue"),
Color("blue".into()),
LineWidth(2.0),
LineStyle(SmallDot),
FillAlpha(0.5),
Expand Down
2 changes: 1 addition & 1 deletion gnuplot/examples/box_xy_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn example(c: Common)
[-1.5f32, 4.5, 3.0].iter(),
[0.5f32, 4.75, 0.125].iter(),
&[
Color("blue"),
Color("blue".into()),
LineWidth(2.0),
LineStyle(SmallDot),
FillAlpha(0.5),
Expand Down
140 changes: 140 additions & 0 deletions gnuplot/examples/color.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
use std::{fmt::Debug, iter};

// This file is released into Public Domain.
use crate::common::*;
use gnuplot::*;

mod common;

fn color_name<T: Debug>(color: &PlotOption<T>) -> String
{
match color
{
Color(color_type) => format!("{:?}", color_type),
_ => panic!(),
}
}

fn example(c: Common)
{
let x = 0..5;

let colors = [
Color("black".into()), // Conversion to RGBString is implicit
Color(ColorType::RGBString("black")), // Explicit use of RGBString
Color("red".into()), // Conversion to RGBString is implicit
Color(RGBString("#ff0000")), // red using Hex coded RRGGBB
Color(RGBString("#00ff0000")), // red using Hex coded AARRGGBB
Color("#ff8888".into()), // pink using Hex coded RRGGBB. Conversion to RGBString is implict
Color("#88ff0000".into()), // pink using Hex coded AARRGGBB. Conversion to RGBString is implict
Color(ColorType::RGBString("#ffff0000")), // transparent using Hex coded AARRGGBB
Color((128, 0, 255).into()), // purple using implict RGBInteger
Color(RGBInteger(128, 0, 255)), // purple using explict RGBInteger
Color((0.5, 0.0, 1.0).try_into().unwrap()), // purple using implict float to int conversion
Color((128, 128, 0, 255).into()), // pale purple using implict ARGBInteger
Color(ARGBInteger(128, 128, 0, 255)), // pale purple using explict ARGBInteger
Color((0.5, 0.5, 0.0, 1.0).try_into().unwrap()), // pale purple using implict float to int conversion
];

let mut fg = Figure::new();
let ax = fg.axes2d();
ax.set_title(
"Demo of RGBString in various forms\nSee code comments for how to construct the colors",
&[],
)
.set_x_range(Fix(-9.0), Auto)
.set_legend(Graph(0.5), Graph(0.9), &[], &[Font("", 14.0)]);

let n_colors = colors.len();
for (i, color) in colors.into_iter().enumerate()
{
ax.box_xy_error_delta(
x.clone(),
iter::repeat((n_colors - 1) - i),
iter::repeat(0.4),
iter::repeat(0.2),
&[
Caption(&color_name(&color)),
LineWidth(1.0),
BorderColor("black".into()),
color,
],
);
}

// Draw line across the boxes in fixed black and background colors
ax.lines(
[0, 0],
[0, n_colors - 1],
&[
LineWidth(7.0),
Color(Black),
Caption(&color_name::<String>(&Color(Black))),
],
);

ax.lines(
[4, 4],
[0, n_colors - 1],
&[
LineWidth(7.0),
Color(Background),
Caption(&color_name::<String>(&Color(Background))),
],
);

// any of the forms used for Color can also be used with TextColor and BorderColor
ax.set_x_label(
"Labels can be colored using the TextColor function",
&[TextColor((128, 0, 255).into())],
);

c.show(&mut fg, "rgb_color");

// ########################################################################

let mut fg = Figure::new();
let ax = fg.axes2d();
let max_cb = 10.0;
ax.set_cb_range(Fix(0.0), Fix(max_cb));
for color_value in 0..=10
{
let color_float = color_value as f64;
let frac_color = Color(PaletteFracColor(color_float / max_cb));
let cb_range_color = Color(PaletteCBColor(color_float));

ax.box_xy_error_delta(
[color_value],
[0],
[0.4],
[0.4],
&[
Caption(&color_name(&frac_color)),
LineWidth(1.0),
BorderColor("black".into()),
frac_color,
],
)
.box_xy_error_delta(
[color_value],
[1],
[0.4],
[0.4],
&[
Caption(&color_name(&cb_range_color)),
LineWidth(1.0),
BorderColor("black".into()),
cb_range_color,
],
);
}
ax.set_x_range(Fix(-10.0), Fix(11.0))
.set_y_range(Fix(-0.5), Fix(1.5))
.set_legend(Graph(0.45), Graph(0.9), &[], &[Font("", 14.0)]);
c.show(&mut fg, "palette_colors");
}

fn main()
{
Common::new().map(|c| example(c));
}
2 changes: 1 addition & 1 deletion gnuplot/examples/dash_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn example(c: Common)
x.clone().map(|v| v * 2 + 2 * i),
&[
LineWidth(2.),
Color("black"),
Color("black".into()),
LineStyle(dt),
Caption(&format!("{:?}", dt)),
],
Expand Down
Loading