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

Polyline layer turns black after turning off all legend filters (legend: true + preferCanvas: false) #272

Open
hupe13 opened this issue Oct 7, 2023 · 6 comments

Comments

@hupe13
Copy link
Contributor

hupe13 commented Oct 7, 2023

Hi Raruto,

if I toggle all chart legend filter off, the polyline is black. Example.

image

Your example works as expected.

If I comment out these lines

if (!this._chartEnabled) {
this._chart._hideDiagramIndicator();
this._marker.remove();
}

it works for me too.

What is the expected behavior? Or what is missing in my code?

Thank you very much.

@Raruto
Copy link
Owner

Raruto commented Oct 9, 2023

Hi @hupe13,

if I toggle all chart legend filter off, the polyline is black. Example.

It should be the intended behavior (somehow related to: #235).

If I comment out these lines

if (!this._chartEnabled) {
this._chart._hideDiagramIndicator();
this._marker.remove();
}

it works for me too.

Actually, the following should be the real cause:

// toggle layer visibility on empty chart
this._layers.eachLayer(layer => _.toggleClass(layer.getElement && layer.getElement(), this.options.polyline.className + ' ' + this.options.theme, this._chartEnabled));

Your example works as expected.

Probably not implemented on canvas layers:

where CSS rules must be transposed into JS code, eg: L.Control.Elevation::_fixCanvasPaths()

👋 Raruto

@Raruto Raruto changed the title Polyline and legend filter Polyline layer turns black after turning it off via legend filter (legend: true + preferCanvas: false) Oct 9, 2023
@Raruto Raruto changed the title Polyline layer turns black after turning it off via legend filter (legend: true + preferCanvas: false) Polyline layer turns black after turning off all legend filters (legend: true + preferCanvas: false) Oct 9, 2023
@hupe13
Copy link
Contributor Author

hupe13 commented Oct 11, 2023

Hi Raruto,

after setting map.options.preferCanvas = true; it works now.

Thank you very much.

@hupe13
Copy link
Contributor Author

hupe13 commented Nov 22, 2023

There are many (other) problems with setting map.options.preferCanvas = true; in my WordPress plugin.

Actually, the following should be the real cause:

// toggle layer visibility on empty chart
this._layers.eachLayer(layer => _.toggleClass(layer.getElement && layer.getElement(), this.options.polyline.className + ' ' + this.options.theme, this._chartEnabled));

Yes, it should be:

// toggle layer visibility on empty chart
this._layers.eachLayer(layer => layer.getElement && this._chartEnabled && this.options.polyline.className && _.toggleClass(layer.getElement && layer.getElement(), this.options.polyline.className + ' ' + this.options.theme, this._chartEnabled));

`

@hupe13 hupe13 reopened this Nov 22, 2023
@Raruto
Copy link
Owner

Raruto commented Nov 22, 2023

@hupe13 umph, some additional code explanation would help (it's somewhat a cryptic condition).

Also, if you feel you have the time: 👉 gifcap.dev (just to show the before/after to others).

👋 Raruto

@hupe13
Copy link
Contributor Author

hupe13 commented Nov 22, 2023

The problem in my first post was about the black polyline when all legend filters are turned off. You told me two possibilities to solve the problem:

  • setting preferCanvas: true
  • the line 913 in /src/control.js

First, I set map.options.preferCanvas = true; and it seemed to work. Today I know, it works with the default theme colors only. I have some options in my WordPress plugin that allow to change the colors. And if the user does this, this solution does not work. So I analyzed the line 913 and I found the solution above. I changed this corresponding line in my repository. Additionally I must set preferCanvas to false and now it works for non default theme colors also.

@hupe13
Copy link
Contributor Author

hupe13 commented Dec 2, 2023

Hi Raruto,

I changed this:

this._layers.eachLayer(layer => _.toggleClass(layer.getElement && layer.getElement(), this.options.polyline.className + ' ' + this.options.theme, this._chartEnabled));

to

 this._layers.eachLayer(layer => layer.getElement && this._chartEnabled && this.options.polyline.className && _.toggleClass(layer.getElement && layer.getElement(), this.options.polyline.className + ' ' + this.options.theme, this._chartEnabled));

I tested it with your example using custom colors. You can see, it works. Toggle Altitude on and off.

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

No branches or pull requests

2 participants