Skip to content

Commit b5527c1

Browse files
committedJan 12, 2022
feat(legends): fix continuous color scale legend when the direction is column
1 parent 9aaaad5 commit b5527c1

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed
 

‎packages/heatmap/src/HeatMapCanvas.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
HeatMapCommonProps,
1515
HeatMapDatum,
1616
CellShape,
17+
CustomLayerProps,
1718
} from './types'
1819

1920
type InnerNetworkCanvasProps<Datum extends HeatMapDatum, ExtraProps extends object> = Omit<
@@ -56,9 +57,6 @@ const InnerHeatMapCanvas = <Datum extends HeatMapDatum, ExtraProps extends objec
5657
legends = canvasDefaultProps.legends,
5758
annotations = canvasDefaultProps.annotations as HeatMapCommonProps<Datum>['annotations'],
5859
isInteractive = canvasDefaultProps.isInteractive,
59-
// onMouseEnter,
60-
// onMouseMove,
61-
// onMouseLeave,
6260
onClick,
6361
hoverTarget = canvasDefaultProps.hoverTarget,
6462
tooltip = canvasDefaultProps.tooltip as HeatMapCommonProps<Datum>['tooltip'],
@@ -115,6 +113,12 @@ const InnerHeatMapCanvas = <Datum extends HeatMapDatum, ExtraProps extends objec
115113

116114
const theme = useTheme()
117115

116+
const customLayerProps: CustomLayerProps<Datum> = {
117+
cells,
118+
activeCell,
119+
setActiveCell,
120+
}
121+
118122
useEffect(() => {
119123
if (canvasEl.current === null) return
120124

@@ -185,6 +189,8 @@ const InnerHeatMapCanvas = <Datum extends HeatMapDatum, ExtraProps extends objec
185189
annotations: computedAnnotations,
186190
theme,
187191
})
192+
} else if (typeof layer === 'function') {
193+
layer(ctx, customLayerProps)
188194
}
189195
})
190196
}, [
@@ -196,6 +202,7 @@ const InnerHeatMapCanvas = <Datum extends HeatMapDatum, ExtraProps extends objec
196202
innerHeight,
197203
margin,
198204
layers,
205+
customLayerProps,
199206
cells,
200207
renderCell,
201208
enableGridX,

‎packages/legends/src/compute.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ export const computeItemLayout = ({
208208
}
209209

210210
export const computeContinuousColorsLegend = ({
211-
// id,
212211
scale,
213212
ticks,
214213
length = continuousColorsLegendDefaults.length,
@@ -223,7 +222,8 @@ export const computeContinuousColorsLegend = ({
223222
titleAlign = continuousColorsLegendDefaults.titleAlign,
224223
titleOffset = continuousColorsLegendDefaults.titleOffset,
225224
}: ContinuousColorsLegendProps) => {
226-
const domain = scale.domain()
225+
// left to right for `row`, bottom to top for `column`
226+
const domain = direction === 'column' ? [...scale.domain()].reverse() : scale.domain()
227227

228228
const positionScale = scaleLinear().domain(domain)
229229
if (domain.length === 2) {
@@ -263,9 +263,9 @@ export const computeContinuousColorsLegend = ({
263263
let height: number
264264

265265
const gradientX1 = 0
266-
const gradientY1 = 0
266+
let gradientY1 = 0
267267
let gradientX2 = 0
268-
let gradientY2 = 0
268+
const gradientY2 = 0
269269

270270
let titleX: number
271271
let titleY: number
@@ -333,7 +333,7 @@ export const computeContinuousColorsLegend = ({
333333
width = thickness
334334
height = length
335335

336-
gradientY2 = 1
336+
gradientY1 = 1
337337

338338
let x1: number
339339
let x2: number

‎website/src/components/components/explorer/ComponentsGridItem.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const ComponentsGridItem = memo(({ name, id, flavors }: ChartNavData) =>
1212
}, [])
1313

1414
return (
15-
<Container to={`/${id}/`}>
15+
<Container>
1616
<Icon className={`sprite-icons-${id}-${theme.id}-colored`} />
1717
<Header>
1818
<Name>{name}</Name>
@@ -39,8 +39,7 @@ export const ComponentsGridItem = memo(({ name, id, flavors }: ChartNavData) =>
3939
)
4040
})
4141

42-
const Container = styled(Link)`
43-
text-decoration: none;
42+
const Container = styled.div`
4443
background-color: ${({ theme }) => theme.colors.cardBackground};
4544
border-radius: 2px;
4645
padding: 12px;

‎website/src/pages/heatmap/canvas.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ const initialProperties: CanvasUnmappedProps = {
7777

7878
renderCell: 'rect',
7979
colors: {
80-
type: 'diverging',
80+
type: 'quantize',
8181
scheme: 'red_yellow_blue',
82-
divergeAt: 0.5,
82+
steps: 10,
8383
minValue: -100_000,
8484
maxValue: 100_000,
8585
},

0 commit comments

Comments
 (0)
Please sign in to comment.