Skip to content
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

Adding Negative Functionallity to MapChartComponent #1349

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/client/app/components/MapChartComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ export default function MapChartComponent() {
if (readingsData !== undefined && !meterIsFetching) {
// Meter name to include in hover on graph.
const label = meterDataById[meterID].identifier;
// The usual color for this meter.
colors.push(getGraphColor(meterID, DataType.Meter));
if (!readingsData) {
throw new Error('Unacceptable condition: readingsData.readings is undefined.');
}
Expand Down Expand Up @@ -208,6 +206,13 @@ export default function MapChartComponent() {
}
// The size is the reading value. It will be scaled later.
size.push(averagedReading);
//The Color checked if negative
if(averagedReading >= 0){
colors.push(getGraphColor(meterID, DataType.Meter));
}
else{
colors.push(getGraphColor(6, DataType.Meter));
}
}
// The hover text.
hoverText.push(`<b> ${timeReading} </b> <br> ${label}: ${averagedReading.toPrecision(6)} ${unitLabel}`);
Expand Down Expand Up @@ -300,11 +305,19 @@ export default function MapChartComponent() {
// The circle size is set to area below. Thus, we need to convert from wanting a max
// diameter of minDimension * maxFeatureFraction to an area.
const maxCircleSize = Math.PI * Math.pow(minDimension * maxFeatureFraction / 2, 2);
const minCircleSize = Math.PI * Math.pow(minDimension * maxFeatureFraction / (10*2), 2);
// Find the largest circle which is usage.
const largestCircleSize = Math.max(...size);
const smallestCircleSize = Math.min(...size);
// Scale largest circle to the max size and others will be scaled to be smaller.
// Not that < 1 => a larger circle.
const scaling = largestCircleSize / maxCircleSize;
const scaling = (largestCircleSize - smallestCircleSize) / (maxCircleSize - minCircleSize);
const minShift = 10*scaling + 5;

for(let i=0;i<size.length;i++){
size[i]+=minShift;
}


// Per https://plotly.com/javascript/reference/scatter/:
// The opacity of 0.5 makes it possible to see the map even when there is a circle but the hover
Expand Down
Loading