11//@ts -nocheck
22import { sortBy , reverse } from "ramda"
3- import React , {
4- useLayoutEffect , useRef , useCallback , useState ,
5- } from "react"
3+ import React , { useLayoutEffect , useRef , useCallback } from "react"
64import classNames from "classnames"
75import { useUpdateEffect , useUnmount , useMount } from "react-use"
86// this version is needed because it contains a fix for handling constant value in the chart
@@ -28,11 +26,14 @@ import {
2826 selectSyncPanAndZoom ,
2927 selectSpacePanelTransitionEndIsActive ,
3028 selectAlarm ,
31- selectTimezoneSetting
29+ selectTimezoneSetting ,
3230} from "domains/global/selectors"
3331import {
34- resetGlobalPanAndZoomAction , setCommonMaxAction , setCommonMinAction ,
35- setGlobalPauseAction , resetGlobalPauseAction
32+ resetGlobalPanAndZoomAction ,
33+ setCommonMaxAction ,
34+ setCommonMinAction ,
35+ setGlobalPauseAction ,
36+ resetGlobalPauseAction ,
3637} from "domains/global/actions"
3738
3839import { resetChartPanAndZoomAction } from "domains/chart/actions"
@@ -47,7 +48,10 @@ import { ChartMetadata, DygraphData } from "../../chart-types"
4748import { selectResizeHeight } from "../../selectors"
4849
4950import {
50- getDygraphChartType , getDataForFakeStacked , transformColors , getDygraphFillAlpha ,
51+ getDygraphChartType ,
52+ getDataForFakeStacked ,
53+ transformColors ,
54+ getDygraphFillAlpha ,
5155 hackDygraphIFrameTarps ,
5256} from "./dygraph/utils"
5357import "./dygraph-chart.css"
@@ -56,7 +60,6 @@ import useProceededChart from "../../hooks/use-proceeded-chart"
5660import useDygraphBadge from "../../hooks/useDygraphBadge"
5761import ProceededChartDisclaimer from "./proceeded-chart-disclaimer"
5862import AlarmBadge , { getBorderColor } from "./alarmBadge"
59- import NeutralPill from "./neutralPill"
6063
6164// This is the threshold above which we assume chart shown duration has changed
6265const timeframeThreshold = 5000
@@ -413,7 +416,6 @@ export const DygraphChart = ({
413416 } , [ chartUuid , dispatch , isSyncPanAndZoom ] )
414417
415418 const [ isAlarmBadgeVisible , alarmBadgeRef , updateAlarmBadge ] = useDygraphBadge ( ) as any
416- const [ isHighlightBadgeVisible , highlightBadgeRef , updateHighlightBadge ] = useDygraphBadge ( ) as any
417419
418420 // setGlobalChartUnderlay is using state from closure (chartData.after), so we need to have always
419421 // the newest callback. Unfortunately we cannot use Dygraph.updateOptions() (library restriction)
@@ -428,7 +430,6 @@ export const DygraphChart = ({
428430 resetGlobalPanAndZoom,
429431 setGlobalChartUnderlay,
430432 updateAlarmBadge,
431- updateHighlightBadge,
432433 updateChartPanOrZoom,
433434 viewAfter,
434435 viewBefore,
@@ -447,14 +448,22 @@ export const DygraphChart = ({
447448 propsRef . current . resetGlobalPanAndZoom = resetGlobalPanAndZoom
448449 propsRef . current . setGlobalChartUnderlay = setGlobalChartUnderlay
449450 propsRef . current . updateAlarmBadge = updateAlarmBadge
450- propsRef . current . updateHighlightBadge = updateHighlightBadge
451451 propsRef . current . updateChartPanOrZoom = updateChartPanOrZoom
452452 propsRef . current . viewAfter = viewAfter
453453 propsRef . current . viewBefore = viewBefore
454- } , [ alarm , chartData , globalChartUnderlay , hoveredX , immediatelyDispatchPanAndZoom ,
455- resetGlobalPanAndZoom , setGlobalChartUnderlay , updateAlarmBadge , updateHighlightBadge , updateChartPanOrZoom , viewAfter , viewBefore ] )
456-
457- const [ localHighlight , setLocalHighlight ] = useState < { before ?: number , after ?: number } | null > ( null )
454+ } , [
455+ alarm ,
456+ chartData ,
457+ globalChartUnderlay ,
458+ hoveredX ,
459+ immediatelyDispatchPanAndZoom ,
460+ resetGlobalPanAndZoom ,
461+ setGlobalChartUnderlay ,
462+ updateAlarmBadge ,
463+ updateChartPanOrZoom ,
464+ viewAfter ,
465+ viewBefore ,
466+ ] )
458467
459468 const shouldSmoothPlot = useSelector ( selectSmoothPlot )
460469 useLayoutEffect ( ( ) => {
@@ -561,29 +570,6 @@ export const DygraphChart = ({
561570 )
562571 }
563572
564- const onMetricsCorralation = hasHashParam ( "metrics_correlation" )
565- if ( onMetricsCorralation && propsRef . current . globalChartUnderlay ) {
566- const { before, masterID } = propsRef . current . globalChartUnderlay
567-
568- if ( masterID && masterID !== propsRef . current . chartData . id ) {
569- propsRef . current . updateHighlightBadge ( false )
570- } else {
571- const horizontalPadding = 3
572-
573- propsRef . current . updateHighlightBadge (
574- true ,
575- g ,
576- g . toDomXCoord ( before ) ,
577- ( pillRef , pillX , pillPosition , topMargin ) => {
578- pillRef . current . style . left = `${ pillPosition + horizontalPadding } px`
579- pillRef . current . style . top = topMargin
580- }
581- )
582- }
583- } else {
584- propsRef . current . updateHighlightBadge ( false )
585- }
586-
587573 // the chart is about to be drawn
588574 // this function renders global highlighted time-frame
589575
@@ -669,28 +655,6 @@ export const DygraphChart = ({
669655 latestIsUserAction . current = true
670656 // @ts -ignore
671657 Dygraph . moveZoom ( event , dygraph , context )
672-
673- const onMetricsCorralation = hasHashParam ( "metrics_correlation" )
674- if ( onMetricsCorralation ) {
675- const before = dygraph . toDataXCoord ( event . offsetX )
676- const after = dygraphHighlightAfter . current
677- if ( before - after > 1000 ) { // more than a sec
678- setLocalHighlight ( {
679- after,
680- before,
681- } )
682- propsRef . current . updateHighlightBadge (
683- true ,
684- dygraph ,
685- dygraph . toDomXCoord ( before ) ,
686- ( pillRef , pillX , pillPosition , topMargin ) => {
687- pillRef . current . style . left = `${ pillPosition } px`
688- pillRef . current . style . top = topMargin
689- }
690- )
691- }
692- }
693-
694658 event . preventDefault ( )
695659 } else if ( context . isPanning ) {
696660 latestIsUserAction . current = true
@@ -718,7 +682,6 @@ export const DygraphChart = ({
718682 masterID : chartData . id ,
719683 } )
720684 dygraphHighlightAfter . current = null
721- setLocalHighlight ( null )
722685 // eslint-disable-next-line no-param-reassign
723686 context . isZooming = false
724687
@@ -732,13 +695,11 @@ export const DygraphChart = ({
732695 // eslint-disable-next-line no-underscore-dangle
733696 dygraph . drawGraph_ ( false )
734697 } else if ( context . isPanning ) {
735-
736698 latestIsUserAction . current = true
737699 // @ts -ignore
738700 Dygraph . endPan ( event , dygraph , context )
739701 propsRef . current . immediatelyDispatchPanAndZoom ( )
740702 } else if ( context . isZooming ) {
741-
742703 latestIsUserAction . current = true
743704 // @ts -ignore
744705 Dygraph . endZoom ( event , dygraph , context )
@@ -1205,11 +1166,12 @@ export const DygraphChart = ({
12051166 ) }
12061167 { alarm ?. value && hasLegend && (
12071168 // @ts -ignore
1208- < AlarmBadge isVisible = { isAlarmBadgeVisible } ref = { alarmBadgeRef } status = { alarm . status } label = { alarm . value } />
1209- ) }
1210- { hasLegend && (
1211- // @ts -ignore
1212- < NeutralPill isVisible = { isHighlightBadgeVisible } ref = { highlightBadgeRef } { ...globalChartUnderlay } { ...localHighlight } />
1169+ < AlarmBadge
1170+ isVisible = { isAlarmBadgeVisible }
1171+ ref = { alarmBadgeRef }
1172+ status = { alarm . status }
1173+ label = { alarm . value }
1174+ />
12131175 ) }
12141176 < div className = "dygraph-chart__labels-hidden" id = { hiddenLabelsElementId } />
12151177 </ >
0 commit comments