Skip to content

Commit 8dfb3fd

Browse files
committed
feat(series): Define the opacity of the line or area
Fixes #57
1 parent 5a325f4 commit 8dfb3fd

File tree

6 files changed

+9
-2
lines changed

6 files changed

+9
-2
lines changed

.devcontainer/ui-lovelace.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,14 @@ views:
196196
- entity: sensor.humidity
197197
type: area
198198
name: Outside Humidity
199+
opacity: 0.3
199200
group_by:
200201
func: avg
201202
duration: 1h
202203
- entity: sensor.random0_100
203204
type: area
204205
name: Office Humidity
206+
opacity: 0.3
205207
group_by:
206208
func: avg
207209
duration: 1h
@@ -541,6 +543,7 @@ views:
541543
- entity: sensor.random0_100
542544
type: area
543545
stroke_width: 0
546+
opacity: 0.5
544547
transform: return x / 2 - 15;
545548
invert: true
546549
color_threshold:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ The card stricly validates all the options available (but not for the `apex_conf
147147
| `attribute` | string | | v1.4.0 | Instead of retrieving the state, it will retrieve an `attribute` of the entity. Make sure you increase `update_delay` if the chart doesn't reflect the last value of the attribute |
148148
| `name` | string | | v1.0.0 | Override the name of the entity |
149149
| `color` | string | | v1.1.0 | Color of the serie. Supported formats: `yellow`, `#aabbcc`, `rgb(128, 128, 128)` or `var(--css-color-variable)` |
150+
| `opacity` | number | `0.7` for `area`<br/>else `1` | NEXT_VERSION | The opacity of the line or filled area, between `0` and `1` |
150151
| `stroke_width` | number | `5` | NEXT_VERSION | Change the width of the line. Only works for `area` and `line` |
151152
| `type` | string | `line` | v1.0.0 | `line`, `area` or `column` are supported for now |
152153
| `curve` | string | `smooth` | v1.0.0 | `smooth` (nice curve), `straight` (direct line between points) or `stepline` (flat line until next point then straight up or down) |

src/apex-layouts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { HomeAssistant } from 'custom-card-helpers';
22
import parse from 'parse-duration';
33
import {
4+
DEFAULT_AREA_OPACITY,
45
DEFAULT_FLOAT_PRECISION,
56
DEFAULT_SERIE_TYPE,
67
HOUR_24,
@@ -89,7 +90,7 @@ export function getLayoutConfig(config: ChartCardConfig, hass: HomeAssistant | u
8990

9091
function getFillOpacity(config: ChartCardConfig): number[] {
9192
return config.series_in_graph.map((serie) => {
92-
return serie.type === 'area' ? 0.7 : 1;
93+
return serie.opacity !== undefined ? serie.opacity : serie.type === 'area' ? DEFAULT_AREA_OPACITY : 1;
9394
});
9495
}
9596

src/apexcharts-card.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ class ChartsCard extends LitElement {
631631

632632
const result = serie.color_threshold.map((thres, index, arr) => {
633633
let color: string | undefined = undefined;
634-
const defaultOp = serie.type === 'line' ? 1 : DEFAULT_AREA_OPACITY;
634+
const defaultOp = serie.opacity !== undefined ? serie.opacity : serie.type === 'area' ? DEFAULT_AREA_OPACITY : 1;
635635
let opacity = thres.opacity === undefined ? defaultOp : thres.opacity;
636636
if (thres.value > max && arr[index - 1]) {
637637
const factor = (max - arr[index - 1].value) / (thres.value - arr[index - 1].value);

src/types-config-ti.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const ChartCardSeriesExternalConfig = t.iface([], {
4646
"name": t.opt("string"),
4747
"type": t.opt(t.union(t.lit('line'), t.lit('column'), t.lit('area'))),
4848
"color": t.opt("string"),
49+
"opacity": t.opt("number"),
4950
"curve": t.opt(t.union(t.lit('smooth'), t.lit('straight'), t.lit('stepline'))),
5051
"stroke_width": t.opt("number"),
5152
"extend_to_end": t.opt("boolean"),

src/types-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export interface ChartCardSeriesExternalConfig {
4242
name?: string;
4343
type?: 'line' | 'column' | 'area';
4444
color?: string;
45+
opacity?: number;
4546
curve?: 'smooth' | 'straight' | 'stepline';
4647
stroke_width?: number;
4748
extend_to_end?: boolean;

0 commit comments

Comments
 (0)