Skip to content

Commit 2b5e670

Browse files
committed
docstrings 2
1 parent 114cf55 commit 2b5e670

File tree

8 files changed

+138
-7
lines changed

8 files changed

+138
-7
lines changed

src/commands.ts

Lines changed: 3 additions & 0 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';

src/dashboard.tsx

Lines changed: 1 addition & 1 deletion
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

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: 1 addition & 1 deletion
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

File renamed without changes.

src/model.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ import { Dashboard } from './dashboard';
3333

3434
import { getNotebookById } from './utils';
3535

36+
/**
37+
* The definition of a model object for a dashboard widget.
38+
*/
3639
export interface IDashboardModel extends DocumentRegistry.IModel {
3740
/**
3841
* The widget store for the dashboard.
@@ -49,24 +52,54 @@ export interface IDashboardModel extends DocumentRegistry.IModel {
4952
*/
5053
readonly contentsManager: ContentsManager;
5154

55+
/**
56+
* The metadata associated with the dashboard.
57+
*/
5258
metadata: IObservableJSON;
5359

60+
/**
61+
* A signal emitted when the dashboard finishes deserializing from a file.
62+
*/
5463
loaded: Signal<this, void>;
5564

65+
/**
66+
* The display mode of the dashboard.
67+
*/
5668
mode: Dashboard.Mode;
5769

70+
/**
71+
* The path to the dashboard file.
72+
*/
5873
path: string;
5974

75+
/**
76+
* The name of the dashboard.
77+
*/
6078
name: string;
6179

80+
/**
81+
* The width of the dashboard in pixels.
82+
*/
6283
width: number;
6384

85+
/**
86+
* The height of the dashboard in pixels.
87+
*/
6488
height: number;
6589

90+
/**
91+
* The scroll mode of the dashboard.
92+
*/
6693
scrollMode: Dashboard.ScrollMode;
6794
}
6895

96+
/**
97+
* An implementation of a dashboard Model.
98+
*/
6999
export class DashboardModel extends DocumentModel implements IDashboardModel {
100+
/**
101+
* Construct a new dashboard model.
102+
*/
70103
constructor(options: DashboardModel.IOptions) {
71104
super(options.languagePreference, options.modelDB);
72105

@@ -78,6 +111,9 @@ export class DashboardModel extends DocumentModel implements IDashboardModel {
78111
this.contentsManager = options.contentsManager || new ContentsManager();
79112
}
80113

114+
/**
115+
* Deserialize the model from JSON.
116+
*/
81117
async fromJSON(value: IDashboardContent): Promise<void> {
82118
const outputs: Widgetstore.WidgetInfo[] = [];
83119

@@ -122,6 +158,9 @@ export class DashboardModel extends DocumentModel implements IDashboardModel {
122158
// this.mode = 'present';
123159
}
124160

161+
/**
162+
* Serialize the model to JSON.
163+
*/
125164
toJSON(): IDashboardContent {
126165
const notebookTracker = this.notebookTracker;
127166

@@ -175,10 +214,16 @@ export class DashboardModel extends DocumentModel implements IDashboardModel {
175214
return file;
176215
}
177216

217+
/**
218+
* Serialize the model to a string.
219+
*/
178220
toString(): string {
179221
return JSON.stringify(this.toJSON(), undefined, 2);
180222
}
181223

224+
/**
225+
* Deserialize the model from a string.
226+
*/
182227
async fromString(value: string): Promise<void> {
183228
if (!value) {
184229
this._loaded.emit(void 0);

src/widget.ts

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,37 @@ import { Signal, ISignal } from '@lumino/signaling';
2626
import { DashboardIcons } from './icons';
2727

2828
import { Widgetstore, WidgetPosition } from './widgetstore';
29-
import { DashboardLayout } from './custom_layout';
3029

31-
// HTML element classes
30+
import { DashboardLayout } from './layout';
3231

32+
/**
33+
* The class name added to dashboard outputs
34+
*/
3335
const DASHBOARD_WIDGET_CLASS = 'pr-DashboardWidget';
3436

37+
/**
38+
* The class name for the widget drag mime.
39+
*/
3540
const DASHBOARD_WIDGET_MIME = 'pr-DashboardWidgetMine';
3641

42+
/**
43+
* The class name added to the children of dashboard outputs.
44+
*/
3745
const DASHBOARD_WIDGET_CHILD_CLASS = 'pr-DashboardWidgetChild';
3846

47+
/**
48+
* The class name added to editable dashboard outputs.
49+
*/
3950
const EDITABLE_WIDGET_CLASS = 'pr-EditableWidget';
4051

52+
/**
53+
* The class name added to dashboard outputs being dragged.
54+
*/
4155
const IN_DRAG_CLASS = 'pr-InDrag';
4256

57+
/**
58+
* The class name added to markdown dashboard outputs.
59+
*/
4360
const MARKDOWN_OUTPUT_CLASS = 'pr-MarkdownOutput';
4461

4562
/**
@@ -237,7 +254,7 @@ export class DashboardWidget extends Widget {
237254
}
238255

239256
/**
240-
* Handle the `'dblclick'` event for the widget.
257+
* Handle the `'dblclick'` event for the widget. Currently a no-op.
241258
*/
242259
private _evtDblClick(event: MouseEvent): void {
243260
// Do nothing if it's not a left mouse press.
@@ -301,7 +318,7 @@ export class DashboardWidget extends Widget {
301318
}
302319

303320
/**
304-
* Handle `mousemove` event of widget
321+
* Handle `mousemove` events for the widget.
305322
*/
306323
private _evtMouseMove(event: MouseEvent): void {
307324
switch (this._mouseMode) {
@@ -316,6 +333,9 @@ export class DashboardWidget extends Widget {
316333
}
317334
}
318335

336+
/**
337+
* Handle `mousemove` events when the widget mouseMode is `drag`.
338+
*/
319339
private _dragMouseMove(event: MouseEvent): void {
320340
const data = this._clickData;
321341
const { clientX, clientY } = event;
@@ -328,6 +348,9 @@ export class DashboardWidget extends Widget {
328348
}
329349
}
330350

351+
/**
352+
* Handle `mousemove` events when the widget mouseMode is `resize`.
353+
*/
331354
private _resizeMouseMove(event: MouseEvent): void {
332355
const { pressX, pressY, pressWidth, pressHeight } = this._clickData;
333356

@@ -358,6 +381,12 @@ export class DashboardWidget extends Widget {
358381
this.node.style.height = `${element.clientHeight + 2}px`;
359382
}
360383

384+
/**
385+
* Determines whether the widget contains the point (left, top).
386+
*
387+
* ### Notes
388+
* Both `left` and `top` are relative to the dashboard.
389+
*/
361390
containsPoint(left: number, top: number): boolean {
362391
const pos = {
363392
left,
@@ -369,6 +398,13 @@ export class DashboardWidget extends Widget {
369398
return overlap.type !== 'none';
370399
}
371400

401+
/**
402+
* Determines whether the widget overlaps an area.
403+
*
404+
* @param _pos - the position and size of the test area.
405+
*
406+
* @returns - an object containing the type of overlap and this widget.
407+
*/
372408
overlaps(_pos: Widgetstore.WidgetPosition): DashboardWidget.Overlap {
373409
const { left, top, width, height } = _pos;
374410
const pos = this.pos;
@@ -430,6 +466,9 @@ export class DashboardWidget extends Widget {
430466
});
431467
}
432468

469+
/**
470+
* Handle `mouseUp` events for the widget.
471+
*/
433472
private _evtMouseUp(event: MouseEvent): void {
434473
event.stopPropagation();
435474
event.preventDefault();
@@ -449,6 +488,10 @@ export class DashboardWidget extends Widget {
449488

450489
/**
451490
* The widget's position on its dashboard.
491+
*
492+
* ### Notes
493+
* When setting the widget pos, fields that you don't want to modify
494+
* can be set as `undefined`.
452495
*/
453496
get pos(): WidgetPosition {
454497
return {
@@ -565,13 +608,19 @@ export class DashboardWidget extends Widget {
565608
return this._ready;
566609
}
567610

611+
/**
612+
* Whether the widget can be moved during a resize.
613+
*/
568614
get locked(): boolean {
569615
return this._locked;
570616
}
571617
set locked(newState: boolean) {
572618
this._locked = newState;
573619
}
574620

621+
/**
622+
* The content of the widget.
623+
*/
575624
get content(): Widget {
576625
return this._content;
577626
}
@@ -641,17 +690,29 @@ export namespace DashboardWidget {
641690
fit?: boolean;
642691
}
643692

693+
/**
694+
* A type for desccribing the direction of an overlap.
695+
*/
644696
export type Direction = 'left' | 'right' | 'up' | 'down' | 'none';
645697

698+
/**
699+
* A type for describing an overlap between two widgets.
700+
*/
646701
export type Overlap = {
647702
widget: DashboardWidget;
648703
type: Direction;
649704
};
650705

706+
/**
707+
* Create a unique widget id.
708+
*/
651709
export function createDashboardWidgetId(): string {
652710
return `DashboardWidget-${UUID.uuid4()}`;
653711
}
654712

713+
/**
714+
* Create a resizer element for a dashboard widget.
715+
*/
655716
export function createResizer(): HTMLElement {
656717
const resizer = document.createElement('div');
657718
resizer.classList.add('pr-Resizer');
@@ -665,6 +726,18 @@ export namespace DashboardWidget {
665726
return resizer;
666727
}
667728

729+
/**
730+
* Create a dashboard widget based on a WidgetInfo object.
731+
*
732+
* @param options - the options used to create the widget.
733+
*
734+
* @param notebookTracker - a notebook tracker used to locate a
735+
* notebook/cell for the widget given a notebook/cell id.
736+
*
737+
* @param fit - whether to fit the new widget to its content.
738+
*
739+
* @returns - a new dashboard widget.
740+
*/
668741
export function createWidget(
669742
options: Widgetstore.WidgetInfo,
670743
notebookTracker: INotebookTracker,
@@ -701,6 +774,10 @@ export namespace DashboardWidget {
701774
return widget;
702775
}
703776

777+
/**
778+
* A type to describe the different kinds of mouseMoves that can occur
779+
* on a widget.
780+
*/
704781
export type MouseMode = 'drag' | 'resize' | 'none';
705782

706783
/**
@@ -740,8 +817,11 @@ namespace Private {
740817
* mouse is moved beyond a certain distance (DRAG_THRESHOLD).
741818
*
742819
* @param prevX - X Coordinate of the mouse pointer during the mousedown event
820+
*
743821
* @param prevY - Y Coordinate of the mouse pointer during the mousedown event
822+
*
744823
* @param nextX - Current X Coordinate of the mouse pointer
824+
*
745825
* @param nextY - Current Y Coordinate of the mouse pointer
746826
*/
747827
export function shouldStartDrag(

src/widgetstore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Cell } from '@jupyterlab/cells';
1010

1111
import { getNotebookById, getCellById } from './utils';
1212

13-
import { IDashboardChange, DashboardLayout } from './custom_layout';
13+
import { IDashboardChange, DashboardLayout } from './layout';
1414

1515
import { Dashboard } from './dashboard';
1616

0 commit comments

Comments
 (0)