Skip to content

Commit c078b27

Browse files
authored
Merge pull request #75 from estie-inc/add_chart_options
Add chart options
2 parents 2ba8470 + 221eb5d commit c078b27

10 files changed

+417
-12
lines changed

rust/src/wrapper/chart/chart_axis.rs

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use std::sync::{Arc, Mutex};
33
use rust_xlsxwriter as xlsx;
44
use wasm_bindgen::prelude::*;
55

6+
use crate::wrapper::chart::chart_font::ChartFont;
7+
68
#[derive(Copy, Clone)]
79
pub enum AxisType {
810
X,
@@ -66,4 +68,18 @@ impl ChartAxis {
6668
axis.set_max(max);
6769
})
6870
}
71+
72+
#[wasm_bindgen(js_name = "setFont", skip_jsdoc)]
73+
pub fn set_font(&self, font: &ChartFont) -> ChartAxis {
74+
self.with_chart(|axis| {
75+
axis.set_font(&font.inner);
76+
})
77+
}
78+
79+
#[wasm_bindgen(js_name = "setNameFont", skip_jsdoc)]
80+
pub fn set_name_font(&self, font: &ChartFont) -> ChartAxis {
81+
self.with_chart(|axis| {
82+
axis.set_name_font(&font.inner);
83+
})
84+
}
6985
}
+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
use rust_xlsxwriter::{self as xlsx};
2+
use wasm_bindgen::prelude::*;
3+
4+
use crate::wrapper::chart::chart_data_label_position::ChartDataLabelPosition;
5+
use crate::wrapper::chart::chart_font::ChartFont;
6+
use crate::wrapper::chart::chart_format::ChartFormat;
7+
8+
#[wasm_bindgen]
9+
pub struct ChartDataLabel {
10+
pub(crate) inner: xlsx::ChartDataLabel,
11+
}
12+
13+
#[wasm_bindgen]
14+
impl ChartDataLabel {
15+
#[wasm_bindgen(constructor)]
16+
pub fn new() -> ChartDataLabel {
17+
ChartDataLabel {
18+
inner: xlsx::ChartDataLabel::new(),
19+
}
20+
}
21+
22+
#[wasm_bindgen(js_name = "showValue")]
23+
pub fn show_value(&mut self) -> ChartDataLabel {
24+
self.inner.show_value();
25+
ChartDataLabel {
26+
inner: self.inner.clone(),
27+
}
28+
}
29+
30+
#[wasm_bindgen(js_name = "showCategoryName")]
31+
pub fn show_category_name(&mut self) -> ChartDataLabel {
32+
self.inner.show_category_name();
33+
ChartDataLabel {
34+
inner: self.inner.clone(),
35+
}
36+
}
37+
38+
#[wasm_bindgen(js_name = "showSeriesName")]
39+
pub fn show_series_name(&mut self) -> ChartDataLabel {
40+
self.inner.show_series_name();
41+
ChartDataLabel {
42+
inner: self.inner.clone(),
43+
}
44+
}
45+
46+
#[wasm_bindgen(js_name = "showLeaderLines")]
47+
pub fn show_leader_lines(&mut self) -> ChartDataLabel {
48+
self.inner.show_leader_lines();
49+
ChartDataLabel {
50+
inner: self.inner.clone(),
51+
}
52+
}
53+
54+
#[wasm_bindgen(js_name = "showLegendKey")]
55+
pub fn show_legend_key(&mut self) -> ChartDataLabel {
56+
self.inner.show_legend_key();
57+
ChartDataLabel {
58+
inner: self.inner.clone(),
59+
}
60+
}
61+
62+
#[wasm_bindgen(js_name = "showPercentage")]
63+
pub fn show_percentage(&mut self) -> ChartDataLabel {
64+
self.inner.show_percentage();
65+
ChartDataLabel {
66+
inner: self.inner.clone(),
67+
}
68+
}
69+
70+
#[wasm_bindgen(js_name = "setPosition")]
71+
pub fn set_position(&mut self, position: ChartDataLabelPosition) -> ChartDataLabel {
72+
self.inner.set_position(position.into());
73+
ChartDataLabel {
74+
inner: self.inner.clone(),
75+
}
76+
}
77+
78+
#[wasm_bindgen(js_name = "setFont")]
79+
pub fn set_font(&mut self, font: &ChartFont) -> ChartDataLabel {
80+
self.inner.set_font(&font.inner);
81+
ChartDataLabel {
82+
inner: self.inner.clone(),
83+
}
84+
}
85+
86+
#[wasm_bindgen(js_name = "setFormat")]
87+
pub fn set_format(&mut self, format: &mut ChartFormat) -> ChartDataLabel {
88+
self.inner.set_format(&mut format.inner);
89+
ChartDataLabel {
90+
inner: self.inner.clone(),
91+
}
92+
}
93+
94+
#[wasm_bindgen(js_name = "setNumFormat")]
95+
pub fn set_num_format(&mut self, num_format: &str) -> ChartDataLabel {
96+
self.inner.set_num_format(num_format);
97+
ChartDataLabel {
98+
inner: self.inner.clone(),
99+
}
100+
}
101+
102+
#[wasm_bindgen(js_name = "setSeparator")]
103+
pub fn set_separator(&mut self, separator: char) -> ChartDataLabel {
104+
self.inner.set_separator(separator);
105+
ChartDataLabel {
106+
inner: self.inner.clone(),
107+
}
108+
}
109+
110+
#[wasm_bindgen(js_name = "showYValue")]
111+
pub fn show_y_value(&mut self) -> ChartDataLabel {
112+
self.inner.show_y_value();
113+
ChartDataLabel {
114+
inner: self.inner.clone(),
115+
}
116+
}
117+
118+
#[wasm_bindgen(js_name = "showXValue")]
119+
pub fn show_x_value(&mut self) -> ChartDataLabel {
120+
self.inner.show_x_value();
121+
ChartDataLabel {
122+
inner: self.inner.clone(),
123+
}
124+
}
125+
126+
#[wasm_bindgen(js_name = "setHidden")]
127+
pub fn set_hidden(&mut self) -> ChartDataLabel {
128+
self.inner.set_hidden();
129+
ChartDataLabel {
130+
inner: self.inner.clone(),
131+
}
132+
}
133+
134+
#[wasm_bindgen(js_name = "setValue")]
135+
pub fn set_value(&mut self, value: &str) -> ChartDataLabel {
136+
self.inner.set_value(value);
137+
ChartDataLabel {
138+
inner: self.inner.clone(),
139+
}
140+
}
141+
142+
#[wasm_bindgen(js_name = "toCustom")]
143+
pub fn to_custom(&mut self) -> ChartDataLabel {
144+
self.inner.to_custom();
145+
ChartDataLabel {
146+
inner: self.inner.clone(),
147+
}
148+
}
149+
}
150+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use rust_xlsxwriter as xlsx;
2+
use wasm_bindgen::prelude::*;
3+
4+
#[derive(Debug, Clone, Copy)]
5+
#[wasm_bindgen]
6+
pub enum ChartDataLabelPosition {
7+
Default,
8+
Center,
9+
Right,
10+
Left,
11+
Above,
12+
Below,
13+
InsideBase,
14+
InsideEnd,
15+
OutsideEnd,
16+
BestFit,
17+
}
18+
19+
impl From<ChartDataLabelPosition> for xlsx::ChartDataLabelPosition {
20+
fn from(position: ChartDataLabelPosition) -> Self {
21+
match position {
22+
ChartDataLabelPosition::Default => xlsx::ChartDataLabelPosition::Default,
23+
ChartDataLabelPosition::Center => xlsx::ChartDataLabelPosition::Center,
24+
ChartDataLabelPosition::Right => xlsx::ChartDataLabelPosition::Right,
25+
ChartDataLabelPosition::Left => xlsx::ChartDataLabelPosition::Left,
26+
ChartDataLabelPosition::Above => xlsx::ChartDataLabelPosition::Above,
27+
ChartDataLabelPosition::Below => xlsx::ChartDataLabelPosition::Below,
28+
ChartDataLabelPosition::InsideBase => xlsx::ChartDataLabelPosition::InsideBase,
29+
ChartDataLabelPosition::InsideEnd => xlsx::ChartDataLabelPosition::InsideEnd,
30+
ChartDataLabelPosition::OutsideEnd => xlsx::ChartDataLabelPosition::OutsideEnd,
31+
ChartDataLabelPosition::BestFit => xlsx::ChartDataLabelPosition::BestFit,
32+
}
33+
}
34+
}

rust/src/wrapper/chart/chart_font.rs

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
use rust_xlsxwriter as xlsx;
2+
use wasm_bindgen::prelude::*;
3+
4+
use crate::wrapper::color::Color;
5+
6+
/// The `ChartFont` struct represents a chart font.
7+
///
8+
/// The `ChartFont` struct is used to define the font properties for chart elements
9+
/// such as chart titles, axis labels, data labels and other text elements in a chart.
10+
///
11+
/// It is used in conjunction with the {@link Chart} struct.
12+
#[wasm_bindgen]
13+
pub struct ChartFont {
14+
pub(crate) inner: xlsx::ChartFont,
15+
}
16+
17+
#[wasm_bindgen]
18+
impl ChartFont {
19+
/// Create a new `ChartFont` object.
20+
#[wasm_bindgen(constructor)]
21+
pub fn new() -> ChartFont {
22+
ChartFont {
23+
inner: xlsx::ChartFont::new(),
24+
}
25+
}
26+
27+
/// Set the font bold property.
28+
///
29+
/// @return {ChartFont} - The ChartFont instance.
30+
#[wasm_bindgen(js_name = "setBold")]
31+
pub fn set_bold(mut self) -> ChartFont {
32+
self.inner.set_bold();
33+
self
34+
}
35+
36+
/// Set the font character set value.
37+
///
38+
/// Set the font character set value using the standard Windows values.
39+
/// This is generally only required when using non-standard fonts.
40+
///
41+
/// @param {number} charset - The font character set value.
42+
/// @return {ChartFont} - The ChartFont instance.
43+
#[wasm_bindgen(js_name = "setCharacterSet")]
44+
pub fn set_character_set(mut self, character_set: u8) -> ChartFont {
45+
self.inner.set_character_set(character_set);
46+
self
47+
}
48+
49+
/// Set the font color property.
50+
///
51+
/// @param {Color} color - The font color property.
52+
/// @return {ChartFont} - The ChartFont instance.
53+
#[wasm_bindgen(js_name = "setColor")]
54+
pub fn set_color(mut self, color: &Color) -> ChartFont {
55+
self.inner.set_color(color.inner);
56+
self
57+
}
58+
59+
/// Set the font italic property.
60+
///
61+
/// @return {ChartFont} - The ChartFont instance.
62+
#[wasm_bindgen(js_name = "setItalic")]
63+
pub fn set_italic(mut self) -> ChartFont {
64+
self.inner.set_italic();
65+
self
66+
}
67+
68+
/// Set the font name/family property.
69+
///
70+
/// Set the font name for the chart element. Excel can only display fonts that
71+
/// are installed on the system that it is running on. Therefore it is generally
72+
/// best to use standard Excel fonts.
73+
///
74+
/// @param {string} name - The font name property.
75+
/// @return {ChartFont} - The ChartFont instance.
76+
#[wasm_bindgen(js_name = "setName")]
77+
pub fn set_name(mut self, name: &str) -> ChartFont {
78+
self.inner.set_name(name);
79+
self
80+
}
81+
82+
/// Set the font pitch and family value.
83+
///
84+
/// Set the font pitch and family value using the standard Windows values.
85+
/// This is generally only required when using non-standard fonts.
86+
///
87+
/// @param {number} pitch_family - The font pitch and family value.
88+
/// @return {ChartFont} - The ChartFont instance.
89+
#[wasm_bindgen(js_name = "setPitchFamily")]
90+
pub fn set_pitch_family(mut self, pitch_family: u8) -> ChartFont {
91+
self.inner.set_pitch_family(pitch_family);
92+
self
93+
}
94+
95+
/// Set the right to left property.
96+
///
97+
/// Set the right to left property. This is generally only required when using
98+
/// non-standard fonts.
99+
///
100+
/// @param {boolean} enable - Turn the property on/off. Defaults to true.
101+
/// @return {ChartFont} - The ChartFont instance.
102+
#[wasm_bindgen(js_name = "setRightToLeft")]
103+
pub fn set_right_to_left(mut self, enable: bool) -> ChartFont {
104+
self.inner.set_right_to_left(enable);
105+
self
106+
}
107+
108+
/// Set the font rotation angle.
109+
///
110+
/// Set the rotation angle of the font text in the range -90 to 90 degrees.
111+
///
112+
/// @param {number} rotation - The rotation angle in degrees.
113+
/// @return {ChartFont} - The ChartFont instance.
114+
#[wasm_bindgen(js_name = "setRotation")]
115+
pub fn set_rotation(mut self, rotation: i16) -> ChartFont {
116+
self.inner.set_rotation(rotation);
117+
self
118+
}
119+
120+
/// Set the font size property.
121+
///
122+
/// Set the font size for the chart element.
123+
///
124+
/// @param {number} size - The font size property.
125+
/// @return {ChartFont} - The ChartFont instance.
126+
#[wasm_bindgen(js_name = "setSize")]
127+
pub fn set_size(mut self, size: f64) -> ChartFont {
128+
self.inner.set_size(size);
129+
self
130+
}
131+
132+
/// Set the font strikethrough property.
133+
///
134+
/// Set the strikethrough property. This is generally only required when using
135+
/// non-standard fonts.
136+
///
137+
/// @return {ChartFont} - The ChartFont instance.
138+
#[wasm_bindgen(js_name = "setStrikethrough")]
139+
pub fn set_strikethrough(mut self) -> ChartFont {
140+
self.inner.set_strikethrough();
141+
self
142+
}
143+
144+
/// Set the font underline property.
145+
///
146+
/// Set the font underline. This is generally only required when using
147+
/// non-standard fonts.
148+
///
149+
/// @param {number} underline - The font underline value.
150+
/// @return {ChartFont} - The ChartFont instance.
151+
#[wasm_bindgen(js_name = "setUnderline")]
152+
pub fn set_underline(mut self) -> ChartFont {
153+
self.inner.set_underline();
154+
self
155+
}
156+
157+
/// Unset bold property.
158+
///
159+
/// Unset the bold property. This is generally only required when using
160+
/// non-standard fonts.
161+
///
162+
/// @return {ChartFont} - The ChartFont instance.
163+
#[wasm_bindgen(js_name = "unsetBold")]
164+
pub fn unset_bold(mut self) -> ChartFont {
165+
self.inner.unset_bold();
166+
self
167+
}
168+
}

0 commit comments

Comments
 (0)