Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New-TablePercentageBar - Conditional BarColor? #408

Closed
smasterson opened this issue Sep 11, 2023 · 10 comments
Closed

New-TablePercentageBar - Conditional BarColor? #408

smasterson opened this issue Sep 11, 2023 · 10 comments
Labels
enhancement New feature or request

Comments

@smasterson
Copy link
Contributor

With New-TablePercentageBar it doesn't seem possible to create a condition for things like BarColor?

Ideally, being able to say something like the following would be great:

  • If Value > 70 BarColor eq Yellow
  • If Value > 80 BarColoer eq Orage
  • If Value > 90 BarColor eq Red

Love this addition, not sure when it popped in, just needs this one tweak to be super useful!

@PrzemyslawKlys
Copy link
Member

hi,

Not sure it's natively possible:

The JS code is here:

Source codes (to commit back to DataTables after fixes)

This would require some modification to support conditions, but doable.

Some links to consider:
-https://datatables.net/examples/basic_init/data_rendering.html

@PrzemyslawKlys
Copy link
Member

I actually just hardcoded this and it seems to work, so I'll work on it to make it nice and fancy

@smasterson
Copy link
Contributor Author

smasterson commented Sep 11, 2023

Gotcha, I didn't assume it was tied directly to DataTables - thanks!

My current workaround is to use manual HTML with -InvokeHTMLTags:

$tmp1 | % { $_.'% Used' = "$($_.'% Used')" + '% <meter value="' + "$($_.'% Used')" + '" optimum="25" low="70" high="85" max="100"></meter>' }

Very ugly but works...my biggest issue was trying to make it 'pretty' as I am not familiar with CSS, etc...

@PrzemyslawKlys
Copy link
Member

The change is pretty trivial

image

Just before returning style, you can hardcode cBar to some value. I am now checking on how you can pass hashtable of sorts so it would work

@PrzemyslawKlys
Copy link
Member

I've created PR for this change in datatables. Lets see how that works out. I'll probably release my own version until they process it properly on their own side.

@PrzemyslawKlys
Copy link
Member

From a PowerShell perspective:

$DataTable = @(
    [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3'; Test4 = 1.42; Percents = 50 }
    [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3'; Test4 = 5.72; Percents = 5 }
    [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3'; Test4 = 16.22; Percents = 17 }
    [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3'; Test4 = 23.73; Percents = 99 }
    [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3'; Test4 = 50.73; Percents = 105 } # will be trimmed to 100%
    [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3'; Test4 = 90; Percents = 105 } # will be trimmed to 100%
)

New-HTML {
    New-HTMLTable -DataTable $DataTable -AlphabetSearch {
        New-TablePercentageBar -ColumnID 4 # runs on defaults
        New-TablePercentageBar -ColumnID 3 -BackgroundColor Blue -TextColor White -BorderColor Grey -BarColor gold -BorderStyle ridge -Type round {
            New-TablePercentageBarCondition -Minimum 0 -Maximum 10 -BackgroundColor Blue -TextColor White -BarColor Red
            New-TablePercentageBarCondition -Minimum 11 -Maximum 20 -BackgroundColor Blue -TextColor White -BarColor Green
            New-TablePercentageBarCondition -Minimum 21 -Maximum 25 -BackgroundColor Blue -TextColor White -BarColor AppleBlossom
            New-TablePercentageBarCondition -Minimum 26 -Maximum 85 -BackgroundColor Grey -TextColor Black -BarColor Cyan
            New-TablePercentageBarCondition -Minimum 86 -Maximum 100 -BackgroundColor Blue -TextColor White -BarColor Yellow
        }
    } -ImmediatelyShowHiddenDetails
} -ShowHTML -FilePath $PSScriptRoot\Example7_PercentageBar.html -Online

@smasterson
Copy link
Contributor Author

Love it, as usual! Thanks!

@PrzemyslawKlys PrzemyslawKlys added the enhancement New feature or request label Sep 12, 2023
@smasterson
Copy link
Contributor Author

Is this working in 1.9.0?
The example does not appear to be working for me...no errors
image

@PrzemyslawKlys
Copy link
Member

It is, but was working without -Online. I forgot to change version number in configuration url. Republished 1.10.0 which should work in both cases.

@smasterson
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants