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

Make display of color swatches slightly robust #463

Merged
merged 1 commit into from
Mar 16, 2021

Conversation

kimikage
Copy link
Collaborator

@kimikage kimikage commented Mar 3, 2021

This reduces the risk of having invalid suffixes when converting numbers to strings. This also supports indices that start with other than 1.
There is almost no improvement in performance.

This reduces the risk of having invalid suffixes when converting numbers to strings.
This also supports indices that start with other than 1.
There is almost no improvement in performance.
@codecov
Copy link

codecov bot commented Mar 3, 2021

Codecov Report

Merging #463 (1c0bcd8) into master (cf7b34b) will decrease coverage by 0.11%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #463      +/-   ##
==========================================
- Coverage   92.53%   92.42%   -0.12%     
==========================================
  Files          10       10              
  Lines         951      950       -1     
==========================================
- Hits          880      878       -2     
- Misses         71       72       +1     
Impacted Files Coverage Δ
src/display.jl 100.00% <100.00%> (ø)
src/precompile.jl 84.21% <0.00%> (-5.27%) ⬇️
src/conversions.jl 99.30% <0.00%> (-0.01%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cf7b34b...1c0bcd8. Read the comment docs.

for (i, c) in enumerate(cs)
i > actual_max_swatches && break
hexc = hex(color(c))
opacity = string(round(float(alpha(c)), digits=4))
Copy link
Collaborator Author

@kimikage kimikage Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alpha() may return a FixedPoint number. FixedPointNumbers v0.8 does not support round(x, digits=n), and the fallback returns a floating-point number. However, this problem has been fixed in JuliaMath/FixedPointNumbers.jl#235.

julia> round(0.5N0f8, digits=4)
0.502f0 # FPN v0.8
0.502N0f8 # FPN #master

Here is another problem. Unlike Float32 etc., string(::FixedPoint) currently returns a string with the suffix.

julia> string(0.5N0f8)
"0.502N0f8"

julia> string(0.5f0)
"0.5"

Perhaps string(::FixedPoint) should return a string without suffix, but that is a matter of FixedPointNumbers. (Edit: cf. JuliaMath/FixedPointNumbers.jl#241)

@kimikage kimikage merged commit e2c7b87 into JuliaGraphics:master Mar 16, 2021
@mcabbott
Copy link

mcabbott commented Apr 2, 2021

Would it be possible to make a release with this PR? Some weird errors in Pluto and some git blame eventually led me to discover that the problem has been fixed, I think.

@kimikage kimikage deleted the robust_display branch April 3, 2021 00:56
@kimikage
Copy link
Collaborator Author

kimikage commented Apr 3, 2021

Colors v0.12.7 was released. If the issue is still not resolved, please report it.

@mcabbott
Copy link

mcabbott commented Apr 3, 2021

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants