Skip to content

Commit 1634e60

Browse files
committed
added ability to embed multiple metadata dashboards
1 parent f9a95eb commit 1634e60

File tree

4 files changed

+58
-35
lines changed

4 files changed

+58
-35
lines changed

src/dashboard.tsx

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ export class Dashboard extends Widget {
9898
outputTracker,
9999
model,
100100
mode,
101-
width: options.dashboardWidth || Dashboard.DEFAULT_WIDTH,
102-
height: options.dashboardHeight || Dashboard.DEFAULT_HEIGHT
101+
width: options.dashboardWidth || window.innerWidth,
102+
height: options.dashboardHeight || window.innerHeight
103103
});
104104

105105
widgetstore.connectDashboard(this);
@@ -261,19 +261,21 @@ export class Dashboard extends Widget {
261261
return;
262262
}
263263

264+
// Changed to only "infinitely" scroll on the vertical
265+
264266
const elem = this.node;
265-
const rightEdge = elem.offsetWidth + elem.scrollLeft;
267+
// const rightEdge = elem.offsetWidth + elem.scrollLeft;
266268
const bottomEdge = elem.offsetHeight + elem.scrollTop;
267269

268-
if (rightEdge >= model.width && rightEdge > this._oldRightEdge) {
269-
model.width += 200;
270-
}
270+
// if (rightEdge >= model.width && rightEdge > this._oldRightEdge) {
271+
// model.width += 200;
272+
// }
271273
if (bottomEdge >= model.height && bottomEdge > this._oldBottomEdge) {
272-
model.height += 200;
274+
model.height += (this.layout as DashboardLayout).tileSize;
273275
}
274276

275277
this._oldBottomEdge = bottomEdge;
276-
this._oldRightEdge = rightEdge;
278+
// this._oldRightEdge = rightEdge;
277279
}
278280

279281
/**
@@ -388,12 +390,10 @@ export class Dashboard extends Widget {
388390

389391
if ((oldDashboardMetadata as Object).hasOwnProperty('views')) {
390392
const dashboardIds = Object.keys(oldDashboardMetadata.views);
391-
if (dashboardIds.length != 1) {
392-
throw new Error(
393-
'Multiple dashboards are embedded--currently only a single embedded dashboard is supported.'
394-
);
395-
}
396-
dashboardId = dashboardIds[0];
393+
const names = new Map<string, string>(
394+
dashboardIds.map(id => [oldDashboardMetadata.views[id].name, id])
395+
);
396+
dashboardId = names.get(name) || UUID.uuid4();
397397
} else {
398398
dashboardId = UUID.uuid4();
399399
}
@@ -456,7 +456,7 @@ export class Dashboard extends Widget {
456456

457457
private _model: IDashboardModel;
458458
private _context: DocumentRegistry.IContext<DocumentRegistry.IModel>;
459-
private _oldRightEdge = 0;
459+
// private _oldRightEdge = 0;
460460
private _oldBottomEdge = 0;
461461
}
462462

@@ -468,10 +468,6 @@ export namespace Dashboard {
468468

469469
export type ScrollMode = 'infinite' | 'constrained';
470470

471-
export const DEFAULT_WIDTH = 1920;
472-
473-
export const DEFAULT_HEIGHT = 1080;
474-
475471
export interface IOptions extends Widget.IOptions {
476472
/**
477473
* Tracker for child widgets.

src/index.ts

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ const extension: JupyterFrontEndPlugin<IDashboardTracker> = {
131131
const model = widget.content.model;
132132
// TODO: Make scrollMode changable in JL. Default 'infinite' for now.
133133
model.scrollMode = 'infinite';
134-
model.width = Dashboard.DEFAULT_WIDTH;
135-
model.height = Dashboard.DEFAULT_HEIGHT;
134+
model.width = (widget.content.layout as DashboardLayout).width;
135+
model.height = (widget.content.layout as DashboardLayout).height;
136136
});
137137

138138
// Add commands to context menus.
@@ -442,8 +442,8 @@ function addCommands(
442442
label: 'Set Dashboard Dimensions',
443443
execute: async args => {
444444
const model = dashboardTracker.currentWidget.model;
445-
const width = model.width ? model.width : Dashboard.DEFAULT_WIDTH;
446-
const height = model.height ? model.height : Dashboard.DEFAULT_HEIGHT;
445+
const width = model.width ? model.width : window.innerWidth;
446+
const height = model.height ? model.height : window.innerHeight;
447447
await showDialog({
448448
title: 'Enter Dimensions',
449449
body: new Private.ResizeHandler(width, height),
@@ -458,14 +458,14 @@ function addCommands(
458458
}
459459
if (!newWidth) {
460460
if (!model.width) {
461-
newWidth = Dashboard.DEFAULT_WIDTH;
461+
newWidth = window.innerWidth;
462462
} else {
463463
newWidth = model.width;
464464
}
465465
}
466466
if (!newHeight) {
467467
if (!model.height) {
468-
newHeight = Dashboard.DEFAULT_HEIGHT;
468+
newHeight = window.innerHeight;
469469
} else {
470470
newHeight = model.height;
471471
}
@@ -543,9 +543,17 @@ function addCommands(
543543

544544
commands.addCommand(CommandIDs.saveToMetadata, {
545545
label: 'Save Dashboard To Notebook Metadata',
546-
execute: args => {
547-
const dashboard = dashboardTracker.currentWidget;
548-
dashboard.saveToNotebookMetadata();
546+
execute: async args => {
547+
548+
const name = await InputDialog.getText({
549+
title: 'Dashboard name',
550+
text: 'default'
551+
});
552+
if (name.value) {
553+
const dashboard = dashboardTracker.currentWidget;
554+
dashboard.saveToNotebookMetadata(name.value);
555+
}
556+
549557
}
550558
});
551559

@@ -588,7 +596,7 @@ function addCommands(
588596

589597
commands.addCommand(CommandIDs.openFromMetadata, {
590598
label: 'Open Metadata Dashboard',
591-
execute: args => {
599+
execute: async args => {
592600
const notebook = notebookTracker.currentWidget;
593601
const notebookMetadata = getMetadata(notebook);
594602
if (!('views' in notebookMetadata)) {
@@ -602,7 +610,20 @@ function addCommands(
602610
throw new Error(`Dashboard id ${dashboardId} doesn't exist in notebook ${notebookId}`);
603611
}
604612
} else {
605-
dashboardId = Object.keys(notebookMetadata.views)[0]
613+
const dashboardIds = Object.keys(notebookMetadata.views);
614+
const nameMap = new Map<string, string>(
615+
dashboardIds.map(id => [notebookMetadata.views[id].name, id])
616+
);
617+
const dashboardName = await InputDialog.getItem({
618+
title: 'Select a Dashboard',
619+
current: 0,
620+
items: Array.from(nameMap.keys()),
621+
});
622+
if (dashboardName.value) {
623+
dashboardId = nameMap.get(dashboardName.value);
624+
} else {
625+
return;
626+
}
606627
}
607628

608629
const dashboardView = notebookMetadata.views[dashboardId];

src/widget.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,12 @@ export class DashboardWidget extends Widget {
245245
const pos = this.pos;
246246
const oldPos = { ...pos };
247247

248-
const bumpDistance = event.altKey ? 1 : DashboardWidget.BUMP_DISTANCE;
248+
let bumpDistance: number;
249+
if (this._mode === 'grid-edit') {
250+
bumpDistance = (this.parent.layout as DashboardLayout).tileSize
251+
} else {
252+
bumpDistance = event.altKey ? 1 : DashboardWidget.BUMP_DISTANCE;
253+
}
249254

250255
switch (event.keyCode) {
251256
// Left arrow key

style/base.css

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
.pr-DashboardWidget {
66
display: inline-flex;
7+
align-items: flex-start;
8+
justify-content: left;
79
}
810

911
.pr-DashboardWidget .pr-MarkdownOutput {
@@ -75,12 +77,11 @@
7577
}
7678

7779
.pr-DashboardWidgetChild {
78-
/* width: 100%;
79-
height: 100%; */
80+
max-width: 100%;
81+
max-height: 100%;
8082
overflow: hidden;
8183
display: inline-flex;
82-
align-items: center;
83-
justify-content: center;
84+
justify-content: left;
8485
}
8586

8687
.pr-EditableWidget:focus .pr-Resizer {

0 commit comments

Comments
 (0)