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

EnhancedLegendRenderer incorrectly strike through the label #195

Open
loc829 opened this issue Apr 8, 2020 · 2 comments
Open

EnhancedLegendRenderer incorrectly strike through the label #195

loc829 opened this issue Apr 8, 2020 · 2 comments

Comments

@loc829
Copy link

loc829 commented Apr 8, 2020

Hi developers,

I am using jqplot in my project now and have the problem with EnhancedLegendRenderer.
Detail:
My page is using the bar chart with EnhancedLegendRenderer, for the feature to toggle on/off series.
When clicking on the label of the chart, the corresponding serrie is filtered out but the legend is striked through incorrectly.

Step to reproduce:
image

Look at the chart with 3 legends above. When I click to the legend "label 1", the corresponding bar is filtered out. However, the stroked through legend is not correct. It strikes through "label 3" instead of "label 1":
image

Same thing happens if I click to the legend "label 3", the "label 1" is stroked through.
Clicking to "label 2" has no problem, it strikes label 2 correctly.

Expected:
The bar is filtered out, the label is stroked through correctly

Note:
I found the example in the link below having the same problem
http://www.jqplot.com/examples/blockPlot.php#
The second chart has kinda similar problem with my problem. When I click to "Independant Brands" it strikes "Coke brands" instead.
Clicking to "Pepsi brands" and "Coke brands", it strikes nothing.

@dnprod
Copy link

dnprod commented Dec 22, 2020

i stumbled on the same issue, legends with showSwatches:false do this :(

as a workaround, is there away to turn on swatches but redefine their appearance/size/shape/colour/transparency to be virtually invisible?

update: interesting...
i have $(window).resize(function(event) {} defined which does MyChart.replot({resetAxes:true})
and when i resize the browser window the correct legend label(s) get the stroke-through line.

@dnprod
Copy link

dnprod commented Jan 2, 2021

i fixed the bug for me (in jqplot v1.0.9), seems to behave better than not fixed -- but i have NOT tested all possible cases or looked for other side effects.
-ken

in jqplot.enhancedLegendRenderer.js i changed the else clause in doLegendToggle function to now be:

         else {                                                                                                                         
            var s = plot.series[sidx];                                                                                                 
            var sidxsteps = 0;
                       
            sidxsteps += (typeof plot.options.legend.showSwatches == 'undefined' || plot.options.legend.showSwatches === true) ? 1 : 0;
            sidxsteps += (typeof plot.options.legend.showLabels == 'undefined' || plot.options.legend.showLabels === true) ? 1 : 0;    
                                                                                                                                       
            if (s.canvas._elem.is(':hidden') || !s.show) {                                                                             
                // Not sure if there is a better way to check for showSwatches and showLabels === true.                     
                // Test for "undefined" since default values for both showSwatches and showLables is true.                             
                if (typeof plot.options.legend.showSwatches === 'undefined' || plot.options.legend.showSwatches === true) { 
                    plot.legend._elem.find('td').eq(sidx * sidxsteps).addClass('jqplot-series-hidden');                                
                }                                                                                                           
                if (typeof plot.options.legend.showLabels === 'undefined' || plot.options.legend.showLabels === true) {                
                    plot.legend._elem.find('td').eq((sidx * sidxsteps) + (sidxsteps-1)).addClass('jqplot-series-hidden');   
                }                                                                                                                      
            }                                                                                                               
            else {                                                                                                                     
                if (typeof plot.options.legend.showSwatches === 'undefined' || plot.options.legend.showSwatches === true) { 
                    plot.legend._elem.find('td').eq(sidx * sidxsteps).removeClass('jqplot-series-hidden');                             
                }                                                                                                           
                if (typeof plot.options.legend.showLabels === 'undefined' || plot.options.legend.showLabels === true) {                
                    plot.legend._elem.find('td').eq((sidx * sidxsteps) + (sidxsteps-1)).removeClass('jqplot-series-hidden');
                }                                                                                                                      
            }                                                                                                               
        }

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