Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:hackforla/311-data into INF_backendInit
Browse files Browse the repository at this point in the history
  • Loading branch information
sellnat77 committed Mar 18, 2020
2 parents 43790b3 + c440ebc commit b47ab2a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
5 changes: 3 additions & 2 deletions src/components/Visualizations/Chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ class Chart extends React.Component {
}

componentDidUpdate(prevProps) {
const { data } = this.props;
const { data, options } = this.props;

if (prevProps.data !== data) {
if (prevProps.data !== data || prevProps.options !== options) {
this.chart.data = data;
this.chart.options = options;
this.chart.update();
}
}
Expand Down
40 changes: 19 additions & 21 deletions src/components/Visualizations/TimeToClose.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,30 @@ import { REQUEST_TYPES } from '@components/common/CONSTANTS';
import Chart from './Chart';

const TimeToClose = ({
requestTypes,
timeToClose,
}) => {
// // DATA ////

const randomSeries = (count, min, max) => Array.from({ length: count })
.map(() => Math.random() * (max - min) + min);

const dummyData = REQUEST_TYPES.reduce((p, c) => {
const acc = p;
acc[c.type] = randomSeries(8, 0, 11);
return acc;
}, {});

const selectedTypes = REQUEST_TYPES.filter(el => requestTypes[el.type]);
const boxes = Object.keys(timeToClose).map(key => {
const requestType = REQUEST_TYPES.find(t => t.type === key);
return {
abbrev: requestType?.abbrev,
color: requestType?.color,
stats: {
...timeToClose[key],
outliers: [],
},
};
});

const chartData = {
labels: selectedTypes.map(t => t.abbrev),
labels: boxes.map(b => b.abbrev),
datasets: [{
data: selectedTypes.map(t => dummyData[t.type]),
backgroundColor: selectedTypes.map(t => t.color),
data: boxes.map(b => b.stats),
backgroundColor: boxes.map(b => b.color),
borderColor: '#000',
borderWidth: 1,
outlierColor: '#000',
}],
};

Expand All @@ -36,9 +38,6 @@ const TimeToClose = ({

const chartOptions = {
maintainAspectRatio: false,
title: {
text: 'Time to Close',
},
scales: {
xAxes: [{
scaleLabel: {
Expand All @@ -47,8 +46,7 @@ const TimeToClose = ({
},
ticks: {
beginAtZero: true,
stepSize: 1,
coef: 0,
maxStats: 'whiskerMax',
},
}],
yAxes: [{
Expand Down Expand Up @@ -78,11 +76,11 @@ const TimeToClose = ({
};

const mapStateToProps = state => ({
requestTypes: state.filters.requestTypes,
timeToClose: state.data.timeToClose,
});

export default connect(mapStateToProps)(TimeToClose);

TimeToClose.propTypes = {
requestTypes: PropTypes.shape({}).isRequired,
timeToClose: PropTypes.shape({}).isRequired,
};
8 changes: 6 additions & 2 deletions src/redux/rootSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ function* getFrequency() {
return yield {};
}

function* getTimeToClose() {
return yield {};
function* getTimeToClose(filters) {
const ttcUrl = `${BASE_URL}/timetoclose`;

const { data: { data } } = yield call(axios.post, ttcUrl, filters);

return data;
}

/* //////////// COMBINED API CALL //////////// */
Expand Down

0 comments on commit b47ab2a

Please sign in to comment.