Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ The modules form one product. Judge code, tests, docs and these rules as a whole
A module without `package.json` is PowerShell only (the demo modules with their app in `Apps/`).
A module's `Build.psd1` names files from elsewhere in the repository the build copies into it (the
pivot demo carries the site's examples and data snapshots and the pivot showcase), so each is defined once.
- `shared/js/` - JavaScript used by several modules: the PSU theme bridge, column matching and the answer
- `shared/js/` - JavaScript used by several modules: the PSU theme bridge, the latest props for handlers
registered once (`useLatest.js`), column matching and the answer
to `Get-UDElement` in `elementState.js`. Compiled into each module's bundle; never a runtime dependency
between modules. Formats, the CSV/XLSX export and text contrast on fills serve only the ECharts module
and live in its `Components/`.
Expand Down
4 changes: 2 additions & 2 deletions build/growth-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"modules/PowerShellUniversal.Component.ECharts/Components/cartesian.js Arrow function": [35]
},
"lines": {
"Function 'EChart'": [276],
"Function 'Perspective'": [138],
"Function 'EChart'": [254],
"Function 'Perspective'": [135],
"Function 'cartesian'": [337],
"modules/PowerShellUniversal.Component.ECharts/Components/EChart.jsx Arrow function": [127]
}
Expand Down
13 changes: 7 additions & 6 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// `npm run lint`: ESLint's recommended rules, which find real errors (undefined names, unreachable
// code, unused variables), and the rules of hooks for the React code. Formatting is left to
// code, unused variables), and the React hooks rules for the React code. Formatting is left to
// .editorconfig. Function length and complexity are no rules here: they are a ratchet in
// build/growth.js (`npm run growth`), because today's long functions would fail a rule. Both read the
// same code the same way (build/javascript-sources.js).
Expand Down Expand Up @@ -42,12 +42,13 @@ export default [
languageOptions: { globals: { ...globals.browser, UniversalDashboard: "readonly", require: "readonly", __PIVOT_IMPORT_WORKER__: "readonly" } },
},
{
// a broken rule of hooks fails. A missing effect dependency only warns: the components keep
// the latest props in a ref for event handlers registered once, which this rule cannot see.
// The React Compiler rules of the plugin's recommended set stay off: they flag that same
// ref pattern, and the modules are not built with the React Compiler
// the plugin's recommended rules for React 18 code, with a missing effect dependency as an
// error too: the rules of hooks and the React Compiler's checks (no ref read or written during
// render, no setState in an effect body). Props that handlers registered once need are kept in a
// ref written in an effect (shared/js/useLatest.js); a dependency left out on purpose is
// disabled on its line with the reason
files: BROWSER,
plugins: { "react-hooks": reactHooks },
rules: { "react-hooks/rules-of-hooks": "error", "react-hooks/exhaustive-deps": "warn" },
rules: { ...reactHooks.configs["recommended-latest"].rules, "react-hooks/exhaustive-deps": "error" },
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,12 @@ New-UDApp -Title 'ECharts for PowerShell Universal' -Pages @(
}
New-UDGrid -Item -ExtraSmallSize 12 -MediumSize 8 -Content {
New-UDCard -Title 'Opened per day: this period vs previous period' -Content {
# last 60 days against the 60 before, aligned by day number
$today = (Get-Date).Date
# the last 60 days of the data against the 60 before, aligned by day number. The period
# ends on the newest ticket's day, not today: the data ends yesterday and stays in
# $Cache: for days, so counting up to today would show days without data as zeros
$lastDay = ($tickets.Created | Measure-Object -Maximum).Maximum.Date
$perDay = foreach ($offset in 0..59) {
$now = $today.AddDays(-59 + $offset)
$now = $lastDay.AddDays(-59 + $offset)
$before = $now.AddDays(-60)
[pscustomobject]@{
Day = 'Day {0}' -f ($offset + 1)
Expand All @@ -202,7 +204,7 @@ New-UDApp -Title 'ECharts for PowerShell Universal' -Pages @(
}
}
New-UDEChart -Data $perDay -Type line -X Day -Y Current, Previous -Smooth -Height 260px -MarkLine average `
-Options @{ series = @(@{ name = 'This period' }, @{ name = 'Previous period'; lineStyle = @{ type = 'dashed' }; itemStyle = @{ opacity = 0.6 } }) }
-Options @{ series = @(@{ name = 'This period' }, @{ name = 'Previous period'; lineStyle = @{ type = 'dashed' }; itemStyle = @{ opacity = 0.6 }; markLine = @{ label = @{ position = 'insideStartBottom' } } }) }
}
}
New-UDGrid -Item -ExtraSmallSize 12 -MediumSize 6 -Content {
Expand Down Expand Up @@ -246,7 +248,7 @@ New-UDApp -Title 'ECharts for PowerShell Universal' -Pages @(
New-UDGrid -Item -ExtraSmallSize 12 -Content {
New-UDCard -Title 'Tickets per day: select a range (brush button) to filter the table' -Content {
$daily = $tickets | Group-Object { $_.Created.Date } | ForEach-Object {
[pscustomobject]@{ Day = [datetime]$_.Name; Opened = $_.Count; P1 = @($_.Group | Where-Object Priority -EQ 'P1').Count }
[pscustomobject]@{ Day = $_.Group[0].Created.Date; Opened = $_.Count; P1 = @($_.Group | Where-Object Priority -EQ 'P1').Count }
} | Sort-Object Day
New-UDEChart -Data $daily -Type bar -X Day -Y Opened, P1 -SecondaryY P1 -SecondaryTitle 'P1' -Zoom Both -Brush -Height 320px `
-Options @{ series = @(@{}, @{ type = 'line'; smooth = $true }) } -OnSelect {
Expand Down
10 changes: 10 additions & 0 deletions modules/PowerShellUniversal.Component.ECharts.Demo/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ All notable changes to PowerShellUniversal.Component.ECharts.Demo. Format:
The diverging survey chart lost an `-Options` entry that changed nothing.
- The help and README say that the generated data counts its dates from today.

### Fixed

- Ticket report, "Opened per day: this period vs previous period": the period ends on the day of the
newest ticket. Before, it ended today, and the generated tickets end yesterday and stay cached for
days, so the last days of "This period" dropped to 0.
- The same chart labels the previous period's average at the start of its line. The two "Average"
labels overlapped at the right edge when the averages were close.
- The "Tickets per day" chart of the Ticket report no longer fails on a server whose culture writes
dates other than en-US does, such as de-DE.

## [0.3.0] - 2026-11-09

### Changed
Expand Down
4 changes: 4 additions & 0 deletions modules/PowerShellUniversal.Component.ECharts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ All notable changes to PowerShellUniversal.Component.ECharts. Format:
`New-UDEChart` runs its steps through helpers. Commands, parameters, help and output are unchanged
([#169](https://github.com/eizedev/powershell-universal-components/issues/169)).
- The help of `-Value`, `-Path`, `-Source` and `-Target` names every chart type that reads them.
- The component passes the React hooks lint rules, which are now errors in CI: the latest props
for its event handlers are kept in a ref written in an effect, not during render
([#217](https://github.com/eizedev/powershell-universal-components/issues/217)). Clicks, selections, zoom, the
export buttons and the theme switch work as before.

## [0.3.1] - 2026-11-22

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useMemo, useRef, useState } from "react";
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
import * as echarts from "echarts";
import { buildOption, dataRows, rowOf, responsive, optionForWidth, tooltipTracksHover, NARROW, TINY } from "./buildOption";
import { tooltipState } from "./tooltipMode";
Expand All @@ -11,6 +11,7 @@ import { defaultLocale } from "./formatters.js";
import { toCsv, toXlsxBytes, download, safeFileName } from "./exporter.js";
import { pickColumns } from "../../../shared/js/columns";
import { answerStateRequests } from "../../../shared/js/elementState";
import { useLatest } from "../../../shared/js/useLatest";

// components replaced (not merged) on every update, so a live update that changes the shape of the
// chart leaves no stale axes or coordinate systems behind; zoom and legend state are kept
Expand All @@ -32,6 +33,30 @@ function fullscreenElement() {
return document.fullscreenElement || document.webkitFullscreenElement || null;
}

// CSV/Excel of the rows behind the chart (p: the chart's props), columns and types from -ExportColumns
function exportRows(kind, p) {
const name = safeFileName(p.exportFileName || p.title, "chart");
const data = p.data || [];
if (kind === "csv") {
download(`${name}.csv`, toCsv(data, p.exportColumns, defaultLocale(p.locale)), "text/csv;charset=utf-8");
} else {
download(`${name}.xlsx`, toXlsxBytes(data, p.exportColumns, p.title || "Data"), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
}

// the chart (its outer element) alone on the whole screen and back (Esc or the button); zoom,
// selection and the hidden series stay, because it is the same chart
function toggleFullscreen(el) {
if (!el) {
return;
}
if (fullscreenElement() === el) {
(document.exitFullscreen || document.webkitExitFullscreen).call(document);
} else {
(el.requestFullscreen || el.webkitRequestFullscreen).call(el);
}
}

/*
* Values from ECharts events turned into something PowerShell can use: time axis values (epoch ms)
* become ISO strings, category indices become the category names.
Expand Down Expand Up @@ -59,19 +84,21 @@ export default function EChart(props) {
const mode = effectiveMode(props.theme, psuTheme);
const locale = defaultLocale(props.locale);
// -LightTheme / -DarkTheme: the corporate ECharts theme for the current mode
const customTheme = mode === "dark" ? props.darkTheme : props.lightTheme;
const customKey = customTheme ? JSON.stringify(customTheme) : "";
const customProp = mode === "dark" ? props.darkTheme : props.lightTheme;
const customKey = customProp ? JSON.stringify(customProp) : "";
// one object per content: PSU sends the theme anew with every update of the props, which must
// not set the theme again
const customTheme = useMemo(() => (customKey ? JSON.parse(customKey) : undefined), [customKey]);
// the latest props for event handlers registered once
const latest = useRef(props);
latest.current = props;
const latest = useLatest(props);
// Get-UDElement: the last click, range and zoom, kept here because PSU asks for them synchronously
// (shared/js/elementState.js). The component's state holds them too; the wrapper's late POST sends
// that copy, which PSU ignores
const elementState = useRef({});
const remember = (part) => {
const remember = useCallback((part) => {
elementState.current = { ...elementState.current, ...part };
if (typeof latest.current.setState === "function") latest.current.setState(part);
};
}, [latest]);
useEffect(() => {
const pubsub = typeof window !== "undefined" ? window.UniversalDashboard : undefined;
elementState.current = {};
Expand All @@ -91,42 +118,20 @@ export default function EChart(props) {
try {
const exportIcons = {
...EXPORT_ICONS,
onCsv: props.export === false ? undefined : () => exportAs("csv"),
onXlsx: props.export === false ? undefined : () => exportAs("xlsx"),
onFullscreen: props.fullscreen === false || !canFullscreen() ? undefined : () => toggleFullscreen()
onCsv: props.export === false ? undefined : () => exportRows("csv", latest.current),
onXlsx: props.export === false ? undefined : () => exportRows("xlsx", latest.current),
onFullscreen: props.fullscreen === false || !canFullscreen() ? undefined : () => toggleFullscreen(outer.current)
};
// the option only keeps these: the buttons read the props and the element when clicked, the
// tooltip formatter reads its state on hover, never during render
// eslint-disable-next-line react-hooks/refs
const base = buildOption(props, { locale, exportIcons, mode, tooltipState: tipState.current });
return { value: base, rules: responsive(base, props, { locale }) };
} catch (e) {
return { error: e.message };
}
}, [props, locale, mode]);
}, [props, locale, mode, latest]);

// CSV/Excel of the rows behind the chart, columns and types from -ExportColumns
function exportAs(kind) {
const p = latest.current;
const name = safeFileName(p.exportFileName || p.title, "chart");
const data = p.data || [];
if (kind === "csv") {
download(`${name}.csv`, toCsv(data, p.exportColumns, defaultLocale(p.locale)), "text/csv;charset=utf-8");
} else {
download(`${name}.xlsx`, toXlsxBytes(data, p.exportColumns, p.title || "Data"), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
}

// the chart alone on the whole screen and back (Esc or the button); zoom, selection and the
// hidden series stay, because it is the same chart
function toggleFullscreen() {
const el = outer.current;
if (!el) {
return;
}
if (fullscreenElement() === el) {
(document.exitFullscreen || document.webkitExitFullscreen).call(document);
} else {
(el.requestFullscreen || el.webkitRequestFullscreen).call(el);
}
}
useEffect(() => {
const onChange = () => setFull(fullscreenElement() === outer.current);
document.addEventListener("fullscreenchange", onChange);
Expand All @@ -141,8 +146,7 @@ export default function EChart(props) {
// limit, or - for charts without a grid, whose plot is placed by size (fitPlot) - when the size or
// the number of legend lines changes noticeably
const [layoutKey, setLayoutKey] = useState("wide");
const latestOption = useRef(null);
latestOption.current = option.value;
const latestOption = useLatest(option.value);
const keyOf = (w, h) => {
const base = w <= TINY ? "tiny" : w <= NARROW ? "narrow" : "wide";
const o = latestOption.current;
Expand Down Expand Up @@ -176,6 +180,9 @@ export default function EChart(props) {
chart.dispose();
chartRef.current = null;
};
// made again only for another renderer or locale: the theme is the starting one, a new theme
// goes to the living chart (next effect), so zoom, legend and brush stay
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [props.renderer, locale]);

// theme follows PSU's light/dark switch
Expand All @@ -184,7 +191,7 @@ export default function EChart(props) {
if (chart) {
chart.setTheme(ensureTheme(echarts, mode, psuTheme, customTheme));
}
}, [mode, psuTheme.text, customKey]);
}, [mode, psuTheme, customTheme]);

// option: series, axes and datasets are replaced, zoom and legend state survive data updates.
// After the width rules and the text sizes: the plot of a chart without a grid placed clear of title, toolbox and
Expand All @@ -202,7 +209,7 @@ export default function EChart(props) {
chart.setOption(insideLabelColors(placed, theme.color, theme.textStyle && theme.textStyle.color), { replaceMerge: REPLACED });
// the series are as built again (a toolbox switch to line, bar or stack is gone)
tipState.current.live = null;
}, [option, layoutKey, mode, psuTheme.text, customKey]);
}, [option, layoutKey, mode, psuTheme, customTheme, props.options]);

// linked charts: same -Group share tooltip, zoom and legend; a removed group unlinks the chart
useEffect(() => {
Expand Down Expand Up @@ -358,7 +365,7 @@ export default function EChart(props) {
chart.off("datazoom", onZoom);
chart.off("legendselectchanged", onLegend);
};
}, [option]);
}, [option, latest, remember]);

return (
// -ClassName and -Style as on PSU's own components; -Width wins over a width in -Style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ All notable changes to PowerShellUniversal.Component.Perspective. Format:
before, about 40 ms now, measured on a PSU test instance): no function call per cell, and large
DataTables go through a small class compiled on first use (Add-Type, once per PSU process). The rows
the component gets are the same as before.
- The component passes the React hooks lint rules, which are now errors in CI: the latest props
for its event handlers are kept in a ref written in an effect, not during render
([#217](https://github.com/eizedev/powershell-universal-components/issues/217)). Clicks, the toolbar and the theme switch
work as before.

### Fixed

- New `columnNames` with the same rows (`Set-UDElement -Properties @{ columnNames = ... }`) reach the
viewer. Before, they waited for the next new data. As with new columns in the data, the view then
starts again from the parameters.
- In dark mode, the chart picker at the top of the editor no longer turns white under the mouse.
- When new rows hold a value the table refuses, the viewer frees the half-built table in its worker.
Before, its memory stayed until the reader closed the page.
Expand Down
Loading
Loading