@mwater/visualization 5.3.0 → 5.3.2

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.
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ /** Palettes are groups of 6 colors. Pad with nulls if fewer than 6 colors are provided. */
2
3
  export interface CustomColorsContextType {
3
4
  customColors: (string | null)[];
4
5
  }
@@ -100,11 +100,10 @@ function ColorPaletteCollectionComponent(props) {
100
100
  // Number of colors needed. Null doesn't count to length
101
101
  const numColors = props.categories.filter((c) => c.value != null).length;
102
102
  if (customColorsContext && customColorsContext.customColors.filter((c) => c != null).length > 0) {
103
- const filteredCustomColors = customColorsContext.customColors.filter((c) => c != null);
104
103
  const customPalettes = [];
105
- for (let i = 0; i < filteredCustomColors.length; i += 6) {
106
- const customPalette = filteredCustomColors.slice(i, i + 6);
107
- customPalettes.push({ type: "custom", reversed: false, colors: customPalette });
104
+ for (let i = 0; i < customColorsContext.customColors.length; i += 6) {
105
+ const customPalette = customColorsContext.customColors.slice(i, i + 6);
106
+ customPalettes.push({ type: "custom", reversed: false, colors: customPalette.filter((c) => c != null) });
108
107
  }
109
108
  palettes.unshift(...customPalettes);
110
109
  }
@@ -148,12 +147,13 @@ class ColorPaletteComponent extends react_1.default.Component {
148
147
  return this.props.onPaletteSelected(this.props.index);
149
148
  };
150
149
  render() {
151
- return (react_1.default.createElement("div", { onClick: this.handleSelect, className: "axis-palette" }, lodash_1.default.map(this.props.colorSet, (color, i) => {
150
+ return (react_1.default.createElement("div", { onClick: this.handleSelect, className: "axis-palette" }, lodash_1.default.range(Math.max(6, this.props.colorSet.length)).map((i) => {
151
+ const color = this.props.colorSet[i];
152
152
  const cellStyle = {
153
153
  display: "inline-block",
154
154
  height: 20,
155
155
  width: 20,
156
- backgroundColor: color
156
+ backgroundColor: color ?? "transparent"
157
157
  };
158
158
  return react_1.default.createElement("div", { style: cellStyle, key: i }, " ");
159
159
  })));
@@ -203,7 +203,7 @@ function CustomizeLayout(props) {
203
203
  onLayoutOptionsChange({ ...layoutOptions, blockBackgroundColor: blockBackgroundColor ?? "white" });
204
204
  } })),
205
205
  react_1.default.createElement(bootstrap_1.FormGroup, { label: "Custom Colors" },
206
- react_1.default.createElement("div", { style: { display: 'grid', gridTemplateColumns: 'repeat(6, 1fr)', gap: '5px' } }, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map((colorIndex) => (react_1.default.createElement(ColorComponent_1.default, { key: colorIndex, color: layoutOptions.customColors[colorIndex], onChange: (color) => {
206
+ react_1.default.createElement("div", { style: { display: 'grid', gridTemplateColumns: 'repeat(6, 1fr)', gap: '5px' } }, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17].map((colorIndex) => (react_1.default.createElement(ColorComponent_1.default, { key: colorIndex, color: layoutOptions.customColors[colorIndex], onChange: (color) => {
207
207
  onLayoutOptionsChange((0, immer_1.default)(layoutOptions, (draft) => {
208
208
  draft.customColors[colorIndex] = color;
209
209
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mwater/visualization",
3
- "version": "5.3.0",
3
+ "version": "5.3.2",
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]}