Repository navigation
Auto change color based on the theme - #25702
Conversation
|
✅ Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes.
Click here to see the pull request description that was parsed. |
| .. raw:: html | ||
|
|
||
| <svg class="align-center" viewbox="0 0 350 175" width="350px"> | ||
| <use xlink:href="../../../_static/modules/physics/vector/vec_rep.svg#vec_rep_id"></use> |
There was a problem hiding this comment.
How is this different from what gets generated by the .. image directive?
There was a problem hiding this comment.
The .. image wraps the svg in img object, which seems to cause the css (currentColor) not to work anymore. This solution did work for me here.
There was a problem hiding this comment.
I can confirm your example site works. Are you using any custom CSS on that site?
There was a problem hiding this comment.
No, I'm just changing the #000000 color references in the image to currentColor, which is a CSS variable.
There was a problem hiding this comment.
The other solution with :file: does actually work here as well.
Hmmm, I would guess that it cannot find the image, though if I look in the CircleCI build the file is in the expected location. Bit strange that it does not work here, as it did work for me when building the documentation locally. |
|
If we would be able by the way to get this working we could opt for creating a custom directive specifically for SVGs. |
|
Came across the solution I just implemented here. The advantage of this solution is that it would keep the rst code clean. However, it will require one to write the scaling etc inside the SVG file itself. |
|
Nice, I can confirm this does work, with all 6 combinations of system/page light/dark/auto settings. https://output.circle-artifacts.com/output/job/77eab45b-b8fd-4228-bf13-ab66ca3ac746/artifacts/0/doc/_build/html/modules/physics/vector/vectors.html So now we need to change all the remaining SVGs in the docs, and also document this somewhere. We might also consider making some upstream improvements or at least open issues in Furo and/or Sphinx about this. |
|
Just took the time to go through all SVGs. During this process, I also cleaned up some of the SVGs in terms of code. The primary change in the commits so far is still making the images dark theme compatible by just letting colors switch from black to white. The 'kin_angvel2.svg' image has also undergone a subtle color adjustment. It's worth noting that the SVGs referenced in the docstrings, such as the images from the joints framework, do not currently auto-adjust their colors. In my opinion, this isn't a significant concern as they remain generally readable. Nevertheless, if there is auto-changing the color is desired, it is possible. However, the disadvantage is that the entire file paths within docstrings need to be specified, which is cumbersome. Let me know if this is a required change. |
|
Benchmark results from GitHub Actions Lower numbers are good, higher numbers are bad. A ratio less than 1 Significantly changed benchmark results (PR vs master) Significantly changed benchmark results (master vs previous release) | Change | Before [a00718ba] | After [0b25b279] | Ratio | Benchmark (Parameter) |
|----------|----------------------|---------------------|---------|----------------------------------------------------------------------|
| - | 69.9±1ms | 45.2±0.5ms | 0.65 | integrate.TimeIntegrationRisch02.time_doit(10) |
| - | 67.5±0.9ms | 43.9±0.6ms | 0.65 | integrate.TimeIntegrationRisch02.time_doit_risch(10) |
| + | 19.1±0.1μs | 30.7±0.3μs | 1.61 | integrate.TimeIntegrationRisch03.time_doit(1) |
| - | 5.43±0.01ms | 2.85±0.01ms | 0.53 | logic.LogicSuite.time_load_file |
| - | 72.4±0.4ms | 29.0±0.1ms | 0.4 | polys.TimeGCD_GaussInt.time_op(1, 'dense') |
| - | 25.9±0.08ms | 16.8±0.2ms | 0.65 | polys.TimeGCD_GaussInt.time_op(1, 'expr') |
| - | 72.6±0.6ms | 29.2±0.4ms | 0.4 | polys.TimeGCD_GaussInt.time_op(1, 'sparse') |
| - | 254±1ms | 126±0.6ms | 0.49 | polys.TimeGCD_GaussInt.time_op(2, 'dense') |
| - | 255±1ms | 123±0.3ms | 0.49 | polys.TimeGCD_GaussInt.time_op(2, 'sparse') |
| - | 651±1ms | 368±2ms | 0.57 | polys.TimeGCD_GaussInt.time_op(3, 'dense') |
| - | 655±1ms | 371±2ms | 0.57 | polys.TimeGCD_GaussInt.time_op(3, 'sparse') |
| - | 499±2μs | 290±2μs | 0.58 | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(1, 'dense') |
| - | 1.81±0.01ms | 1.04±0.01ms | 0.57 | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(2, 'dense') |
| - | 5.88±0.01ms | 3.12±0.02ms | 0.53 | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(3, 'dense') |
| - | 453±3μs | 230±3μs | 0.51 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(1, 'dense') |
| - | 1.48±0ms | 684±5μs | 0.46 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(2, 'dense') |
| - | 4.93±0.03ms | 1.67±0.01ms | 0.34 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(3, 'dense') |
| - | 377±2μs | 205±2μs | 0.54 | polys.TimeGCD_SparseGCDHighDegree.time_op(1, 'dense') |
| - | 2.45±0.04ms | 1.25±0.01ms | 0.51 | polys.TimeGCD_SparseGCDHighDegree.time_op(3, 'dense') |
| - | 10.0±0.03ms | 4.37±0.02ms | 0.44 | polys.TimeGCD_SparseGCDHighDegree.time_op(5, 'dense') |
| - | 361±1μs | 168±2μs | 0.47 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(1, 'dense') |
| - | 2.49±0.01ms | 904±2μs | 0.36 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(3, 'dense') |
| - | 9.58±0.2ms | 2.63±0.01ms | 0.28 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(5, 'dense') |
| - | 1.03±0.02ms | 429±2μs | 0.42 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(3, 'dense') |
| - | 1.73±0.01ms | 506±2μs | 0.29 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(3, 'sparse') |
| - | 5.83±0.05ms | 1.83±0.02ms | 0.31 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(5, 'dense') |
| - | 8.39±0.04ms | 1.50±0.01ms | 0.18 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(5, 'sparse') |
| - | 283±1μs | 64.2±0.3μs | 0.23 | polys.TimePREM_QuadraticNonMonicGCD.time_op(1, 'sparse') |
| - | 3.41±0.02ms | 394±3μs | 0.12 | polys.TimePREM_QuadraticNonMonicGCD.time_op(3, 'dense') |
| - | 4.02±0.02ms | 282±1μs | 0.07 | polys.TimePREM_QuadraticNonMonicGCD.time_op(3, 'sparse') |
| - | 7.14±0.09ms | 1.25±0.01ms | 0.17 | polys.TimePREM_QuadraticNonMonicGCD.time_op(5, 'dense') |
| - | 8.68±0.04ms | 841±3μs | 0.1 | polys.TimePREM_QuadraticNonMonicGCD.time_op(5, 'sparse') |
| - | 5.16±0.03ms | 2.99±0.01ms | 0.58 | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(2, 'sparse') |
| - | 12.3±0.05ms | 6.57±0.04ms | 0.53 | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(3, 'dense') |
| - | 22.4±0.06ms | 9.12±0.02ms | 0.41 | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(3, 'sparse') |
| - | 5.20±0.03ms | 875±2μs | 0.17 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(1, 'sparse') |
| - | 12.7±0.04ms | 7.13±0.05ms | 0.56 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(2, 'sparse') |
| - | 102±0.8ms | 25.6±0.05ms | 0.25 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(3, 'dense') |
| - | 167±2ms | 54.7±0.5ms | 0.33 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(3, 'sparse') |
| - | 173±1μs | 111±0.6μs | 0.64 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(1, 'dense') |
| - | 361±3μs | 217±1μs | 0.6 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(1, 'sparse') |
| - | 4.30±0.03ms | 831±5μs | 0.19 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(3, 'dense') |
| - | 5.27±0.03ms | 382±1μs | 0.07 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(3, 'sparse') |
| - | 20.2±0.3ms | 2.80±0.01ms | 0.14 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(5, 'dense') |
| - | 22.8±0.2ms | 629±2μs | 0.03 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(5, 'sparse') |
| - | 482±1μs | 134±0.6μs | 0.28 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(1, 'sparse') |
| - | 4.70±0.02ms | 614±2μs | 0.13 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(3, 'dense') |
| - | 5.28±0.07ms | 138±1μs | 0.03 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(3, 'sparse') |
| - | 13.3±0.2ms | 1.28±0ms | 0.1 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(5, 'dense') |
| - | 13.8±0.07ms | 141±0.9μs | 0.01 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(5, 'sparse') |
| - | 134±0.8μs | 73.9±0.5μs | 0.55 | solve.TimeMatrixOperations.time_rref(3, 0) |
| - | 248±0.6μs | 87.5±0.6μs | 0.35 | solve.TimeMatrixOperations.time_rref(4, 0) |
| - | 24.1±0.2ms | 10.2±0.06ms | 0.42 | solve.TimeSolveLinSys189x49.time_solve_lin_sys |
| - | 28.6±0.2ms | 15.4±0.1ms | 0.54 | solve.TimeSparseSystem.time_linsolve_Aaug(20) |
| - | 55.4±0.4ms | 24.8±0.05ms | 0.45 | solve.TimeSparseSystem.time_linsolve_Aaug(30) |
| - | 28.3±0.1ms | 15.2±0.07ms | 0.54 | solve.TimeSparseSystem.time_linsolve_Ab(20) |
| - | 54.4±0.4ms | 24.5±0.2ms | 0.45 | solve.TimeSparseSystem.time_linsolve_Ab(30) |
Full benchmark results can be found as artifacts in GitHub Actions |
|
What do these docstring images look like in dark mode? |
|
They are all on this page. |
|
There are some examples on that page that end up with black text against the background. |
|
|
||
| .. image:: PinJoint.svg | ||
| .. raw:: html | ||
| :file: ../../../doc/src/modules/physics/mechanics/api/PinJoint.svg |
There was a problem hiding this comment.
Changed it for the PinJoint (see here). Don't really like specifying the path here, but it does fix it. Shall I also update it for the other joints?
|
Is there an upstream issue in Sphinx to make it so that we don't have to use these workarounds? |
I would say that it is related to this issue. One of the workarounds suggested in this issue is actually what I've done in this PR. |
|
Looks like the diagonal lines at the top of the svg on this page aren't modified correctly https://output.circle-artifacts.com/output/job/7e1d9056-97bf-4724-9663-09d92b9894b5/artifacts/0/doc/_build/html/modules/physics/mechanics/examples/lin_pend_nonmin_example.html |
There was a problem hiding this comment.
I'm concerned about the color contrast of this SVG, especially in dark mode. Please make sure that the text color and background colors are WGAC AA compliant. You can use https://accessible-colors.com/ to check.
There was a problem hiding this comment.
Awesome tool. Thank you for the suggestion. The contrast ratio is now 4.54 in dark theme and 4.62 in light theme. Addressed in 0b4fa71
|
This looks good to me now, thanks. |

References to other Issues or PRs
Proposal to fix #24695
Brief description of what is fixed or changed
This PR uses the proposal from this comment, where css can be used in the svg to autochange the color, by using raw html in the rst file.
Other comments
Release Notes
NO ENTRY