Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DjangoChart/__pycache__
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [{
"name": "Python:Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver",
"--noreload"
],
"django": true
}]
}
26 changes: 15 additions & 11 deletions DjangoChart/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

Expand All @@ -27,7 +26,6 @@

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
Expand Down Expand Up @@ -69,7 +67,6 @@

WSGI_APPLICATION = 'DjangoChart.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

Expand All @@ -80,26 +77,28 @@
}
}


# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
'NAME':
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'NAME':
'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
'NAME':
'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
'NAME':
'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

Expand All @@ -113,12 +112,17 @@

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

REACT_APP_DIR = os.path.join(BASE_DIR, 'reactui')

STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
os.path.join(REACT_APP_DIR, 'build', 'static'),
]

# STATICFILES_DIRS = [
# os.path.join(BASE_DIR, "static"),
# ]

STATIC_URL = '/static/'
9 changes: 4 additions & 5 deletions DjangoChart/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# added by grimmer
from django.conf.urls import url
from . import view
from .view import ChartView, ChartView2
from .view import ChartView #, ChartView2

urlpatterns = [
path('admin/', admin.site.urls),
Expand All @@ -28,8 +28,7 @@
# url(r'^$', view.hello),
# https://stackoverflow.com/questions/47947673/is-it-better-to-use-path-or-url-in-urls-py-for-django-2-0
# path('', view.hello, name="index"),
path('', view.hello, name="index"),

path('chart/mode1', ChartView.as_view()),
path('chart/mode2', ChartView2.as_view()),
path('', ChartView.as_view(), name="index"),
# path('chart/mode1', ChartView.as_view()),
# path('chart/mode2', ChartView2.as_view()),
]
61 changes: 43 additions & 18 deletions DjangoChart/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# 'musics': musics,
# })


# deprecated
def hello(request):
return render(request, 'hello_world.html', {
'current_time': str(datetime.now()),
Expand All @@ -34,36 +36,59 @@ class ChartView(TemplateView):

def get_context_data(self, **kwargs):
context = super(ChartView, self).get_context_data(**kwargs)

x = [-2,0,4,6,7]
y = [q**2-q+3 for q in x]
trace1 = go.Scatter(x=x, y=y, marker={'color': 'red', 'symbol': 104, 'size': "10"},
mode="lines", name='1st Trace')

data=go.Data([trace1])
layout=go.Layout(title="Meine Daten", xaxis={'title':'x1'}, yaxis={'title':'x2'})
figure=go.Figure(data=data,layout=layout)
if "timeStart" in self.request.GET:
print("timeStart:" + self.request.GET["timeStart"])
if "timeEnd" in self.request.GET:
print("timeEnd:" + self.request.GET["timeEnd"])
x = [-2, 0, 4, 6, 7]
y = [q**2 - q + 3 for q in x]
trace1 = go.Scatter(x=x,
y=y,
marker={
'color': 'red',
'symbol': 104,
'size': "10"
},
mode="lines",
name='1st Trace')

data = go.Data([trace1])
layout = go.Layout(title="Meine Daten",
xaxis={'title': 'x1'},
yaxis={'title': 'x2'})
figure = go.Figure(data=data, layout=layout)
div = opy.plot(figure, auto_open=False, output_type='div')

context['graph'] = div

return context

# TODO: Extract the same code of drawing charts for reuse

# deprecated
# TODO: Extract the same code of drawing charts for reuse
class ChartView2(TemplateView):
template_name = "chart.html"

def get_context_data(self, **kwargs):
context = super(ChartView2, self).get_context_data(**kwargs)

x = [-2,0,4,6,7]
y = [q**2-q+3 for q in x]
trace1 = go.Scatter(x=x, y=y, marker={'color': 'green', 'symbol': 104, 'size': "10"},
mode="lines", name='1st Trace')

data=go.Data([trace1])
layout=go.Layout(title="Meine Daten", xaxis={'title':'x1'}, yaxis={'title':'x2'})
figure=go.Figure(data=data,layout=layout)
x = [-2, 0, 4, 6, 7]
y = [q**2 - q + 3 for q in x]
trace1 = go.Scatter(x=x,
y=y,
marker={
'color': 'green',
'symbol': 104,
'size': "10"
},
mode="lines",
name='1st Trace')

data = go.Data([trace1])
layout = go.Layout(title="Meine Daten",
xaxis={'title': 'x1'},
yaxis={'title': 'x2'})
figure = go.Figure(data=data, layout=layout)
div = opy.plot(figure, auto_open=False, output_type='div')

context['graph'] = div
Expand Down
53 changes: 43 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
### Install dependencies
## Prepare

### Install Python dependencies

`pip/pip3 install -r requirements.txt`

### Start
Use Django 2, the latest is 3.
Use Plotly 2.7, the latest is 4.5.0.

### Install Node.js and Yarn and node packages

1. node: >=12. https://nodejs.org/en/
2. yarn: 1.x. https://classic.yarnpkg.com/en/docs/install#mac-stable
3. In `./reactui`, execute `yarn install` to install node.js packages.

`reactui` is created by https://create-react-app.dev/ and uses react hooks, https://zh-hant.reactjs.org/docs/hooks-intro.html.

Rearding building part on react side, extra steps after creating react project were done. Here is the note,

1. `yarn run eject` to generate webpack config file
2. `webpack.config.js`
1. `runtimeChunk: false`
2. comment `splitChunks`
3. regarding output css, `filename: "static/css/[name].css"`
4. regarding output js, `filename: isEnvProduction ? "static/js/[name].js"`

## Dev (two servers)

1. Start React web server (hot reload): `yarn`, then open `http://localhost:3000` for reactui part. You can set breakpoint on react code in chrome.
2. Start the django dev server (hot reload): `python manage.py runserver` or use VSCode to launch django

### usage

Open http://localhost:3000

## Production (one server)

1. [Produciton] Build output react js, `yarn build` in `./reactui`
2. [Caution] (**Should swtich to produciton build!!**). Start the django dev server: `python manage.py runserver` or use VSCode to launch django

### usage

Open http://127.0.0.1:8000

Start the web server:
```
python manage.py runserver 0.0.0.0:8000
```
## Deprecated part

Then open the following pages to see the demo
1. http://127.0.0.1:8000 to see automatical-reload time page
2. http://127.0.0.1:8000/chart/mode1 use semantic-ui-react's Dropdown to change mode
3. http://127.0.0.1:8000/chart/mode2
1. http://127.0.0.1:8000 to see automatical-reload time page (just for testing)
2. http://127.0.0.1:8000/chart/mode2
23 changes: 23 additions & 0 deletions reactui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
68 changes: 68 additions & 0 deletions reactui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `yarn 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.

### `yarn 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.

### `yarn 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.

### `yarn 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/).

### Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

### Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

### Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

### Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

### Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

### `yarn build` fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
Loading