Skip to content

Commit

Permalink
fix(localconf): vis colors in localconf.js
Browse files Browse the repository at this point in the history
  • Loading branch information
qingyashu committed Aug 15, 2018
1 parent 3f350ea commit 606b3ca
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 184 deletions.
4 changes: 1 addition & 3 deletions src/DataExplorer/DataExplorerVisualizations.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import SummaryChartGroup from '../components/charts/SummaryChartGroup/.';
import PercentageStackedBarChart from '../components/charts/PercentageStackedBarChart/.';
import DataSummaryCardGroup from '../components/cards/DataSummaryCardGroup/.';
import { getCharts } from '../components/charts/helper';
import { localTheme } from '../localconf';

class DataExplorerVisualizations extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -45,14 +44,13 @@ class DataExplorerVisualizations extends React.Component {
{ charts && this.state.showVisualization ?
<div className='data-explorer__charts'>
<DataSummaryCardGroup summaryItems={charts.countItems} connected />
<SummaryChartGroup summaries={charts.summaries} localTheme={localTheme} />
<SummaryChartGroup summaries={charts.summaries} />
{
charts.stackedBarCharts.map((chart, i) =>
(<PercentageStackedBarChart
key={i}
data={chart.data}
title={chart.title}
localTheme={localTheme}
width='100%'
/>),
)
Expand Down
3 changes: 1 addition & 2 deletions src/Index/reduxer.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { connect } from 'react-redux';
import { sortCompare } from '../utils';
import { localTheme } from '../localconf';
import dictIcons from '../img/icons';
import { setActive } from '../Top/reduxer';
import IndexBarChart from '../components/charts/IndexBarChart/.';
Expand All @@ -13,7 +12,7 @@ export const ReduxIndexBarChart = (() => {
const projectList = Object.values(
state.homepage.projectsByName,
).sort(sortCompare);
return { projectList, countNames: components.charts.indexChartNames, localTheme };
return { projectList, countNames: components.charts.indexChartNames };
}
return {};
};
Expand Down
1 change: 0 additions & 1 deletion src/components/ProjectDashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class ProjectDashboard extends Component {
summaryItems={this.props.summaries}
align='left'
/>
{/* <ReduxProjectBarChart projectList={this.props.projectList} /> */}
</div>
<ProjectTable projectList={projectList} summaries={this.props.details} />
</React.Fragment>
Expand Down
17 changes: 6 additions & 11 deletions src/components/charts/IndexBarChart/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Spinner from '../../Spinner';
import TooltipCDIS from '../TooltipCDIS/.';
import Tick from '../Tick';
import './IndexBarChart.less';
import helper from '../helper';

const sortCount = (a, b) => {
const countA = a.counts.reduce((res, item) => res + item);
Expand Down Expand Up @@ -95,9 +96,7 @@ class IndexBarChart extends React.Component {
countNames: PropTypes.arrayOf(
PropTypes.string,
),
localTheme: PropTypes.objectOf(
PropTypes.any,
),
xAxisColor: PropTypes.string,
};

render() {
Expand All @@ -106,11 +105,8 @@ class IndexBarChart extends React.Component {
}
const projectList = [...this.props.projectList.sort(sortCount)];
const topList = (projectList.length <= 5) ? projectList : getTopList(projectList);

const localTheme = this.props.localTheme;
const sumList = computeSummations(topList, this.props.countNames);
const indexChart = createChartData(topList, this.props.countNames, sumList);

const projectNames = topList.map(project => project.code);
const barNames = createBarNames(indexChart);
let countBar = 0;
Expand All @@ -125,8 +121,8 @@ class IndexBarChart extends React.Component {
>
<h4>Project Submission status</h4>
<XAxis
stroke={localTheme['barGraph.lineColor']}
fill={localTheme['barGraph.lineColor']}
stroke={this.props.xAxisColor}
fill={this.props.xAxisColor}
domain={[0, 100]}
ticks={[0, 25, 50, 75, 100]}
allowDecimals={false}
Expand All @@ -152,7 +148,7 @@ class IndexBarChart extends React.Component {
name={projectNames[index]}
dataKey={barName}
stackId='a'
fill={localTheme[`barGraph.bar${(index + 1).toString()}Color`]}
fill={helper.getCategoryColor(index)}
/>
);
},
Expand All @@ -166,11 +162,10 @@ class IndexBarChart extends React.Component {
}
}


IndexBarChart.defaultProps = {
projectList: [],
countNames: [],
localTheme: {},
xAxisColor: '#666666',
};

export default IndexBarChart;
6 changes: 2 additions & 4 deletions src/components/charts/PercentageStackedBarChart/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const labelListStyle = {
fontWeight: 600,
};


// FIXME: add back in animation (https://github.com/recharts/recharts/issues/1083)
class PercentageStackedBarChart extends React.Component {
render() {
Expand Down Expand Up @@ -64,8 +63,8 @@ class PercentageStackedBarChart extends React.Component {
key={name}
dataKey={name}
stackId='a'
fill={helper.getCategoryColor(index, this.props.localTheme)}
isAnimationActive={false}
fill={helper.getCategoryColor(index)}
>
<LabelList dataKey={name} position='center' style={labelListStyle} formatter={helper.addPercentage} className='percentage-bar-chart__label-list' />
</Bar>
Expand All @@ -80,7 +79,7 @@ class PercentageStackedBarChart extends React.Component {
<span
className='percentage-bar-chart__legend-color'
style={{
background: helper.getCategoryColor(index, this.props.localTheme),
background: helper.getCategoryColor(index),
}}
/>
<span className='percentage-bar-chart__legend-name form-body'>
Expand All @@ -106,7 +105,6 @@ const ChartDataShape = PropTypes.shape({

PercentageStackedBarChart.propTypes = {
data: PropTypes.arrayOf(ChartDataShape).isRequired,
localTheme: PropTypes.object.isRequired,
percentageFixedPoint: PropTypes.number,
};

Expand Down
7 changes: 0 additions & 7 deletions src/components/charts/ProjectBarChart/ProjectBarChart.less

This file was deleted.

95 changes: 0 additions & 95 deletions src/components/charts/ProjectBarChart/index.jsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { mount } from 'enzyme';
import SummaryChartGroup from '.';
import { localTheme } from '../../../localconf';
import SummaryPieChart from '../SummaryPieChart';
import SummaryHorizontalBarChart from '../SummaryHorizontalBarChart';

Expand Down Expand Up @@ -37,7 +36,6 @@ describe('<SummaryChartGroup />', () => {
const charts = mount(<SummaryChartGroup
summaries={summaries}
width={1010}
localTheme={localTheme}
/>);

it('renders', () => {
Expand Down
3 changes: 0 additions & 3 deletions src/components/charts/SummaryChartGroup/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ class SummaryChartGroup extends Component {
<SummaryPieChart
data={item.data}
title={item.title}
localTheme={this.props.localTheme}
/>
) : (
<SummaryHorizontalBarChart
data={item.data}
title={item.title}
localTheme={this.props.localTheme}
vertical
color='#3283c8'
/>
Expand All @@ -44,7 +42,6 @@ class SummaryChartGroup extends Component {

SummaryChartGroup.propTypes = {
summaries: PropTypes.arrayOf(PropTypes.object).isRequired,
localTheme: PropTypes.object.isRequired,
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { mount } from 'enzyme';
import { localTheme } from '../../../localconf';
import SummaryHorizontalBarChart from '.';

describe('<SummaryHorizontalBarChart />', () => {
Expand All @@ -14,7 +13,7 @@ describe('<SummaryHorizontalBarChart />', () => {
];

const wrapper = mount(
<SummaryHorizontalBarChart data={chartData} title='bar chart title' color='#3283c8' localTheme={localTheme} />,
<SummaryHorizontalBarChart data={chartData} title='bar chart title' color='#3283c8' />,
);
const charts = wrapper.find(SummaryHorizontalBarChart);

Expand Down
3 changes: 1 addition & 2 deletions src/components/charts/SummaryHorizontalBarChart/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SummaryBarChart extends React.Component {
<Cell
key={dataKey}
fill={this.props.color
|| helper.getCategoryColor(index, this.props.localTheme)}
|| helper.getCategoryColor(index)}
/>
))
}
Expand All @@ -79,7 +79,6 @@ const ChartDataShape = PropTypes.shape({
SummaryBarChart.propTypes = {
title: PropTypes.string.isRequired,
data: PropTypes.arrayOf(ChartDataShape).isRequired,
localTheme: PropTypes.object.isRequired,
color: PropTypes.string,
barSize: PropTypes.number,
barGap: PropTypes.number,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { mount } from 'enzyme';
import { localTheme } from '../../../localconf';
import SummaryPieChart from '.';

describe('<SummaryPieChart />', () => {
Expand All @@ -16,7 +15,6 @@ describe('<SummaryPieChart />', () => {
const charts = mount(<SummaryPieChart
title='test'
data={chartData}
localTheme={localTheme}
/>).find(SummaryPieChart);

it('renders', () => {
Expand Down
3 changes: 1 addition & 2 deletions src/components/charts/SummaryPieChart/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SummaryPieChart extends React.Component {
<Cell
key={dataKey}
dataKey={dataKey}
fill={getColor(index, this.props.localTheme, useTwoColors)}
fill={getColor(index)}
/>))
}
</Pie>
Expand All @@ -85,7 +85,6 @@ const ChartDataShape = PropTypes.shape({
SummaryPieChart.propTypes = {
title: PropTypes.string.isRequired,
data: PropTypes.arrayOf(ChartDataShape).isRequired,
localTheme: PropTypes.object.isRequired,
innerRadius: PropTypes.number,
outerRadius: PropTypes.number,
showPercentage: PropTypes.bool,
Expand Down
10 changes: 4 additions & 6 deletions src/components/charts/helper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { colorsForCharts } from '../../localconf';

const percentageFormatter = showPercentage => v => (showPercentage ? `${v}%` : v);

const addPercentage = v => (percentageFormatter(true)(v));
Expand Down Expand Up @@ -39,13 +41,9 @@ const getPercentageData = (chartData, percentageFixedPoint) => {
return [result];
};

const getCategoryColor = (index, localTheme) => {
// map index to (1-9)
const i = (index % 9) + 1;
return localTheme[`barGraph.bar${i}Color`];
};
const getCategoryColor = index => (colorsForCharts.categorical9Colors[index % 9]);

const getCategoryColorFrom2Colors = (index, localTheme) => localTheme[`pieChartTwoColor.pie${(index % 2) + 1}Color`];
const getCategoryColorFrom2Colors = index => colorsForCharts.categorical2Colors[index % 2];

const getDataKey = showPercentage => (showPercentage ? 'percentage' : 'value');

Expand Down
Loading

0 comments on commit 606b3ca

Please sign in to comment.