Skip to content

Commit

Permalink
Updated to latest version of JavaScript which required changing metaD…
Browse files Browse the repository at this point in the history
…ata to be saved as a js file instead of jsonp.
  • Loading branch information
sburton42 committed Oct 7, 2023
1 parent d8c1aaa commit 41a3e61
Show file tree
Hide file tree
Showing 44 changed files with 24 additions and 17 deletions.
Binary file modified .DS_Store
Binary file not shown.
8 changes: 4 additions & 4 deletions trelliscope/html_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def write_widget(output_path:str, trelliscope_id:str, config_info:str, is_spa:bo
def _get_index_html_content(output_path:str, trelliscope_id:str, config_info:str, is_spa:bool) -> str:
# TODO: Decide how to handle Javascript file version numbers to include
HTML_WIDGET_FILE = "lib/htmlwidgets-1.6.2/htmlwidgets.js"
CSS_FILE = "lib/trelliscope_widget-0.6.0/css/main.682e4122.css"
TRELLISCOPE_WIDGET_FILE = "lib/trelliscope_widget-0.6.0/js/main.1c0011ce.js"
TRELLISCOPE_WIDGET_BINDING_FILE = "lib/trelliscope_widget-binding-0.1.0/trelliscope_widget.js"
CSS_FILE = "lib/trs-0.6.0/css/main.74ce0792.css"
TRELLISCOPE_WIDGET_FILE = "lib/trs-0.6.0/js/main.173baec5.js"
TRELLISCOPE_WIDGET_BINDING_FILE = "lib/trs-binding-0.1.3/trs.js"

# TODO: What is this? Where does it come from?
# It is something like "376b27d6688cc9ba8689"
Expand Down Expand Up @@ -77,7 +77,7 @@ def _get_index_html_content(output_path:str, trelliscope_id:str, config_info:str
</head>
<body>
<div id="htmlwidget-{html_widget_id}" style="width:{width};height:{height};" class="trelliscope_widget html-widget "></div>
<div id="htmlwidget-{html_widget_id}" style="width:{width};height:{height};" class="trs html-widget "></div>
<script type="application/json" data-for="htmlwidget-{html_widget_id}">{widget_params_str}</script>
</body>
</html>
Expand Down
Binary file added trelliscope/resources/.DS_Store
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

Binary file not shown.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function px(x) {
}

HTMLWidgets.widget({
name: 'trelliscope_widget',
name: 'trs',
type: 'output',
factory: function(el, width, height) {
// define shared variables for this instance...
Expand Down
15 changes: 8 additions & 7 deletions trelliscope/trelliscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def write_display(self, force_write: bool = False, jsonp: bool = True):
tr = tr._infer_thumbnail_url()

tr._write_display_info(jsonp, config["id"])
tr._write_meta_data(jsonp, config["id"])
tr._write_meta_data(config["id"])

# TODO: Should this look in the path or the output path (ie. with the current name on it)
# In R it was just the path, but from my example run, it seemed to have the dataset
Expand Down Expand Up @@ -1065,17 +1065,16 @@ def _get_metas_list(self) -> list:
meta_list = [meta.to_dict() for meta in self.metas.values()]
return meta_list

def _write_meta_data(self, jsonp:bool, id:str):
def _write_meta_data(self, id:str):
"""
Writes the meta data file.
Params:
jsonp: bool - Should jsonp format be used instead of json?
id: str - The id for the data set.
"""
meta_data_file = utils.get_file_path(self.get_dataset_display_path(),
Trelliscope.METADATA_FILE_NAME,
jsonp)
meta_data_filename = Trelliscope.METADATA_FILE_NAME + ".js"
meta_data_file = os.path.join(self.get_dataset_display_path(), meta_data_filename)

# TODO: Verify that we only want the meta columns here
meta_columns = [meta_name for meta_name in self.metas]
Expand All @@ -1100,8 +1099,10 @@ def _write_meta_data(self, jsonp:bool, id:str):
# Turn the escaped \/ into just /
meta_data_json = meta_data_json.replace("\\/", "/")

function_name = f"__loadMetaData__{id}"
utils.write_json_file(meta_data_file, jsonp, function_name, meta_data_json)
window_var_name = "metaData"
utils.write_window_js_file(file_path=meta_data_file,
window_var_name=window_var_name,
content=meta_data_json)

def _write_javascript_lib(self):
"""
Expand Down
6 changes: 6 additions & 0 deletions trelliscope/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,12 @@ def write_json_file(file_path: str, jsonp: bool, function_name: str, content: st
with open(file_path, "w") as output_file:
output_file.write(wrapped_content)

def write_window_js_file(file_path: str, window_var_name: str, content: str):
wrapped_content = f"window.{window_var_name} = {content}"

with open(file_path, "w") as output_file:
output_file.write(wrapped_content)

def get_file_path(directory: str, filename_no_ext: str, jsonp: bool):
file_ext = "jsonp" if jsonp else "json"
filename = f"{filename_no_ext}.{file_ext}"
Expand Down

0 comments on commit 41a3e61

Please sign in to comment.