Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/heatmap #24

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
201 changes: 201 additions & 0 deletions data/heatmap.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
x,y,z
x1,y1,5795
x1,y2,-9140
x1,y3,-4610
x1,y4,1964
x1,y5,1284
x1,y6,-3735
x1,y7,6850
x1,y8,-5574
x1,y9,4423
x1,y10,1363
x2,y1,6023
x2,y2,-1678
x2,y3,-8315
x2,y4,-9231
x2,y5,-7567
x2,y6,-4689
x2,y7,-4949
x2,y8,-3580
x2,y9,7568
x2,y10,9769
x3,y1,-3604
x3,y2,-1334
x3,y3,8942
x3,y4,8431
x3,y5,-7253
x3,y6,-9811
x3,y7,9118
x3,y8,-6995
x3,y9,-8101
x3,y10,-8733
x4,y1,7912
x4,y2,1394
x4,y3,-6444
x4,y4,-6110
x4,y5,-1162
x4,y6,4502
x4,y7,627
x4,y8,-1208
x4,y9,555
x4,y10,253
x5,y1,-1567
x5,y2,233
x5,y3,1016
x5,y4,-7388
x5,y5,5787
x5,y6,7159
x5,y7,2206
x5,y8,-1774
x5,y9,4541
x5,y10,-6848
x6,y1,-8415
x6,y2,-6057
x6,y3,9457
x6,y4,-8979
x6,y5,1653
x6,y6,805
x6,y7,3417
x6,y8,-2011
x6,y9,-308
x6,y10,2990
x7,y1,-3127
x7,y2,-4325
x7,y3,-9839
x7,y4,-5703
x7,y5,-9005
x7,y6,1534
x7,y7,-2371
x7,y8,-8984
x7,y9,-1471
x7,y10,7262
x8,y1,-732
x8,y2,2185
x8,y3,-3669
x8,y4,-1429
x8,y5,-2792
x8,y6,-4724
x8,y7,8446
x8,y8,6448
x8,y9,6216
x8,y10,-1994
x9,y1,-7432
x9,y2,-7973
x9,y3,-7305
x9,y4,5422
x9,y5,-4742
x9,y6,-3264
x9,y7,-9609
x9,y8,3986
x9,y9,2666
x9,y10,-4108
x10,y1,-6439
x10,y2,-3816
x10,y3,9483
x10,y4,-1608
x10,y5,3067
x10,y6,5265
x10,y7,9488
x10,y8,-7546
x10,y9,1837
x10,y10,4039
x11,y1,9115
x11,y2,965
x11,y3,-238
x11,y4,-4944
x11,y5,4948
x11,y6,-1890
x11,y7,3773
x11,y8,7412
x11,y9,-9498
x11,y10,-3090
x12,y1,2685
x12,y2,-9794
x12,y3,7868
x12,y4,5934
x12,y5,7247
x12,y6,9174
x12,y7,-1245
x12,y8,2383
x12,y9,8141
x12,y10,4820
x13,y1,-2426
x13,y2,-3626
x13,y3,-8322
x13,y4,9626
x13,y5,-8941
x13,y6,6198
x13,y7,-86
x13,y8,9541
x13,y9,817
x13,y10,921
x14,y1,-211
x14,y2,6312
x14,y3,1252
x14,y4,-7307
x14,y5,3931
x14,y6,-6373
x14,y7,6157
x14,y8,173
x14,y9,8047
x14,y10,230
x15,y1,5707
x15,y2,1494
x15,y3,-8694
x15,y4,-3224
x15,y5,-526
x15,y6,-2474
x15,y7,-4470
x15,y8,-6252
x15,y9,3545
x15,y10,-9337
x16,y1,-8002
x16,y2,-2006
x16,y3,7879
x16,y4,-6696
x16,y5,8237
x16,y6,3808
x16,y7,-3415
x16,y8,7675
x16,y9,9965
x16,y10,1649
x17,y1,-8364
x17,y2,7082
x17,y3,-5263
x17,y4,4555
x17,y5,3877
x17,y6,-9146
x17,y7,-4145
x17,y8,-2608
x17,y9,3949
x17,y10,8091
x18,y1,-4209
x18,y2,-5069
x18,y3,9894
x18,y4,-9798
x18,y5,1447
x18,y6,2688
x18,y7,-5611
x18,y8,-7673
x18,y9,-1996
x18,y10,9315
x19,y1,-2223
x19,y2,-9803
x19,y3,-8070
x19,y4,1774
x19,y5,5087
x19,y6,-661
x19,y7,1589
x19,y8,8895
x19,y9,5708
x19,y10,7043
x20,y1,-7189
x20,y2,4243
x20,y3,-3454
x20,y4,-8014
x20,y5,-1662
x20,y6,1411
x20,y7,-7089
x20,y8,-8266
x20,y9,8227
x20,y10,-1320
59 changes: 22 additions & 37 deletions src/common/layout.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use plotly::{
color::Rgb as RgbPlotly,
common::{Font, Title},
common::Font,
layout::{Axis as AxisPlotly, Legend as LegendPlotly},
Layout as LayoutPlotly,
};
Expand All @@ -21,7 +20,7 @@ pub(crate) trait Layout {
let mut layout = LayoutPlotly::new();

if let Some(title) = plot_title {
layout = layout.title(Self::set_title(title));
layout = layout.title(title.to_plotly());
}

layout = layout.x_axis(Self::set_axis(x_title, x_axis));
Expand All @@ -30,23 +29,12 @@ pub(crate) trait Layout {
layout
}

fn set_title(title: Text) -> Title {
Title::with_text(title.content)
.font(
Font::new()
.family(title.font.as_str())
.size(title.size)
.color(RgbPlotly::new(title.color.0, title.color.1, title.color.2)),
)
.x(title.x)
.y(title.y)
}

// TODO: Move axis functions to Axis struct like colorbar
fn set_axis(title: Option<Text>, format: Option<&Axis>) -> AxisPlotly {
let mut axis = AxisPlotly::new();

if let Some(title) = title {
axis = axis.title(Self::set_title(title));
axis = axis.title(title.to_plotly());
}

if let Some(format) = format {
Expand All @@ -56,11 +44,12 @@ pub(crate) trait Layout {
axis
}

// TODO: Move legend functions to Axis struct like colorbar
fn set_legend(title: Option<Text>, format: Option<&Legend>) -> LegendPlotly {
let mut legend = LegendPlotly::new();

if let Some(title) = title {
legend = legend.title(Self::set_title(title));
legend = legend.title(title.to_plotly());
}

if let Some(format) = format {
Expand All @@ -76,15 +65,15 @@ pub(crate) trait Layout {
}

if let Some(axis_position) = &format.axis_side {
axis = axis.side(axis_position.get_side());
axis = axis.side(axis_position.to_plotly());
}

if let Some(axis_type) = &format.axis_type {
axis = axis.type_(axis_type.get_type());
axis = axis.type_(axis_type.to_plotly());
}

if let Some(color) = format.value_color {
axis = axis.color(RgbPlotly::new(color.0, color.1, color.2));
axis = axis.color(color.to_plotly());
}

if let Some(range) = &format.value_range {
Expand All @@ -96,7 +85,7 @@ pub(crate) trait Layout {
}

if let Some(exponent) = &format.value_exponent {
axis = axis.exponent_format(exponent.get_exponent());
axis = axis.exponent_format(exponent.to_plotly());
}

if let Some(range_values) = &format.tick_values {
Expand All @@ -108,7 +97,7 @@ pub(crate) trait Layout {
}

if let Some(tick_direction) = &format.tick_direction {
axis = axis.ticks(tick_direction.get_direction());
axis = axis.ticks(tick_direction.to_plotly_tickdirection());
}

if let Some(tick_length) = format.tick_length {
Expand All @@ -119,8 +108,8 @@ pub(crate) trait Layout {
axis = axis.tick_width(tick_width.to_owned());
}

if let Some(tick_color) = format.tick_color {
axis = axis.tick_color(RgbPlotly::new(tick_color.0, tick_color.1, tick_color.2));
if let Some(color) = format.tick_color {
axis = axis.tick_color(color.to_plotly());
}

if let Some(tick_angle) = format.tick_angle {
Expand All @@ -135,8 +124,8 @@ pub(crate) trait Layout {
axis = axis.show_line(show_line.to_owned());
}

if let Some(line_color) = format.line_color {
axis = axis.line_color(RgbPlotly::new(line_color.0, line_color.1, line_color.2));
if let Some(color) = format.line_color {
axis = axis.line_color(color.to_plotly());
}

if let Some(line_width) = format.line_width {
Expand All @@ -147,8 +136,8 @@ pub(crate) trait Layout {
axis = axis.show_grid(show_grid.to_owned());
}

if let Some(grid_color) = format.grid_color {
axis = axis.grid_color(RgbPlotly::new(grid_color.0, grid_color.1, grid_color.2));
if let Some(color) = format.grid_color {
axis = axis.grid_color(color.to_plotly());
}

if let Some(grid_width) = format.grid_width {
Expand All @@ -159,12 +148,8 @@ pub(crate) trait Layout {
axis = axis.zero_line(show_zero_line.to_owned());
}

if let Some(zero_line_color) = format.zero_line_color {
axis = axis.zero_line_color(RgbPlotly::new(
zero_line_color.0,
zero_line_color.1,
zero_line_color.2,
));
if let Some(color) = format.zero_line_color {
axis = axis.zero_line_color(color.to_plotly());
}

if let Some(zero_line_width) = format.zero_line_width {
Expand All @@ -180,11 +165,11 @@ pub(crate) trait Layout {

fn set_legend_format(mut legend: LegendPlotly, format: &Legend) -> LegendPlotly {
if let Some(color) = format.background_color {
legend = legend.background_color(RgbPlotly::new(color.0, color.1, color.2));
legend = legend.background_color(color.to_plotly());
}

if let Some(color) = format.border_color {
legend = legend.border_color(RgbPlotly::new(color.0, color.1, color.2));
legend = legend.border_color(color.to_plotly());
}

if let Some(width) = format.border_width {
Expand All @@ -196,7 +181,7 @@ pub(crate) trait Layout {
}

if let Some(orientation) = &format.orientation {
legend = legend.orientation(orientation.get_orientation());
legend = legend.orientation(orientation.to_plotly());
}

if let Some(x) = format.x {
Expand Down
4 changes: 2 additions & 2 deletions src/common/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ pub(crate) trait Line {
index: usize,
) -> LinePlotly {
if let Some(style) = style {
line = line.dash(style.get_line_type());
line = line.dash(style.to_plotly());
return line;
}

if let Some(styles) = styles {
if let Some(style) = styles.get(index) {
line = line.dash(style.get_line_type());
line = line.dash(style.to_plotly());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/common/mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ pub(crate) trait Marker {
index: usize,
) -> MarkerPlotly {
if let Some(shape) = shape {
marker = marker.symbol(shape.get_shape());
marker = marker.symbol(shape.to_plotly());
return marker;
}

if let Some(shapes) = shapes {
if let Some(shape) = shapes.get(index) {
marker = marker.symbol(shape.get_shape());
marker = marker.symbol(shape.to_plotly());
}
}

Expand Down
Loading