@@ -18,10 +18,11 @@ import {PerspectiveWidget} from "./psp_widget";
1818 */
1919const FACTORY_CSV = "CSVPerspective" ;
2020const FACTORY_JSON = "JSONPerspective" ;
21+ const FACTORY_ARROW = "ArrowPerspective" ;
2122
2223const RENDER_TIMEOUT = 1000 ;
2324
24- type IPerspectiveDocumentType = "csv" | "json" ;
25+ type IPerspectiveDocumentType = "csv" | "json" | "arrow" ;
2526
2627// create here to reuse for exception handling
2728const baddialog = ( ) : void => {
@@ -53,7 +54,7 @@ export class PerspectiveDocumentWidget extends DocumentWidget<PerspectiveWidget>
5354
5455 private _update ( ) : void {
5556 try {
56- if ( this . _type === "csv" ) {
57+ if ( this . _type === "csv" || this . _type === "arrow" ) {
5758 // load csv directly
5859 const data : string = this . _context . model . toString ( ) ;
5960 this . _psp . _update ( data ) ;
@@ -117,6 +118,15 @@ export class PerspectiveJSONFactory extends ABCWidgetFactory<IDocumentWidget<Per
117118 }
118119}
119120
121+ /**
122+ * A widget factory for arrow widgets.
123+ */
124+ export class PerspectiveArrowFactory extends ABCWidgetFactory < IDocumentWidget < PerspectiveWidget > > {
125+ protected createNewWidget ( context : DocumentRegistry . Context ) : IDocumentWidget < PerspectiveWidget > {
126+ return new PerspectiveDocumentWidget ( { context} , "arrow" ) ;
127+ }
128+ }
129+
120130/**
121131 * Activate cssviewer extension for CSV files
122132 */
@@ -135,6 +145,13 @@ function activate(app: JupyterFrontEnd, restorer: ILayoutRestorer | null, themeM
135145 readOnly : true
136146 } ) ;
137147
148+ const factoryarrow = new PerspectiveArrowFactory ( {
149+ name : FACTORY_ARROW ,
150+ fileTypes : [ "arrow" ] ,
151+ defaultFor : [ "arrow" ] ,
152+ readOnly : true
153+ } ) ;
154+
138155 const trackercsv = new WidgetTracker < IDocumentWidget < PerspectiveWidget > > ( {
139156 namespace : "csvperspective"
140157 } ) ;
@@ -143,6 +160,10 @@ function activate(app: JupyterFrontEnd, restorer: ILayoutRestorer | null, themeM
143160 namespace : "jsonperspective"
144161 } ) ;
145162
163+ const trackerarrow = new WidgetTracker < IDocumentWidget < PerspectiveWidget > > ( {
164+ namespace : "arrowperspective"
165+ } ) ;
166+
146167 if ( restorer ) {
147168 // Handle state restoration.
148169 void restorer . restore ( trackercsv , {
@@ -156,17 +177,26 @@ function activate(app: JupyterFrontEnd, restorer: ILayoutRestorer | null, themeM
156177 args : widget => ( { path : widget . context . path , factory : FACTORY_JSON } ) ,
157178 name : widget => widget . context . path
158179 } ) ;
180+
181+ void restorer . restore ( trackerarrow , {
182+ command : "docmanager:open" ,
183+ args : widget => ( { path : widget . context . path , factory : FACTORY_ARROW } ) ,
184+ name : widget => widget . context . path
185+ } ) ;
159186 }
160187
161188 app . docRegistry . addWidgetFactory ( factorycsv ) ;
162189 app . docRegistry . addWidgetFactory ( factoryjson ) ;
190+ app . docRegistry . addWidgetFactory ( factoryarrow ) ;
163191
164192 const ftcsv = app . docRegistry . getFileType ( "csv" ) ;
165193 const ftjson = app . docRegistry . getFileType ( "json" ) ;
194+ const ftarrow = app . docRegistry . getFileType ( "arrow" ) ;
166195
167196 factorycsv . widgetCreated . connect ( ( sender , widget ) => {
168197 // Track the widget.
169198 void trackercsv . add ( widget ) ;
199+
170200 // Notify the widget tracker if restore data needs to update.
171201 widget . context . pathChanged . connect ( ( ) => {
172202 void trackercsv . save ( widget ) ;
@@ -181,6 +211,7 @@ function activate(app: JupyterFrontEnd, restorer: ILayoutRestorer | null, themeM
181211 factoryjson . widgetCreated . connect ( ( sender , widget ) => {
182212 // Track the widget.
183213 void trackerjson . add ( widget ) ;
214+
184215 // Notify the widget tracker if restore data needs to update.
185216 widget . context . pathChanged . connect ( ( ) => {
186217 void trackerjson . save ( widget ) ;
@@ -192,6 +223,21 @@ function activate(app: JupyterFrontEnd, restorer: ILayoutRestorer | null, themeM
192223 }
193224 } ) ;
194225
226+ factoryarrow . widgetCreated . connect ( ( sender , widget ) => {
227+ // Track the widget.
228+ void trackerarrow . add ( widget ) ;
229+
230+ // Notify the widget tracker if restore data needs to update.
231+ widget . context . pathChanged . connect ( ( ) => {
232+ void trackerarrow . save ( widget ) ;
233+ } ) ;
234+
235+ if ( ftarrow ) {
236+ widget . title . iconClass = ftarrow . iconClass || "" ;
237+ widget . title . iconLabel = ftarrow . iconLabel || "" ;
238+ }
239+ } ) ;
240+
195241 // Keep the themes up-to-date.
196242 const updateThemes = ( ) : void => {
197243 const isLight = themeManager && themeManager . theme ? themeManager . isLight ( themeManager . theme ) : true ;
@@ -201,6 +247,9 @@ function activate(app: JupyterFrontEnd, restorer: ILayoutRestorer | null, themeM
201247 trackerjson . forEach ( ( pspDocWidget : PerspectiveDocumentWidget ) => {
202248 pspDocWidget . psp . dark = ! isLight ;
203249 } ) ;
250+ trackerarrow . forEach ( ( pspDocWidget : PerspectiveDocumentWidget ) => {
251+ pspDocWidget . psp . dark = ! isLight ;
252+ } ) ;
204253 } ;
205254
206255 if ( themeManager ) {
0 commit comments