-
Notifications
You must be signed in to change notification settings - Fork 5
[WIP] add min/max limits to temp plot (closes #240) #289
base: master
Are you sure you want to change the base?
Conversation
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.
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.
@@ -38,6 +40,22 @@ class TempPlot extends Component { | |||
return array; | |||
}; | |||
|
|||
filterDataMinMax = (array) => { |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -9,6 +9,8 @@ import Input from 'react-toolbox/lib/input'; | |||
const LINE_COLORS = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33'] | |||
|
|||
const defaultNumberOfPoints = 300; | |||
const tempMin = 0; |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! |
var tempData = []; | ||
if (this.props.temps.data) { | ||
tempData = this.props.temps.data.map(currentItem => { | ||
return {...currentItem.temps, time: currentItem.time}; | ||
}); | ||
tempData = tempData.reverse() | ||
} | ||
|
||
this.props.dataMin = (tempData.min() < tempDataMin ? tempDataMin : tempData.min()); |
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.
@suyashkumar trying to set these here seems to break the plots... insights?
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.
by breaking the plots, they just don't render
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
@@ -92,7 +92,7 @@ class Plot extends Component { | |||
<ResponsiveContainer width="94%" height={300}> | |||
<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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!
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.
Fixed
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@suyashkumar Better way to do this in Javascript?
@@ -72,6 +72,12 @@ class BucketView extends Component { | |||
} | |||
} | |||
|
|||
var flowDataValues = []; | |||
for (var i in flowData) { |
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.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.