# all files / candela/components/TrackerDash/ utility.js

38.89% Statements 14/36
16.67% Branches 4/24
14.29% Functions 1/7
29.03% Lines 9/31

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    581×

    1×

    1×

    1×

    1×

    1×

    1×

    1×

     import md5 from 'md5';

    import colors from './colors.js';

    export let failValue = (value, warning, fail, lower_is_better) => {
      if (lower_is_better === undefined || lower_is_better === null) {
        lower_is_better = (warning < fail);
      }
      if (lower_is_better) {
        return (value >= fail);
      } else {
        return (value <= fail);
      }
    };

    export let warningValue = (value, warning, fail, lower_is_better) => {
      if (lower_is_better === undefined || lower_is_better === null) {
        lower_is_better = (warning < fail);
      }
      if (lower_is_better) {
        return (value >= warning);
      } else {
        return (value <= warning);
      }
    };

    export let sanitizeSelector = (input) => {
      // Prefix with an '_' as selectors can't start with numbers.
      return '_' + md5(input);
    };

    export let standardRound = (input) => {
      return Math.round(input * 10000) / 10000;
    };

    export let computeColor = (trend, value) => {
      if (trend.incompleteThreshold) {
        return colors.incomplete;
      } else {
        if (failValue(value, trend.warning, trend.fail, trend.lower_is_better)) {
          return colors.fail;
        } else if (warningValue(value, trend.warning, trend.fail, trend.lower_is_better)) {
          return colors.bad;
        } else {
          return colors.good;
        }
      }
    };

    export let deArray = (values, reducer) => {
      if (Array.isArray(values)) {
        return reducer(values);
      } else {
        return values;
      }
    };