Skip to content

Commit 2313f95

Browse files
committed
feat: add chart_solid_fill
1 parent b8043b2 commit 2313f95

File tree

6 files changed

+74
-2
lines changed

6 files changed

+74
-2
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.

rust/src/wrapper/chart/chart_point.rs

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ impl ChartPoint {
3838
}
3939
}
4040

41+
#[wasm_bindgen(js_name = "setFormat")]
4142
pub fn set_format(&self, format: &mut ChartFormat) -> ChartPoint {
4243
ChartPoint {
4344
inner: self.clone().inner.set_format(&mut format.inner),

rust/src/wrapper/chart/chart_series.rs

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

6-
use super::{chart_data_label::ChartDataLabel, chart_marker::ChartMarker, chart_point::ChartPoint, chart_range::ChartRange};
6+
use super::{chart_data_label::ChartDataLabel, chart_format::ChartFormat, chart_marker::ChartMarker, chart_point::ChartPoint, chart_range::ChartRange};
77

88
#[wasm_bindgen]
99
pub struct ChartSeries {
@@ -151,4 +151,13 @@ impl ChartSeries {
151151
inner: Arc::clone(&self.inner),
152152
}
153153
}
154+
155+
#[wasm_bindgen(js_name = "setFormat", skip_jsdoc)]
156+
pub fn set_format(&self, format: &mut ChartFormat) -> ChartSeries {
157+
let mut series = self.inner.lock().unwrap();
158+
series.set_format(&mut format.inner);
159+
ChartSeries {
160+
inner: Arc::clone(&self.inner),
161+
}
162+
}
154163
}
+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

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import {
1010
ChartDataLabelPosition,
1111
ChartMarker,
1212
ChartMarkerType,
13+
ChartSolidFill,
14+
ChartFormat,
15+
Color,
1316
} from "../web/wasm_xlsxwriter";
1417
import { describe, test, beforeAll, expect } from "vitest";
1518
import { initWasModule, readXlsx, readXlsxFile } from "./common";
@@ -54,6 +57,7 @@ describe("xlsx-wasm test", () => {
5457
.setCategories(categoriesRange1)
5558
.setValues(valuesRange1)
5659
.setDataLabel(chartDataLabel)
60+
.setFormat(new ChartFormat().setSolidFill(new ChartSolidFill().setColor(Color.green())))
5761
.setMarker(chartMarker1);
5862
const chartSeries2 = new ChartSeries();
5963
const chartMarker2 = new ChartMarker().setType(ChartMarkerType.Diamond).setSize(10);
@@ -64,6 +68,7 @@ describe("xlsx-wasm test", () => {
6468
.setCategories(categoriesRange2)
6569
.setValues(valuesRange2)
6670
.setDataLabel(chartDataLabel)
71+
.setFormat(new ChartFormat().setSolidFill(new ChartSolidFill().setColor(Color.purple())))
6772
.setMarker(chartMarker2);
6873
chart
6974
.pushSeries(chartSeries1)

0 commit comments

Comments
 (0)