Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Add data group class to Graph3d #2804

Closed
wants to merge 10 commits into from
Closed

Conversation

wimrijnders
Copy link
Contributor

This is the next step in the implementation of multiple graphs in a view for Graph3D.

Added class DataGroup, which is a container for all data of one specific graph.

In this implementation, only one instance is used internally. Eventually, multiple instances will be possible, one per graph to display. The interface of Graph3D is unchanged.

@Tooa Tooa added the Graph3D label Feb 28, 2017
@Tooa Tooa added this to the Minor Release v4.20 milestone Feb 28, 2017
var Range = require('./Range');


function DataGroup() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding a comment with @constructor annotation and a small explanation similar to the one in your pull request?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all matters related to jsdoc annotations, I am assuming that http://usejsdoc.org is leading.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree that header commenting should be reviewed as well. However, I would really like to see this explicitly stated in the programming guidelines. It's something that developers should be aware of and should adhere to, throughout the entire codebase of vis.js.

* the Graph.
* @param {Number} style Style Number
*/
DataGroup.prototype.dataInitialize = function(graph3d, rawData, style) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use active voice with verb first for your function calls i.e. initializeData ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't here the graph3d @param missing or is this optional?



function DataGroup() {
this.dataTable = null; // The original data table
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention the consequences for this assignment in the constructor comment. For example, do we need to call initializeData? What happens when we don't call initializeData?

// calculate minimums and maximums
var NUMSTEPS = 5;

var xRange = this.getColumnRange(data, this.colX);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way we can shorten the following lines? Looks quite similar to me. Only the axis is different.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tough one, but I'll do my best. #2853 will take away a lot of the hurt here eventually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See new methods DataGroup.prototype._collectRangeSettings() and DataGroup.prototype._initializeRange()

};


DataGroup.prototype.getDistinctValues = function(column) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsdoc missing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure no problem. But then also make it a requirement in the guidelines.



/**
* NOTE: This method is used nowhere.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then remove it?

DataGroup.prototype.reload = function() {
if (this.dataTable) {
this.setData(this.dataTable);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incorrect spaces

@@ -392,8 +327,10 @@ Graph3d.prototype._checkValueField = function (data) {
return; // No need to check further
}

var colValue = this.colValue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would inline the value when the overhead of retrieving the value i.e. this.colValue is cheap. For expensive function calls etc. it would be indeed better to assign it once. Personal taste here.

if (defaultMin !== undefined) {
range.min = defaultMin;
}
Graph3d.prototype._dataInitialize = function(rawData, style) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initializeData

}
}
var dataX = this.getPresentXValues(data);
var dataY = this.getPresentYValues(data);

var sortNumber = function (a, b) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used in so many places. Maybe we should add it to a util class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean here. This is the only place in graph3d where getPresent[XY]Values() are called.

Or perhaps you mean the sort function? That does occur in several places.

Copy link
Contributor Author

@wimrijnders wimrijnders Mar 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what you mean. getPresentXValues() and getPresentYValues() are almost the same.

On top of that, my shiny new method DataGroup.getDistinctValues() does almost the same thing. I'll DRY the code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to the sort function. I'm fine with the getPresentXValues calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can now not unsee the similarity between getPresent[X|Y]Values() and DataGroup.getDistinctValues(). I will need to DRY them!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous DRY takes care of some sort functions. All the regular sorts have now been reduced to a single instance in DataGroup.prototype.getDistinctValues().

For the remaining sorts:

  • Graph3d.prototype._redrawBar() - Distinctly different sorting order, can't combine.
  • Graph3d.prototype.calcTranslations() - Distinctly different sorting order, can't combine.
  • Filter() (constructor) - sort is now redundant, done in getDistinctValues(). And the data values are never strings, so it was silly anyway.

In addition:

  • Graph3d.prototype._calcTranslations() - optional parameter sort never used, removed.

@wimrijnders
Copy link
Contributor Author

I pushed the changes till now. All the review points are addressed except the last - I want to think a bit about how to handle that.

Copy link
Contributor

@yotamberk yotamberk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice clean work! Looking forward to the multiple graphs option =)

@wimrijnders
Copy link
Contributor Author

@yotamberk Thanks! I'm totally going to bring graph3d forward!

@wimrijnders
Copy link
Contributor Author

@Tooa please approve #2804. I've addressed all your review comments over two months ago.

@wimrijnders
Copy link
Contributor Author

Republishing this PR to circumvent unapproved review.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants