Skip to content

Commit

Permalink
Add arrow renderer, fix some problems from finos#1290
Browse files Browse the repository at this point in the history
  • Loading branch information
timkpaine authored and zepaz committed Jan 22, 2021
1 parent acc3d04 commit 5032199
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cpp/perspective/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,10 @@ elseif(PSP_CPP_BUILD OR PSP_PYTHON_BUILD)

# .dll not importable
set_property(TARGET binding PROPERTY SUFFIX .pyd)
elseif (MACOS OR NOT MANYLINUX)
target_compile_options(binding PRIVATE -Wdeprecated-declarations)
set_property(TARGET psp PROPERTY INSTALL_RPATH ${CMAKE_INSTALL_RPATH} ${module_origin_path})
set_property(TARGET binding PROPERTY INSTALL_RPATH ${CMAKE_INSTALL_RPATH} ${module_origin_path})
else()
target_compile_options(binding PRIVATE -Wdeprecated-declarations)
endif()
Expand Down
53 changes: 51 additions & 2 deletions packages/perspective-jupyterlab/src/ts/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import {PerspectiveWidget} from "./psp_widget";
*/
const FACTORY_CSV = "CSVPerspective";
const FACTORY_JSON = "JSONPerspective";
const FACTORY_ARROW = "ArrowPerspective";

const RENDER_TIMEOUT = 1000;

type IPerspectiveDocumentType = "csv" | "json";
type IPerspectiveDocumentType = "csv" | "json" | "arrow";

// create here to reuse for exception handling
const baddialog = (): void => {
Expand Down Expand Up @@ -53,7 +54,7 @@ export class PerspectiveDocumentWidget extends DocumentWidget<PerspectiveWidget>

private _update(): void {
try {
if (this._type === "csv") {
if (this._type === "csv" || this._type === "arrow") {
// load csv directly
const data: string = this._context.model.toString();
this._psp._update(data);
Expand Down Expand Up @@ -117,6 +118,15 @@ export class PerspectiveJSONFactory extends ABCWidgetFactory<IDocumentWidget<Per
}
}

/**
* A widget factory for arrow widgets.
*/
export class PerspectiveArrowFactory extends ABCWidgetFactory<IDocumentWidget<PerspectiveWidget>> {
protected createNewWidget(context: DocumentRegistry.Context): IDocumentWidget<PerspectiveWidget> {
return new PerspectiveDocumentWidget({context}, "arrow");
}
}

/**
* Activate cssviewer extension for CSV files
*/
Expand All @@ -135,6 +145,13 @@ function activate(app: JupyterFrontEnd, restorer: ILayoutRestorer | null, themeM
readOnly: true
});

const factoryarrow = new PerspectiveArrowFactory({
name: FACTORY_ARROW,
fileTypes: ["arrow"],
defaultFor: ["arrow"],
readOnly: true
});

const trackercsv = new WidgetTracker<IDocumentWidget<PerspectiveWidget>>({
namespace: "csvperspective"
});
Expand All @@ -143,6 +160,10 @@ function activate(app: JupyterFrontEnd, restorer: ILayoutRestorer | null, themeM
namespace: "jsonperspective"
});

const trackerarrow = new WidgetTracker<IDocumentWidget<PerspectiveWidget>>({
namespace: "arrowperspective"
});

if (restorer) {
// Handle state restoration.
void restorer.restore(trackercsv, {
Expand All @@ -156,17 +177,26 @@ function activate(app: JupyterFrontEnd, restorer: ILayoutRestorer | null, themeM
args: widget => ({path: widget.context.path, factory: FACTORY_JSON}),
name: widget => widget.context.path
});

void restorer.restore(trackerarrow, {
command: "docmanager:open",
args: widget => ({path: widget.context.path, factory: FACTORY_ARROW}),
name: widget => widget.context.path
});
}

app.docRegistry.addWidgetFactory(factorycsv);
app.docRegistry.addWidgetFactory(factoryjson);
app.docRegistry.addWidgetFactory(factoryarrow);

const ftcsv = app.docRegistry.getFileType("csv");
const ftjson = app.docRegistry.getFileType("json");
const ftarrow = app.docRegistry.getFileType("arrow");

factorycsv.widgetCreated.connect((sender, widget) => {
// Track the widget.
void trackercsv.add(widget);

// Notify the widget tracker if restore data needs to update.
widget.context.pathChanged.connect(() => {
void trackercsv.save(widget);
Expand All @@ -181,6 +211,7 @@ function activate(app: JupyterFrontEnd, restorer: ILayoutRestorer | null, themeM
factoryjson.widgetCreated.connect((sender, widget) => {
// Track the widget.
void trackerjson.add(widget);

// Notify the widget tracker if restore data needs to update.
widget.context.pathChanged.connect(() => {
void trackerjson.save(widget);
Expand All @@ -192,6 +223,21 @@ function activate(app: JupyterFrontEnd, restorer: ILayoutRestorer | null, themeM
}
});

factoryarrow.widgetCreated.connect((sender, widget) => {
// Track the widget.
void trackerarrow.add(widget);

// Notify the widget tracker if restore data needs to update.
widget.context.pathChanged.connect(() => {
void trackerarrow.save(widget);
});

if (ftarrow) {
widget.title.iconClass = ftarrow.iconClass || "";
widget.title.iconLabel = ftarrow.iconLabel || "";
}
});

// Keep the themes up-to-date.
const updateThemes = (): void => {
const isLight = themeManager && themeManager.theme ? themeManager.isLight(themeManager.theme) : true;
Expand All @@ -201,6 +247,9 @@ function activate(app: JupyterFrontEnd, restorer: ILayoutRestorer | null, themeM
trackerjson.forEach((pspDocWidget: PerspectiveDocumentWidget) => {
pspDocWidget.psp.dark = !isLight;
});
trackerarrow.forEach((pspDocWidget: PerspectiveDocumentWidget) => {
pspDocWidget.psp.dark = !isLight;
});
};

if (themeManager) {
Expand Down

0 comments on commit 5032199

Please sign in to comment.