# Pad every trend (chart) in a display file to 50 visible pens so it also draws in the HTML # display (web client). CI Server R1.03.00: the web trend always builds 50 data columns but only # labels the visible pens with an item; with fewer than 50 such pens it draws nothing (ISS-041). # # Spare pens copy the first real pen's source, are scaled far outside the data (manual scale # 1E30..2E30, so the line is clipped), hidden from the legend and get blank, unique legend texts # (1, 2, 3 ... spaces) in the legend background colour, because the web legend ignores # "Show in legend". Empty pens are removed; do not keep hidden real pens (they count against 50). # Run it again after editing the trend in the Edit Module (it only adds what is missing). # # Usage: powershell -ExecutionPolicy Bypass -File add_trend_spares.ps1 -Path .xml param([Parameter(Mandatory = $true)][string]$Path) $target = 50 $text = [IO.File]::ReadAllText($Path) $nl = "`r`n" if (-not $text.Contains($nl)) { $nl = "`n" } function Set-Tag([string]$pen, [string]$tag, [string]$value) { $rx = New-Object Text.RegularExpressions.Regex ("<$tag>[^<]*|<$tag/>") return $rx.Replace($pen, "<$tag>$value", 1) } $panelRx = New-Object Text.RegularExpressions.Regex '(?s).*?' $penRx = New-Object Text.RegularExpressions.Regex '(?s)[ \t]*.*?\r?\n?' $changed = 0 $text = $panelRx.Replace($text, { param($m) $panel = $m.Value $pens = $penRx.Matches($panel) if ($pens.Count -eq 0) { return $panel } $real = @(); $spareCount = 0 foreach ($p in $pens) { $v = $p.Value $empty = $v.Contains('uri=""') $isSpare = $v.Contains('1.0E30') if ($isSpare) { $spareCount++ } elseif (-not $empty) { $real += $v } } if ($real.Count -eq 0) { return $panel } $visibleReal = 0 foreach ($v in $real) { if ($v.Contains('true')) { $visibleReal++ } } $need = $target - $visibleReal if ($need -lt 0) { $need = 0 } $template = $real[0] # spare colour = legend background, so their (blank) web legend entries do not show $bg = (New-Object Text.RegularExpressions.Regex '').Match($panel) $spareColor = '' if ($bg.Success) { $spareColor = $bg.Value.Replace('').Replace($s, $spareColor, 1) $s = (New-Object Text.RegularExpressions.Regex '.*?(?=\s*)', 'Singleline').Replace($s, '@NULL', 1) $spares += $s } # rebuild: real pens first, then spares, at the place of the first pen $first = $pens[0].Index $last = $pens[$pens.Count - 1] $before = $panel.Substring(0, $first) $after = $panel.Substring($last.Index + $last.Length) $body = '' foreach ($v in $real) { $body += $v } foreach ($v in $spares) { $body += $v } $panel = $before + $body + $after $panel = (New-Object Text.RegularExpressions.Regex '\d+').Replace($panel, "$target", 1) $script:changed++ Write-Host ("Trend {0}: {1} real pen(s), {2} old spare(s) replaced, {3} spare(s) written" -f $script:changed, $real.Count, $spareCount, $need) return $panel }) [IO.File]::WriteAllText($Path, $text) Write-Host "Done: $changed trend(s) in $Path"