Skip to content

Commit 71a9ad4

Browse files
authored
fix(6598): properly use default static legend height. (#6615)
1 parent b30fab4 commit 71a9ad4

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/visualization/components/internal/StaticLegend.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Libraries
2-
import React, {FC, useCallback, useRef, useState} from 'react'
2+
import React, {FC, useCallback, useRef, useState, useEffect} from 'react'
33
import {debounce} from 'lodash'
44

55
// Utils
@@ -46,6 +46,7 @@ import {
4646
LegendDisplayStatus,
4747
STATIC_LEGEND_HEIGHT_RATIO_MAXIMUM,
4848
STATIC_LEGEND_HEIGHT_RATIO_MINIMUM,
49+
STATIC_LEGEND_HEIGHT_RATIO_DEFAULT,
4950
STATIC_LEGEND_HEIGHT_RATIO_NOT_SET,
5051
STATIC_LEGEND_HEIGHT_RATIO_STEP,
5152
STATIC_LEGEND_SHOW_DEFAULT,
@@ -71,7 +72,7 @@ const StaticLegend: FC<Props> = ({properties, update}) => {
7172
const {
7273
staticLegend = {
7374
colorizeRows: LEGEND_COLORIZE_ROWS_DEFAULT,
74-
heightRatio: STATIC_LEGEND_HEIGHT_RATIO_NOT_SET,
75+
heightRatio: STATIC_LEGEND_HEIGHT_RATIO_DEFAULT,
7576
opacity: LEGEND_OPACITY_DEFAULT,
7677
orientationThreshold: LEGEND_ORIENTATION_THRESHOLD_DEFAULT,
7778
show: STATIC_LEGEND_SHOW_DEFAULT,
@@ -81,7 +82,7 @@ const StaticLegend: FC<Props> = ({properties, update}) => {
8182
const {valueAxis} = staticLegend
8283
const {
8384
colorizeRows = false, // undefined is considered false because of omitempty
84-
heightRatio: defaultHeightRatio = STATIC_LEGEND_HEIGHT_RATIO_NOT_SET,
85+
heightRatio: defaultHeightRatio = STATIC_LEGEND_HEIGHT_RATIO_DEFAULT,
8586
opacity = LEGEND_OPACITY_DEFAULT,
8687
orientationThreshold = LEGEND_ORIENTATION_THRESHOLD_DEFAULT,
8788
show,
@@ -91,14 +92,15 @@ const StaticLegend: FC<Props> = ({properties, update}) => {
9192
const heightRatioRef = useRef<number>(null)
9293
heightRatioRef.current = heightRatio
9394

94-
React.useEffect(() => {
95-
if (
96-
heightRatio === STATIC_LEGEND_HEIGHT_RATIO_NOT_SET &&
97-
heightRatio !== defaultHeightRatio
98-
) {
99-
setHeightRatio(defaultHeightRatio)
95+
useEffect(() => {
96+
setHeightRatio(defaultHeightRatio)
97+
}, [defaultHeightRatio])
98+
99+
useEffect(() => {
100+
if (showOptions && heightRatio === STATIC_LEGEND_HEIGHT_RATIO_NOT_SET) {
101+
updateHeightRatio(STATIC_LEGEND_HEIGHT_RATIO_DEFAULT)
100102
}
101-
}, [defaultHeightRatio, heightRatio])
103+
}, [showOptions])
102104

103105
const handleChooseStaticLegend = (value: string) => {
104106
setShowOptions(value === LegendDisplayStatus.SHOW)

0 commit comments

Comments
 (0)