Skip to content

Commit

Permalink
Change Path of colorPalette.json
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanzwicknagl committed Feb 2, 2024
1 parent 45e277e commit 59fc435
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
File renamed without changes.
30 changes: 15 additions & 15 deletions backend/src/viasp/server/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@
import shutil
from subprocess import Popen
from time import time
import json

import viasp_dash
from dash import Dash, jupyter_dash
from dash._jupyter import _jupyter_config

from viasp import clingoApiClient
from viasp.shared.defaults import (DEFAULT_BACKEND_HOST, DEFAULT_BACKEND_PORT,
DEFAULT_BACKEND_PROTOCOL, CLINGRAPH_PATH,
GRAPH_PATH, PROGRAM_STORAGE_PATH, STDIN_TMP_STORAGE_PATH,
COLOR_PALETTE)
DEFAULT_BACKEND_PROTOCOL, CLINGRAPH_PATH,
GRAPH_PATH, PROGRAM_STORAGE_PATH,
STDIN_TMP_STORAGE_PATH, COLOR_PALETTE_PATH)



def run(host=DEFAULT_BACKEND_HOST, port=DEFAULT_BACKEND_PORT):
""" create the dash app, set layout and start the backend on host:port """

# if running in binder, get proxy information
# and set the backend URL, which will be used
# by the frontend
Expand All @@ -40,17 +41,16 @@ def run(host=DEFAULT_BACKEND_HOST, port=DEFAULT_BACKEND_PORT):
_default_server_url = _jupyter_config['server_url']

_default_requests_pathname_prefix = (
_jupyter_config['base_subpath'].rstrip('/') + '/proxy/' + str(port)
)
_jupyter_config['base_subpath'].rstrip('/') + '/proxy/' +
str(port))

backend_url = _default_server_url+_default_requests_pathname_prefix
backend_url = _default_server_url + _default_requests_pathname_prefix
elif 'google.colab' in sys.modules:
from google.colab.output import eval_js # type: ignore
backend_url=eval_js(f"google.colab.kernel.proxyPort({port})")
from google.colab.output import eval_js # type: ignore
backend_url = eval_js(f"google.colab.kernel.proxyPort({port})")
else:
backend_url = f"{DEFAULT_BACKEND_PROTOCOL}://{host}:{port}"


command = ["viasp_server", "--host", host, "--port", str(port)]

# if 'ipykernel_launcher.py' in sys.argv[0]:
Expand All @@ -60,12 +60,12 @@ def run(host=DEFAULT_BACKEND_HOST, port=DEFAULT_BACKEND_PORT):
log = open('viasp.log', 'w', encoding="utf-8")
viasp_backend = Popen(command, stdout=log, stderr=log)

color_palette = json.load(
open(COLOR_PALETTE_PATH, "r"))
app = Dash(__name__)
app.layout = viasp_dash.ViaspDash(
id="myID",
backendURL=backend_url,
colorPalette=COLOR_PALETTE
)
app.layout = viasp_dash.ViaspDash(id="myID",
backendURL=backend_url,
colorPalette=color_palette)
app.title = "viASP"

# make sure the backend is up, before continuing with other modules
Expand Down
6 changes: 3 additions & 3 deletions backend/src/viasp/shared/defaults.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pathlib
import os
import json

DEFAULT_BACKEND_PROTOCOL = "http"
DEFAULT_BACKEND_HOST = "localhost"
Expand All @@ -9,8 +8,9 @@
DEFAULT_BACKEND_URL = f"{DEFAULT_BACKEND_PROTOCOL}://{DEFAULT_BACKEND_HOST}:{DEFAULT_BACKEND_PORT}"
SHARED_PATH = pathlib.Path(__file__).parent.resolve()
GRAPH_PATH = SHARED_PATH / "viasp_graph_storage.db"
STATIC_PATH = pathlib.Path(__file__).parent.parent.resolve() / "server/static/"
SERVER_PATH = pathlib.Path(__file__).parent.parent.resolve() / "server/"
STATIC_PATH = SERVER_PATH / "static/"
CLINGRAPH_PATH = os.path.join(STATIC_PATH, "clingraph")
PROGRAM_STORAGE_PATH = SHARED_PATH / "prg.lp"
STDIN_TMP_STORAGE_PATH = SHARED_PATH / "viasp_stdin_tmp.lp"
COLOR_PALETTE = json.load(open(os.path.join(STATIC_PATH, "colorPalette.json"), "r"))
COLOR_PALETTE_PATH = SERVER_PATH / "colorPalette.json"
2 changes: 1 addition & 1 deletion docs/viasp/colorPalette.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Color Palette
=================

The color Palette of viASP's frontend is defined by the file `/server/static/colorPalette.json`.
The color Palette of viASP's frontend is defined by the file `/server/colorPalette.json`.

The default file contains the following JSON object:

Expand Down
4 changes: 4 additions & 0 deletions examples/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def main():
ctl.viasp.mark(m)
print(handle.get())
ctl.viasp.show()
ctl.viasp.clingraph(viz_encoding="viz_hamiltonian.lp",
engine="dot",
graphviz_type="graph")



app = startup.run()
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/demo/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint no-magic-numbers: 0 */
import React from 'react';
import colorPaletteData from '../../../backend/src/viasp/server/static/colorPalette.json';
import colorPaletteData from '../../../backend/src/viasp/server/colorPalette.json';

import { ViaspDash } from '../lib';

Expand Down

0 comments on commit 59fc435

Please sign in to comment.