-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add graph visualization for selected numbers #2884
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
base: alpha
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,84 @@ | ||||||||||||||||||||||||||||||
import React from 'react'; | ||||||||||||||||||||||||||||||
import Chart from 'components/Chart/Chart.react'; | ||||||||||||||||||||||||||||||
import { ChartColorSchemes } from 'lib/Constants'; | ||||||||||||||||||||||||||||||
import styles from './GraphPanel.scss'; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
function parseDate(val) { | ||||||||||||||||||||||||||||||
if (!val) { | ||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
if (val instanceof Date) { | ||||||||||||||||||||||||||||||
return val.getTime(); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
if (typeof val === 'string') { | ||||||||||||||||||||||||||||||
const d = new Date(val); | ||||||||||||||||||||||||||||||
return isNaN(d) ? null : d.getTime(); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
if (val.iso) { | ||||||||||||||||||||||||||||||
const d = new Date(val.iso); | ||||||||||||||||||||||||||||||
return isNaN(d) ? null : d.getTime(); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
export default function GraphPanel({ selectedCells, order, data, columns, width }) { | ||||||||||||||||||||||||||||||
if (!selectedCells || selectedCells.rowStart < 0) { | ||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
const { rowStart, rowEnd, colStart, colEnd } = selectedCells; | ||||||||||||||||||||||||||||||
const columnNames = order.slice(colStart, colEnd + 1).map(o => o.name); | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add bounds checking for array slicing. The code slices the Add bounds checking: + if (colStart < 0 || colEnd >= order.length) {
+ return <div className={styles.empty}>Invalid column selection.</div>;
+ }
const columnNames = order.slice(colStart, colEnd + 1).map(o => o.name); 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||
const columnTypes = columnNames.map(name => columns[name]?.type); | ||||||||||||||||||||||||||||||
const timeSeries = | ||||||||||||||||||||||||||||||
columnTypes.length > 1 && | ||||||||||||||||||||||||||||||
columnTypes[0] === 'Date' && | ||||||||||||||||||||||||||||||
columnTypes.slice(1).every(t => t === 'Number'); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const chartData = {}; | ||||||||||||||||||||||||||||||
if (timeSeries) { | ||||||||||||||||||||||||||||||
for (let j = 1; j < columnNames.length; j++) { | ||||||||||||||||||||||||||||||
chartData[columnNames[j]] = { color: ChartColorSchemes[j - 1], points: [] }; | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify ChartColorSchemes array has sufficient colors. The code uses Also applies to: 57-57 🏁 Script executed: #!/bin/bash
# Search for ChartColorSchemes definition to verify available colors
ast-grep --pattern 'ChartColorSchemes = $_' Length of output: 45 🏁 Script executed: #!/bin/bash
# Locate all references and the definition of ChartColorSchemes
rg -n "ChartColorSchemes" Length of output: 2197 🏁 Script executed: #!/bin/bash
# Display the contents of ChartColorSchemes in lib/Constants.js
sed -n '1,100p' src/lib/Constants.js | sed -n '22,50p' Length of output: 515 🏁 Script executed: #!/bin/bash
# Show context around ChartColorSchemes usage in GraphPanel.js
sed -n '1,200p' src/components/GraphPanel/GraphPanel.js Length of output: 2548 Ensure ChartColorSchemes won’t be indexed out-of-bounds ChartColorSchemes currently has 12 entries, but GraphPanel can request more if the user selects >12 series. To prevent undefined colors (or runtime errors), clamp or wrap your index and/or provide a fallback: • File: src/components/GraphPanel/GraphPanel.js
– Line 57:
Alternatively, check 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
for (let i = rowStart; i <= rowEnd; i++) { | ||||||||||||||||||||||||||||||
const row = data[i]; | ||||||||||||||||||||||||||||||
if (!row) continue; | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix linting issues: Add braces after if conditions. The static analysis tool correctly identifies missing braces after if conditions, which violates the project's style guide. Apply this diff to fix the linting issues: - if (!row) continue;
+ if (!row) {
+ continue;
+ }
const ts = parseDate(row.attributes[columnNames[0]]);
- if (ts === null) continue;
+ if (ts === null) {
+ continue;
+ }
for (let j = 1; j < columnNames.length; j++) {
const val = row.attributes[columnNames[j]];
if (typeof val === 'number' && !isNaN(val)) {
chartData[columnNames[j]].points.push([ts, val]);
}
}
}
} else {
let seriesIndex = 0;
columnNames.forEach((col, idx) => {
if (columnTypes[idx] === 'Number') {
chartData[col] = { color: ChartColorSchemes[seriesIndex], points: [] };
seriesIndex++;
}
});
let x = 0;
for (let i = rowStart; i <= rowEnd; i++, x++) {
const row = data[i];
- if (!row) continue;
+ if (!row) {
+ continue;
+ } Also applies to: 45-45, 64-64 🧰 Tools🪛 GitHub Check: Lint[failure] 43-43: 🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||
const ts = parseDate(row.attributes[columnNames[0]]); | ||||||||||||||||||||||||||||||
if (ts === null) continue; | ||||||||||||||||||||||||||||||
for (let j = 1; j < columnNames.length; j++) { | ||||||||||||||||||||||||||||||
const val = row.attributes[columnNames[j]]; | ||||||||||||||||||||||||||||||
if (typeof val === 'number' && !isNaN(val)) { | ||||||||||||||||||||||||||||||
chartData[columnNames[j]].points.push([ts, val]); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||
let seriesIndex = 0; | ||||||||||||||||||||||||||||||
columnNames.forEach((col, idx) => { | ||||||||||||||||||||||||||||||
if (columnTypes[idx] === 'Number') { | ||||||||||||||||||||||||||||||
chartData[col] = { color: ChartColorSchemes[seriesIndex], points: [] }; | ||||||||||||||||||||||||||||||
seriesIndex++; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||
let x = 0; | ||||||||||||||||||||||||||||||
for (let i = rowStart; i <= rowEnd; i++, x++) { | ||||||||||||||||||||||||||||||
const row = data[i]; | ||||||||||||||||||||||||||||||
if (!row) continue; | ||||||||||||||||||||||||||||||
columnNames.forEach(col => { | ||||||||||||||||||||||||||||||
const val = row.attributes[col]; | ||||||||||||||||||||||||||||||
if (typeof val === 'number' && !isNaN(val)) { | ||||||||||||||||||||||||||||||
chartData[col].points.push([x, val]); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if (Object.keys(chartData).length === 0) { | ||||||||||||||||||||||||||||||
return <div className={styles.empty}>No numeric data selected.</div>; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const chartWidth = width - 20; | ||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||
<div className={styles.graphPanel}> | ||||||||||||||||||||||||||||||
<Chart width={chartWidth} height={400} data={chartData} /> | ||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.graphPanel { | ||
height: 100%; | ||
overflow: auto; | ||
background-color: #fefafb; | ||
padding: 10px; | ||
} | ||
|
||
.empty { | ||
padding: 10px; | ||
color: #555; | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,6 +17,7 @@ | |||||
import styles from './Databrowser.scss'; | ||||||
|
||||||
import AggregationPanel from '../../../components/AggregationPanel/AggregationPanel'; | ||||||
import GraphPanel from 'components/GraphPanel/GraphPanel'; | ||||||
|
||||||
const BROWSER_SHOW_ROW_NUMBER = 'browserShowRowNumber'; | ||||||
|
||||||
|
@@ -80,7 +81,7 @@ | |||||
const storedRowNumber = | ||||||
window.localStorage?.getItem(BROWSER_SHOW_ROW_NUMBER) === 'true'; | ||||||
|
||||||
this.state = { | ||||||
this.state = { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix indentation to match coding standards. The static analysis tool correctly identifies an indentation issue. The line should use 4 spaces instead of 6. - this.state = {
+ this.state = { 📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Check: Lint[failure] 84-84: 🤖 Prompt for AI Agents
|
||||||
order: order, | ||||||
current: null, | ||||||
editing: false, | ||||||
|
@@ -99,6 +100,8 @@ | |||||
showAggregatedData: true, | ||||||
frozenColumnIndex: -1, | ||||||
showRowNumber: storedRowNumber, | ||||||
graphVisible: false, | ||||||
graphWidth: 300, | ||||||
}; | ||||||
|
||||||
this.handleResizeDiv = this.handleResizeDiv.bind(this); | ||||||
|
@@ -109,6 +112,9 @@ | |||||
this.handleHeaderDragDrop = this.handleHeaderDragDrop.bind(this); | ||||||
this.handleResize = this.handleResize.bind(this); | ||||||
this.togglePanelVisibility = this.togglePanelVisibility.bind(this); | ||||||
this.handleGraphResizeStart = this.handleGraphResizeStart.bind(this); | ||||||
this.handleGraphResizeStop = this.handleGraphResizeStop.bind(this); | ||||||
this.handleGraphResizeDiv = this.handleGraphResizeDiv.bind(this); | ||||||
this.setCurrent = this.setCurrent.bind(this); | ||||||
this.setEditing = this.setEditing.bind(this); | ||||||
this.handleColumnsOrder = this.handleColumnsOrder.bind(this); | ||||||
|
@@ -120,6 +126,7 @@ | |||||
this.unfreezeColumns = this.unfreezeColumns.bind(this); | ||||||
this.setShowRowNumber = this.setShowRowNumber.bind(this); | ||||||
this.handleCellClick = this.handleCellClick.bind(this); | ||||||
this.toggleGraphVisibility = this.toggleGraphVisibility.bind(this); | ||||||
this.saveOrderTimeout = null; | ||||||
} | ||||||
|
||||||
|
@@ -215,6 +222,21 @@ | |||||
this.setState({ panelWidth: size.width }); | ||||||
} | ||||||
|
||||||
handleGraphResizeStart() { | ||||||
this.setState({ isResizing: true }); | ||||||
} | ||||||
|
||||||
handleGraphResizeStop(event, { size }) { | ||||||
this.setState({ | ||||||
isResizing: false, | ||||||
graphWidth: size.width, | ||||||
}); | ||||||
} | ||||||
|
||||||
handleGraphResizeDiv(event, { size }) { | ||||||
this.setState({ graphWidth: size.width }); | ||||||
} | ||||||
|
||||||
setShowAggregatedData(bool) { | ||||||
this.setState({ | ||||||
showAggregatedData: bool, | ||||||
|
@@ -264,6 +286,10 @@ | |||||
} | ||||||
} | ||||||
|
||||||
toggleGraphVisibility() { | ||||||
this.setState(prevState => ({ graphVisible: !prevState.graphVisible })); | ||||||
} | ||||||
|
||||||
getAllClassesSchema(schema) { | ||||||
const allClasses = Object.keys(schema.data.get('classes').toObject()); | ||||||
const schemaSimplifiedData = {}; | ||||||
|
@@ -667,6 +693,7 @@ | |||||
}, | ||||||
selectedObjectId: undefined, | ||||||
selectedData, | ||||||
graphVisible: true, | ||||||
}); | ||||||
} else { | ||||||
this.setCurrent({ row, col }); | ||||||
|
@@ -677,6 +704,7 @@ | |||||
selectedData: [], | ||||||
current: { row, col }, | ||||||
firstSelectedCell: clickedCellKey, | ||||||
graphVisible: false, | ||||||
}); | ||||||
} | ||||||
} | ||||||
|
@@ -758,6 +786,29 @@ | |||||
</div> | ||||||
</ResizableBox> | ||||||
)} | ||||||
{this.state.graphVisible && ( | ||||||
<ResizableBox | ||||||
width={this.state.graphWidth} | ||||||
height={Infinity} | ||||||
minConstraints={[100, Infinity]} | ||||||
maxConstraints={[this.state.maxWidth, Infinity]} | ||||||
onResizeStart={this.handleGraphResizeStart} | ||||||
onResizeStop={this.handleGraphResizeStop} | ||||||
onResize={this.handleGraphResizeDiv} | ||||||
resizeHandles={['w']} | ||||||
className={styles.resizablePanel} | ||||||
> | ||||||
<div className={styles.aggregationPanelContainer}> | ||||||
<GraphPanel | ||||||
selectedCells={this.state.selectedCells} | ||||||
order={this.state.order} | ||||||
data={this.props.data} | ||||||
columns={this.props.columns} | ||||||
width={this.state.graphWidth} | ||||||
/> | ||||||
</div> | ||||||
</ResizableBox> | ||||||
)} | ||||||
</div> | ||||||
|
||||||
<BrowserToolbar | ||||||
|
@@ -787,6 +838,8 @@ | |||||
allClassesSchema={this.state.allClassesSchema} | ||||||
togglePanel={this.togglePanelVisibility} | ||||||
isPanelVisible={this.state.isPanelVisible} | ||||||
toggleGraph={this.toggleGraphVisibility} | ||||||
isGraphVisible={this.state.graphVisible} | ||||||
appId={this.props.app.applicationId} | ||||||
appName={this.props.appName} | ||||||
{...other} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add PropTypes validation.
The component is missing PropTypes validation, which would help catch type-related issues during development.
Add PropTypes validation:
📝 Committable suggestion
🤖 Prompt for AI Agents