lucid-ui
Version:
A UI component library from Xandr.
113 lines • 4.16 kB
JavaScript
import _ from 'lodash';
import React from 'react';
import Bars from '../Bars/Bars';
import * as chartConstants from '../../constants/charts';
import * as d3Scale from 'd3-scale';
export default {
title: 'Private/Bars',
component: Bars,
parameters: {
docs: {
description: {
component: Bars.peek.description,
},
},
},
};
/* Basic */
export const Basic = (args) => {
/* eslint-disable comma-spacing */
const width = 750;
const height = 400;
const data = [
{ x: 'one', y0: 1, y1: 2, y2: 3, y3: 5 },
{ x: 'two', y0: 2, y1: 3, y2: 4, y3: 6 },
{ x: 'three', y0: 2, y1: 4, y2: 5, y3: 6 },
{ x: 'four', y0: 3, y1: 6, y2: 7, y3: 7 },
{ x: 'five', y0: 4, y1: 8, y2: 9, y3: 8 },
{ x: 'six', y0: 11, y1: 8, y2: 9, y3: 5 },
];
const yFields = ['y0', 'y1', 'y2', 'y3'];
const yMax = _.max(_.reduce(yFields, (acc, field) => {
return acc.concat(_.map(data, field));
}, []));
const xScale = d3Scale
.scaleBand()
.domain(_.map(data, 'x'))
.range([0, width])
.round(true)
.paddingInner(0.1);
const yScale = d3Scale
.scaleLinear()
.domain([0, yMax])
.range([height, 0]);
const style = {
paddingTop: '9rem',
};
return (React.createElement("div", { style: style },
React.createElement("svg", { width: width, height: height },
React.createElement(Bars, { ...args, data: data, xScale: xScale, yScale: yScale, yFields: yFields, hasToolTips: true })),
React.createElement("svg", { width: width, height: height },
React.createElement(Bars, { ...args, data: data, xScale: xScale, yScale: yScale, yFields: yFields, isStacked: true, hasToolTips: true }))));
};
/* Custom Colors */
export const CustomColors = (args) => {
/* eslint-disable comma-spacing */
const width = 750;
const height = 400;
const data = [
{ x: 'one', y0: 1, y1: 2, y2: 3, y3: 5 },
{ x: 'two', y0: 2, y1: 3, y2: 4, y3: 6 },
{ x: 'three', y0: 2, y1: 4, y2: 5, y3: 6 },
{ x: 'four', y0: 3, y1: 6, y2: 7, y3: 7 },
{ x: 'five', y0: 4, y1: 8, y2: 9, y3: 8 },
{ x: 'six', y0: 11, y1: 8, y2: 9, y3: 5 },
];
const yFields = ['y0', 'y1', 'y2', 'y3'];
const yMax = _.max(_.reduce(yFields, (acc, field) => {
return acc.concat(_.map(data, field));
}, []));
const xScale = d3Scale
.scaleBand()
.domain(_.map(data, 'x'))
.range([0, width])
.round(true)
.paddingInner(0.1);
const yScale = d3Scale
.scaleLinear()
.domain([0, yMax])
.range([height, 0]);
const style = {
paddingTop: '9rem',
};
return (React.createElement("div", { style: style },
React.createElement("svg", { width: width, height: height },
React.createElement(Bars, { ...args, data: data, xScale: xScale, yScale: yScale, yFields: yFields, colorMap: {
y0: chartConstants.COLOR_GOOD,
y2: chartConstants.COLOR_BAD,
}, hasToolTips: true }))));
};
/* Log Scale */
export const LogScale = (args) => {
const data = [
{ x: 'one', y: 10 },
{ x: 'two', y: 100 },
{ x: 'three', y: 1000 },
{ x: 'four', y: 10000 },
{ x: 'five', y: 100000 },
];
const width = 750;
const height = 400;
const yScale = d3Scale.scaleLog().domain([1, 1000000]).range([height, 0]);
const xScale = d3Scale
.scaleBand()
.domain(_.map(data, 'x'))
.range([0, width]);
return (React.createElement("svg", { height: 600, width: 1000 },
React.createElement("g", null,
React.createElement(Bars, { ...args, data: data, xScale: xScale, yScale: yScale })),
React.createElement("g", null, _.map(data, (item, idx) => {
return (React.createElement("text", { key: idx, textAnchor: 'middle', x: xScale(item.x) + xScale.bandwidth() / 2, y: yScale(item.y) - 10, fill: 'gray' }, item.y));
}))));
};
//# sourceMappingURL=Bars.stories.js.map