All files / modules/85-cv/pages/monitored-service/CVMonitoredService/components/MonitoredServiceGraphView MonitoredServiceGraphView.utils.tsx

16% Statements 4/25
0% Branches 0/14
20% Functions 1/5
12.5% Lines 3/24

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                              13x         13x       4x                                                                                                                    
/*
 * 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 { Chart as _Chart } from 'highcharts'
import type { NetworkgraphOptions } from '@cv/components/DependencyGraph/DependencyGraph.types'
import type { ServicePoint } from './ServiceDependencyGraph.types'
 
interface Chart extends _Chart {
  sticky?: any
}
 
const destroySticky = (chart: Chart): void => {
  chart.sticky?.destroy()
  delete chart.sticky
}
 
export const getDependencyGraphOptions = (
  setPoint: (point?: ServicePoint) => void,
  height: number | string
): NetworkgraphOptions => {
  return {
    chart: {
      height,
      spacing: [0, 0, 0, 0],
      events: {
        click: function () {
          destroySticky(this.series[0].chart)
        }
      }
    },
    series: [
      {
        type: 'networkgraph',
        point: {
          events: {
            click: function () {
              const text = '<span></span>'
              const cardWidth = 360
              const cardHeight = 435
              const chart: Chart = this.series.chart
 
              const anchorX = (this as any).plotX + (this.series.xAxis as any).pos
              const anchorY = (this as any).plotY + (this.series.yAxis as any).pos
              const align = anchorX < chart.chartWidth - cardWidth ? 'left' : 'right'
              const x = align === 'left' ? anchorX : anchorX - cardWidth
 
              let y = 50
 
              if (anchorY > cardHeight) {
                y = anchorY - cardHeight
              } else if (anchorY < chart.chartHeight - cardHeight) {
                y = anchorY
              }
 
              if (!chart.sticky) {
                chart.sticky = chart.renderer
                  .label(text, x, y, 'callout', anchorX, anchorY)
                  .attr({
                    align,
                    zIndex: 7
                  })
                  .add()
              } else {
                chart.sticky.attr({ align, text }).animate({ anchorX, anchorY, x, y }, { duration: 100 })
              }
 
              setPoint({
                sticky: chart.sticky,
                monitoredServiceIdentifier: (this as any).id,
                destroySticky: () => destroySticky(chart)
              })
            }
          }
        }
      }
    ]
  }
}