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

New event to hide/show all elements #85

Merged

Conversation

Indigo744
Copy link
Collaborator

Hiding and showing slices is available through a click on legend element (if legend.area.hideElemsOnClick.enabled if set to true).
I needed a function to hide/show all elements at once (and it seems related to #26, no workaround would be needed).

This patch implements a new event call hideAllElems which accept a boolean parameter hide. It allows to show/hide all elements at once. I'm up to debate for this event name, but I think it's the most simple and similar to hideElemsOnClick.

Also, it corrects an issue in the update event where the Reset hidden map elements parts would never do its job because el.hidden is actually never set (no error was thrown since we check for its existence, but it didn't do anything).

Hiding and showing slices is available through a click on legend element (if `legend.area.hideElemsOnClick.enabled` if set to true).
I needed a function to hide/show all elements at once.

This patch implements a new event call `hideAllElems` which accept a boolean parameter `hide`. It allows to show/hide all elements at once. I'm up to debate for this event name, but I think it's the most simple and similar to `hideElemsOnClick`.

Also, it corrects an issue in the `update` event where the *Reset hidden map elements* parts would never do its job because `el.hidden` is actually never set (no error was thrown since we check for its existence, but it didn't do anything).
}
});
});
$self.trigger("hideAllElems", true);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wow, I miss an issue... This should be set to false of course...

$self.trigger("hideAllElems", false);

My bad...

This was an issue introduced in last patch. The `update` event shall reset the map elements (i.e. show them).
@neveldo
Copy link
Owner

neveldo commented Oct 30, 2015

Hello,

Thank you for the PR !

I think $("[data-type='elem']").each() should be replaced by $("[data-type='elem']", $(this)).each(), otherwise, in case there are more than one map on a page, all legends items of all the maps will be hidden when the event is triggered on a specific map container.

Regarding the name, we could keep 'hideElemsOnClick', or maybe something like that : 'toggleLegendElemsState' will be more explicit (but a bit too long ?)

@Indigo744
Copy link
Collaborator Author

Right! Good catch :-)
I made a commit to correct this.

Regarding the name, the thing is that this event hide or show all the elements. This is not a toggle: elements already hidden will stay hidden for instance (or already shown will stay shown).
I'm not really fond of the name either, to be honest. However, I can't think of another name...

@neveldo
Copy link
Owner

neveldo commented Nov 1, 2015

Thank for the fix :) What do you think about "updateLegendElemsState" instead ? Otherwise, we will keep 'hideElemsOnClick' for the event name.

@Indigo744
Copy link
Collaborator Author

updateLegendElemsState would be OK.

However, the more I think of it, the more I wonder if we shouldn't integrate this inside the existing update event, in the opt object parameter for instance: opt.setLegendElemsState (value shown|hidden). What do you think ?

@neveldo
Copy link
Owner

neveldo commented Nov 2, 2015

I didn't thought about this alternative, but I agree with you, I think that the 'update' event is an appropriate place ... and no more headhache to choose the event name :) Could you update the PR to move the code within the 'update' event as you have explained ?

I think I will clean the "update" event signature later (and make it backward compatible with the current signature) in order to have a single object as parameter and get something like that :

var options = {
  'mapOptions' : {},
  'replace' : true/false // whether mapsOptions should entirely replace current map options, or just extend it,
  'newPlots' : {},
  'newLinks' : {},
  'deletedPlots: [],
  'deletedLinks' : [],
  'setLegendElemsState' => '...'
  'afterUpdate' => ...,
  'animDuration' : ...
};
$(".container").trigger('update', [options]);

@Indigo744
Copy link
Collaborator Author

Here is the commit. What do you think?

@Indigo744
Copy link
Collaborator Author

Regarding the cleaning of update event, I think you shouldn't be backward compatible.
With a new major release with some breaking change, you can avoid using this kind of legacy code that will only bloat the code.

@neveldo
Copy link
Owner

neveldo commented Nov 2, 2015

It's ok for me, approved !

neveldo added a commit that referenced this pull request Nov 2, 2015
@neveldo neveldo merged commit 2b02034 into neveldo:master Nov 2, 2015
@Indigo744 Indigo744 deleted the Indigo744-patch-hideAllElems-event branch November 2, 2015 18:40
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