Skip to content

Commit 5657ce9

Browse files
committed
feat: add chart_solid_fill
1 parent d3a37de commit 5657ce9

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

rust/src/wrapper/chart/chart_format.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use rust_xlsxwriter::{self as xlsx};
22
use wasm_bindgen::prelude::*;
33

44
use crate::wrapper::color::Color;
5+
use crate::wrapper::chart::chart_solid_fill::ChartSolidFill;
56

67
/// The `ChartFormat` struct represents formatting for various chart objects.
78
///
@@ -79,7 +80,12 @@ impl ChartFormat {
7980
self
8081
}
8182

82-
// TODO: set_gradient_fill, set_pattern_fill, set_solid_fill
83+
// TODO: set_gradient_fill, set_pattern_fill
84+
#[wasm_bindgen(js_name = "setSolidFill")]
85+
pub fn set_solid_fill(mut self, fill: &ChartSolidFill) -> ChartFormat {
86+
self.inner.set_solid_fill(&fill.inner);
87+
self
88+
}
8389
}
8490

8591
/// The `ChartLine` struct represents a chart line/border.
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use rust_xlsxwriter as xlsx;
2+
use wasm_bindgen::prelude::*;
3+
4+
use crate::wrapper::color::Color;
5+
6+
/// The `ChartSolidFill` struct represents a solid fill for chart elements.
7+
///
8+
/// The `ChartSolidFill` struct is used to define the solid fill properties
9+
/// for chart elements such as plot areas, chart areas, data series, and other
10+
/// fillable elements in a chart.
11+
///
12+
/// It is used in conjunction with the {@link Chart} struct.
13+
#[wasm_bindgen]
14+
pub struct ChartSolidFill {
15+
pub(crate) inner: xlsx::ChartSolidFill,
16+
}
17+
18+
#[wasm_bindgen]
19+
impl ChartSolidFill {
20+
/// Create a new `ChartSolidFill` object.
21+
#[wasm_bindgen(constructor)]
22+
pub fn new() -> ChartSolidFill {
23+
ChartSolidFill {
24+
inner: xlsx::ChartSolidFill::new(),
25+
}
26+
}
27+
28+
/// Set the color of a solid fill.
29+
///
30+
/// @param {Color} color - The color property.
31+
/// @return {ChartSolidFill} - The ChartSolidFill instance.
32+
#[wasm_bindgen(js_name = "setColor")]
33+
pub fn set_color(mut self, color: &Color) -> ChartSolidFill {
34+
self.inner.set_color(color.inner);
35+
self
36+
}
37+
38+
/// Set the transparency of a solid fill.
39+
///
40+
/// Set the transparency of a solid fill color for a Chart element.
41+
/// You must also specify a fill color in order for the transparency to be applied.
42+
///
43+
/// @param {number} transparency - The color transparency in the range 0-100.
44+
/// @return {ChartSolidFill} - The ChartSolidFill instance.
45+
#[wasm_bindgen(js_name = "setTransparency")]
46+
pub fn set_transparency(mut self, transparency: u8) -> ChartSolidFill {
47+
self.inner.set_transparency(transparency);
48+
self
49+
}
50+
}

rust/src/wrapper/chart/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod chart_marker_type;
1010
mod chart_point;
1111
mod chart_range;
1212
mod chart_series;
13+
mod chart_solid_fill;
1314
mod chart_title;
1415
mod chart_type;
1516

test/chart.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ describe("xlsx-wasm test", () => {
5151

5252
const chartSeries1 = new ChartSeries();
5353
const chartLine1 = new ChartLine().setColor(Color.green());
54-
const chartFormat1 = new ChartFormat().setLine(chartLine1);
54+
const chartSolidFill1 = new ChartSolidFill().setColor(Color.green());
55+
const chartFormat1 = new ChartFormat().setLine(chartLine1).setSolidFill(chartSolidFill1);
5556
const chartMarker1 = new ChartMarker().setType(ChartMarkerType.Circle).setSize(10).setFormat(chartFormat1);
5657
const categoriesRange1 = new ChartRange("Sheet1", 1, 0, 6, 0);
5758
const valuesRange1 = new ChartRange("Sheet1", 1, 1, 6, 1);
@@ -64,7 +65,8 @@ describe("xlsx-wasm test", () => {
6465
.setMarker(chartMarker1);
6566
const chartSeries2 = new ChartSeries();
6667
const chartLine2 = new ChartLine().setColor(Color.purple());
67-
const chartFormat2 = new ChartFormat().setLine(chartLine2);
68+
const chartSolidFill2 = new ChartSolidFill().setColor(Color.purple());
69+
const chartFormat2 = new ChartFormat().setLine(chartLine2).setSolidFill(chartSolidFill2);
6870
const chartMarker2 = new ChartMarker().setType(ChartMarkerType.Diamond).setSize(10).setFormat(chartFormat2);
6971
const categoriesRange2 = new ChartRange("Sheet1", 1, 0, 6, 0);
7072
const valuesRange2 = new ChartRange("Sheet1", 1, 2, 6, 2);

test/expected/insert_chart.xlsx

5 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)