Skip to content

Commit

Permalink
web: Use more readable X axis format for solar forecast and day ahead…
Browse files Browse the repository at this point in the history
… prices
  • Loading branch information
photron committed Sep 24, 2024
1 parent 39289cb commit 55db2f1
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
7 changes: 4 additions & 3 deletions software/web/src/modules/day_ahead_prices/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,10 @@ export class DayAheadPrices extends ConfigComponent<"day_ahead_prices/config", {
legend_time_with_minutes={true}
legend_div_ref={this.uplot_legend_div_ref}
aspect_ratio={3}
x_height={30}
x_format={{weekday: 'short', hour: '2-digit'}}
x_height={50}
x_format={{hour: '2-digit', minute: '2-digit'}}
x_padding_factor={0}
x_include_date={true}
y_min={0}
y_max={5}
y_unit={"ct/kWh"}
Expand All @@ -245,7 +246,7 @@ export class DayAheadPrices extends ConfigComponent<"day_ahead_prices/config", {
y_sync_ref={this.uplot_wrapper_flags_ref}
default_fill={true}
only_show_visible={true}
padding={[15, 5, null, null] as uPlot.Padding}
padding={[15, 5, null, null]}
/>
</UplotLoader>
</div>
Expand Down
3 changes: 3 additions & 0 deletions software/web/src/modules/em_energy_analysis/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export class EMEnergyAnalysisStatus extends Component<{}, EMEnergyAnalysisStatus
x_height={30}
x_format={{hour: '2-digit', minute: '2-digit'}}
x_padding_factor={0}
x_include_date={false}
y_min={0}
y_max={1500}
y_unit={"W"}
Expand Down Expand Up @@ -2026,6 +2027,7 @@ export class EMEnergyAnalysis extends Component<EMEnergyAnalysisProps, EMEnergyA
x_height={30}
x_format={{hour: '2-digit', minute: '2-digit'}}
x_padding_factor={0}
x_include_date={false}
y_min={0}
y_max={100}
y_unit={"W"}
Expand Down Expand Up @@ -2054,6 +2056,7 @@ export class EMEnergyAnalysis extends Component<EMEnergyAnalysisProps, EMEnergyA
x_height={30}
x_format={{month: '2-digit', day: '2-digit'}}
x_padding_factor={0.015}
x_include_date={false}
y_min={0}
y_max={10}
y_unit={"kWh"}
Expand Down
3 changes: 3 additions & 0 deletions software/web/src/modules/meters/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ export class Meters extends ConfigComponent<'meters/0/config', MetersProps, Mete
legend_time_with_seconds={true}
aspect_ratio={3}
x_height={30}
x_format={{hour: '2-digit', minute: '2-digit'}}
x_padding_factor={0}
x_include_date={false}
y_diff_min={100}
Expand All @@ -648,6 +649,7 @@ export class Meters extends ConfigComponent<'meters/0/config', MetersProps, Mete
legend_time_with_seconds={false}
aspect_ratio={3}
x_height={50}
x_format={{hour: '2-digit', minute: '2-digit'}}
x_padding_factor={0}
x_include_date={true}
y_min={0}
Expand Down Expand Up @@ -1204,6 +1206,7 @@ export class MetersStatus extends Component<{}, MetersStatusState> {
legend_time_with_seconds={false}
aspect_ratio={3}
x_height={50}
x_format={{hour: '2-digit', minute: '2-digit'}}
x_padding_factor={0}
x_include_date={true}
y_min={0}
Expand Down
5 changes: 3 additions & 2 deletions software/web/src/modules/solar_forecast/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,10 @@ export class SolarForecast extends ConfigComponent<"solar_forecast/config", {},
legend_time_with_minutes={true}
legend_div_ref={this.uplot_legend_div_ref}
aspect_ratio={3}
x_height={30}
x_format={{weekday: 'short', hour: '2-digit'}}
x_height={50}
x_format={{hour: '2-digit', minute: '2-digit'}}
x_padding_factor={0}
x_include_date={true}
y_min={0}
y_max={0.1}
y_unit={"kW"}
Expand Down
3 changes: 2 additions & 1 deletion software/web/src/ts/components/uplot_wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ interface UplotWrapperProps {
legend_div_ref?: RefObject<HTMLDivElement>;
aspect_ratio: number;
x_height: number;
x_format: Intl.DateTimeFormatOptions;
x_padding_factor: number;
x_include_date: boolean;
y_min?: number;
Expand Down Expand Up @@ -142,7 +143,7 @@ export class UplotWrapper extends Component<UplotWrapperProps, {}> {

for (let i = 0; i < splits.length; ++i) {
let date = new Date(splits[i] * 1000);
let value = date.toLocaleString([], {hour: '2-digit', minute: '2-digit'});
let value = date.toLocaleString([], this.props.x_format);

if (this.props.x_include_date && foundIncr >= 3600) {
let year = date.toLocaleString([], {year: 'numeric'});
Expand Down
26 changes: 24 additions & 2 deletions software/web/src/ts/components/uplot_wrapper_2nd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface UplotWrapperProps {
x_height: number;
x_format: Intl.DateTimeFormatOptions;
x_padding_factor: number;
x_include_date: boolean;
y_min?: number;
y_max?: number;
y_unit: string;
Expand Down Expand Up @@ -161,11 +162,32 @@ export class UplotWrapper extends Component<UplotWrapperProps, {}> {
3600 * 72,
3600 * 168,
],
values: (self: uPlot, splits: number[]) => {
values: (self: uPlot, splits: number[], axisIdx: number, foundSpace: number, foundIncr: number) => {
let values: string[] = new Array(splits.length);
let last_year: string = null;
let last_month_and_day: string = null;

for (let i = 0; i < splits.length; ++i) {
values[i] = (new Date(splits[i] * 1000)).toLocaleString([], this.props.x_format);
let date = new Date(splits[i] * 1000);
let value = date.toLocaleString([], this.props.x_format);

if (this.props.x_include_date && foundIncr >= 3600) {
let year = date.toLocaleString([], {year: 'numeric'});
let month_and_day = date.toLocaleString([], {month: '2-digit', day: '2-digit'});

if (year != last_year) {
value += '\n' + date.toLocaleString([], {year: 'numeric', month: '2-digit', day: '2-digit'});
last_year = year;
last_month_and_day = month_and_day;
}

if (month_and_day != last_month_and_day) {
value += '\n' + date.toLocaleString([], {month: '2-digit', day: '2-digit'});
last_month_and_day = month_and_day;
}
}

values[i] = value;
}

return values;
Expand Down

0 comments on commit 55db2f1

Please sign in to comment.