From 526db6da86766cda7362bee7b6a3209e325da89b Mon Sep 17 00:00:00 2001 From: TheSevenPens <98374109+TheSevenPens@users.noreply.github.com> Date: Thu, 1 Oct 2026 04:42:10 -0700 Subject: [PATCH] Fix DrawOrgChart resizing the target page DrawOrgChart renders the chart into a new document, but then resized the page passed as its TargetPage, which does not contain the chart. That shrank the caller's page for no reason (live-verified: an 8.5 x 11 page became 1.51 x 1.51). The chart's own pages are already sized by the render, so the extra resize is removed; the TargetPage now only supplies the application. Adds a regression test that failed before the change. Updates the changelog, test counts, the CLAUDE.md state and priorities, and the Models docs backlog entry. Closes #219 Co-Authored-By: Claude Sonnet 5.5 --- CLAUDE.md | 19 +++++++------- NuGet/CHANGELOG.md | 1 + .../VTest.Models/OrgChartDrawModelTests.cs | 25 +++++++++++++++++++ .../VisioScripting/Commands/ModelCommands.cs | 3 ++- docs/TESTING.md | 4 +-- docs/futures/docs.md | 2 +- 6 files changed, 40 insertions(+), 14 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index a29109143..6849acc89 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -66,10 +66,10 @@ The full suite exercises real Visio COM calls with no mock/fake layer. CI runs o **Start here; the sections below this one that describe earlier sessions are historical.** For build and test setup use [docs/BUILDING.md](docs/BUILDING.md) and [docs/TESTING.md](docs/TESTING.md). - **Releases:** NuGet `VisioAutomation2010` **3.1.0** (tag `VisioAutomation_3.1.0`) and Visio PowerShell module **4.7.3** (tag `VisioPS_4.7.3`) shipped on 2026-09-30. The Release-build change for the NuGet flow ([#181](https://github.com/saveenr/VisioAutomation/issues/181)) is done and closed. -- **Repo:** `master` at `78fe8c6a` (PRs up to #226 merged), no open PRs, working trees clean. The older `claude/*` and `experiment/linq-shapesheet` branches are leftovers from earlier sessions. -- **Unreleased changes** (`NuGet/CHANGELOG.md` `[Unreleased]`, all Fixed): `DrawDataTable` honors widths and heights, `DrawDataTableModel` draws on the target page, `DrawXmlModel` roots the tree at the document element and now has an undo scope, and `DrawDirectedGraphDocument` honors its `DirectedGraphStyling`. The next version is not decided; these are fixes only, so a patch release is the likely fit. -- **Tests:** 258 tests across four projects (VTest 108, VTest.Models 80, VTest.Scripting 43, VTest.PowerShell 27). The last full Release run (256) was on 2026-09-30; the two newest tests are the regression tests for [#197](https://github.com/saveenr/VisioAutomation/issues/197) and [#222](https://github.com/saveenr/VisioAutomation/issues/222). -- **Docs:** the .NET GitBook's Diagram models section was reorganized on 2026-10-01 (docs repo PRs 8 and 9, live). Every model page now has a "Where the output goes" section; the DOM page has a render performance page beneath it. The 2026-09 entries on the docs-updates page record each change. The "Models docs follow-ups" entry in [`docs/futures/docs.md`](docs/futures/docs.md) lists which doc statements to revisit when each source issue below is decided, and the release-gated "unreleased" notes to turn into version statements at the next release. The fixes for [#197](https://github.com/saveenr/VisioAutomation/issues/197) and [#222](https://github.com/saveenr/VisioAutomation/issues/222) are not yet described in the docs. +- **Repo:** `master` at `92dec356` (PRs up to #227 merged), no open PRs, working trees clean. The older `claude/*` and `experiment/linq-shapesheet` branches are leftovers from earlier sessions. +- **Unreleased changes** (`NuGet/CHANGELOG.md` `[Unreleased]`, all Fixed): `DrawDataTable` honors widths and heights, `DrawDataTableModel` draws on the target page, `DrawXmlModel` roots the tree at the document element and now has an undo scope, `DrawDirectedGraphDocument` honors its `DirectedGraphStyling`, and `DrawOrgChart` no longer resizes the page you pass it. The next version is not decided; these are fixes only, so a patch release is the likely fit. +- **Tests:** 259 tests across four projects (VTest 108, VTest.Models 81, VTest.Scripting 43, VTest.PowerShell 27). The last full Release run (256) was on 2026-09-30; the three newest tests are the regression tests for [#197](https://github.com/saveenr/VisioAutomation/issues/197), [#222](https://github.com/saveenr/VisioAutomation/issues/222) and [#219](https://github.com/saveenr/VisioAutomation/issues/219). +- **Docs:** the .NET GitBook's Diagram models section was reorganized on 2026-10-01 (docs repo PRs 8 and 9, live). Every model page now has a "Where the output goes" section; the DOM page has a render performance page beneath it. The 2026-09 entries on the docs-updates page record each change. The "Models docs follow-ups" entry in [`docs/futures/docs.md`](docs/futures/docs.md) lists which doc statements to revisit when each source issue below is decided, and the release-gated "unreleased" notes to turn into version statements at the next release. The [#219](https://github.com/saveenr/VisioAutomation/issues/219) fix is described in the docs as an unreleased change; the fixes for [#197](https://github.com/saveenr/VisioAutomation/issues/197) and [#222](https://github.com/saveenr/VisioAutomation/issues/222) are not yet described. - **Docs conventions:** no em-dashes in either GitBook. The docs repos publish when a PR merges to `main`, and each PR gets a GitBook preview. Cite the issue number on any page that describes behavior an open issue may change. - **Docs viewer:** the local GitBook viewer now lives in its own private repo, `TheSevenPens/LocalGitbookviewer` (cloned at `C:/Users/savee/Documents/GitHub/LocalGitbookviewer`). Run `view.cmd ` from that checkout. Its backlog is in that repo's `BACKLOG.md`. - **GitHub accounts:** the `gh` CLI is logged in as both `saveenr` and `TheSevenPens`, with `saveenr` active (this repo and the docs repos live under `saveenr`). Commits are authored as `TheSevenPens`. Switch with `gh auth switch --user TheSevenPens` before running `gh` against a `TheSevenPens` repo. @@ -183,13 +183,12 @@ Issues closed: [#131](https://github.com/saveenr/VisioAutomation/issues/131), [# ## Next session priorities -Roughly in the order worth doing. Pick from the top. +Roughly in the order worth doing. Pick from the top. ([#219](https://github.com/saveenr/VisioAutomation/issues/219) was the first item and is now fixed.) -1. **[#219](https://github.com/saveenr/VisioAutomation/issues/219) `DrawOrgChart` resizes the wrong page.** Small, well understood fix: remove the stray `targetpage.Page.ResizeToFitContents()` in `ModelCommands.DrawOrgChart`. Needs a changelog entry under Fixed, a test, and a docs update (the org chart page and the `client.Model` reference row cite the issue). Reproduction is in the issue. -2. **Decide the three public types with no real caller, together:** [#218](https://github.com/saveenr/VisioAutomation/issues/218) Box layout, [#220](https://github.com/saveenr/VisioAutomation/issues/220) form page model, [#221](https://github.com/saveenr/VisioAutomation/issues/221) `ContainerLayout` (draws plain rectangles; the `ContainerMaster` option is never read). The options are in each issue; the docs side of each is listed in the "Models docs follow-ups" backlog entry. -3. **Cut the next release when ready.** Versions are not decided (fixes only, so likely 3.1.1 and a PS module patch). The flow is in [`docs/futures/releases.md`](docs/futures/releases.md). At release time also turn the "unreleased" notes in both GitBooks into version statements and add the new versions to both version-compatibility pages. -4. **Design discussions, not yet quick:** [#223](https://github.com/saveenr/VisioAutomation/issues/223) `client.Model` draw methods are inconsistent, [#225](https://github.com/saveenr/VisioAutomation/issues/225) expose every directed graph option in the XML format, and [#198](https://github.com/saveenr/VisioAutomation/issues/198) / [#199](https://github.com/saveenr/VisioAutomation/issues/199) drawing a single directed graph onto the current page. -5. **Earlier backlog:** [#191](https://github.com/saveenr/VisioAutomation/issues/191) migrate cmdlets to `ThrowTerminatingError` (makes `InvokeScriptStrict` redundant), [#190](https://github.com/saveenr/VisioAutomation/issues/190) the `VTest.PowerShell` two-Client mismatch, [#183](https://github.com/saveenr/VisioAutomation/issues/183) VisioScripting dead-method removal (CY27Q1; re-verify zero callers first), [#173](https://github.com/saveenr/VisioAutomation/issues/173) more cmdlet-binding tests (about 50 cmdlets still untested), [#163](https://github.com/saveenr/VisioAutomation/issues/163) and [#164](https://github.com/saveenr/VisioAutomation/issues/164) (the `PSCmdlet` question; see the memory note on why cmdlets derive from `Cmdlet`). +1. **Decide the three public types with no real caller, together:** [#218](https://github.com/saveenr/VisioAutomation/issues/218) Box layout, [#220](https://github.com/saveenr/VisioAutomation/issues/220) form page model, [#221](https://github.com/saveenr/VisioAutomation/issues/221) `ContainerLayout` (draws plain rectangles; the `ContainerMaster` option is never read). The options are in each issue; the docs side of each is listed in the "Models docs follow-ups" backlog entry. +2. **Cut the next release when ready.** Versions are not decided (fixes only, so likely 3.1.1 and a PS module patch). The flow is in [`docs/futures/releases.md`](docs/futures/releases.md). At release time also turn the "unreleased" notes in both GitBooks into version statements and add the new versions to both version-compatibility pages. +3. **Design discussions, not yet quick:** [#223](https://github.com/saveenr/VisioAutomation/issues/223) `client.Model` draw methods are inconsistent, [#225](https://github.com/saveenr/VisioAutomation/issues/225) expose every directed graph option in the XML format, and [#198](https://github.com/saveenr/VisioAutomation/issues/198) / [#199](https://github.com/saveenr/VisioAutomation/issues/199) drawing a single directed graph onto the current page. +4. **Earlier backlog:** [#191](https://github.com/saveenr/VisioAutomation/issues/191) migrate cmdlets to `ThrowTerminatingError` (makes `InvokeScriptStrict` redundant), [#190](https://github.com/saveenr/VisioAutomation/issues/190) the `VTest.PowerShell` two-Client mismatch, [#183](https://github.com/saveenr/VisioAutomation/issues/183) VisioScripting dead-method removal (CY27Q1; re-verify zero callers first), [#173](https://github.com/saveenr/VisioAutomation/issues/173) more cmdlet-binding tests (about 50 cmdlets still untested), [#163](https://github.com/saveenr/VisioAutomation/issues/163) and [#164](https://github.com/saveenr/VisioAutomation/issues/164) (the `PSCmdlet` question; see the memory note on why cmdlets derive from `Cmdlet`). **Calendar-bound** diff --git a/NuGet/CHANGELOG.md b/NuGet/CHANGELOG.md index 65858f2fc..8df20e1ab 100644 --- a/NuGet/CHANGELOG.md +++ b/NuGet/CHANGELOG.md @@ -13,6 +13,7 @@ The format follows [Keep a Changelog 1.1.0](https://keepachangelog.com/en/1.1.0/ ## [Unreleased] ### Fixed +- `Client.Model.DrawOrgChart`, and so `Out-VisioApplication -OrgChart`, no longer resizes the page passed as its `TargetPage`. The chart is drawn in a new document, and each of its pages is already sized by the render, but the call also resized the caller's own page to fit its contents, which shrank that page for no reason. The `TargetPage` now only supplies the application. Closes [#219](https://github.com/saveenr/VisioAutomation/issues/219). - `Client.Model.DrawDirectedGraphDocument` now honors its `DirectedGraphStyling` parameter. Previously the argument was accepted and ignored, so every page was drawn with the default styling (the `Dynamic Connector` master from `connec_u.vss`). A null styling still means the default. Closes [#197](https://github.com/saveenr/VisioAutomation/issues/197). - `Client.Model.DrawXmlModel` is now wrapped in an undo scope, like `DrawGrid` and `DrawDataTable`, so a single Undo removes the whole drawing. Previously Undo did not remove it. Closes [#222](https://github.com/saveenr/VisioAutomation/issues/222). - `Client.Model.DrawDataTable` now honors its `widths` and `heights` arguments, and `DataTableModel.CellWidth` / `CellHeight` now take effect. Previously every cell was drawn 1 x 1 inch and only the spacing was used. **Behavior change:** a caller that passed sizes other than 1 inch will now get a resized table. A column or row beyond the end of its list keeps the 1 inch default, a zero or negative size throws `ArgumentOutOfRangeException`, and `DataTableModel` now defaults `CellWidth` and `CellHeight` to 1.0 so a model that does not set them draws exactly as before. Closes [#206](https://github.com/saveenr/VisioAutomation/issues/206). diff --git a/VisioAutomation_2010/VTest.Models/OrgChartDrawModelTests.cs b/VisioAutomation_2010/VTest.Models/OrgChartDrawModelTests.cs index 23b1cdf37..78a7d46f8 100644 --- a/VisioAutomation_2010/VTest.Models/OrgChartDrawModelTests.cs +++ b/VisioAutomation_2010/VTest.Models/OrgChartDrawModelTests.cs @@ -26,6 +26,31 @@ public void RenderOrgChart_FromSampleData_DoesNotThrow() client.Document.CloseDocument(VisioScripting.TargetDocuments.Auto); } + [MUT.TestMethod] + public void DrawOrgChart_DrawsInANewDocumentAndLeavesTheTargetPageAlone() + { + var orgchart = new VAORGCHART.OrgChartDocument(); + orgchart.OrgCharts.Add(new VAORGCHART.Node("A")); + + var client = this.GetScriptingClient(); + client.Document.NewDocument(); + var app = this.GetVisioApplication(); + var target_doc = app.ActiveDocument; + var target_page = app.ActivePage; + target_page.DrawRectangle(new VA.Core.Rectangle(1, 1, 2, 2)); + double width_before = target_page.PageSheet.CellsU["PageWidth"].ResultIU; + double height_before = target_page.PageSheet.CellsU["PageHeight"].ResultIU; + + client.Model.DrawOrgChart(VisioScripting.TargetPage.Auto, orgchart); + + MUT.Assert.AreNotEqual(target_doc.ID, app.ActiveDocument.ID, "the chart should be drawn in a new document"); + MUT.Assert.AreEqual(width_before, target_page.PageSheet.CellsU["PageWidth"].ResultIU, 1e-9, "the target page width should not change"); + MUT.Assert.AreEqual(height_before, target_page.PageSheet.CellsU["PageHeight"].ResultIU, 1e-9, "the target page height should not change"); + + app.ActiveDocument.Close(true); + target_doc.Close(true); + } + private void draw_org_chart(VisioScripting.Client client, string text) { var xmldoc = SXL.XDocument.Parse(text); diff --git a/VisioAutomation_2010/VisioScripting/Commands/ModelCommands.cs b/VisioAutomation_2010/VisioScripting/Commands/ModelCommands.cs index 5a3f0d827..563f4d6e9 100644 --- a/VisioAutomation_2010/VisioScripting/Commands/ModelCommands.cs +++ b/VisioAutomation_2010/VisioScripting/Commands/ModelCommands.cs @@ -165,10 +165,11 @@ public void DrawOrgChart(VisioScripting.TargetPage targetpage, ORG.OrgChartDocum this._client.Output.WriteVerbose("Start OrgChart Rendering"); + // The chart is rendered into a new document, and each of its pages is sized by the render itself. + // The target page is only used to find the application and is left unchanged. var application = targetpage.Page.Application; chartdocument.Render(application); - targetpage.Page.ResizeToFitContents(); this._client.Output.WriteVerbose("Finished OrgChart Rendering"); } diff --git a/docs/TESTING.md b/docs/TESTING.md index 8a4fd0829..408c6a73f 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -9,11 +9,11 @@ All under `VisioAutomation_2010/`: | Project | Tests | Library under test | README | |---|---:|---|---| | `VTest` | 108 | `VisioAutomation` (core) | [VTest/README.md](../VisioAutomation_2010/VTest/README.md) | -| `VTest.Models` | 80 | `VisioAutomation.Models` (DOM, layouts) | [VTest.Models/README.md](../VisioAutomation_2010/VTest.Models/README.md) | +| `VTest.Models` | 81 | `VisioAutomation.Models` (DOM, layouts) | [VTest.Models/README.md](../VisioAutomation_2010/VTest.Models/README.md) | | `VTest.Scripting` | 43 | `VisioScripting` (high-level facade) | [VTest.Scripting/README.md](../VisioAutomation_2010/VTest.Scripting/README.md) | | `VTest.PowerShell` | 27 | `VisioPowerShell` (cmdlets) | [VTest.PowerShell/README.md](../VisioAutomation_2010/VTest.PowerShell/README.md) | -256 tests passed with no skips on 2026-09-30 (Release build of `master` at `581ad539`). Two regression tests have since been added to `VTest.Models` (`DrawXmlModel_IsUndoneByASingleUndo` and `DrawDirectedGraphDocument_UsesTheEdgeMasterFromTheStylingParameter`); a Debug run of `VTest.Models`, `VTest.Scripting` and `VTest.PowerShell` on 2026-10-01 passed 80, 43 and 27 tests. Counts come from the Release TRX. [HANDOVER.md](HANDOVER.md) records the environment and the original evidence, taken at 237 tests on 2026-09-29. +256 tests passed with no skips on 2026-09-30 (Release build of `master` at `581ad539`). Three regression tests have since been added to `VTest.Models` (`DrawXmlModel_IsUndoneByASingleUndo`, `DrawDirectedGraphDocument_UsesTheEdgeMasterFromTheStylingParameter` and `DrawOrgChart_DrawsInANewDocumentAndLeavesTheTargetPageAlone`); a Debug run of `VTest.Models`, `VTest.Scripting` and `VTest.PowerShell` on 2026-10-01 passed 81, 43 and 27 tests. Counts come from the Release TRX. [HANDOVER.md](HANDOVER.md) records the environment and the original evidence, taken at 237 tests on 2026-09-29. ## Framework: MSTest 4.x diff --git a/docs/futures/docs.md b/docs/futures/docs.md index f417514eb..cdcc5fbbc 100644 --- a/docs/futures/docs.md +++ b/docs/futures/docs.md @@ -62,7 +62,7 @@ Backlog of documentation items, both in-repo developer docs and the user-facing - **Decide whether `Models.Color`, `Models.Text` and `Models.Geometry` need pages** or are internal helpers. Only incidental mentions exist today. This one is not release-gated. - **Revisit the model pages as the source issues raised by the 2026-10 reorganization are decided.** The reorganized Diagram models section (merged to the docs repo in PR 8) states current behavior that these issues may change, so each page needs a second look when its issue is resolved: - [#218](https://github.com/saveenr/VisioAutomation/issues/218) Box layout: `models/box-geometry.md` (opening paragraph), the Box rows on `models/introduction.md`, and the Layout models overview. If Box is deprecated, removed or given a renderer, rewrite or remove the page. - - [#219](https://github.com/saveenr/VisioAutomation/issues/219) `DrawOrgChart` resizes the wrong page: the org chart page's "Where the output goes" table and "Why a new document" paragraph, and the `DrawOrgChart` row on `visio-scripting/model.md`. + - [#219](https://github.com/saveenr/VisioAutomation/issues/219) `DrawOrgChart` resized the wrong page (fixed, unreleased): the org chart page and the `DrawOrgChart` row on `visio-scripting/model.md` describe it as an unreleased change after NuGet 3.1.0. Turn those notes into version statements at the next release, together with the [#206](https://github.com/saveenr/VisioAutomation/issues/206) to [#208](https://github.com/saveenr/VisioAutomation/issues/208) notes above. - [#220](https://github.com/saveenr/VisioAutomation/issues/220) Form page model: the developer-commands line on `models/forms.md` and the VisioScripting remark on `models/documents.md`. If the model is demoted or made internal, the Document models page and its table of contents entry change. - [#221](https://github.com/saveenr/VisioAutomation/issues/221) `ContainerLayout` draws plain rectangles: the opening and options paragraphs on `models/layouts-container.md` and the Container row on `models/layouts.md`. - [#222](https://github.com/saveenr/VisioAutomation/issues/222) `DrawXmlModel` has no undo scope: the sentence on `visio-scripting/model.md` that only the grid and table renderers wrap their writes in an undo scope.