Rewrite the diff complexity icon to output SVGs.

Review Request #13741 — Created April 17, 2024 and submitted

Information

Review Board
release-7.x

Reviewers

The diff complexity icon, shown in the diff viewer's file index and in
the Review Request Updated boxes, has historically used jquery-flot to
do the rendering. This rendered to a canvas, had a white stroke area,
and did not scale well. It was also not accessible, and not easy to
style. It was a non-starter for dark mode.

This change rewrites this entirely to output SVGs. We do this by hand,
as bringing in a library like D3 at this stage would take some care as
to not impact Power Pack.

The code generates the segments, normalizes percentages to enforce
minimums, and then generates SVG path data for each of the segment arcs.
It calculates an outer radius and an inner radius, as we did with flot,
and give us a graph that correctly shows an overview of the changes made
to the file.

It also comes with a new tooltip and accessibility information
describing the number of changes to a file, and what types of changes
were made. All the relevant numbers are included.

Styling is done with CSS, giving us full control over light and dark
mode styling.

Tested a wide range of boundary conditions for the icon in Storybook,
and compared to the original implementation in each (using a flag I
had in development for triggering the original rendering logic).

Compared against the old rendering for a number of test diffs. Aside
from very minor differences (new color palette, very slight rendering
changes), the appearance was the same.

Tested in light and dark modes.

Checked the accessibility tree.

Summary ID
Rewrite the diff complexity icon to output SVGs.
The diff complexity icon, shown in the diff viewer's file index and in the Review Request Updated boxes, has historically used jquery-flot to do the rendering. This rendered to a canvas, had a white stroke area, and did not scale well. It was also not accessible, and not easy to style. It was a non-starter for dark mode. This change rewrites this entirely to output SVGs. We do this by hand, as bringing in a library like D3 at this stage would take some care as to not impact Power Pack. The code generates the segments, normalizes percentages to enforce minimums, and then generates SVG path data for each of the segment arcs. It calculates an outer radius and an inner radius, as we did with flot, and give us a graph that correctly shows an overview of the changes made to the file. It also comes with a new tooltip and accessibility information describing the number of changes to a file, and what types of changes were made. All the relevant numbers are included. Styling is done with CSS, giving us full control over light and dark mode styling.
6dc4f342a7c38627fc3eda4d50231bd9e7add744

Description From Last Updated

We should specify the unit. And the "in width and height" sounds a bit confusing to me, how about something …

maubinmaubin

Missing the "Returns" section.

maubinmaubin

Shouldn't this be DEGREE instead of DEGREES?

daviddavid
maubin
  1. Looks awesome.

  2. Show all issues

    We should specify the unit. And the "in width and height" sounds a bit confusing to me, how about something like:

    "The size to set for the width and height of the icon, in pixels."

  3. reviewboard/static/rb/js/reviews/views/diffComplexityIconView.ts (Diff revision 1)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Show all issues

    Missing the "Returns" section.

  4. 
      
chipx86
maubin
  1. Ship It!
  2. 
      
david
  1. 
      
  2. Show all issues

    Shouldn't this be DEGREE instead of DEGREES?

  3. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-7.x (5ffe803)