Skip to content

Commit 1ba973a

Browse files
committed
Set the 3d coord pixel range
1 parent f09ee08 commit 1ba973a

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/chart/context.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,14 @@ where
604604
.set_projection(actual_x, actual_y, pf);
605605
self
606606
}
607+
608+
pub fn set_3d_pixel_range(&mut self, size: (i32, i32, i32)) -> &mut Self {
609+
let (actual_x, actual_y) = self.drawing_area.get_pixel_range();
610+
self.drawing_area
611+
.as_coord_spec_mut()
612+
.set_coord_pixel_range(actual_x, actual_y, size);
613+
self
614+
}
607615
}
608616

609617
impl<'a, DB, X: Ranged, Y: Ranged, Z: Ranged> ChartContext<'a, DB, Cartesian3d<X, Y, Z>>

src/coord/ranged3d/cartesian3d.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ impl<X: Ranged, Y: Ranged, Z: Ranged> Cartesian3d<X, Y, Z> {
2121
fn create_projection<F: FnOnce(ProjectionMatrixBuilder) -> ProjectionMatrix>(
2222
actual_x: Range<i32>,
2323
actual_y: Range<i32>,
24+
coord_size: (i32, i32, i32),
2425
f: F,
2526
) -> ProjectionMatrix {
26-
let default_size = Self::compute_default_size(actual_x.clone(), actual_y.clone());
27-
let center_3d = (default_size / 2, default_size / 2, default_size / 2);
27+
let center_3d = (coord_size.0 / 2, coord_size.1 / 2, coord_size.2 / 2);
2828
let center_2d = (
2929
(actual_x.end + actual_x.start) / 2,
3030
(actual_y.end + actual_y.start) / 2,
@@ -46,22 +46,41 @@ impl<X: Ranged, Y: Ranged, Z: Ranged> Cartesian3d<X, Y, Z> {
4646
build_projection_matrix: F,
4747
) -> Self {
4848
let default_size = Self::compute_default_size(actual_x.clone(), actual_y.clone());
49+
let coord_size = (default_size, default_size, default_size);
4950
Self {
5051
logic_x: logic_x.into(),
5152
logic_y: logic_y.into(),
5253
logic_z: logic_z.into(),
53-
coord_size: (default_size, default_size, default_size),
54-
projection: Self::create_projection(actual_x, actual_y, build_projection_matrix),
54+
coord_size,
55+
projection: Self::create_projection(
56+
actual_x,
57+
actual_y,
58+
coord_size,
59+
build_projection_matrix,
60+
),
5561
}
5662
}
63+
64+
pub fn set_coord_pixel_range(
65+
&mut self,
66+
actual_x: Range<i32>,
67+
actual_y: Range<i32>,
68+
coord_size: (i32, i32, i32),
69+
) -> &mut Self {
70+
self.coord_size = coord_size;
71+
self.projection =
72+
Self::create_projection(actual_x, actual_y, coord_size, |pb| pb.into_matrix());
73+
self
74+
}
75+
5776
/// Set the projection matrix
5877
pub fn set_projection<F: FnOnce(ProjectionMatrixBuilder) -> ProjectionMatrix>(
5978
&mut self,
6079
actual_x: Range<i32>,
6180
actual_y: Range<i32>,
6281
f: F,
6382
) -> &mut Self {
64-
self.projection = Self::create_projection(actual_x, actual_y, f);
83+
self.projection = Self::create_projection(actual_x, actual_y, self.coord_size, f);
6584
self
6685
}
6786

0 commit comments

Comments
 (0)