Skip to content

Commit

Permalink
Add logarithmic scale option to Statistics graph card
Browse files Browse the repository at this point in the history
  • Loading branch information
wittypluck committed Nov 12, 2023
1 parent 9417f13 commit d110d8d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/components/chart/statistics-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export class StatisticsChart extends LitElement {

@property({ type: Boolean }) public hideLegend = false;

@property({ type: Boolean }) public logarithmicScale = false;

@property({ type: Boolean }) public isLoadingData = false;

@property() public period?: string;
Expand Down Expand Up @@ -98,7 +100,8 @@ export class StatisticsChart extends LitElement {
!this.hasUpdated ||
changedProps.has("unit") ||
changedProps.has("period") ||
changedProps.has("chartType")
changedProps.has("chartType") ||
changedProps.has("logarithmicScale")
) {
this._createOptions();
}
Expand Down Expand Up @@ -198,6 +201,7 @@ export class StatisticsChart extends LitElement {
display: unit || this.unit,
text: unit || this.unit,
},
type: this.logarithmicScale ? "logarithmic" : "linear",
},
},
plugins: {
Expand Down
1 change: 1 addition & 0 deletions src/panels/lovelace/cards/hui-statistics-graph-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
.names=${this._names}
.unit=${this._unit}
.hideLegend=${this._config.hide_legend || false}
.logarithmicScale=${this._config.logarithmic_scale || false}
></statistics-chart>
</div>
</ha-card>
Expand Down
1 change: 1 addition & 0 deletions src/panels/lovelace/cards/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ export interface StatisticsGraphCardConfig extends LovelaceCardConfig {
stat_types?: StatisticType | StatisticType[];
chart_type?: "line" | "bar";
hide_legend?: boolean;
logarithmic_scale?: boolean;
}

export interface StatisticCardConfig extends LovelaceCardConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const cardConfigStruct = assign(
stat_types: optional(union([array(statTypeStruct), statTypeStruct])),
unit: optional(string()),
hide_legend: optional(boolean()),
logarithmic_scale: optional(boolean()),
})
);

Expand Down Expand Up @@ -211,6 +212,11 @@ export class HuiStatisticsGraphCardEditor
required: false,
selector: { boolean: {} },
},
{
name: "logarithmic_scale",
required: false,
selector: { boolean: {} },
},
],
},
];
Expand Down Expand Up @@ -347,6 +353,7 @@ export class HuiStatisticsGraphCardEditor
case "period":
case "unit":
case "hide_legend":
case "logarithmic_scale":
return this.hass!.localize(
`ui.panel.lovelace.editor.card.statistics-graph.${schema.name}`
);
Expand Down
4 changes: 3 additions & 1 deletion src/resources/chartjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Chart,
BarElement,
BarController,
LogarithmicScale,
} from "chart.js";
import { TextBarElement } from "../components/chart/timeline-chart/textbar-element";
import { TimelineController } from "../components/chart/timeline-chart/timeline-controller";
Expand All @@ -35,5 +36,6 @@ Chart.register(
TextBarElement,
TimeLineScale,
TimelineController,
CategoryScale
CategoryScale,
LogarithmicScale
);
3 changes: 2 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4997,7 +4997,8 @@
},
"pick_statistic": "Add a statistic",
"picked_statistic": "Statistic",
"hide_legend": "Hide legend"
"hide_legend": "Hide legend",
"logarithmic_scale": "Logarithmic scale"
},
"statistic": {
"name": "Statistic",
Expand Down

0 comments on commit d110d8d

Please sign in to comment.