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

custom colors for negative numbers #29

Merged
merged 7 commits into from
Sep 20, 2016
Merged

custom colors for negative numbers #29

merged 7 commits into from
Sep 20, 2016

Conversation

mrjones-plip
Copy link
Contributor

first stab at getting custom colors for negative numbers working per #28. Fix some bugs that should help, but not entirely fix, #27

.  Fix some bugs that should help, but not entirely fix, #27
@mrjones-plip
Copy link
Contributor Author

@melalj - i need to do some more testing - but any input is welcome!

Copy link
Contributor Author

@mrjones-plip mrjones-plip left a 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') {
Copy link
Contributor Author

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!

Copy link
Member

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

Copy link
Contributor Author

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]));
Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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') {
Copy link
Member

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])) {
Copy link
Member

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 :)

Copy link
Contributor Author

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;
Copy link
Member

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

Copy link
Contributor Author

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){
Copy link
Member

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

Copy link
Contributor Author

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;
Copy link
Member

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);

Copy link
Contributor Author

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]));
Copy link
Member

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%')
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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!

Copy link
Contributor Author

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.

@mrjones-plip
Copy link
Contributor Author

@melalj - thanks so much for all the feedback! d6a98e8 should fix all of GeoMap.js, but I still need to fix Legend.js's display of of negative numbers in legend.

@mrjones-plip
Copy link
Contributor Author

Ohhh - the current branch is doing weird stuff with the legend now. If I remove the minNegative and maxNegative declarations in negative.example.html the legend works correctly. However, if I add them in, the color of the country isn't on the right scale. So I've given Mozambique the value of 11, but his color looks to be the value of about 30 or 40. I edited the exported SVG to better illustrate the error. I added a white "1" to denote the country value and a red arrow to show where it should be:

wrong country color

@mrjones-plip mrjones-plip merged commit d5e3d0f into master Sep 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants