@mwater/visualization 5.3.0 → 5.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mwater/visualization",
3
- "version": "5.3.0",
3
+ "version": "5.3.1",
4
4
  "description": "Visualization library",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -1,5 +1,6 @@
1
1
  import { createContext } from "react"
2
2
 
3
+ /** Palettes are groups of 6 colors. Pad with nulls if fewer than 6 colors are provided. */
3
4
  export interface CustomColorsContextType {
4
5
  customColors: (string | null)[]
5
6
  }
@@ -92,11 +92,10 @@ function ColorPaletteCollectionComponent(props: ColorPaletteCollectionComponentP
92
92
  const numColors = props.categories.filter((c) => c.value != null).length
93
93
 
94
94
  if (customColorsContext && customColorsContext.customColors.filter((c) => c != null).length > 0) {
95
- const filteredCustomColors = customColorsContext.customColors.filter((c) => c != null)
96
95
  const customPalettes: Palette[] = []
97
- for (let i = 0; i < filteredCustomColors.length; i += 6) {
98
- const customPalette = filteredCustomColors.slice(i, i + 6)
99
- customPalettes.push({ type: "custom", reversed: false, colors: customPalette })
96
+ for (let i = 0; i < customColorsContext.customColors.length; i += 6) {
97
+ const customPalette = customColorsContext.customColors.slice(i, i + 6)
98
+ customPalettes.push({ type: "custom", reversed: false, colors: customPalette.filter((c) => c != null) as string[] })
100
99
  }
101
100
  palettes.unshift(...customPalettes)
102
101
  }
@@ -174,12 +173,13 @@ class ColorPaletteComponent extends React.Component<ColorPaletteComponentProps>
174
173
  render() {
175
174
  return (
176
175
  <div onClick={this.handleSelect} className="axis-palette">
177
- {_.map(this.props.colorSet, (color, i) => {
176
+ {_.range(Math.max(6, this.props.colorSet.length)).map((i) => {
177
+ const color = this.props.colorSet[i]
178
178
  const cellStyle: React.CSSProperties = {
179
179
  display: "inline-block",
180
180
  height: 20,
181
181
  width: 20,
182
- backgroundColor: color
182
+ backgroundColor: color ?? "transparent"
183
183
  }
184
184
  return <div style={cellStyle} key={i}> </div>
185
185
  })}
@@ -344,7 +344,8 @@ function CustomizeLayout(props: { layoutOptions: BlocksLayoutOptions; onLayoutOp
344
344
  </FormGroup>
345
345
  <FormGroup label="Custom Colors">
346
346
  <div style={{ display: 'grid', gridTemplateColumns: 'repeat(6, 1fr)', gap: '5px' }}>
347
- {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map((colorIndex) => (
347
+ {/* 18 colors, 3 rows of 6 */}
348
+ {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17].map((colorIndex) => (
348
349
  <ColorComponent
349
350
  key={colorIndex}
350
351
  color={layoutOptions.customColors[colorIndex]}