这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions react-weather-analytics-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Tech stack

- Frontend

- React v16.8.3
- Apollo Client 2.6.10

- Backend
- Hasura GraphQL Engine

## Run the React app

Follow the instructions in this blog to set up your Snowflake as a prerequisite.
Post that, run `npm install` and `npm start` to start the analytics app.

We have showcased a bar chart in this example; you can easily add the other types with minimal changes.
You can read more here, https://github.com/hasura/graphql2chartjs
2 changes: 2 additions & 0 deletions react-weather-analytics-app/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
build
6 changes: 6 additions & 0 deletions react-weather-analytics-app/app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
To run this example:

```
npm install
npm start
```
18,745 changes: 18,745 additions & 0 deletions react-weather-analytics-app/app/package-lock.json

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions react-weather-analytics-app/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "graphql2chartjs-examples",
"version": "0.1.0",
"private": true,
"dependencies": {
"apollo-boost": "^0.1.28",
"apollo-link-http": "^1.5.17",
"apollo-link-ws": "^1.0.14",
"bootstrap": "^4.3.1",
"chart.js": "^2.7.3",
"graphql": "^14.1.1",
"graphql2chartjs": "^0.2.1",
"react": "^16.8.3",
"react-apollo": "^2.4.1",
"react-bootstrap": "^1.0.0-beta.5",
"react-chartjs-2": "^2.7.4",
"react-dom": "^16.8.3",
"react-scripts": "2.1.5",
"react-syntax-highlighter": "^10.1.3",
"subscriptions-transport-ws": "^0.9.15"
},
"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"
],
"devDependencies": {
"@playlyfe/gql": "^2.6.1"
}
}
Binary file not shown.
48 changes: 48 additions & 0 deletions react-weather-analytics-app/app/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!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 installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous"/>
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"
crossorigin="anonymous"
/>
<!--
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>graphql2chartjs examples</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>
15 changes: 15 additions & 0 deletions react-weather-analytics-app/app/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"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"
}
65 changes: 65 additions & 0 deletions react-weather-analytics-app/app/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.App {
text-align: center;
}

.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 40vmin;
pointer-events: none;
}

.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);
}
}

.half_screen {
width: 50%;
display: inline-block;
position: relative;
}

.chartWrapper {
display: flex;
}

.loadingIndicator {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

@media(max-width: 767px) {
.half_screen {
width: 100%;
display: block;
}
.chartWrapper {
display: block;
}
}

.fiftypercent {
width: 100px;
display: inline-block;
}
23 changes: 23 additions & 0 deletions react-weather-analytics-app/app/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import './App.css';
import NavBar from './Navbar';

import {
BasicBarChart,
StyledBarChart,
MultiDatasetBarChart,
MixedLineBarChart,
LiveChart,
RealtimeTimeseriesChart
} from './charts';

const App = () => (
<div>
<NavBar />
<div style={{margin: '10px', paddingTop: '65px'}}>
<StyledBarChart/>
</div>
</div>
);

export default App;
9 changes: 9 additions & 0 deletions react-weather-analytics-app/app/src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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);
});
33 changes: 33 additions & 0 deletions react-weather-analytics-app/app/src/Navbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import { Navbar, Nav, NavDropdown, Button } from 'react-bootstrap';

const Bar = () => {
return (
<Navbar bg="light" fixed="top">
<Navbar.Brand href="/">graphql2chartjs examples</Navbar.Brand>
<Navbar.Collapse id="basic-navbar-nav">
<Nav>
<NavDropdown title="Jump" id="basic-nav-dropdown">
<NavDropdown.Item href="#bar">Basic bar chart</NavDropdown.Item>
<NavDropdown.Item href="#styled-bar">Styled bar chart</NavDropdown.Item>
<NavDropdown.Item href="#multi-bar">Bar (multiple datasets)</NavDropdown.Item>
<NavDropdown.Item href="#mixed">Mixed chart (bar and line)</NavDropdown.Item>
<NavDropdown.Item href="#live-chart">Live chart</NavDropdown.Item>
<NavDropdown.Item href="#timeseries-chart">Time series</NavDropdown.Item>
</NavDropdown>
</Nav>
<Nav>
<Nav.Link href="https://github.com/hasura/graphql-engine/tree/master/community/tools/graphql2chartjs">
<Button variant="dark" size="sm">GitHub</Button>
</Nav.Link>
<Nav.Link href="https://codesandbox.io/s/p2wpj1o8pj">
<Button variant="link" size="sm">Edit in sandbox</Button>
</Nav.Link>
</Nav>
</Navbar.Collapse>
</Navbar>
)
}

export default Bar;

78 changes: 78 additions & 0 deletions react-weather-analytics-app/app/src/charts/StyledBarChart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React from 'react';
import { Bar} from 'react-chartjs-2';
import { docco } from 'react-syntax-highlighter/dist/esm/styles/hljs';
import SyntaxHighlighter from 'react-syntax-highlighter';
import graphql2chartjs from 'graphql2chartjs';
import { Query } from 'react-apollo';
import gql from 'graphql-tag';


const query = `
{
NewYorkWeeklyTemprature: AVG_TEMPRATURE_WEEKLY(order_by: {weekly: asc}) {
data: TEMPRATURE
label: weekly
}
}
`;

// Chart component
const Chart = ({ query }) => (
<Query
query={gql`${query}`}
>
{
({data, error, loading}) => {
if (loading || error) {
return <div className="loadingIndicator">Please wait </div>;
}
// create graphql2chartjs instance
const g2c = new graphql2chartjs();
// add graphql data to graphql2chartjs instance while adding the backgroundcolor property
g2c.add(data, (datasetName, dataPoint) => ({
...dataPoint,
chartType: 'bar',
backgroundColor: '#44c0c1',
}));
// render chart with g2c data :)
return (
<Bar data={g2c.data} />
)
}
}
</Query>
)

/****************************************UTILS*****************************************/

const HighlightedQuery = ({ query }) => (
<SyntaxHighlighter
language="graphql"
style={docco}
>
{query}
</SyntaxHighlighter>
)

const StyledBarChart = ({ path }) => {
return (
<div style={{margin: '10px', paddingTop: '65px'}}>
<div key="styled-bar">
<div style={{marginBottom: '20px'}} id="styled-bar">
<div className="chartWrapper">
<div className="half_screen">
<HighlightedQuery query={query} />
</div>
<div className="half_screen">
<Chart query={query}/>
</div>
</div>
</div>
<a href="https://github.com/hasura/graphql-engine/tree/master/community/tools/graphql2chartjs/example/app/src/charts/StyledBarChart.js">View source </a>
<hr />
</div>
</div>
)
}

export { StyledBarChart };
6 changes: 6 additions & 0 deletions react-weather-analytics-app/app/src/charts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export { BasicBarChart } from './BasicBarChart';
export { StyledBarChart } from './StyledBarChart';
export { MultiDatasetBarChart } from './MultiDatasetBarChart';
export { MixedLineBarChart } from './MixedLineBarChart';
export { LiveChart } from './LiveChart';
export { RealtimeTimeseriesChart } from './RealtimeTimeseriesChart';
14 changes: 14 additions & 0 deletions react-weather-analytics-app/app/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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;
}
Loading