Skip to content
Snippets Groups Projects
Commit 42cef119 authored by advait22's avatar advait22
Browse files

final front end build push

parent aa16196d
Branches
No related tags found
1 merge request!11Webserver
Showing
with 67511 additions and 0 deletions
node_modules
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.<br>
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.<br>
You will also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.<br>
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.<br>
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.<br>
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
{
"name": "mappractice",
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.9.14",
"axios": "^0.19.2",
"chart.js": "^2.9.3",
"datamaps": "^0.5.9",
"jquery": "^3.5.1",
"react": "^16.6.3",
"react-chartkick": "^0.4.0",
"react-dom": "^16.6.3",
"react-scripts": "2.1.1",
"react-simple-maps": "^2.0.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
react ui/choropleth-map/public/favicon.ico

3.78 KiB

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Covid Analysis</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
\ No newline at end of file
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
.App {
text-align: center;
}
.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 40vmin;
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
import React, { Component } from 'react';
import './App.css';
import ChoroplethMap from './components/ChoroplethMap';
import $ from 'jquery';
import Button from '@material-ui/core/Button';
import InputLabel from '@material-ui/core/InputLabel';
import FormControl from '@material-ui/core/FormControl';
import Select from '@material-ui/core/Select';
import Info from './components/Info';
const styles = {
backgroundColor: '#a2a3a9'
};
class App extends Component {
constructor(props){
super(props)
this.state = {
data_values : null,
reset: "none",
defaultSelection : "total_covid19_case",
aurinData:null,
tweets:null,
chartData: null,
city:null,
info:null,
addPer:false
}
this.info_ref = React.createRef();
this.populateAurinData = this.populateAurinData.bind(this)
}
componentDidMount(){
var that = this;
$.ajax({
dataType: "json",
url: "http://172.26.132.221:5984/aurin-data/_design/test/_view/test",
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + btoa('admin:admin')
},
success: function (response) {
if(response.rows.length > 0){
that.setState({aurinData:response})
that.populateAurinData(that,response,that.state.defaultSelection)
}
},
error: function (err) {
console.log("Error: " + err.responseText);
}
});
}
populateAurinData (that,response,tag) {
let map_data = []
for(var i = 0;i < (response.rows).length;i++){
if(response.rows[i].key === "VIC" ){
map_data.push({state:"VI",values: parseFloat(response.rows[i].value[tag]).toFixed(2)
})}
else if(response.rows[i].key === "QLD" ){
map_data.push({state:"QL",values: parseFloat(response.rows[i].value[tag]).toFixed(2)
})}
else if(response.rows[i].key === "TAS" ){
map_data.push({state:"TS",values: parseFloat(response.rows[i].value[tag]).toFixed(2)
})
}
else if(response.rows[i].key === "NSW" ){
map_data.push({state:"NS",values: parseFloat(response.rows[i].value[tag]).toFixed(2)
})
}
else if(response.rows[i].key === "SA" ){
map_data.push({state:"SA",values: parseFloat(response.rows[i].value[tag]).toFixed(2)
})
}
else if(response.rows[i].key === "WA" ){
map_data.push({state:"WA",values: parseFloat(response.rows[i].value[tag]).toFixed(2)
})
}
else if(response.rows[i].key === "NT" ){
map_data.push({state:"NT",values: parseFloat(response.rows[i].value[tag]).toFixed(2)
})
}
}
if(tag === "employ_growth_total"){
that.setState({data_values:map_data,reset:'none',addPer:true})
}
else {
that.setState({data_values:map_data,reset:'none',addPer:false})
}
}
handleChange = (event) => {
let that = this
that.populateAurinData(that,that.state.aurinData,event.target.value)
}
updateChart = (that,response,selectedProv,city) => {
let d = null
if(selectedProv === "QL"){
d = "QLD"
}
else if(selectedProv === "VI"){
d = "VIC"
}
else if(selectedProv === "NS"){
d = "NSW"
}
else if(selectedProv === "TS"){
d = "TAS"
}
else if(selectedProv === "NT"){
d = "NA"
}
else if(selectedProv === "WA"){
d = "WA"
}
else if(selectedProv === "SA"){
d = "SA"
}
let a = []
for(let i = 0; i < this.state.data_values.length;i++){
if(this.state.data_values[i].state === selectedProv ){
a.push({
state:this.state.data_values[i].state,
values:this.state.data_values[i].values
})
}
}
let group = response.map((item)=> item.key[0] ).filter((item, i, ar) => ar.indexOf(item) === i).map(item=>{
let new_list = response.filter(itm => itm.key[0] === item).map(itm=>(itm.value))
return {state:item,values:new_list}
})
let data = []
for(let i = 0; i < group.length;i++){
if(group[i].state === d){
data.push({
state:group[i].state,
values: group[i].values
})
}
}
that.setState({reset:'block',chartData:data,city:city,info:a}, () => {
this.info_ref.current.focus()
})
}
callbackFunction = (childData,city) => {
var that = this;
$.ajax({
dataType: "json",
url: "http://admin:admin@172.26.132.221:5984/twitter/_design/count/_view/count-month?reduce=true&group_level=2",
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + btoa('admin:admin')
},
success: function (response) {
if(response.rows.length){
that.updateChart(that,response.rows,childData,city)
}
},
error: function (err) {
alert('Something went wrong, reload the page again')
}
});
}
reset = () => {
this.setState({reset:'none'}, ()=> {
this.populateAurinData(this,this.state.aurinData,this.state.defaultSelection)
});
}
render() {
return (
<div style={styles}>
{/* {this.state.data_values === null ? '' :<p style={{textAlign:'center',fontWeight:600,textTransform:"capitalize",width:'100%',marginTop:0,fontSize:'15'}}>Analyzing tweets for various scenarios relalted to COVID-19 in Australia</p>} */}
<div style={{
height:"90%",
width: "100%",
overflow:'hidden'
}}>
{this.state.data_values === null ? '' :<ChoroplethMap data={this.state.data_values} parentCallback = {(childData,city)=>this.callbackFunction(childData,city)} addPer = {this.state.addPer}/>}
</div>
<div style={{height:"10%", width:"100%",overflow:'hidden',display: "flex", justifyContent: "center",
alignItems: "center"}}>
<Button variant="contained" style={{marginBottom:10,marginRight:30,backgroundColor:'#f70000'}} onClick={this.reset}>
Reset
</Button>
<FormControl style={{width:'auto',marginBottom:13}}>
<InputLabel>Scenario</InputLabel>
<Select
native
onChange={this.handleChange}
>
<option aria-label="Scenario" value="total_covid19_case">Total Covid Cases</option>
<option value="employ_growth_total"> Growth in Employment</option>
<option value="net_migration"> Net Migration</option>
<option value="property_sale_avg"> Average Price of Property Sales</option>
</Select>
</FormControl>
</div>
{this.state.chartData === null && this.state.chartData === null ? '': <div style={{display:this.state.reset,outline: 'none'}} ref={this.info_ref} tabIndex="0" >
<Info pie = {this.state.chartData} city = {this.state.city} info = {this.state.info}/>
</div>}
</div>
);
}
}
export default App;
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
This diff is collapsed.
/* eslint-disable no-undef */
import React, { Component } from 'react';
import Datamap from 'datamaps/dist/datamaps.world.min.js';
import d3 from 'd3';
import AustraliaJson from './Australia.topo.json';
class ChoroplethMap extends Component {
constructor(props) {
super(props);
this.updateMap = this.updateMap.bind(this)
}
updateMap(this_new,props){
if(props.data){
let dataset = {};
let onlyValues = props.data.map(function (obj) { return obj.values; });
let minValue = Math.min.apply(null, onlyValues),
maxValue = Math.max.apply(null, onlyValues);
let paletteScale = d3.scale.linear()
.domain([minValue, maxValue])
.range(["#ff926e", "#ff4800"]);
if (props.addPer){
props.data.forEach(function (item) {
let iso = item.state,
value1 =item.values + "%",
value = item.values;
dataset[iso] = { numberOfThings: value1, fillColor: paletteScale(value) };
});
}
else {
props.data.forEach(function (item) {
let iso = item.state,
value = item.values;
dataset[iso] = { numberOfThings: value, fillColor: paletteScale(value) };
});
}
let map = new Datamap({
element: document.getElementById('cloropleth_map'),
scope: 'australia',
height:570,
width:"100%",
done: (datamap) => {
datamap.svg.selectAll('.datamaps-subunit').on('click', (geography) => {
if(geography.id !== "CT"){
this_new.props.parentCallback(geography.id,geography.properties.name)
}
else {
alert('Data is not available for state ' + geography.properties.name)
}
})},
geographyConfig: {
popupOnHover: true,
hideAntarctica: false,
highlightOnHover: true,
highlightFillColor: '#000287',
borderColor: '#444',
highlightBorderWidth: 1,
borderWidth: 1,
borderOpacity: 1,
highlightBorderOpacity: 1,
dataJson: AustraliaJson,
popupTemplate: function (geo, data) {
if (!data) { return ['<div class="hoverinfo"><strong>No data available</strong></div>']; }
return ['<div class="hoverinfo">',
'<strong>', geo.properties.name, '</strong>',
'<br>Count: <strong>', data.numberOfThings, '</strong>',
'</div>'].join('');
}
},
fills: {
HIGH: '#012140f',
LOW: '#c8e1fa',
MEDIUM: 'orange',
UNKNOWN: 'rgb(0,0,0)',
defaultFill: '#eee'
},
data: dataset,
setProjection: function (element) {
var projection = d3.geo.mercator()
.center([132, -28 ])
.scale(700)
.translate([element.offsetWidth / 2, element.offsetHeight / 2]);
var path = d3.geo.path().projection(projection);
return { path: path, projection: projection };
}
}
// map.legend()
);
}
}
componentDidUpdate(prevProps){
let this_new = this;
if(prevProps.data && this.props.data && prevProps.data !== this.props.data && prevProps.data[0].values !== this.props.data[0].values) {
let element = document.getElementById('cloropleth_map');
element.innerHTML = ""
this_new.updateMap(this_new,this.props)
}
}
componentDidMount() {
var this_new = this;
this_new.updateMap(this_new,this_new.props)
}
render() {
return (
<div id="cloropleth_map" style={{
height: "50%",
width: "100%",
overflow:'hidden',
backgroundColor: '#a2a3a9'
}}></div>
);
}
}
export default ChoroplethMap;
\ No newline at end of file
import React, {Component} from 'react';
import Grid from '@material-ui/core/Grid';
import Paper from '@material-ui/core/Paper';
import ReactChartkick, { PieChart, ColumnChart } from 'react-chartkick';
import Chart from 'chart.js'
ReactChartkick.addAdapter(Chart)
class Info extends Component {
constructor(props){
super(props)
this.state = {
neg : null,
pos:null,
neu:null,
info:null,
total:null,
city: null
}
}
updateState = (that,props) => {
that.setState({neg:parseFloat(props.pie[0].values[0]),
neu:parseFloat(props.pie[0].values[1]),
pos:parseFloat(props.pie[0].values[2]),
total:parseFloat(props.pie[0].values[0] + props.pie[0].values[1] + props.pie[0].values[2]),
info : props.info[0].values,
city:props.city
})
}
componentDidMount(){
let that = this
that.updateState(that,that.props)
}
componentDidUpdate(prevProps) {
let that = this
if(prevProps.pie && this.props.pie && prevProps.pie !== this.props.pie && prevProps.pie[0].values !== this.props.pie[0].values) {
that.updateState(that,that.props)
}
}
render() {
let negPer = ((this.state.neg / this.state.total)).toFixed(2)
let neuPer = ((this.state.neu / this.state.total)).toFixed(2)
let posPer = ((this.state.pos / this.state.total)).toFixed(2)
let city = this.state.city
let pos = this.state.pos
let neg = this.state.neg
let neu = this.state.neu
return (
<div style={{overflow:'hidden',paddingLeft:10,paddingRight:10}}>
<Grid container spacing={3}>
<Grid item xs={6}>
<Paper style={{padding:5,marginBottom:5}}>
<p style={{textAlign:'center',fontWeight:600,textTransform:"capitalize"}}>Proportion of Sentiment Analysis for {city}.</p>
{negPer !== null || negPer !== undefined ?<PieChart donut={true} data={[["Negative", negPer], ["Neutral", neuPer],["Positive", posPer]]} legend={true}/>
:""}
</Paper>
</Grid>
<Grid item xs={6}>
<Paper style={{padding:5,marginBottom:5}}>
<p style={{textAlign:'center',fontWeight:600,textTransform:"capitalize"}}>Column Chart displaying absolute number of tweets for {city}.</p>
<ColumnChart dataset={{ borderWidth: 0, width: 0, barThickness: 30,maxBarThickness:35,backgroundColor: ['#FF9900', '#3366CC' ,'#DC3912'], }} colors={["#b00"]} stacked={true} data={[["Positive Tweets", pos], ["Negative", neg], ["Neutral", neu]]} xtitle="Sentiment Data" ytitle="Number of Tweets"/>
</Paper>
</Grid>
</Grid>
</div>
);
}
}
export default Info;
\ No newline at end of file
body {
margin: 0;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace;
}
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: http://bit.ly/CRA-PWA
serviceWorker.unregister();
// This optional code is used to register a service worker.
// register() is not called by default.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on subsequent visits to a page, after all the
// existing tabs open on the page have been closed, since previously cached
// resources are updated in the background.
// To learn more about the benefits of this model and instructions on how to
// opt-in, read http://bit.ly/CRA-PWA
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
export function register(config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return;
}
window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit http://bit.ly/CRA-PWA'
);
});
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
}
});
}
}
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See http://bit.ly/CRA-PWA.'
);
// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration);
}
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
// Execute callback
if (config && config.onSuccess) {
config.onSuccess(registration);
}
}
}
};
};
})
.catch(error => {
console.error('Error during service worker registration:', error);
});
}
function checkValidServiceWorker(swUrl, config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl)
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload();
});
});
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl, config);
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
});
}
export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => {
registration.unregister();
});
}
}
{
"name": "new-folder",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"chart.js": "^2.9.3",
"express": "^4.17.1"
}
}
const port = process.env.PORT || 5000;
const express = require('express');
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, 'build')));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen(port, () => console.log(`Listening on port ${port}`));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment