Skip to content

Commit cfb02bf

Browse files
authored
Merge pull request #89 from jupytercalpoly/docstrings
docstrings
2 parents 2caa6bd + 8e27dfb commit cfb02bf

File tree

8 files changed

+488
-122
lines changed

8 files changed

+488
-122
lines changed

src/commands.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* A namespace for dashboard command ids.
3+
*/
14
export namespace CommandIDs {
25
export const deleteOutput = 'dashboard:delete-dashboard-widget';
36
export const undo = 'dashboard:undo';
@@ -15,6 +18,5 @@ export namespace CommandIDs {
1518
export const runAllAboveOutput = 'dashboard:run-all-above-output';
1619
export const startFullscreen = 'dashboard:start-fullscreen';
1720
export const createNew = 'dashboard:create-new';
18-
export const enableGrid = 'dashboard:enable-grid';
19-
export const setGridSize = 'dashboard:set-grid-size';
21+
export const setTileSize = 'dashboard:set-tile-size';
2022
}

src/dashboard.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { Message } from '@lumino/messaging';
2222

2323
import { IDragEvent } from '@lumino/dragdrop';
2424

25-
import { DashboardLayout } from './custom_layout';
25+
import { DashboardLayout } from './layout';
2626

2727
import { DashboardWidget } from './widget';
2828

@@ -144,7 +144,7 @@ export class Dashboard extends Widget {
144144
if (pos) {
145145
pos.left = event.offsetX + this.node.scrollLeft;
146146
pos.top = event.offsetY + this.node.scrollTop;
147-
(this.layout as DashboardLayout).drawDropZone(pos);
147+
(this.layout as DashboardLayout).drawDropZone(pos, '#2b98f0');
148148
}
149149
event.preventDefault();
150150
event.stopPropagation();
@@ -239,7 +239,6 @@ export class Dashboard extends Widget {
239239
private _evtScroll(_event: Event): void {
240240
const model = this.model;
241241

242-
console.log('scrollMode', model.scrollMode);
243242
if (model.scrollMode !== 'infinite') {
244243
return;
245244
}

src/dbformat.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export interface IOutputInfo extends PartialJSONObject {
4545
*/
4646
cellId: string;
4747

48+
/**
49+
* The position and size of an output.
50+
*/
4851
pos: {
4952
top: number;
5053
left: number;

src/index.ts

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import { CommandIDs } from './commands';
5151

5252
import { ReadonlyJSONObject } from '@lumino/coreutils';
5353

54-
import { DashboardLayout } from './custom_layout';
54+
import { DashboardLayout } from './layout';
5555

5656
import { Widgetstore } from './widgetstore';
5757

@@ -120,6 +120,9 @@ const extension: JupyterFrontEndPlugin<IDashboardTracker> = {
120120

121121
app.docRegistry.addModelFactory(modelFactory);
122122
app.docRegistry.addWidgetFactory(widgetFactory);
123+
124+
// Add newly created dashboards to the tracker, set their icon and label,
125+
// and set the default width, height, and scrollMode.
123126
widgetFactory.widgetCreated.connect((_sender, widget) => {
124127
void dashboardTracker.add(widget.content);
125128

@@ -128,6 +131,7 @@ const extension: JupyterFrontEndPlugin<IDashboardTracker> = {
128131
widget.title.iconLabel = dashboardFiletype.iconLabel || '';
129132

130133
const model = widget.content.model;
134+
// TODO: Make scrollMode changable in JL. Default 'infinite' for now.
131135
model.scrollMode = 'infinite';
132136
model.width = Dashboard.DEFAULT_WIDTH;
133137
model.height = Dashboard.DEFAULT_HEIGHT;
@@ -152,36 +156,24 @@ const extension: JupyterFrontEndPlugin<IDashboardTracker> = {
152156
rank: 2,
153157
});
154158

155-
// app.contextMenu.addItem({
156-
// command: CommandIDs.toggleMode,
157-
// selector: '.pr-JupyterDashboard',
158-
// rank: 3,
159-
// });
160-
161159
app.contextMenu.addItem({
162160
command: CommandIDs.cut,
163161
selector: '.pr-JupyterDashboard',
164-
rank: 4,
162+
rank: 3,
165163
});
166164

167165
app.contextMenu.addItem({
168166
command: CommandIDs.copy,
169167
selector: '.pr-JupyterDashboard',
170-
rank: 5,
168+
rank: 4,
171169
});
172170

173171
app.contextMenu.addItem({
174172
command: CommandIDs.paste,
175173
selector: '.pr-JupyterDashboard',
176-
rank: 6,
174+
rank: 5,
177175
});
178176

179-
// app.contextMenu.addItem({
180-
// command: CommandIDs.enableGrid,
181-
// selector: '.pr-JupyterDashboard',
182-
// rank: 7,
183-
// });
184-
185177
app.contextMenu.addItem({
186178
command: CommandIDs.deleteOutput,
187179
selector: '.pr-EditableWidget',
@@ -222,13 +214,6 @@ const extension: JupyterFrontEndPlugin<IDashboardTracker> = {
222214
selector: '.pr-JupyterDashboard',
223215
});
224216

225-
// app.commands.addKeyBinding({
226-
// command: CommandIDs.toggleMode,
227-
// args: {},
228-
// keys: ['I'],
229-
// selector: '.pr-JupyterDashboard',
230-
// });
231-
232217
app.commands.addKeyBinding({
233218
command: CommandIDs.cut,
234219
args: {},
@@ -263,7 +248,7 @@ const extension: JupyterFrontEndPlugin<IDashboardTracker> = {
263248
command: CommandIDs.setDimensions,
264249
},
265250
{
266-
command: CommandIDs.setGridSize,
251+
command: CommandIDs.setTileSize,
267252
},
268253
]);
269254

@@ -283,6 +268,21 @@ const extension: JupyterFrontEndPlugin<IDashboardTracker> = {
283268
},
284269
};
285270

271+
/**
272+
* Add commands to the main JupyterLab command registry.
273+
*
274+
* @param app - the JupyterLab instance.
275+
*
276+
* @param dashboardTracker - a tracker for dashboards.
277+
*
278+
* @param outputTracker - a tracker for dashboard outputs.
279+
*
280+
* @param clipboard - a set used to keep track of widgets for copy/pasting.
281+
*
282+
* @param docManager - a document manager used to create/rename files.
283+
*
284+
* @param notebookTracker - a tracker for notebooks.
285+
*/
286286
function addCommands(
287287
app: JupyterFrontEnd,
288288
dashboardTracker: WidgetTracker<Dashboard>,
@@ -395,14 +395,6 @@ function addCommands(
395395
},
396396
});
397397

398-
commands.addCommand(CommandIDs.enableGrid, {
399-
label: 'Enable Tiled Layout (EXPERIMENTAL)',
400-
execute: (args) => {
401-
const dashboard = dashboardTracker.currentWidget;
402-
dashboard.model.mode = 'grid';
403-
},
404-
});
405-
406398
commands.addCommand(CommandIDs.runOutput, {
407399
label: (args) => (inToolbar(args) ? '' : 'Run Output'),
408400
icon: runIcon,
@@ -452,15 +444,15 @@ function addCommands(
452444
isEnabled: hasDashboard,
453445
});
454446

455-
commands.addCommand(CommandIDs.setGridSize, {
447+
commands.addCommand(CommandIDs.setTileSize, {
456448
label: 'Set Grid Dimensions',
457449
execute: async (args) => {
458450
const newSize = await InputDialog.getNumber({
459451
title: 'Enter Grid Size',
460452
});
461453
if (newSize.value) {
462454
const layout = dashboardTracker.currentWidget.layout as DashboardLayout;
463-
layout.gridSize = newSize.value;
455+
layout.setTileSize(newSize.value);
464456
}
465457
},
466458
isEnabled: hasDashboard,
@@ -549,14 +541,19 @@ function addCommands(
549541
icon: saveIcon,
550542
execute: (args) => {
551543
const dashboard = dashboardTracker.currentWidget;
552-
dashboard.model.path;
553544
dashboard.context.save();
554545
},
555546
isEnabled: (args) => inToolbar(args) || hasDashboard(),
556547
});
557548
}
558549

550+
/**
551+
* A namespace for private functionality.
552+
*/
559553
namespace Private {
554+
/**
555+
* A dialog with two boxes for setting a dashboard's width and height.
556+
*/
560557
export class ResizeHandler extends Widget {
561558
constructor(oldWidth: number, oldHeight: number) {
562559
const node = document.createElement('div');
@@ -575,8 +572,6 @@ namespace Private {
575572
height.required = true;
576573
width.placeholder = `Width (${oldWidth})`;
577574
height.placeholder = `Height (${oldHeight})`;
578-
// width.value = oldWidth.toString();
579-
// height.value = oldHeight.toString();
580575

581576
node.appendChild(name);
582577
node.appendChild(width);

0 commit comments

Comments
 (0)