[WIP] add min/max limits to temp plot (closes #240)#289
[WIP] add min/max limits to temp plot (closes #240)#289
Conversation
suyashkumar
left a comment
There was a problem hiding this comment.
Overall LGTM, but had some comments about using map and moving over these changes to the new more generalized Plot component! I should have removed the temp-plot component earlier once it was successfully switched out with the more general Plot component, my apologies for the delay there.
| return array; | ||
| }; | ||
|
|
||
| filterDataMinMax = (array) => { |
There was a problem hiding this comment.
This seems reasonable, but for the implementation of this function, consider using the map function as described here which will allow you to apply a function f to each element e in an array with the output f(e) populating the corresponding index in an output array.
There was a problem hiding this comment.
Yeah, I wanted to use map... But I wasn't in Python. Syntax. Bah.
| @@ -9,6 +9,8 @@ import Input from 'react-toolbox/lib/input'; | |||
| const LINE_COLORS = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33'] | |||
There was a problem hiding this comment.
also, as seen here the TempPlot component has actually been replaced by a more generalized Plot component which is used to render both the temperature plot and the bucket view plot so these changes should likely go into the plot component! My apologies for not promptly removing this legacy component right away. Since it seems like the Plot component is working fine I can go ahead and remove this component once I ensure there are no lingering dependencies.
| const LINE_COLORS = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33'] | ||
|
|
||
| const defaultNumberOfPoints = 300; | ||
| const tempMin = 0; |
There was a problem hiding this comment.
since these changes will be in the generalized plot component as described above, these should likely be input props to the component (perhaps minLimit and maxLimit). These values can be passed into the Plot component by the parent, as is seen here. Inside the Plot component, you can of course access the current prop value using syntax similar to the following this.props.minLimit
There was a problem hiding this comment.
Would it be worth putting these in constants.js? I'll take a stab at using the correct class for this now...
There was a problem hiding this comment.
oh wait, this plot component is also used for the bucket tips... that wouldn't make sense as a default for that.
* Aaron requested limits on the temperature y-axis plots ranging from [0:80] degrees. Implemented this through a YAxis domain option that will impose these hard limits if the data exceed these; otherwise the y-axis will be dynamically set based on the data. * Chose this as opposed to re-mapping the data points that fall outside of this range so that the temperature data array integrity is maintained.
|
Making some attempted changes just to get more familiar with the code base. Latest commit imposes |
|
This is broken right now... so definitely do not merge this in! |
| tempData = tempData.reverse() | ||
| } | ||
|
|
||
| this.props.dataMin = (tempData.min() < tempDataMin ? tempDataMin : tempData.min()); |
There was a problem hiding this comment.
@suyashkumar trying to set these here seems to break the plots... insights?
There was a problem hiding this comment.
by breaking the plots, they just don't render
There was a problem hiding this comment.
nvm - I realize this is broken b/c of trying to assign something to props incorrectly (I think)
There was a problem hiding this comment.
ah yes, you should not be setting this components own props from within it -- the parent to this component passes in props to this component somewhat like function inputs.
Likely what you want to be doing is passing in dataMin and dataMax as input props to the plot itself right? In which case you would be passing them into PlotCard like data is being passed in on L56.
There was a problem hiding this comment.
yep... I realized this was a broken approach. not surprised by that.
|
@suyashkumar help... in general things were working with this approach to both have the temp and bucket plots have appropriate y-axis scaling, but in refactoring the code, something happened where now I get plot timeouts. before I spend more time figuring this out, can you vet the approach to setting the y-axis limits this way? |
|
also, the unit test is broken, but I think that it was calling things that the new |
| <LineChart data={dataToShow}> | ||
| <XAxis dataKey="time" label="Date" interval={tickInterval} tickFormatter={this.formatDate} /> | ||
| <YAxis /> | ||
| <YAxis type="number" domain={[this.props.yAxisMinMax[0], this.props.yAxisMinMax[1]]}/> |
There was a problem hiding this comment.
props.yAxisMinMax is not available here yet, it needs to be passed into this Plot component from the PlotCard component and you should be good to use it!
|
Plots are now rendering, though the plots don't seem to be respecting the actual min/max limits correctly. That sometimes seems to change as a function of when the plot is getting reloaded (?). Not sure... |
|
Two suggestions:
Thoughts @aforbis-stokes @Graham-H-Miller |
|
hmm may have to look deeper into that later, |
|
figured it out, but will need some time to fix... |
|
@suyashkumar I fixed the caluclation of the min/max y-axis values... they are properly console logged by from the This could use your eyes when you have a chance... |
| var tempDataMax = 80; | ||
|
|
||
| var allTempData = []; | ||
| for (var i in tempData) { |
There was a problem hiding this comment.
@suyashkumar Better way to do this in Javascript?
| } | ||
|
|
||
| var flowDataValues = []; | ||
| for (var i in flowData) { |
There was a problem hiding this comment.
@suyashkumar better way to do this in Javascript?
| for (var i in flowData) { | ||
| flowDataValues[i] = flowData[i].flow; | ||
| } | ||
| var yAxisMinMax = [Math.min.apply(Math, flowDataValues), Math.max.apply(Math, flowDataValues)]; |
There was a problem hiding this comment.
@suyashkumar do you really have to do Math.min.apply(Math... to work with an array?!
It appears the recharts will override your YAxis domain unless you explicitly set `allowDataOverflow=True`.
|
In regards to the hard limit/data scrubbing, voiding the faulty data would be better in my opinion for the reason you suggested for skewing averages. |
|
@aforbis-stokes what would you like bad data points set to, just |
|
I do think NaN is better than setting to 0 or 80. There is some value in knowing that data is funky, and the extreme numbers we see are good indicators of hardware issues. Is it possible to get something like "-NaN" for <0 and "Nan" or "+NaN" for >80? Typically a negative value means a probe is disconnected, while a very large number means things are connected, but something is damaged. |
|
ok - I don't think that we can assign a sign to the |
|
That sounds good to me. |
|
@suyashkumar will also need help updating the unit tests that you have for I'm flying completely blind on what you are actually testing with those, but there appears to be something that has internally changed when you went from a |
@suyashkumar completely unsure if this is the correct way to this... almost definitely not the most elegant, or even remotely so, but hey... its JavaScript, what do you expect. ;) Please correct.