Skip to content

Commit

Permalink
Merge pull request #47 from hackforla/react_containers_2
Browse files Browse the repository at this point in the history
Enabled containerization of collab components
  • Loading branch information
sellnat77 authored Oct 2, 2019
2 parents b179a49 + d6ec400 commit 633dc1d
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 32 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ matrix:
cache:
directories:
- node_modules
before_install:
- cd Project/react/311-data
install:
- npm install
script:
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 28 additions & 9 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
import React from 'react';
import './App.css';
import TreeMapVis from './components/TreeMapVis/TreeMapVis.js';
import PinMap from './components/TreeMapVis/TreeMapVis.jsx';

function App() {
return (
<div className="App">
<TreeMapVis />
<PinMap />
</div>
);

class App extends React.Component{
constructor(props){
super(props);
this.state = {selectedId: ""}
}

handleMockSelected = (e) => {
this.setState({selectedId: e.target.value});
}

render(){
const prototypeMap = {
TreeMapVis: <TreeMapVis/>,
// PinMap: <PinMap/>
}

return (
<div className="App" >
{Object.keys(prototypeMap).map( proto =>
<div key={proto}>
<input type="radio" name="prototypes" value={proto} onClick={this.handleMockSelected}/>{proto}<br/>
</div>
)}
{ prototypeMap[this.state.selectedId] }
</div>
);
}
}

export default App;
21 changes: 17 additions & 4 deletions src/Util/DataService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import DataFrame from 'dataframe-js';

const dataResources = {
2019:"pvft-t768",
2018:"h65r-yf5i",
2017:"d4vt-q4t5",
2016:"ndkd-k878",
2015:"ms7h-a45h"
}

export function getColorMap(discrete){
if(discrete){
return [
Expand Down Expand Up @@ -34,10 +42,13 @@ export function getColorMap(discrete){
}
}

export function getBroadCallVolume(onBroadDataReady){
export function getBroadCallVolume(year, startMonth=0, endMonth=13, onBroadDataReady){
let treemap_data = {"title": "Broad 311 Calls Map", "color": "#FFFFFF", "children": []};
const start = Math.min(startMonth, endMonth)
const end = Math.max(startMonth, endMonth)

DataFrame.fromJSON('https://data.lacity.org/resource/h65r-yf5i.json?$select=count(*)+AS+CallVolume,NCName,RequestType&$group=NCName,RequestType&$order=CallVolume DESC').then(df => {
DataFrame.fromJSON(`https://data.lacity.org/resource/${dataResources[year]}.json?$select=count(*)+AS+CallVolume,NCName,RequestType&$where=date_extract_m(CreatedDate)+between+${start}+and+${end}&$group=NCName,RequestType&$order=CallVolume DESC`)
.then(df => {
df.show();

const totalCounts = df.groupBy("ncname").aggregate(group => group.stat.sum("callvolume")).rename("aggregation", "callvolume");
Expand All @@ -64,10 +75,12 @@ export function getBroadCallVolume(onBroadDataReady){
});
}

export function getZoomedCallVolume(ncName, onZoomedDataReady){
export function getZoomedCallVolume(ncName, year, startMonth=0, endMonth=13, onZoomedDataReady){
let treemap_data = {"title": "Zoomed 311 Calls Map", "color": "#FFFFFF", "children": []};
const start = Math.min(startMonth, endMonth)
const end = Math.max(startMonth, endMonth)

DataFrame.fromJSON(`https://data.lacity.org/resource/h65r-yf5i.json?$select=count(*)+AS+CallVolume,NCName,RequestType&$where=NCName+=+'${ncName}'&$group=NCName,RequestType&$order=CallVolume DESC`).then(df => {
DataFrame.fromJSON(`https://data.lacity.org/resource/${dataResources[year]}.json?$select=count(*)+AS+CallVolume,NCName,RequestType&$where=NCName+=+'${ncName}'+and+date_extract_m(CreatedDate)+between+${start}+and+${end}&$group=NCName,RequestType&$order=CallVolume DESC`).then(df => {
const colorMap = getColorMap(false);
df.toCollection().forEach(row => {
const data_point = {"title": row.requesttype, "color": colorMap[row.requesttype] , "size": row.callvolume};
Expand Down
73 changes: 73 additions & 0 deletions src/components/DateSlider/DateSlider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// import React from 'react';
// import Picker from 'react-month-picker';
//
// const DateSlider = () => {
// let pickerLang = {
// months: ['Jan', 'Feb', 'Mar', 'Spr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
// , from: 'From', to: 'To'
// }
// , mvalue = {year: 2015, month: 11}
// , mrange = {from: {year: 2014, month: 8}, to: {year: 2015, month: 5}}
//
// let makeText = m => {
// if (m && m.year && m.month) return (pickerLang.months[m.month-1] + '. ' + m.year)
// return '?'
// }
//
// const handleRangeChange = () =>{
//
// };
// const handleRangeDismiss = () =>{
//
// };
// return (
// <div className="edit">
// <label>Pick A Span of Months</label>
// <Picker
// ref="pickRange"
// years={{min: 2015, max: 2018}}
// range={mrange}
// lang={pickerLang}
// theme="dark"
// onChange={handleRangeChange}
// onDismiss={handleRangeDismiss}
// >
//
// </Picker>
// </div>
// );
// }
//
//
// //
// //
// // class DateSlider extends React.Component {
// // constructor(props) {
// // super(props);
// //
// // this.state = {
// // value: { min: 0, max: 13 },
// // };
// // }
// // render(){
// // return (
// // <InputRange
// // maxValue={13}
// // minValue={0}
// // value={this.state.value}
// // onChange={this.props.onSliderChange} />
// // );
// // }
// // }
// export default DateSlider;
// //
// // //
// // //
// // // const DateSlider = (label) => {
// // // return (
// // // <div class="slidecontainer">
// // // <p>{label}:</p>
// // // <input type="range" min="1" max="100" value="50" class="slider" id="myRange">
// // // </div>
// // // );
// // // }
34 changes: 34 additions & 0 deletions src/components/DateSlider/DateSlider.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.slidecontainer {
width: 100%;
}

.slider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}

.slider:hover {
opacity: 1;
}

.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #4CAF50;
cursor: pointer;
}

.slider::-moz-range-thumb {
width: 25px;
height: 25px;
background: #4CAF50;
cursor: pointer;
}
75 changes: 75 additions & 0 deletions src/components/TreeMapVis/Filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React from 'react';
// import DateSlider from '../DateSlider/DateSlider.js';
const Filters = ({yearChange, sMonthChange, eMonthChange, targetYear, sMonth, eMonth}) => {
const months = [
{
num:1,
name:"January"
},{
num:2,
name:"February"
},{
num:3,
name:"March"
},{
num:4,
name:"April"
},{
num:5,
name:"May"
},{
num:6,
name:"June"
},{
num:7,
name:"July"
},{
nunm:8,
name:"August"
},{
num:9,
name:"September"
},{
num:10,
name:"October"
},{
num:11,
name:"November"
},{
num:12,
name:"December"
}];

const years = [2015, 2016, 2017, 2018, 2019];

return (
<div>
Year
<select id="yearSelection" className="data-dropdown" value={targetYear} onChange={yearChange}>
{
years.map(year => {
return <option key={year} value={year}>{year}</option>
})
}
</select>
Start Month
<select id="startMonthSelection" className="data-dropdown" value={sMonth} onChange={sMonthChange}>
{
months.map(month => {
return <option key={month.name} value={month.num}>{month.name}</option>
})
}
</select>
<br/>
End Month
<select id="endMonthSelection" className="data-dropdown" value={eMonth} onChange={eMonthChange}>
{
months.map(month => {
return <option key={month.name} value={month.num}>{month.name}</option>
})
}
</select>
</div>
);
}
export default Filters;
Loading

0 comments on commit 633dc1d

Please sign in to comment.