Skip to content

Commit

Permalink
feat(series): Direct support for dashed lines
Browse files Browse the repository at this point in the history
Closes #413
  • Loading branch information
RomRider committed Jul 5, 2024
1 parent 998cb99 commit 29aad77
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions .devcontainer/ui-lovelace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,7 @@ views:
entity: sensor.random_0_1000
- entity: sensor.random0_100
transform: 'return Number(x) + 1230;'
stroke_dash: 2
yaxis:
- min: 0
max: ~1200
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ The card stricly validates all the options available (but not for the `apex_conf
| `color` | string | | v1.1.0 | Color of the serie. Supported formats: `yellow`, `#aabbcc`, `rgb(128, 128, 128)` or `var(--css-color-variable)` |
| `opacity` | number | `0.7` for `area`<br/>else `1` | v1.6.0 | The opacity of the line or filled area, between `0` and `1` |
| `stroke_width` | number | `5` | v1.6.0 | Change the width of the line. Only works for `area` and `line` |
| `stroke_dash` | number | `0` | NEXT_VERSION | Creates a dashed line. The higher the number, the bigger the dash. |
| `type` | string | `line` | v1.0.0 | `line`, `area` or `column` are supported for now |
| `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), `monotoneCubic` (create a monotone cubic spline) |
| ~~`extend_to_end`~~ | ~~boolean~~ | ~~`true`~~ | ~~v1.0.0~~ | **DEPRECATED since v2.0.0** ~~If the last data is older than the end time displayed on the graph, setting to true will extend the value until the end of the timeline. Only works for `line` and `area` types.~~ |
Expand Down
9 changes: 9 additions & 0 deletions src/apex-layouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export function getLayoutConfig(
colors:
config.chart_type === 'pie' || config.chart_type === 'donut' ? ['var(--card-background-color)'] : undefined,
width: getStrokeWidth(config, false),
dashArray: getStrokeDash(config, false),
},
markers: {
showNullDataPoints: false,
Expand Down Expand Up @@ -163,6 +164,7 @@ export function getBrushLayoutConfig(
colors:
config.chart_type === 'pie' || config.chart_type === 'donut' ? ['var(--card-background-color)'] : undefined,
width: getStrokeWidth(config, true),
dashArray: getStrokeDash(config, false),
},
markers: {
showNullDataPoints: false,
Expand Down Expand Up @@ -452,6 +454,13 @@ function getStrokeWidth(config: ChartCardConfig, brush: boolean) {
});
}

function getStrokeDash(config: ChartCardConfig, brush: boolean) {
const series = brush ? config.series_in_brush : config.series_in_graph;
return series.map((serie) => {
return serie.stroke_dash;
});
}

function getFillType(config: ChartCardConfig, brush: boolean) {
if (!config.experimental?.color_threshold) {
return brush ? config.brush?.apex_config?.fill?.type || 'solid' : config.apex_config?.fill?.type || 'solid';
Expand Down
1 change: 1 addition & 0 deletions src/types-config-ti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const ChartCardAllSeriesExternalConfig = t.iface([], {
"opacity": t.opt("number"),
"curve": t.opt(t.union(t.lit('smooth'), t.lit('straight'), t.lit('stepline'), t.lit('monotoneCubic'))),
"stroke_width": t.opt("number"),
"stroke_dash": t.opt("number"),
"extend_to": t.opt(t.union(t.lit(false), t.lit('end'), t.lit('now'))),
"unit": t.opt("string"),
"invert": t.opt("boolean"),
Expand Down
1 change: 1 addition & 0 deletions src/types-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export interface ChartCardAllSeriesExternalConfig {
opacity?: number;
curve?: 'smooth' | 'straight' | 'stepline' | 'monotoneCubic';
stroke_width?: number;
stroke_dash?: number;
extend_to?: false | 'end' | 'now';
unit?: string;
invert?: boolean;
Expand Down

0 comments on commit 29aad77

Please sign in to comment.