Skip to content

Commit 6499edd

Browse files
Merge pull request #209 from BaCaRoZzo/issue#192_2
Ditch color function and CSS variables usage
2 parents 6414b9d + a53f223 commit 6499edd

File tree

5 files changed

+54
-66
lines changed

5 files changed

+54
-66
lines changed

README.MD

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -234,28 +234,9 @@ If you prefer, you can use CDN for assets.
234234
- **Type:** `path`
235235
- **Mandatory:** No
236236

237-
If you need to add some custom style to your report. Add it like this `customStyle: 'your-path-where/custom.css'`
238-
Customization is now possible also for the doughnut chart by using [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties).
239-
The user can define colors for the chart by defining variables for the different categories as follows:
240-
```css
241-
:root {
242-
--ambiguous-color:#AAAAAA;
243-
--failed-color:#BBBBBB;
244-
--not-defined-color:#CCCCCC;
245-
--passed-color:#DDDDDD;
246-
--pending-color:#EEEEEE;
247-
--skipped-color:#FFFFFF;
248-
}
249-
```
250-
Please note that these colors do _not_ affect the main colors CSS. To have homogeneous styling you can simply link those
251-
colors to the variables, e.g.:
252-
253-
```css
254-
.ambiguous-color {
255-
color: var(--ambiguous-color) !important;
256-
}
257-
```
258-
Please refer to the `test` directory and the `embedded-array` test report for a complete color customization example.
237+
If you need to add some custom style to your report. Add it like this `customStyle: 'your-path-where/custom.css'`.
238+
Please note that the doughnut charts uses the same colors as used by the status icons, i.e. the `.*-color` classes.
239+
Refer to the `test` directory and the `embedded-array` test report for a complete color customization example.
259240

260241
### `overrideStyle`
261242
- **Type:** `path`

templates/assets/js/Chart.style.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

templates/feature-overview.index.tmpl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@
170170
<% } %>
171171

172172
<!-- Custom -->
173-
<script src="../assets/js/Chart.style.js"></script>
174173
<script>
175174
var hideResult;
176175
var showAll;
@@ -181,6 +180,13 @@
181180
responsive: false
182181
};
183182

183+
var getColor = function(selector, defaultColor) {
184+
if (document.querySelector(selector)) {
185+
return getComputedStyle(document.querySelector(selector)).color
186+
}
187+
return defaultColor
188+
}
189+
184190
new Chart(document.getElementById("scenario-chart"), {
185191
type: 'doughnut',
186192
tooltipFillColor: "rgba(51, 51, 51, 0.55)",
@@ -202,7 +208,14 @@
202208
<%= feature.scenarios.ambiguous %>,
203209
<%= feature.scenarios.notDefined %>
204210
],
205-
backgroundColor: getChartColors()
211+
backgroundColor: [
212+
getColor(".passed-color", "#26B99A"),
213+
getColor(".failed-color", "#E74C3C"),
214+
getColor(".pending-color", "#FFD119"),
215+
getColor(".skipped-color", "#3498DB"),
216+
getColor(".ambiguous-color", "#b73122"),
217+
getColor(".not-defined-color", "#F39C12")
218+
]
206219
}]
207220
},
208221
options: scenarioOptions

templates/features-overview.index.tmpl

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@
126126
<% } %>
127127

128128
<!-- Custom -->
129-
<script src="assets/js/Chart.style.js"></script>
130129
<script>
131130
$(document).ready(function () {
132131
$('#features-table').dataTable({
@@ -139,6 +138,13 @@
139138
legend: false,
140139
responsive: false
141140
};
141+
142+
var getColor = function(selector, defaultColor) {
143+
if (document.querySelector(selector)) {
144+
return getComputedStyle(document.querySelector(selector)).color
145+
}
146+
return defaultColor
147+
}
142148

143149
new Chart(document.getElementById("feature-chart"), {
144150
type: 'doughnut',
@@ -161,7 +167,14 @@
161167
<%= suite.featureCount.ambiguous %>,
162168
<%= suite.featureCount.notDefined %>
163169
],
164-
backgroundColor: getChartColors()
170+
backgroundColor: [
171+
getColor(".passed-color", "#26B99A"),
172+
getColor(".failed-color", "#E74C3C"),
173+
getColor(".pending-color", "#FFD119"),
174+
getColor(".skipped-color", "#3498DB"),
175+
getColor(".ambiguous-color", "#b73122"),
176+
getColor(".not-defined-color", "#F39C12")
177+
]
165178
}]
166179
},
167180
options: featureOptions
@@ -193,7 +206,14 @@
193206
<%= suite.scenarios.ambiguous %>,
194207
<%= suite.scenarios.notDefined %>
195208
],
196-
backgroundColor: getChartColors()
209+
backgroundColor: [
210+
getColor(".passed-color", "#26B99A"),
211+
getColor(".failed-color", "#E74C3C"),
212+
getColor(".pending-color", "#FFD119"),
213+
getColor(".skipped-color", "#3498DB"),
214+
getColor(".ambiguous-color", "#b73122"),
215+
getColor(".not-defined-color", "#F39C12")
216+
]
197217
}]
198218
},
199219
options: scenarioOptions

test/custom.css

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,57 @@ body {
22
background: rgb(58,58,58);
33
}
44

5-
/* CSS custom properties are used to style doughnut charts */
6-
:root {
7-
--ambiguous-color:#AAAAAA;
8-
--failed-color:#FF0000;
9-
--not-defined-color:#0000FF;
10-
--passed-color:#00FF00;
11-
--pending-color:#FFAA33;
12-
--skipped-color:#770077;
13-
}
14-
155
/* If your custom theme doesn't properly support dark mode, you can easily hide the toggle button */
166
.fa-toggle-off {
177
display: none
188
}
199

20-
/* Style colors are derived from custom properties to have a homogeneous style */
10+
/* This styling applies also to the doughnut charts */
2111
.ambiguous-color {
22-
color: var(--ambiguous-color) !important;
12+
color: #AAAAAA !important;
2313
}
2414

2515
.failed-color {
26-
color: var(--failed-color) !important;
16+
color: #FF0000 !important;
2717
}
2818

2919
.not-defined-color {
30-
color: var(--not-defined-color) !important;
20+
color: #0000FF !important;
3121
}
3222

3323
.passed-color {
34-
color: var(--passed-color) !important;
24+
color: #00FF00 !important;
3525
}
3626

3727
.pending-color {
38-
color: var(--pending-color) !important;
28+
color: #FFAA33 !important;
3929
}
4030

4131
.skipped-color {
42-
color: var(--skipped-color) !important;
32+
color: #770077 !important;
4333
}
4434

4535
/* backgrounds */
4636
.ambiguous-background {
47-
background: var(--ambiguous-color) !important;
37+
background: #AAAAAA !important;
4838
}
4939

5040
.failed-background {
51-
background: var(--failed-color) !important;
41+
background: #FF0000 !important;
5242
}
5343

5444
.not-defined-background {
55-
background: var(--not-defined-color) !important;
45+
background: #0000FF !important;
5646
}
5747

5848
.passed-background {
59-
background: var(--passed-color) !important;
49+
background: #00FF00 !important;
6050
}
6151

6252
.pending-background {
63-
background: var(--pending-color) !important;
53+
background: #FFAA33 !important;
6454
}
6555

6656
.skipped-background {
67-
background: var(--skipped-color) !important;
57+
background: #770077 !important;
6858
}

0 commit comments

Comments
 (0)