1
- import { DataGrid } from 'tde-datagrid' ;
1
+ import { DataGrid , SelectionModel } from 'tde-datagrid' ;
2
2
import { LabIcon , addIcon } from '@jupyterlab/ui-components' ;
3
- import { EditorModel } from './newmodel ' ;
3
+ import { EditorModel } from './model ' ;
4
4
5
5
export class PaintedGrid extends DataGrid {
6
6
constructor ( options : PaintedGrid . IOptions ) {
@@ -45,6 +45,30 @@ export class PaintedGrid extends DataGrid {
45
45
return this . defaultSizes . columnWidth ;
46
46
}
47
47
48
+ /**
49
+ * Selects cells using the selection model
50
+ * @param row The row being selected
51
+ * @param column The column being selected
52
+ */
53
+ selectCells ( selection : SelectionModel . Selection ) : void {
54
+ // Bail if no selection
55
+ if ( ! selection ) {
56
+ return ;
57
+ }
58
+
59
+ const { r1, r2, c1, c2 } = selection ;
60
+ const select : SelectionModel . SelectArgs = {
61
+ r1,
62
+ r2,
63
+ c1,
64
+ c2,
65
+ cursorRow : r1 ,
66
+ cursorColumn : c1 ,
67
+ clear : 'all'
68
+ } ;
69
+ this . selectionModel . select ( select ) ;
70
+ }
71
+
48
72
/**
49
73
* @override paints on the ghost row and column as well after painting the other regions.
50
74
* Paint the grid content for the given dirty rect.
@@ -86,13 +110,17 @@ export class PaintedGrid extends DataGrid {
86
110
// Draw the icons.
87
111
const model = this . dataModel as EditorModel ;
88
112
if ( model && model . isDataFormatted ) {
89
- this . _drawIcons ( rx , ry , rw , rh ) ;
113
+ this . _paintDatatypeIcons ( rx , ry , rw , rh ) ;
90
114
this . drawCornerHeaderRegion ( 0 , 0 , this . headerWidth , this . headerHeight ) ;
91
115
}
92
116
}
93
117
94
118
/**
95
119
* Draw the ghost row.
120
+ * @param rx
121
+ * @param ry
122
+ * @param rw
123
+ * @param rh
96
124
*/
97
125
private _drawGhostRow ( rx : number , ry : number , rw : number , rh : number ) : void {
98
126
// Get the visible content dimensions.
@@ -136,6 +164,10 @@ export class PaintedGrid extends DataGrid {
136
164
137
165
/**
138
166
* Draw the ghost column.
167
+ * @param rx
168
+ * @param ry
169
+ * @param rw
170
+ * @param rh
139
171
*/
140
172
private _drawGhostColumn (
141
173
rx : number ,
@@ -182,6 +214,13 @@ export class PaintedGrid extends DataGrid {
182
214
this . canvasGC . fillRect ( x1 , y1 , x2 - x1 + 1 , y2 - y1 + 1 ) ;
183
215
}
184
216
217
+ /**
218
+ * Draw the ghost row header
219
+ * @param rx
220
+ * @param ry
221
+ * @param rw
222
+ * @param rh
223
+ */
185
224
private _drawGhostRowHeader (
186
225
rx : number ,
187
226
ry : number ,
@@ -226,9 +265,16 @@ export class PaintedGrid extends DataGrid {
226
265
this . canvasGC . fillStyle = this . _extraStyle . ghostRowColor ;
227
266
this . canvasGC . fillRect ( x1 , y1 , x2 - x1 + 1 , y2 - y1 + 1 ) ;
228
267
229
- this . _drawGhostRowIcon ( ) ;
268
+ this . _paintGhostRowIcon ( ) ;
230
269
}
231
270
271
+ /**
272
+ * Draw the ghost column header
273
+ * @param rx
274
+ * @param ry
275
+ * @param rw
276
+ * @param rh
277
+ */
232
278
private _drawGhostColumnHeader (
233
279
rx : number ,
234
280
ry : number ,
@@ -272,10 +318,13 @@ export class PaintedGrid extends DataGrid {
272
318
// Fill the region with the specified color.
273
319
this . canvasGC . fillStyle = this . _extraStyle . ghostColumnColor ;
274
320
this . canvasGC . fillRect ( x1 , y1 , x2 - x1 + 1 , y2 - y1 + 1 ) ;
275
- this . _drawColumnIcon ( ) ;
321
+ this . _paintGhostColumnIcon ( ) ;
276
322
}
277
323
278
- private _drawGhostRowIcon ( ) : void {
324
+ /**
325
+ * Paints the ghost row icon
326
+ */
327
+ private _paintGhostRowIcon ( ) : void {
279
328
// Get the dimensions for the cell.
280
329
const cellH = this . defaultSizes . rowHeight ;
281
330
@@ -286,41 +335,20 @@ export class PaintedGrid extends DataGrid {
286
335
if ( ! iconArgs ) {
287
336
return ;
288
337
}
289
- // Get the current transform state.
290
- const transform = this . canvasGC . getTransform ( ) ;
291
338
292
339
// Unpack the icon arguments.
293
340
const { icon, color, size, top, left } = iconArgs ;
294
341
295
- // Parse the icon path from the icon string.
296
- const { defaultSize, path } = Private . parseSVG ( icon . svgstr ) ;
297
-
298
- // Create a path 2d object from the path string.
299
- const canvasPath = new Path2D ( path ) ;
300
-
301
- // Solve for the scaling factor using the provided width or the default.
302
- const scale = size / defaultSize ;
303
-
304
- // Orient the canvas to the desired origin for the icon.
305
- this . canvasGC . translate (
306
- left ,
307
- this . headerHeight + this . bodyHeight - cellH + top - this . scrollY
308
- ) ;
342
+ // Calculate the y position for the icon
343
+ const y = this . headerHeight + this . bodyHeight - cellH + top - this . scrollY ;
309
344
310
- // Scale the canvas.
311
- this . canvasGC . scale ( scale , scale ) ;
312
-
313
- // Set the canvas fill style.
314
- this . canvasGC . fillStyle = color ;
315
-
316
- // Draw the icon.
317
- this . canvasGC . fill ( canvasPath , 'nonzero' ) ;
318
-
319
- // Reset the canvas to it's default position.
320
- this . canvasGC . setTransform ( transform ) ;
345
+ this . _drawIcon ( left , y , size , color , icon . svgstr ) ;
321
346
}
322
347
323
- private _drawColumnIcon ( ) : void {
348
+ /**
349
+ * Paints the ghost column icon
350
+ */
351
+ private _paintGhostColumnIcon ( ) : void {
324
352
// Get the dimensions for the cell.
325
353
const cellW = this . defaultSizes . columnWidth ;
326
354
@@ -332,38 +360,13 @@ export class PaintedGrid extends DataGrid {
332
360
return ;
333
361
}
334
362
335
- // Get the current transform state.
336
- const transform = this . canvasGC . getTransform ( ) ;
337
-
338
363
// Unpack the icon arguments.
339
364
const { icon, color, size, left, top } = iconArgs ;
340
365
341
- // Parse the icon path from the icon string.
342
- const { defaultSize , path } = Private . parseSVG ( icon . svgstr ) ;
366
+ // Calculate x position for the icon
367
+ const x = this . headerWidth + this . bodyWidth - cellW + left - this . scrollX ;
343
368
344
- // Create a path 2d object from the path string.
345
- const canvasPath = new Path2D ( path ) ;
346
-
347
- // Solve for the scaling factor using the provided width or the default.
348
- const scale = size / defaultSize ;
349
-
350
- // Orient to the desired origin for the icon.
351
- this . canvasGC . translate (
352
- this . headerWidth + this . bodyWidth - cellW + left - this . scrollX ,
353
- top
354
- ) ;
355
-
356
- // Scale the canvas.
357
- this . canvasGC . scale ( scale , scale ) ;
358
-
359
- // Set the canvas fill style.
360
- this . canvasGC . fillStyle = color ;
361
-
362
- // Draw the icon.
363
- this . canvasGC . fill ( canvasPath , 'nonzero' ) ;
364
-
365
- // Reset the transform to the initial state
366
- this . canvasGC . setTransform ( transform ) ;
369
+ this . _drawIcon ( x , top , size , color , icon . svgstr ) ;
367
370
}
368
371
369
372
private _drawOverCorner (
@@ -412,7 +415,19 @@ export class PaintedGrid extends DataGrid {
412
415
this . canvasGC . fillRect ( x1 , y1 , x2 - x1 + 1 , y2 - y1 + 1 ) ;
413
416
}
414
417
415
- private _drawIcons ( rx : number , ry : number , rw : number , rh : number ) : void {
418
+ /**
419
+ * Paints the datatype icons (string, number, boolean, date)
420
+ * @param rx
421
+ * @param ry
422
+ * @param rw
423
+ * @param rh
424
+ */
425
+ private _paintDatatypeIcons (
426
+ rx : number ,
427
+ ry : number ,
428
+ rw : number ,
429
+ rh : number
430
+ ) : void {
416
431
// Get the visible content dimensions.
417
432
const contentW = this . bodyWidth - this . scrollX ;
418
433
const contentH = this . headerHeight ;
@@ -548,36 +563,54 @@ export class PaintedGrid extends DataGrid {
548
563
// Unpack the icon arguments.
549
564
const { icon, color, size, left, top } = iconArgs ;
550
565
551
- // Parse the icon path from the icon string.
552
- const { defaultSize, path } = Private . parseSVG ( icon . svgstr ) ;
566
+ this . _drawIcon ( x + left , y + top , size , color , icon . svgstr ) ;
567
+
568
+ // Increment the running X coordinate.
569
+ x += columnSize ;
570
+ }
571
+ }
553
572
554
- // Create a path 2d object from the path string.
555
- const canvasPath = new Path2D ( path ) ;
573
+ /**
574
+ * Utilizes the canvas GC to draw the icon in the correct position with the correct styles
575
+ * @param x The horizontal position of the icon
576
+ * @param y The vertical position of the icon
577
+ * @param size The original size of the icon
578
+ * @param color The fill color for the icon
579
+ * @param svgstr A string containing the raw contents of the svg file
580
+ */
581
+ private _drawIcon (
582
+ x : number ,
583
+ y : number ,
584
+ size : number ,
585
+ color : string ,
586
+ svgstr : string
587
+ ) : void {
588
+ // Parse the icon path from the icon string.
589
+ const { defaultSize, path } = Private . parseSVG ( svgstr ) ;
556
590
557
- // Get the default position of the canvas drawer .
558
- const transform = this . canvasGC . getTransform ( ) ;
591
+ // Solve for the scaling factor using the provided width or the default .
592
+ const scale = size / defaultSize ;
559
593
560
- // Orient to the desired origin for the icon .
561
- this . canvasGC . translate ( x + left , y + top ) ;
594
+ // Create a path 2d object from the path string .
595
+ const canvasPath = new Path2D ( path ) ;
562
596
563
- // Solve for the scaling factor using the provided width or the default .
564
- const scale = size / defaultSize ;
597
+ // Get the current transform state .
598
+ const transform = this . canvasGC . getTransform ( ) ;
565
599
566
- // Scale the canvas .
567
- this . canvasGC . scale ( scale , scale ) ;
600
+ // Orient to the desired origin for the icon .
601
+ this . canvasGC . translate ( x , y ) ;
568
602
569
- // Set the canvas fill style .
570
- this . canvasGC . fillStyle = color ;
603
+ // Scale the canvas.
604
+ this . canvasGC . scale ( scale , scale ) ;
571
605
572
- // Draw the icon .
573
- this . canvasGC . fill ( canvasPath , 'nonzero' ) ;
606
+ // Set the canvas fill style .
607
+ this . canvasGC . fillStyle = color ;
574
608
575
- // Reset the transform to the initial state
576
- this . canvasGC . setTransform ( transform ) ;
609
+ // Draw the icon.
610
+ this . canvasGC . fill ( canvasPath , 'nonzero' ) ;
577
611
578
- // Increment the running X coordinate.
579
- x += columnSize ;
580
- }
612
+ // Reset the transform to the initial state
613
+ this . canvasGC . setTransform ( transform ) ;
581
614
}
582
615
583
616
private _extraStyle : PaintedGrid . ExtraStyle ;
0 commit comments