Skip to content

Commit b07d5d2

Browse files
committed
Added docstrings to all classes/methods
1 parent 648791e commit b07d5d2

25 files changed

+264
-88
lines changed

src/card/NeoCard.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ import Card from "react-materialize/lib/Card";
33
import Icon from "react-materialize/lib/Icon";
44
import Textarea from "react-materialize/lib/Textarea";
55
import Button from "react-materialize/lib/Button";
6-
import NeoTable from "./report/NeoTableReport";
7-
import NeoPagination from "./footer/NeoTableFooter";
8-
import NeoGraphViz from "./report/NeoGraphVisReport";
6+
import NeoTableReport from "./report/NeoTableReport";
7+
import NeoTableFooter from "./footer/NeoTableFooter";
8+
import NeoGraphVisReport from "./report/NeoGraphVisReport";
99
import Col from "react-materialize/lib/Col";
1010
import NeoCardSettings from "./NeoCardSettings";
1111
import NeoJSONView from "./report/NeoJSONViewReport";
12-
import NeoGraphChips from "./footer/NeoGraphVisFooter";
13-
import NeoMarkdownView from "./report/NeoMarkdownReport";
14-
import NeoBarChart from "./report/NeoBarChartReport";
15-
import NeoBarPropertySelect from "./footer/NeoBarChartFooter";
16-
import NeoLineChart from "./report/NeoLineChartReport";
17-
import NeoLinePropertySelect from "./footer/NeoLineChartFooter";
12+
import NeoGraphVisFooter from "./footer/NeoGraphVisFooter";
13+
import NeoMarkdownReport from "./report/NeoMarkdownReport";
14+
import NeoBarChartReport from "./report/NeoBarChartReport";
15+
import NeoBarChartFooter from "./footer/NeoBarChartFooter";
16+
import NeoLineChartReport from "./report/NeoLineChartReport";
17+
import NeoLineChartFooter from "./footer/NeoLineChartFooter";
1818
import NeoPropertySelectReport from "./report/NeoPropertySelectReport";
1919

2020

@@ -284,24 +284,24 @@ export class NeoCard extends React.Component {
284284
*/
285285
setCardTypeToTableView() {
286286
this.state.content =
287-
<NeoTable connection={this.props.connection}
288-
rows={this.state.height == 4 ? NeoTable.normalRowCount : NeoTable.tallRowCount}
287+
<NeoTableReport connection={this.props.connection}
288+
rows={this.state.height == 4 ? NeoTableReport.normalRowCount : NeoTableReport.tallRowCount}
289289
page={this.state.page}
290290
query={this.state.query}
291291
stateChanged={this.stateChanged}
292292
params={this.state.parsedParameters}
293293
refresh={this.state.refresh}
294294
/>
295295
this.state.action =
296-
<NeoPagination page={this.state.page} key={0} data={this.state.data} onChange={this.stateChanged}/>
296+
<NeoTableFooter page={this.state.page} key={0} data={this.state.data} onChange={this.stateChanged}/>
297297
}
298298

299299
/**
300300
* Updates the card's report to a bar chart.
301301
*/
302302
setCardTypeToBarChart() {
303303
this.state.content =
304-
<NeoBarChart connection={this.props.connection}
304+
<NeoBarChartReport connection={this.props.connection}
305305
page={this.state.page}
306306
query={this.state.query}
307307
clientWidth={(this.cardRef.current) ? this.cardRef.current.clientWidth : 0}
@@ -321,7 +321,7 @@ export class NeoCard extends React.Component {
321321
*/
322322
setCardTypeToLineChart() {
323323
this.state.content =
324-
<NeoLineChart connection={this.props.connection}
324+
<NeoLineChartReport connection={this.props.connection}
325325
page={this.state.page}
326326
query={this.state.query}
327327
clientWidth={(this.cardRef.current) ? this.cardRef.current.clientWidth : 0}
@@ -342,7 +342,7 @@ export class NeoCard extends React.Component {
342342
setCardTypeToGraph() {
343343
this.state.page += 1;
344344
this.state.content =
345-
<NeoGraphViz
345+
<NeoGraphVisReport
346346
connection={this.props.connection}
347347
query={this.state.query}
348348
params={this.state.parsedParameters}
@@ -377,7 +377,7 @@ export class NeoCard extends React.Component {
377377
*/
378378
setCardTypeToMarkdown() {
379379
this.state.content =
380-
<NeoMarkdownView
380+
<NeoMarkdownReport
381381
connection={this.props.connection}
382382
query={'return true'}
383383
data={this.state.query}
@@ -478,7 +478,7 @@ export class NeoCard extends React.Component {
478478
updateBarPropertySelect(labels) {
479479
this.state.page += 1;
480480
this.state.action =
481-
<NeoBarPropertySelect propertiesSelected={this.state.propertiesSelected} page={this.state.page} key={0}
481+
<NeoBarChartFooter propertiesSelected={this.state.propertiesSelected} page={this.state.page} key={0}
482482
data={this.state.data}
483483
onChange={this.stateChanged}
484484
categories={labels} values={labels}
@@ -492,7 +492,7 @@ export class NeoCard extends React.Component {
492492
updateLinePropertySelect(labels) {
493493
this.state.page += 1;
494494
this.state.action =
495-
<NeoLinePropertySelect propertiesSelected={this.state.propertiesSelected} page={this.state.page} key={0}
495+
<NeoLineChartFooter propertiesSelected={this.state.propertiesSelected} page={this.state.page} key={0}
496496
data={this.state.data}
497497
onChange={this.stateChanged}
498498
categories={labels} values={labels}
@@ -522,7 +522,7 @@ export class NeoCard extends React.Component {
522522
}
523523

524524

525-
this.state.action = <NeoGraphChips key={0} nodeLabels={Object.keys(labels)}
525+
this.state.action = <NeoGraphVisFooter key={0} nodeLabels={Object.keys(labels)}
526526
width={this.props.width}
527527
params={this.state.parsedParameters}
528528
properties={Object.values(labels).map((labelChoices, index) => {

src/card/footer/NeoBarChartFooter.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ import NeoFooter from "./NeoFooter";
1010
* On selection of new fields, the report corresponding to the footer will be refreshed.
1111
*/
1212
class NeoBarChartFooter extends NeoFooter {
13+
/**
14+
* Initialize and set default state.
15+
*/
1316
constructor(props) {
1417
super(props);
1518
this.state = {}
1619
}
1720

21+
/**
22+
* Draw the two proprety selection boxes.
23+
*/
1824
render() {
1925
return (
2026
<div className="neo-property-select" style={{marginLeft: '20px', marginTop: "-8px"}}>

src/card/footer/NeoFooter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22

33
/**
44
* Parent class for all card footers.
5-
* Handles logic relevant to all footers. Currently unused.
5+
* Handles logic relevant to all footers.
66
*/
77
class NeoFooter extends React.Component {
88
constructor(props) {

src/card/footer/NeoGraphVisFooter.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ import NeoFooter from "./NeoFooter";
1010
* When clicking on a label, the rendered property name on the node can be changed.
1111
*/
1212
class NeoGraphVisFooter extends NeoFooter {
13+
/**
14+
* Set default state of the footer.
15+
*/
1316
constructor(props) {
1417
super(props);
1518
this.state = {}
1619
}
1720

1821

22+
/**
23+
* Draw the footer (with chips) based on selected values.
24+
*/
1925
render() {
2026
let colors = ["#588c7e", "#f2e394", "#f2ae72", "#d96459", "#5b9aa0", "#d6d4e0",
2127
"#b8a9c9", "#622569", "#ddd5af", "#d9ad7c", "#a2836e", "#674d3c", "grey"]

src/card/footer/NeoLineChartFooter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class NeoLineChartFooter extends NeoFooter {
1515
this.state = {}
1616
}
1717

18+
/**
19+
* Draw the property selection boxes with selected properties.
20+
*/
1821
render() {
1922
return (
2023
<div className="neo-property-select" style={{marginLeft: '20px', marginTop: "-8px"}}>

src/card/footer/NeoTableFooter.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ import Icon from "react-materialize/lib/Icon";
44
import NeoFooter from "./NeoFooter";
55

66
/**
7-
* A table report footer can be used to switch pages in the table.
7+
* A table footer is a Pagination (https://materializecss.com/pagination.html) component.
8+
* The component is used to switch pages in the table report.
89
*/
910
class NeoTableFooter extends NeoFooter {
1011
constructor(props) {
1112
super(props);
1213
}
1314

15+
/**
16+
* Draw the pagination component based on the currently selected page in the table.
17+
*/
1418
render() {
1519
return <Pagination
1620
activePage={(this.props.page ? this.props.page : 1)}

src/card/report/NeoBarChartReport.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import React from "react";
22
import NeoReport from "./NeoReport";
33
import * as d3 from "d3";
44

5+
/**
6+
* A bar chart report draws the resulting data from Neo4j as a bar chart.
7+
* The x-axis (categories) and the y-axis (values) can be selected from the returned field names.
8+
*/
59
class NeoBarChartReport extends NeoReport {
6-
7-
componentDidUpdate(prevProps) {
8-
super.componentDidUpdate(prevProps);
9-
this.componentDidMount();
10-
}
11-
10+
/**
11+
* On initialization, generate the visualization with d3.
12+
* The drawn axes are generated from the selected properties.
13+
* The size and style of the visualization is set based on the provided properties.
14+
*/
1215
componentDidMount() {
1316
let data = this.state.data;
1417
let page = this.state.page;
@@ -117,6 +120,17 @@ class NeoBarChartReport extends NeoReport {
117120

118121
}
119122

123+
/**
124+
* Handle updates to the component. Perform a remount on each update.
125+
*/
126+
componentDidUpdate(prevProps) {
127+
super.componentDidUpdate(prevProps);
128+
this.componentDidMount();
129+
}
130+
131+
/**
132+
* Helper function to get the max/min values from the values selected for the plot's axes.
133+
*/
120134
getDataLimits(data) {
121135
let yValues = data.map(row => row[1]);
122136
let categoryLengths = data.map(row => (row[0] ? row[0] : "").toString().length);
@@ -139,6 +153,10 @@ class NeoBarChartReport extends NeoReport {
139153
return {maxY, minY, xTextLength: maxX};
140154
}
141155

156+
/**
157+
* Attempt to parse a 'drawable' value from what was returned by Neo4j.
158+
* Since these may have any type (string, number, node, relationship, path), we need to handle a variety of cases.
159+
*/
142160
parseChartValue(value, index, i) {
143161
// If there's no data, fill it with some blanks.
144162
if (value === null) {
@@ -148,7 +166,6 @@ class NeoBarChartReport extends NeoReport {
148166
return NaN
149167
}
150168
}
151-
152169
// if it's a number, just return it.
153170
if (!isNaN(value)) {
154171
return value
@@ -160,11 +177,9 @@ class NeoBarChartReport extends NeoReport {
160177
if (typeof (value) === "object" && !isNaN(value["low"])) {
161178
return value.low
162179
}
163-
164180
if (typeof (value) === "string") {
165181
return value;
166182
}
167-
168183
if (value && value["labels"] && value["identity"] && value["properties"]) {
169184
return value.labels + "(" + value.identity + ")"
170185
}
@@ -174,6 +189,9 @@ class NeoBarChartReport extends NeoReport {
174189
return (value) ? value.toString() : "";
175190
}
176191

192+
/**
193+
* Draw the report based on the generated visualization.
194+
*/
177195
render() {
178196
let rendered = super.render();
179197
if (rendered) {

0 commit comments

Comments
 (0)