Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(legends): add support for continuous color scale legends
- Loading branch information
Showing
9 changed files
with
405 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ContinuousColorsLegendProps } from './types' | ||
|
||
export const continuousColorsLegendDefaults: { | ||
length: NonNullable<ContinuousColorsLegendProps['length']> | ||
thickness: NonNullable<ContinuousColorsLegendProps['thickness']> | ||
direction: NonNullable<ContinuousColorsLegendProps['direction']> | ||
tickPosition: NonNullable<ContinuousColorsLegendProps['tickPosition']> | ||
tickSize: NonNullable<ContinuousColorsLegendProps['tickSize']> | ||
tickSpacing: NonNullable<ContinuousColorsLegendProps['tickSpacing']> | ||
tickOverlap: NonNullable<ContinuousColorsLegendProps['tickOverlap']> | ||
tickFormat: NonNullable<ContinuousColorsLegendProps['tickFormat']> | ||
titleAlign: NonNullable<ContinuousColorsLegendProps['titleAlign']> | ||
titleOffset: NonNullable<ContinuousColorsLegendProps['titleOffset']> | ||
} = { | ||
length: 200, | ||
thickness: 16, | ||
direction: 'row', | ||
tickPosition: 'after', | ||
tickSize: 4, | ||
tickSpacing: 3, | ||
tickOverlap: false, | ||
tickFormat: (value: number) => `${value}`, | ||
titleAlign: 'start', | ||
titleOffset: 4, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
export * from './svg' | ||
export * from './canvas' | ||
export * from './defaults' | ||
export * from './hooks' | ||
export * from './props' | ||
export * from './types' | ||
export * from './compute' | ||
export * from './defaults' |
47 changes: 47 additions & 0 deletions
47
packages/legends/src/svg/AnchoredContinuousColorsLegendSvg.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { AnchoredContinuousColorsLegendProps } from '../types' | ||
import { computePositionFromAnchor } from '../compute' | ||
import { continuousColorsLegendDefaults } from '../defaults' | ||
import { ContinuousColorsLegendSvg } from './ContinuousColorsLegendSvg' | ||
|
||
export const AnchoredContinuousColorsLegendSvg = ({ | ||
containerWidth, | ||
containerHeight, | ||
anchor, | ||
translateX = 0, | ||
translateY = 0, | ||
length = continuousColorsLegendDefaults.length, | ||
thickness = continuousColorsLegendDefaults.thickness, | ||
direction = continuousColorsLegendDefaults.direction, | ||
...legendProps | ||
}: AnchoredContinuousColorsLegendProps) => { | ||
let width: number | ||
let height: number | ||
if (direction === 'row') { | ||
width = length | ||
height = thickness | ||
} else { | ||
width = thickness | ||
height = length | ||
} | ||
|
||
const { x, y } = computePositionFromAnchor({ | ||
anchor, | ||
translateX, | ||
translateY, | ||
containerWidth, | ||
containerHeight, | ||
width, | ||
height, | ||
}) | ||
|
||
return ( | ||
<g transform={`translate(${x}, ${y})`}> | ||
<ContinuousColorsLegendSvg | ||
length={length} | ||
thickness={thickness} | ||
direction={direction} | ||
{...legendProps} | ||
/> | ||
</g> | ||
) | ||
} |
Oops, something went wrong.