-
Notifications
You must be signed in to change notification settings - Fork 33
feat: Table rendering support for databars #1212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mofojed
merged 18 commits into
deephaven:main
from
emilyhuxng:feature-1151-table-rendering-support-for-databars
May 4, 2023
Merged
Changes from 7 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c467052
Fix imports
emilyhuxng 4d85164
Address requested changes
emilyhuxng 4c3a2e3
Fix error
emilyhuxng 589ce79
Merge branch 'main' into feature-1151-table-rendering-support-for-dat…
emilyhuxng ba02a7f
Fix gradients to accept array
emilyhuxng 8400e8e
Fix unit test
emilyhuxng 80d8e43
Remove textOverride
emilyhuxng 9277d26
Merge branch 'main' into feature-1151-table-rendering-support-for-dat…
emilyhuxng 7c203c0
Fix imports
emilyhuxng a90494b
Rename types and methods
emilyhuxng 4edcb22
Check for null or empty only if the column is text
emilyhuxng 0bf9426
Refactor renderer code
emilyhuxng 6904d92
Fix text vertical alignment
emilyhuxng 33f6f59
Refactor icon code
emilyhuxng f822828
Fix truncated string
emilyhuxng c5ab1ba
Merge branch 'main' into feature-1151-table-rendering-support-for-dat…
emilyhuxng 669384b
Refactor duplicate code
emilyhuxng f482077
Merge remote-tracking branch 'origin/main' into feature-1151-table-re…
mofojed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
packages/code-studio/src/styleguide/grid-examples/DataBarExample.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import React, { useState } from 'react'; | ||
| import { Grid, MockDataBarGridModel } from '@deephaven/grid'; | ||
| import { ColorMap } from 'packages/grid/src/DataBarGridModel'; | ||
|
|
||
| function DataBarExample() { | ||
| const columnData = [100, 50, 20, 10, -10, -20, -50, -30, 100, 0, 1]; | ||
| const data: number[][] = []; | ||
| const columnAxes = new Map([ | ||
| [0, 'proportional'], | ||
| [1, 'middle'], | ||
| [2, 'directional'], | ||
| [6, 'directional'], | ||
| [7, 'directional'], | ||
| [8, 'directional'], | ||
| [9, 'directional'], | ||
| [10, 'directional'], | ||
| ]); | ||
| const positiveColors: ColorMap = new Map([ | ||
| [3, '#72d7df'], | ||
| [4, '#ac9cf4'], | ||
| ]); | ||
| positiveColors.set(5, ['#f3cd5b', '#9edc6f']); | ||
| positiveColors.set(19, ['#42f54b', '#42b9f5', '#352aa8']); | ||
|
|
||
| const negativeColors: ColorMap = new Map([ | ||
| [3, '#f3cd5b'], | ||
| [4, '#ac9cf4'], | ||
| ]); | ||
| negativeColors.set(5, ['#f95d84', '#f3cd5b']); | ||
| negativeColors.set(19, ['#e05536', '#e607de', '#e6e207']); | ||
|
|
||
| const valuePlacements = new Map([ | ||
| [6, 'hide'], | ||
| [7, 'overlap'], | ||
| [8, 'overlap'], | ||
| [9, 'overlap'], | ||
| ]); | ||
| const opacities = new Map([ | ||
| [7, 0.5], | ||
| [8, 0.5], | ||
| [9, 0.5], | ||
| ]); | ||
| const directions = new Map([ | ||
| [8, 'RTL'], | ||
| [10, 'RTL'], | ||
| [16, 'RTL'], | ||
| [19, 'RTL'], | ||
| ]); | ||
| const textAlignments = new Map([ | ||
| [9, 'left'], | ||
| [11, 'left'], | ||
| ]); | ||
| const markers = new Map([ | ||
| [ | ||
| 12, | ||
| [ | ||
| { column: 13, color: 'white' }, | ||
| { column: 14, color: 'gray' }, | ||
| ], | ||
| ], | ||
| ]); | ||
| for (let i = 0; i < 13; i += 1) { | ||
| data.push(columnData.slice()); | ||
| } | ||
| data.push([70, 60, 30, 20, -10, -30, -20, -50, 80, 50, 10]); | ||
| data.push([50, 20, 10, 0, 0, -10, -30, 10, 90, 20, 40]); | ||
| data.push([-100, -90, -80, -70, -60, -50, -40, -30, -20, -10, 0]); | ||
| data.push(columnData.slice()); | ||
| // Decimals | ||
| data.push([ | ||
| 100, | ||
| 10.5, | ||
| 11.234, | ||
| -20.5, | ||
| -50, | ||
| -2.5, | ||
| -15.1234, | ||
| 94.254, | ||
| 25, | ||
| 44.4444, | ||
| -50.5, | ||
| ]); | ||
|
|
||
| // Big values | ||
| data.push([ | ||
| 1000000, | ||
| 10, | ||
| 200, | ||
| -20000, | ||
| -2000000, | ||
| -25, | ||
| -900000, | ||
| 800000, | ||
| 100000, | ||
| 450000, | ||
| 1, | ||
| ]); | ||
|
|
||
| // RTL gradient with multiple colors | ||
| data.push(columnData.slice()); | ||
| const [model] = useState( | ||
| () => | ||
| new MockDataBarGridModel( | ||
| data, | ||
| columnAxes, | ||
| positiveColors, | ||
| negativeColors, | ||
| valuePlacements, | ||
| opacities, | ||
| directions, | ||
| textAlignments, | ||
| markers | ||
| ) | ||
| ); | ||
|
|
||
| return <Grid model={model} />; | ||
| } | ||
|
|
||
| export default DataBarExample; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* eslint-disable class-methods-use-this */ | ||
| import { getOrThrow } from '@deephaven/utils'; | ||
| import { isExpandableGridModel } from './ExpandableGridModel'; | ||
| import { VisibleIndex, Coordinate, BoxCoordinates } from './GridMetrics'; | ||
| import { GridRenderState } from './GridRenderer'; | ||
|
emilyhuxng marked this conversation as resolved.
Outdated
|
||
| import { GridColor } from './GridTheme'; | ||
|
|
||
| export type CellRendererType = 'text' | 'databar'; | ||
|
emilyhuxng marked this conversation as resolved.
Outdated
|
||
|
|
||
| abstract class CellRenderer { | ||
| abstract drawCellContent( | ||
| context: CanvasRenderingContext2D, | ||
| state: GridRenderState, | ||
| column: VisibleIndex, | ||
| row: VisibleIndex | ||
| ): void; | ||
|
|
||
| drawCellRowTreeMarker( | ||
| context: CanvasRenderingContext2D, | ||
| state: GridRenderState, | ||
| row: VisibleIndex | ||
| ): void { | ||
| const { metrics, model, mouseX, mouseY, theme } = state; | ||
| const { | ||
| firstColumn, | ||
| gridX, | ||
| gridY, | ||
| allColumnXs, | ||
| allColumnWidths, | ||
| allRowYs, | ||
| allRowHeights, | ||
| visibleRowTreeBoxes, | ||
| } = metrics; | ||
| const { treeMarkerColor, treeMarkerHoverColor } = theme; | ||
| const columnX = getOrThrow(allColumnXs, firstColumn); | ||
| const columnWidth = getOrThrow(allColumnWidths, firstColumn); | ||
| const rowY = getOrThrow(allRowYs, row); | ||
| const rowHeight = getOrThrow(allRowHeights, row); | ||
| if (!isExpandableGridModel(model) || !model.isRowExpandable(row)) { | ||
| return; | ||
| } | ||
|
|
||
| const treeBox = getOrThrow(visibleRowTreeBoxes, row); | ||
| const color = | ||
| mouseX != null && | ||
| mouseY != null && | ||
| mouseX >= gridX + columnX && | ||
| mouseX <= gridX + columnX + columnWidth && | ||
| mouseY >= gridY + rowY && | ||
| mouseY <= gridY + rowY + rowHeight | ||
| ? treeMarkerHoverColor | ||
| : treeMarkerColor; | ||
|
|
||
| this.drawTreeMarker( | ||
| context, | ||
| state, | ||
| columnX, | ||
| rowY, | ||
| treeBox, | ||
| color, | ||
| model.isRowExpanded(row) | ||
| ); | ||
| } | ||
|
|
||
| drawTreeMarker( | ||
| context: CanvasRenderingContext2D, | ||
| state: GridRenderState, | ||
| columnX: Coordinate, | ||
| rowY: Coordinate, | ||
| treeBox: BoxCoordinates, | ||
| color: GridColor, | ||
| isExpanded: boolean | ||
| ): void { | ||
| const { x1, y1, x2, y2 } = treeBox; | ||
| const markerText = isExpanded ? '⊟' : '⊞'; | ||
| const textX = columnX + (x1 + x2) * 0.5 + 0.5; | ||
| const textY = rowY + (y1 + y2) * 0.5 + 0.5; | ||
| context.fillStyle = color; | ||
| context.textAlign = 'center'; | ||
| context.fillText(markerText, textX, textY); | ||
| } | ||
| } | ||
|
|
||
| export default CellRenderer; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.