1+ import { IRenderMime } from '@jupyterlab/rendermime-interfaces' ;
2+ import { Widget } from '@lumino/widgets' ;
3+ import Plotly from "plotly.js" ;
4+
5+ /**
6+ * The default mime type for the extension.
7+ */
8+ const MIME_TYPE = 'plotly/vnd' ;
9+
10+
11+ /**
12+ * The CSS class to add to the Plotly Widget.
13+ */
14+ const CSS_CLASS = "jp-RenderedPlotly" ;
15+
16+ /**
17+ * The CSS class for a Plotly icon.
18+ */
19+ const CSS_ICON_CLASS = "jp-MaterialIcon jp-PlotlyIcon" ;
20+
21+ /**
22+ * A widget for rendering mp4.
23+ */
24+ export class PlotlyMimeRenderer extends Widget implements IRenderMime . IRenderer {
25+ private _data : any ;
26+ private _config : any ;
27+ private _plotly_layout : any ;
28+ /**
29+ * Construct a new output widget.
30+ */
31+ constructor ( options : any ) {
32+ super ( ) ;
33+ this . addClass ( CSS_CLASS ) ;
34+ this . _data = options . data ;
35+ this . _config = options . config ;
36+ this . _plotly_layout = options . layout ;
37+ }
38+
39+ /**
40+ * Render plotly into this widget's node.
41+ */
42+ renderModel ( model : IRenderMime . IMimeModel ) : Promise < void > {
43+ return new Promise < void > ( ( resolve , reject ) => {
44+ Plotly . react ( this . node , this . _data , this . _plotly_layout , this . _config )
45+ } ) ;
46+ }
47+ }
48+
49+ /**
50+ * A mime renderer factory for mp4 data.
51+ */
52+ export const rendererFactory : IRenderMime . IRendererFactory = {
53+ safe : true ,
54+ mimeTypes : [ MIME_TYPE ] ,
55+ createRenderer : options => new PlotlyMimeRenderer ( options )
56+ } ;
57+
58+ /**
59+ * Extension definition.
60+ */
61+ const extension : IRenderMime . IExtension = {
62+ id : "@jupyterlab/plotly-extension:factory" ,
63+ rendererFactory,
64+ rank : 0 ,
65+ dataType : "json" ,
66+ fileTypes : [
67+ {
68+ name : "plotly" ,
69+ mimeTypes : [ MIME_TYPE ] ,
70+ extensions : [ ".plotly" , ".plotly.json" ] ,
71+ iconClass : CSS_ICON_CLASS ,
72+ } ,
73+ ] ,
74+ documentWidgetFactoryOptions : {
75+ name : "Plotly" ,
76+ primaryFileType : "plotly" ,
77+ fileTypes : [ "plotly" , "json" ] ,
78+ defaultFor : [ "plotly" ] ,
79+ } ,
80+ }
81+
82+ export default extension ;
0 commit comments