site-kit-wp icon indicating copy to clipboard operation
site-kit-wp copied to clipboard

UI issues on All Traffic Widget With Small Amount of Data

Open wpdarren opened this issue 5 years ago • 9 comments

Bug Description

I have a site with a very small amount of data and when viewing Site Kit dashboard there are a few UI issues

  1. 100% appears within the centre of the pie chart, overlapping By Channels

image.png

  1. Legends appear in Channels, Locations and Devices that are not in the pie chart for 28 days. When you extend the period to 90 days then data does appear for those legends. For 7 and 14 days the legends display as expected.

image.png image.png image.png

Report data

Channels
[
  {
    "nextPageToken": null,
    "columnHeader": {
      "dimensions": [
        "ga:channelGrouping"
      ],
      "metricHeader": {
        "metricHeaderEntries": [
          {
            "name": "ga:users",
            "type": "INTEGER"
          }
        ]
      }
    },
    "data": {
      "dataLastRefreshed": null,
      "isDataGolden": null,
      "rowCount": 3,
      "samplesReadCounts": null,
      "samplingSpaceSizes": null,
      "rows": [
        {
          "dimensions": [
            "Referral"
          ],
          "metrics": [
            {
              "values": [
                "3"
              ]
            },
            {
              "values": [
                "7"
              ]
            }
          ]
        },
        {
          "dimensions": [
            "Direct"
          ],
          "metrics": [
            {
              "values": [
                "0"
              ]
            },
            {
              "values": [
                "5"
              ]
            }
          ]
        },
        {
          "dimensions": [
            "Social"
          ],
          "metrics": [
            {
              "values": [
                "0"
              ]
            },
            {
              "values": [
                "1"
              ]
            }
          ]
        }
      ],
      "totals": [
        {
          "values": [
            "3"
          ]
        },
        {
          "values": [
            "13"
          ]
        }
      ],
      "minimums": [
        {
          "values": [
            "0"
          ]
        },
        {
          "values": [
            "1"
          ]
        }
      ],
      "maximums": [
        {
          "values": [
            "3"
          ]
        },
        {
          "values": [
            "7"
          ]
        }
      ]
    }
  }
]
Locations
[
  {
    "nextPageToken": null,
    "columnHeader": {
      "dimensions": [
        "ga:country"
      ],
      "metricHeader": {
        "metricHeaderEntries": [
          {
            "name": "ga:users",
            "type": "INTEGER"
          }
        ]
      }
    },
    "data": {
      "dataLastRefreshed": null,
      "isDataGolden": null,
      "rowCount": 5,
      "samplesReadCounts": null,
      "samplingSpaceSizes": null,
      "rows": [
        {
          "dimensions": [
            "China"
          ],
          "metrics": [
            {
              "values": [
                "3"
              ]
            },
            {
              "values": [
                "7"
              ]
            }
          ]
        },
        {
          "dimensions": [
            "Malaysia"
          ],
          "metrics": [
            {
              "values": [
                "0"
              ]
            },
            {
              "values": [
                "1"
              ]
            }
          ]
        },
        {
          "dimensions": [
            "Peru"
          ],
          "metrics": [
            {
              "values": [
                "0"
              ]
            },
            {
              "values": [
                "1"
              ]
            }
          ]
        },
        {
          "dimensions": [
            "United Arab Emirates"
          ],
          "metrics": [
            {
              "values": [
                "0"
              ]
            },
            {
              "values": [
                "2"
              ]
            }
          ]
        },
        {
          "dimensions": [
            "United States"
          ],
          "metrics": [
            {
              "values": [
                "0"
              ]
            },
            {
              "values": [
                "2"
              ]
            }
          ]
        }
      ],
      "totals": [
        {
          "values": [
            "3"
          ]
        },
        {
          "values": [
            "13"
          ]
        }
      ],
      "minimums": [
        {
          "values": [
            "0"
          ]
        },
        {
          "values": [
            "1"
          ]
        }
      ],
      "maximums": [
        {
          "values": [
            "3"
          ]
        },
        {
          "values": [
            "7"
          ]
        }
      ]
    }
  }
]
Devices
[
  {
    "nextPageToken": null,
    "columnHeader": {
      "dimensions": [
        "ga:deviceCategory"
      ],
      "metricHeader": {
        "metricHeaderEntries": [
          {
            "name": "ga:users",
            "type": "INTEGER"
          }
        ]
      }
    },
    "data": {
      "dataLastRefreshed": null,
      "isDataGolden": null,
      "rowCount": 2,
      "samplesReadCounts": null,
      "samplingSpaceSizes": null,
      "rows": [
        {
          "dimensions": [
            "mobile"
          ],
          "metrics": [
            {
              "values": [
                "3"
              ]
            },
            {
              "values": [
                "7"
              ]
            }
          ]
        },
        {
          "dimensions": [
            "desktop"
          ],
          "metrics": [
            {
              "values": [
                "0"
              ]
            },
            {
              "values": [
                "6"
              ]
            }
          ]
        }
      ],
      "totals": [
        {
          "values": [
            "3"
          ]
        },
        {
          "values": [
            "13"
          ]
        }
      ],
      "minimums": [
        {
          "values": [
            "0"
          ]
        },
        {
          "values": [
            "6"
          ]
        }
      ],
      "maximums": [
        {
          "values": [
            "3"
          ]
        },
        {
          "values": [
            "7"
          ]
        }
      ]
    }
  }
]

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • In the Analytics All Traffic widget, if a single slice is displayed in the piechart, labels should not be displayed.
    • Specifically, even if the report source includes multiple dimensions, labels should not be displayed if all data is from just one of them (i.e. it amounts to 100%).

Implementation Brief

  • Create a new file: assets/js/util/chart.js
  • The file should export a function, isSingleSlice
  • Given a report, the function should return true if one or both of the following cases apply:
    • There is a single row in the data
    • One row is contributing 100% of the total for a given dimension Example: in the Users report above, the Referral dimension is the only one with a non-zero value for the latest metric (metrics[0] ).
  • The function should return false if none of these conditions apply
  • The function should return undefined if the report is undefined
  • Refactor the check at line 367 in UserDimensionsPieChart.js so that it uses the isSingleSlice function instead. We want options.pieSliceText to be none if isSingleSlice returns true.
  • Add unit tests for isSingleSlice

Test Coverage

  • New unit tests for the isSingleSlice utility; existing tests should pass.

Visual Regression Changes

  • The 100% label will be removed from the pie chart in cases where a single metric accounts for 100% of the data, or where there is a single row of data (see issue #2660).

QA Brief

  • Steps to reproduce above - verify that the 100% label is no longer visible, and the text is simply By Channels etc.

Changelog entry

  • Fix UI issues on the pie chart of the All Traffic widget when there is just a single slice.

wpdarren avatar Mar 19 '21 11:03 wpdarren

@johnPhillips Can you verify what's going on here?

felixarntz avatar Mar 19 '21 15:03 felixarntz

@felixarntz It looks like what is happening is that there is more than one row in the report, so it isn't getting picked up by our fix.

Here it looks like we have a single user, from China, by referral, on their mobile. So we have a single metric in each case that is contributing 100% of the traffic, meaning the 100% pieSliceText is applied to the centre of the donut, overlapping our label.

But all the other rows are still present - [referral = 1 , direct = 0 , social = 0], [China = 1 , Peru = 0 , Malaysia = 0 , ...] and [ mobile = 1 , desktop = 0], as you can see from the chart legend.

I think we have a route A and a route B here:

Route A would be to create a utility, not unlike isZeroReport, that can detect these edge cases where we have a single row contributing 100%. We refactor the current fix to use that utility, e.g.

// UserDimensionsPieChart.js : 367
if ( isTotalFromSingleMetric( report ) ) {
  // When there is only one row contributing all the data, the chart 
  // will add a label which we need to hide - see issues #2660, 2991
  options.pieSliceText = 'none';
}

Route B occurred to me when I stepped back a little bit from the problem. Do we ever need pieSliceText to be any value other than "none"? There is a useful JSFiddle on the documentation, here under 'Making a donut chart' - scroll down under the code snippet and see the link: Code it yourself on JSFiddle. Anyway, it seems that this option adds a label to the slices, but when there is only one slice (i.e. 100%), the label goes in the centre of the donut.

pieSliceText with multiple slices pieSliceText with single slice 100% pieSliceText: "none"
Screenshot 2021-03-22 at 11 59 23 Screenshot 2021-03-22 at 12 00 04 Screenshot 2021-03-22 at 12 00 20

Given that we have our own tooltip-style labels and aren't using this, I wonder whether we just set pieSliceText to "none" by default? I did this locally and couldn't see any issues, but you may be able to think of a problem with this solution that I am unaware of. I'm happy to investigate / test this further if you are interested.

Let me know what you think - very happy to write the IB based on your preferred route (or if you have another idea).

johnPhillips avatar Mar 22 '21 12:03 johnPhillips

@johnPhillips I think we should maintain the labels for all other cases than the one with a single slice, so it would be great if we could go with the approach of detecting whether the report is a single dimension taking all 100%.

felixarntz avatar Mar 22 '21 17:03 felixarntz

Note: thanks to @wpdarren I managed to get hold of the reports that caused this - adding to the issue.

johnPhillips avatar Mar 24 '21 15:03 johnPhillips

Thanks @johnPhillips – the IB looks good regarding logic that needs to happen. Regarding the utility, can we maybe generalize this a bit? That is, could we extract a more general utility to use for any pie chart that would tell us if the resulting chart would be a single slice? It might be called isSingleSlice(). What do you think?

aaemnnosttv avatar Mar 25 '21 11:03 aaemnnosttv

@aaemnnosttv I've updated the IB to reflect your thoughts. I suggest we create assets/js/util/chart.js where we can put all chart related utility functions.

asvinb avatar Mar 31 '21 11:03 asvinb

I suggest we create assets/js/util/chart.js where we can put all chart related utility functions.

Sounds good to me @asvinb 👍

IB ✅

aaemnnosttv avatar Mar 31 '21 11:03 aaemnnosttv

QA Update: Pass ✅

  • Verified that the 100% label is no longer visible, and the text is simply By Channels etc.
  • Verified that only the legends relating to the pie chart appear.
  • Verified correct data, legends for 7, 14, 28 and 90 days.
  • Verified that the pie widget displayed as expected on mobile devices

image

wpdarren avatar Apr 12 '21 13:04 wpdarren

Thought I could still repro it, but it was just a caching issue.

ivankruchkoff avatar Apr 14 '21 16:04 ivankruchkoff