Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into fix-timeseries-scale
  • Loading branch information
scottdickerson committed Nov 11, 2020
2 parents eb49304 + b737def commit be23902
Show file tree
Hide file tree
Showing 37 changed files with 3,685 additions and 116 deletions.
24 changes: 24 additions & 0 deletions .storybook/__snapshots__/Welcome.story.storyshot
Original file line number Diff line number Diff line change
Expand Up @@ -2856,6 +2856,18 @@ exports[`Storybook Snapshot tests and console checks Storyshots 0/Getting Starte
TableViewDropdown
</div>
</div>
<div
className="bx--structured-list-row"
>
<div
className="bx--structured-list-td"
/>
<div
className="bx--structured-list-td"
>
IconDropdown
</div>
</div>
<div
className="bx--structured-list-row"
>
Expand Down Expand Up @@ -3504,6 +3516,18 @@ exports[`Storybook Snapshot tests and console checks Storyshots 0/Getting Starte
FilterTags
</div>
</div>
<div
className="bx--structured-list-row"
>
<div
className="bx--structured-list-td"
/>
<div
className="bx--structured-list-td"
>
ColorDropdown
</div>
</div>
<div
className="bx--structured-list-row"
>
Expand Down
6 changes: 3 additions & 3 deletions src/components/BarChartCard/BarChartCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ const BarChartCard = ({
);

// Set the colors for each dataset
const uniqueDatasets = [
...new Set(chartData.map((dataset) => dataset.group)),
];
const uniqueDatasets = !isAllValuesEmpty
? [...new Set(chartData.map((dataset) => dataset.group))]
: [];
const colors = !isAllValuesEmpty
? formatColors(series, uniqueDatasets, isEditable)
: null;
Expand Down
5 changes: 3 additions & 2 deletions src/components/BarChartCard/barChartUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ export const formatChartData = (
timeDataSourceId,
type
) => {
const data = [];
if (!isNil(values) || !isEmpty(series)) {
let data = values;
if (!isNil(values) && !isEmpty(series)) {
data = [];
// grouped or stacked
if (type === BAR_CHART_TYPES.GROUPED || type === BAR_CHART_TYPES.STACKED) {
let uniqueDatasetNames;
Expand Down
14 changes: 14 additions & 0 deletions src/components/BarChartCard/barChartUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ describe('barChartUtils', () => {
value: 270,
},
]);
expect(
formatChartData(series, null, 'city', null, BAR_CHART_TYPES.GROUPED)
).toBeNull();
});

it('formatChartData returns formatted data for time-based and group-based chart', () => {
Expand Down Expand Up @@ -258,6 +261,11 @@ describe('barChartUtils', () => {
value: 200,
},
]);

// Handle nulls
expect(
formatChartData(series, null, null, 'timestamp', BAR_CHART_TYPES.STACKED)
).toBeNull();
});

it('formatChartData returns formatted data for simple, non-time and non-group chart', () => {
Expand Down Expand Up @@ -293,6 +301,9 @@ describe('barChartUtils', () => {
value: 388,
},
]);
expect(
formatChartData(series, null, 'city', null, BAR_CHART_TYPES.SIMPLE)
).toBeNull();
});

it('formatChartData returns formatted data for time-based, non-group chart', () => {
Expand Down Expand Up @@ -333,6 +344,9 @@ describe('barChartUtils', () => {
value: 565,
},
]);
expect(
formatChartData(series, null, null, 'timestamp', BAR_CHART_TYPES.SIMPLE)
).toBeNull();
});

it('formatChartData doesnt return null values', () => {
Expand Down
120 changes: 120 additions & 0 deletions src/components/ColorDropdown/ColorDropdown.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Dropdown } from 'carbon-components-react';
import {
purple70,
cyan50,
teal70,
magenta70,
red50,
red90,
green60,
blue80,
magenta50,
purple50,
teal50,
cyan90,
} from '@carbon/colors';

import { settings } from '../../constants/Settings';

const { iotPrefix } = settings;

const colorPropType = PropTypes.shape({
carbonColor: PropTypes.string,
name: PropTypes.string,
});

const propTypes = {
/** Array of colors to be shown */
colors: PropTypes.arrayOf(colorPropType),
/** The label of the Dropdown, defaults to 'Select a color' */
label: PropTypes.string,
/** The title of the Dropdown, defaults to 'Color' */
titleText: PropTypes.string,
/** Required Id string */
id: PropTypes.string.isRequired,
/** True if the light theme is to be used, defaults to false */
light: PropTypes.bool,
/** Callback for when any of the Dropdown color value changes */
onChange: PropTypes.func.isRequired,
/** The selected color, use to set initial color */
selectedColor: colorPropType,
/** Id used if needed for testing */
testID: PropTypes.string,
};

const defaultProps = {
colors: [
{ carbonColor: purple70, name: 'purple70' },
{ carbonColor: cyan50, name: 'cyan50' },
{ carbonColor: teal70, name: 'teal70' },
{ carbonColor: magenta70, name: 'magenta70' },
{ carbonColor: red50, name: 'red50' },
{ carbonColor: red90, name: 'red90' },
{ carbonColor: green60, name: 'green60' },
{ carbonColor: blue80, name: 'blue80' },
{ carbonColor: magenta50, name: 'magenta50' },
{ carbonColor: purple50, name: 'purple50' },
{ carbonColor: teal50, name: 'teal50' },
{ carbonColor: cyan90, name: 'cyan90' },
],
label: 'Select a color',
light: false,
selectedColor: undefined,
testID: undefined,
titleText: 'Color',
};

const ColorDropdown = ({
colors,
id,
label,
light,
onChange,
selectedColor,
titleText,
testID,
}) => {
const renderColorItem = (item) => {
return (
<div
title={`${item.name}`}
className={`${iotPrefix}--color-dropdown__item`}>
<div className={`${iotPrefix}--color-dropdown__item-border`}>
<div
title={`${item.carbonColor}`}
className={`${iotPrefix}--color-dropdown__color-sample`}
style={{ backgroundColor: item.carbonColor }}
/>
<div className={`${iotPrefix}--color-dropdown__color-name`}>
{item.name}
</div>
</div>
</div>
);
};

return (
<Dropdown
className={`${iotPrefix}--color-dropdown`}
id={id}
itemToString={renderColorItem}
items={colors}
label={label}
light={light}
onChange={(change) => {
onChange({ color: change.selectedItem });
}}
selectedItem={selectedColor}
titleText={titleText}
type="default"
test-id={testID}
/>
);
};

ColorDropdown.propTypes = propTypes;
ColorDropdown.defaultProps = defaultProps;

export default ColorDropdown;
64 changes: 64 additions & 0 deletions src/components/ColorDropdown/ColorDropdown.story.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react';
import { action } from '@storybook/addon-actions';
import { withKnobs, boolean, text } from '@storybook/addon-knobs';
import { red50, blue50, green50, teal70 } from '@carbon/colors';

import ColorDropdown from './ColorDropdown';

export default {
title: 'Watson IoT Experimental/ColorDropdown',
decorators: [withKnobs],
parameters: {
component: ColorDropdown,
},
excludeStories: [],
};

export const DefaultExample = () => (
<div style={{ width: '200px' }}>
<ColorDropdown
id="myColorDropdown"
label={text('label', 'Select a color')}
light={boolean('light', false)}
titleText={text('titleText', 'Color')}
onChange={action('onChange')}
/>
</div>
);

export const PresetSelectionExample = () => (
<div style={{ width: '200px' }}>
<ColorDropdown
id="myColorDropdown"
label={text('label', 'Select a color')}
titleText={text('titleText', 'Color')}
onChange={action('onChange')}
selectedColor={{ carbonColor: teal70, name: 'teal70' }}
/>
</div>
);

export const CustomColorsExample = () => (
<div style={{ width: '200px' }}>
<ColorDropdown
id="myColorDropdown"
label={text('label', 'Select a color')}
titleText={text('titleText', 'Color')}
colors={[
{ carbonColor: red50, name: 'red' },
{ carbonColor: green50, name: 'green' },
{ carbonColor: blue50, name: 'blue' },
]}
onChange={action('onChange')}
/>
</div>
);

DefaultExample.story = {
parameters: {
info: {
propTables: [ColorDropdown],
propTablesExclude: [],
},
},
};
Loading

0 comments on commit be23902

Please sign in to comment.