Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Unified Diff: tools/telemetry/telemetry/web_components/web_component.py

Issue 214143002: [telemetry] WebComponents Cleanups (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/web_components/web_component.py
diff --git a/tools/telemetry/telemetry/web_components/viewer.py b/tools/telemetry/telemetry/web_components/web_component.py
similarity index 56%
rename from tools/telemetry/telemetry/web_components/viewer.py
rename to tools/telemetry/telemetry/web_components/web_component.py
index b5e6db129c081f9dcfc93609444440ed557314fb..7e7d1064d4a130192ad03380b5a17dc16a6034f0 100644
--- a/tools/telemetry/telemetry/web_components/viewer.py
+++ b/tools/telemetry/telemetry/web_components/web_component.py
@@ -11,36 +11,50 @@ from telemetry.web_components import web_components_project
from tvcm import generate
-class Viewer(object):
+class WebComponent(object):
"""An HTML-based viewer of data, built out of telemetry components.
- A viewer is used to visualize complex data that is produced from a telemtry
- benchmark. A viewer is backed by a .js file that contains a telemetry
- component. Python-side, it knows enough to instantiate that component and pass
- it its data. Viewers are typically written to HTML files in order to be
- displayed.
+ A WebComponent is used to visualize complex data that is produced from a
+ telemtry benchmark. A WebComponent is a Javascript class that can be
+ data-bound, plus python-side bindings that let us write HTML files that
+ instantiate that class and bind it to specific data.
- Python-side, a viewer class can be anything, as long as it implements the
- WriteDataToFileAsJSON. The data written here is passed to the
- data_binding_property of the JS-side class specified during the viewer's
- construction.
+ The primary job of the python side of a WebComponent is to implement the
+ WriteDataToFileAsJson. The data written here is passed to the
+ data_binding_property of the JS-side class.
+
+ The primary job of the javascript side of a WebComponent is visualization: it
+ takes the data from python and renders a UI for displaying that data in some
+ manner.
"""
def __init__(self, tvcm_module_name, js_class_name, data_binding_property):
self._tvcm_module_name = tvcm_module_name
self._js_class_name = js_class_name
self._data_binding_property = data_binding_property
+ self._data_to_view = None
+
+ @property
+ def data_to_view(self):
+ return self._data_to_view
+
+ @data_to_view.setter
+ def data_to_view(self, data_to_view):
+ self._data_to_view = data_to_view
def WriteDataToFileAsJson(self, f):
raise NotImplementedError()
- def WriteViewerToFile(self, f):
+ def GetDependentModuleNames(self):
+ return [self._tvcm_module_name]
+
+ def WriteWebComponentToFile(self, f):
project = web_components_project.WebComponentsProject()
load_sequence = project.CalcLoadSequenceForModuleNames(
- [self._tvcm_module_name])
+ self.GetDependentModuleNames())
with open(os.path.join(os.path.dirname(__file__),
- 'viewer_bootstrap.js')) as bfile:
+ 'web_component_bootstrap.js')) as bfile:
bootstrap_js_template = string.Template(bfile.read())
bootstrap_js = bootstrap_js_template.substitute(
js_class_name=self._js_class_name,
@@ -48,13 +62,14 @@ class Viewer(object):
bootstrap_script = generate.ExtraScript(text_content=bootstrap_js)
- class ViewerDataScript(generate.ExtraScript):
+ class WebComponentDataScript(generate.ExtraScript):
def __init__(self, results_component):
- super(ViewerDataScript, self).__init__()
+ super(WebComponentDataScript, self).__init__()
self._results_component = results_component
def WriteToFile(self, output_file):
- output_file.write('<script id="viewer-data" type="application/json">\n')
+ output_file.write('<script id="telemetry-web-component-data" ' +
+ 'type="application/json">\n')
self._results_component.WriteDataToFileAsJson(output_file)
output_file.write('</script>\n')
@@ -62,14 +77,15 @@ class Viewer(object):
generate.GenerateStandaloneHTMLToFile(
f, load_sequence,
title='Telemetry results',
- extra_scripts=[bootstrap_script, ViewerDataScript(self)])
+ extra_scripts=[bootstrap_script, WebComponentDataScript(self)])
@staticmethod
- def ReadDataObjectFromViewerFile(f):
- """Reads the data inside a viewer file written with WriteViewerToFile
+ def ReadDataObjectFromWebComponentFile(f):
+ """Reads the data inside a file written with WriteWebComponentToFile
+
+ Returns None if the data wasn't found, the JSON.parse'd object on success.
+ Raises exception if the HTML file was corrupt.
- Returns None if the viewer data wasn't found, the JSON.parse'd object on
- success. Raises exception if the viewer data was corrupt.
"""
class MyHTMLParser(HTMLParser.HTMLParser):
def __init__(self):
@@ -82,7 +98,7 @@ class Viewer(object):
if tag != 'script':
return
id_attr = dict(attrs).get('id', None)
- if id_attr == 'viewer-data':
+ if id_attr == 'telemetry-web-component-data':
assert not self._got_data_tag
self._got_data_tag = True
self._in_data_tag = True
@@ -97,9 +113,9 @@ class Viewer(object):
@property
def data(self):
if not self._got_data_tag:
- raise Exception('Missing <script> with #data-view')
+ raise Exception('Missing <script> with #telemetry-web-component-data')
if self._in_data_tag:
- raise Exception('Missing </script> on #data-view')
+ raise Exception('Missing </script> on #telemetry-web-component-data')
return json.loads(''.join(self._data_records))
parser = MyHTMLParser()

Powered by Google App Engine
This is Rietveld 408576698