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

Update range display #165

Merged
merged 14 commits into from
Dec 15, 2015
Merged

Update range display #165

merged 14 commits into from
Dec 15, 2015

Conversation

Indigo744
Copy link
Collaborator

Implements #110 second option!

Usage:

opt = {
    hiddenOpacity: 0.3,                 // Opacity to use when hidding element
    animDuration: 200,                  // Animation duration for showing/hiding element
    afterShowRange: function() {},      // User callback
    ranges: {                           // The ranges
        plot: {
            0: {                        // valueIndex
                min: 1000,
                max: 1200
            },
            1: {                        // valueIndex
                min: 10,
                max: 12
            }
        }, 
        area : {
            {min: 10, max: 20}    // No valueIndex, only an object, use 0 as valueIndex (easy case)
        }
    }
};
$(".mapcontainer").trigger("showElementsInRange", [opt]);

Provided are 2 advanced examples using NoUISlider (http://refreshless.com/nouislider).

As a nice effect, I factorized some function using the new setElementOpacity() function.

@Indigo744
Copy link
Collaborator Author

This is weird. UT were passing in Firefox...

@Indigo744
Copy link
Collaborator Author

At last :)

Travis/PhantomJS doesn't seem to like $(".selector").is(":visible")
I changed it for $(".selector").css('display') !== 'none'

@neveldo
Copy link
Owner

neveldo commented Dec 14, 2015

Thank you, this is a great new feature ! Why did you force the installation of phantomJS 2.0.0 for unit testing ?

@@ -219,6 +219,11 @@
self.onUpdateEvent(e, opt);
});

// Attach showElementsInRange event
self.$container.on("showElementsInRange." + pluginName, function (e, ranges) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the argument ranges shouldn't be called options because we can set options like hiddenOpacity or animDuration in this object ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! It was from an earlier version where I only passed a ranged array. I forgot to update this part after extending the event.

@Indigo744
Copy link
Collaborator Author

I commited the new names.
Regarding phantomJS 2.0, I though this was what cause problems in the UT. It turned out it is not the case (see explanation above). I should then remove it.

var range = ranges[valueIndex];
// Check if user defined at least a min or max value
if (range.min === undefined && range.max === undefined) {
return true; // next range
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the function is not expected to return any value, maybe we should just do return; here ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, no. This return true; is related to the $.each() function callback.
Returning true will go to the next item (like a continue statement). Whereas false will end the loop (much like a break statement). See jQuery doc: http://api.jquery.com/jQuery.each/

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, thank you !

elem.mapElem.attr({"opacity": opacity});
// For extrem opacity, hide or show
if (opacity === 0) elem.mapElem.hide();
else if (opacity === 1) elem.mapElem.show();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be redundent with L761 elem.mapElem.show();

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed :)

self.setElementOpacity(
elem,
(elem.mapElem.originalAttrs.opacity !== undefined) ? elem.mapElem.originalAttrs.opacity : 1,
animDuration
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the 'animDuration' should be added to the arguments of fnShowElement() ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? It is available in the parent onUpdateEvent() function as a closure.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, you are right !

neveldo added a commit that referenced this pull request Dec 15, 2015
@neveldo neveldo merged commit 3d5f092 into neveldo:master Dec 15, 2015
@Indigo744 Indigo744 deleted the update-range-display branch December 15, 2015 18:28
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.

2 participants