-
Notifications
You must be signed in to change notification settings - Fork 8
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
custom colors for negative numbers #29
Conversation
. Fix some bugs that should help, but not entirely fix, #27
@melalj - i need to do some more testing - but any input is welcome! |
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.
impact of using Number() and removal of mystery code
@@ -434,32 +434,43 @@ export default class GeoMap { | |||
let minValue = attrValue.min; | |||
let maxValue = attrValue.max; | |||
|
|||
if (attrValue.min === 'minValue') { |
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.
@melalj - I couldn't tell what these lines did and didn't see any changes when removing them. If they're still needed - lemme know!
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.
You should not remove these lines. Here's their application: https://github.com/Packet-Clearing-House/maptable#scaledvalue
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.
great, thanks for confirming! d6a98e8 added them back.
|
||
const scaleDomain = d3.extent(dataset, d => d.rollupValue[attrKey]); | ||
const scaleDomain = d3.extent(dataset, d => Number(d.rollupValue[attrKey])); |
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, or the other call to Number()
has made the column do an ASCII instead of a natural sort. The net result is that it orders the widget
column in the negative.example.html
example as "-10, -100 -110, -40..." :(
while I know in the columnsDetails
you can define a dataParse
function, i was just surprised that it defaulted to ASCII. We should do regression checks to ensure this doesn't change the existing default sort behavior.
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.
Not sure why this would affect the sorting on the table.
We should maybe use dataParse
to parse it as a number so that the sort for the table will work as well.
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.
Hmm - we should check against master branch to see if it's a regression or not. I'll check and report back!
@@ -434,32 +434,43 @@ export default class GeoMap { | |||
let minValue = attrValue.min; | |||
let maxValue = attrValue.max; | |||
|
|||
if (attrValue.min === 'minValue') { |
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.
You should not remove these lines. Here's their application: https://github.com/Packet-Clearing-House/maptable#scaledvalue
|
||
dataset.forEach(d => { | ||
let scaledValue; | ||
if (!d.values.length || isNaN(d.rollupValue[attrKey])) { |
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.
There's any issue with tabs here :)
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.
should be fixed in d6a98e8
maxValue = scaleDomain[1]; | ||
|
||
// check for negative color declorations | ||
var useNegative = false; |
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.
You should use eslint with your IDE.
repalce var
with let
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.
gotcha!
if ((attrValue.maxNegative && !attrValue.minNegative) || | ||
(!attrValue.maxNegative && attrValue.minNegative)) { | ||
throw new Error(`MapTable: maxNegative or minNegative undefined. Please declare both.`); | ||
} else if (attrValue.maxNegative && attrValue.minNegative){ |
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.
When you throw an error, it stop the JS execution.
So no need for a else, here
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.
cools, removed else in d6a98e8.
(!attrValue.maxNegative && attrValue.minNegative)) { | ||
throw new Error(`MapTable: maxNegative or minNegative undefined. Please declare both.`); | ||
} else if (attrValue.maxNegative && attrValue.minNegative){ | ||
useNegative = true; |
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.
You can remove the declaration on L439 and use:
const useNegative = (attrValue.maxNegative && attrValue.minNegative);
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.
lovely! added in d6a98e8
|
||
const scaleDomain = d3.extent(dataset, d => d.rollupValue[attrKey]); | ||
const scaleDomain = d3.extent(dataset, d => Number(d.rollupValue[attrKey])); |
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.
Not sure why this would affect the sorting on the table.
We should maybe use dataParse
to parse it as a number so that the sort for the table will work as well.
.attr('style', `stop-color:${this.map.options.countries.attr.fill.maxNegative};stop-opacity:1`); | ||
|
||
legendGradient.append('stop') | ||
.attr('offset', '49%') |
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.
Putting it as half is a wrong assumption if we have a minimum -20 and a maximum of 60. (for this use case the cut between the negative and positive is 25%). That's why the legend broke, because it's a scale only from 0 -> maxValue.
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.
yes and no ;) yes, I agree that my new code should check to see what the smallest and largest numbers are and put the percentages in accordingly (not covered by d6a98e8, commit pending). However, no, the problem of negative numbers flying off the legend exists in master per #27. So i'll do the work to adjust what % we use for these stops, but it won't fix the legend.
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.
ok - so legend still works as well as it did before with negative numbers flying off to the right, but now the zero position will show in a relative spot based on the min and max of the legend. check be8aa5d for details!
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 - hrm - the problem in #27 will be aggravated by this change. we'll need to update indiceChange()
to pull it all together so it works.
Ohhh - the current branch is doing weird stuff with the legend now. If I remove the |
first stab at getting custom colors for negative numbers working per #28. Fix some bugs that should help, but not entirely fix, #27