All files / modules/75-ce/components/CEChart CEChartOptions.ts

88.89% Statements 8/9
64.29% Branches 9/14
66.67% Functions 2/3
87.5% Lines 7/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110                14x   14x                         14x   14x                                                                                   14x         6x           5x                                                              
/*
 * Copyright 2021 Harness Inc. All rights reserved.
 * Use of this source code is governed by the PolyForm Shield 1.0.0 license
 * that can be found in the licenses directory at the root of this repository, also available at
 * https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt.
 */
 
import type Highcharts from 'highcharts'
import formatCost from '@ce/utils/formatCost'
 
export const CE_COLOR_CONST = [
  '#25A6F7', // blue
  '#8A77DE', // pruple
  '#FF479F', // pink
  '#FFBC08', // yellow
  '#0BC8D6', // teal
  '#F25C61', // red
  '#7FB800', // green 2
  '#ED61B5', // pink 2
  '#35D6CB', // teal 2
  '#36D068' // green
]
 
export const CE_CHARTS_ENTITY_LIMIT = 30
 
export default {
  chart: {
    height: 300,
    animation: {
      duration: 100
    },
    style: {
      fontFamily: 'var(--font-family)'
    }
  },
  boost: {
    seriesThreshold: CE_CHARTS_ENTITY_LIMIT + 2 // https://stackoverflow.com/a/46365043/3860249
  },
  title: {
    text: ''
  },
  yAxis: {
    title: {
      text: ''
    }
  },
  plotOptions: {
    area: {
      lineWidth: 1,
      marker: {
        enabled: false
      }
    },
    column: {
      borderColor: null
    }
  },
  xAxis: {
    type: 'datetime',
    gridLineColor: 'var(--color-chart-line-color)'
  },
  credits: {
    enabled: false
  },
  colors: CE_COLOR_CONST
}
 
export function getRadialChartOptions(
  series: Array<Record<string, string | number>> = [],
  colors: string[],
  options: Record<string, any> = {}
): Highcharts.Options {
  const data: Array<Record<string, string | number>> = series.map(row => ({
    name: row.name,
    id: row.name,
    y: row.value || row.cost
  }))
 
  return {
    chart: options.chart || { height: 260, width: 300 },
    tooltip: {
      useHTML: true,
      enabled: options.tooltipDisabled !== false,
      headerFormat: '',
      pointFormatter: function (this: Record<string, string | any>) {
        return `<b>${this.name}</b>: ${formatCost(this.y)}`
      }
    },
    plotOptions: {
      pie: {
        allowPointSelect: true,
        cursor: 'pointer',
        dataLabels: {
          enabled: false
        },
        ...options?.plotOptions?.pie
      }
    },
    series: [
      {
        name: 'Cost',
        innerSize: '80%',
        type: 'pie',
        data
      }
    ],
    colors
  }
}