Skip to content
This repository was archived by the owner on Apr 19, 2024. It is now read-only.

Commit 0fdcd47

Browse files
authored
Stable chart height fix (#420)
* remove unneeded support for old dashboard localstorage chart-height key * fix changing height of chart container * remove unused metrics_correlation functionality * 2.62.3 * 2.26.4
1 parent f8b1360 commit 0fdcd47

File tree

7 files changed

+34
-143
lines changed

7 files changed

+34
-143
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@netdata/dashboard",
3-
"version": "2.26.2",
3+
"version": "2.26.4",
44
"homepage": ".",
55
"main": "./lib/src/index-npm.js",
66
"files": [

src/domains/chart/components/lib-charts/dygraph-chart.tsx

Lines changed: 30 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//@ts-nocheck
22
import { sortBy, reverse } from "ramda"
3-
import React, {
4-
useLayoutEffect, useRef, useCallback, useState,
5-
} from "react"
3+
import React, { useLayoutEffect, useRef, useCallback } from "react"
64
import classNames from "classnames"
75
import { 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"
3331
import {
34-
resetGlobalPanAndZoomAction, setCommonMaxAction, setCommonMinAction,
35-
setGlobalPauseAction, resetGlobalPauseAction
32+
resetGlobalPanAndZoomAction,
33+
setCommonMaxAction,
34+
setCommonMinAction,
35+
setGlobalPauseAction,
36+
resetGlobalPauseAction,
3637
} from "domains/global/actions"
3738

3839
import { resetChartPanAndZoomAction } from "domains/chart/actions"
@@ -47,7 +48,10 @@ import { ChartMetadata, DygraphData } from "../../chart-types"
4748
import { selectResizeHeight } from "../../selectors"
4849

4950
import {
50-
getDygraphChartType, getDataForFakeStacked, transformColors, getDygraphFillAlpha,
51+
getDygraphChartType,
52+
getDataForFakeStacked,
53+
transformColors,
54+
getDygraphFillAlpha,
5155
hackDygraphIFrameTarps,
5256
} from "./dygraph/utils"
5357
import "./dygraph-chart.css"
@@ -56,7 +60,6 @@ import useProceededChart from "../../hooks/use-proceeded-chart"
5660
import useDygraphBadge from "../../hooks/useDygraphBadge"
5761
import ProceededChartDisclaimer from "./proceeded-chart-disclaimer"
5862
import AlarmBadge, { getBorderColor } from "./alarmBadge"
59-
import NeutralPill from "./neutralPill"
6063

6164
// This is the threshold above which we assume chart shown duration has changed
6265
const 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
</>

src/domains/chart/components/lib-charts/neutralPill.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/domains/chart/components/resize-handler.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { setResizeHeightAction } from "domains/chart/actions"
44
import { LEGEND_BOTTOM_SINGLE_LINE_HEIGHT } from "domains/chart/utils/legend-utils"
55
import { useDispatch } from "store/redux-separate-context"
66

7-
export const LOCALSTORAGE_HEIGHT_KEY_PREFIX_OLD = "chart_heights."
87
export const LOCALSTORAGE_HEIGHT_KEY_PREFIX = "chart_height."
98

109
interface Props {

src/domains/chart/utils/get-portal-node-styles.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
LOCALSTORAGE_HEIGHT_KEY_PREFIX,
3-
LOCALSTORAGE_HEIGHT_KEY_PREFIX_OLD,
4-
} from "domains/chart/components/resize-handler"
1+
import { LOCALSTORAGE_HEIGHT_KEY_PREFIX } from "domains/chart/components/resize-handler"
52

63
import { LEGEND_BOTTOM_SINGLE_LINE_HEIGHT } from "domains/chart/utils/legend-utils"
74
import { Attributes } from "./transformDataAttributes"
@@ -17,8 +14,6 @@ type GetPortalNodeStyles = (
1714
minWidth: string | undefined
1815
}
1916

20-
const oldDefaultHeights = ["180px", "90px"]
21-
2217
const getHeightFromLocalStorage = (heightID: string, isLegendOnBottom: boolean) => {
2318
const persitedHeight = localStorage.getItem(`${LOCALSTORAGE_HEIGHT_KEY_PREFIX}${heightID}`)
2419
if (persitedHeight) {
@@ -31,20 +26,6 @@ const getHeightFromLocalStorage = (heightID: string, isLegendOnBottom: boolean)
3126
}px`
3227
}
3328

34-
// We'll support the old key for few months, so that user's custom heights will be working,
35-
// but we'll save any changes only to the new key.
36-
const persistedHeightOld = localStorage.getItem(
37-
`${LOCALSTORAGE_HEIGHT_KEY_PREFIX_OLD}${heightID}`,
38-
)
39-
if (persistedHeightOld) {
40-
if (oldDefaultHeights.includes(persistedHeightOld)) {
41-
// If saved value looks like `oldDefaultHeights`, then it is most likely an automatic value
42-
// from old dashboard. Don't import it anymore. On next resize the height will be persisted
43-
// to the new key.
44-
return null
45-
}
46-
return persistedHeightOld
47-
}
4829
return null
4930
}
5031

src/styles/main.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ body.modal-open {
294294

295295
.netdata-chartblock-container {
296296
display: inline-block;
297+
overflow: hidden;
297298
}
298299

299300
/* https://github.com/seiyria/bootstrap-slider/issues/746 */

0 commit comments

Comments
 (0)