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

Can I configure a usage threshold? #16

Open
wamoyo opened this issue Nov 17, 2016 · 4 comments
Open

Can I configure a usage threshold? #16

wamoyo opened this issue Nov 17, 2016 · 4 comments

Comments

@wamoyo
Copy link

wamoyo commented Nov 17, 2016

Era is great, but I'd love to be able to only display browsers and usage percentage for only those browser above 1% or some other configurable threshold.

Just a feature idea : )

@sgentle
Copy link
Owner

sgentle commented Nov 20, 2016

Hey, neat idea! Would you be interested in implementing it?

The way it works at the moment is that the makeResults function loops through the versions in the caniuse data and checks them against the versionrange (line 164). Probably the simplest thing would be to add a condition in that loop to check if usage (defined on line 166) is less than the threshold and continue if it is.

That behaviour will cause the tool to ignore below-threshold versions completely. For example, if Firefox 123.45 (10% usage) supports a feature, Firefox 123.46 (0.1% usage) doesn't, and Firefox 123.47 (30% usage) does, we'll display that as "Firefox: ✓123.45+". I think that's in line with user intention, but it might be worth making sure the parameter description reflects it.

@wamoyo
Copy link
Author

wamoyo commented Nov 22, 2016

Woah, that was cool! It actually works : )

Well, almost. It still lists the browser without its versions if they're all under the threshold

For example:

 ./bin.js svg -t 1
SVG (basic support) ✔ 96.78% ◒ 0.75% [W3C Recommendation]
  Method of displaying basic Vector Graphics features using the embed or object elements. Refers to the SVG 1.1 spec.
  #SVG

  IE ✔ ² (4%) 
  Edge ✔ ² (1%) 
  Firefox ✔ (5%) 
  Chrome ✔ (25%) 
  Safari ✔ (1%) 
  Opera
  iOS Safari ✔ (8%) 
  Opera Mini ✔ (4%) 
  Android Browser ✔ (2%) 
  Blackberry Browser
  Opera Mobile
  Chrome for Android ✔ (23%) 
  Firefox for Android
  IE Mobile
  UC Browser for Android ✔ (9%) 
  Samsung Internet ✔ (3%) 

And here's the code I added:

  .option 'threshold',
    alias: 't'
    type: 'number'
    default: 0
    describe: "Show only browsers above usage percentage threshold"

And....

makeResults = (browser, stats) ->
  results = []
  current = {}
  for version, i in browser.versions when version and versionrange[0] <= i <= versionrange[1]
    support = stats[version]
    usage = browser.usage_global[version] || 0
    version += '+' if browser.versions[i + 1]
    threshold = argv.threshold

    # 'p' means no-but-polyfill-available, which we can treat as no
    if support[0] == "p"
      support = "n" + support.slice(1)

    # Check if usage is greater than the threshold, and continue if it is
    if usage <= threshold
      continue

    # Only add a new version result when browser support changes
    if !current.version || current.support != support
      current = version: version, support: support, usage: 0
      results.push current

    current.usage += usage

  results

@wamoyo wamoyo closed this as completed Nov 22, 2016
@wamoyo wamoyo reopened this Nov 22, 2016
@wamoyo
Copy link
Author

wamoyo commented Nov 22, 2016

Sorry meant to click comment, hit close by accident.

@wamoyo
Copy link
Author

wamoyo commented Nov 22, 2016

Noticing decimals don't quite work either...

 (master) $ ./bin.js svg -t .3
SVG (basic support) ✔ 96.78% ◒ 0.75% [W3C Recommendation]
  Method of displaying basic Vector Graphics features using the embed or object elements. Refers to the SVG 1.1 spec.
  #SVG

  IE ✘ 8+ (0%) ✔ 11² (4%) 
  Edge ✔ ² (1%) 
  Firefox ✔ (5%) 
  Chrome ✔ (26%) 
  Safari ✔ (2%) 
  Opera ✔ (0%) 
  iOS Safari ✔ (9%) 
  Opera Mini ✔ (4%) 
  Android Browser ◒ 4.2-4.3+¹ (0%) ✔ 4.4+ (2%) 
  Blackberry Browser
  Opera Mobile ✔ (0%) 
  Chrome for Android ✔ (23%) 
  Firefox for Android
  IE Mobile ✔ ² (0%) 
  UC Browser for Android ✔ (9%) 
  Samsung Internet ✔ (3%) 

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

No branches or pull requests

2 participants