Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(heatmap): define a default legend config to prevent a crash when…
… adding a new one on the interactive demo
  • Loading branch information
plouc committed Jan 12, 2022
1 parent f438ba6 commit a9486b7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
11 changes: 11 additions & 0 deletions website/src/components/controls/ControlsGroup.tsx
Expand Up @@ -36,6 +36,8 @@ import {
QuantizeColorsControl,
} from './colors'

// add some extra logic to render properties conditionally
// depending on the current settings.
export const shouldRenderProperty = (property: ChartProperty, currentSettings: any) => {
if (typeof property.when !== 'function') return true
return property.when(currentSettings)
Expand Down Expand Up @@ -80,9 +82,17 @@ const ControlSwitcher = memo(
}

let shouldRenderControl = controlConfig !== undefined

// the property is not available for the current flavor
if (Array.isArray(property.flavors) && !property.flavors.includes(currentFlavor)) {
shouldRenderControl = false
}

// the control is only available for certain flavors in the UI
// while being available for usage, this is typically used for
// `width` & `height` properties, which cannot be set for the demos
// as we use the responsive version of the charts, but has to bed defined
// when using the HTTP API.
if (
Array.isArray(property.enableControlForFlavors) &&
!property.enableControlForFlavors.includes(currentFlavor)
Expand All @@ -102,6 +112,7 @@ const ControlSwitcher = memo(
)
}

// every property which has a control should have a value
if (value === undefined) {
throw new Error(`no value defined for property: ${property.name}`)
}
Expand Down
19 changes: 18 additions & 1 deletion website/src/data/components/heatmap/props.ts
Expand Up @@ -52,7 +52,7 @@ const props: ChartProperty[] = [
...chartDimensions(allFlavors),
{
key: 'forceSquare',
help: 'Force square cells (width = height).',
help: 'Force square cells (width = height), please note that **padding is ignored**.',
defaultValue: defaults.forceSquare,
type: 'boolean',
control: { type: 'switch' },
Expand Down Expand Up @@ -229,11 +229,28 @@ const props: ChartProperty[] = [
{
key: 'legends',
group: 'Legends',
help: 'Please note that **legends are ignored when using a custom function** for `colors`.',
type: `ContinuousColorsLegendProps[]`,
control: {
type: 'array',
shouldCreate: true,
shouldRemove: true,
defaults: {
anchor: 'center',
translateX: 0,
translateY: 0,
length: 320,
thickness: 8,
direction: 'row',
tickPosition: 'after',
tickSize: 3,
tickSpacing: 4,
tickOverlap: false,
tickFormat: { format: '>-.2s', enabled: true },
title: 'New Legend',
titleAlign: 'start',
titleOffset: 4,
},
props: [
{
key: 'anchor',
Expand Down

0 comments on commit a9486b7

Please sign in to comment.