update legend state after chart update
This commit is contained in:
		
							parent
							
								
									aa8d3798ea
								
							
						
					
					
						commit
						0fe32835c9
					
				@ -314,6 +314,13 @@ Chartist.plugins.legend = function (options: any) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    return function legend(chart: any) {
 | 
					    return function legend(chart: any) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      var isClicked = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      chart.on('created', function (data: any) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (isClicked)
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        function removeLegendElement() {
 | 
					        function removeLegendElement() {
 | 
				
			||||||
          const legendElement = chart.container.querySelector('.ct-legend');
 | 
					          const legendElement = chart.container.querySelector('.ct-legend');
 | 
				
			||||||
            if (legendElement) {
 | 
					            if (legendElement) {
 | 
				
			||||||
@ -442,7 +449,9 @@ Chartist.plugins.legend = function (options: any) {
 | 
				
			|||||||
                    chart.data.labels = newLabels;
 | 
					                    chart.data.labels = newLabels;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                isClicked = true;
 | 
				
			||||||
                chart.update();
 | 
					                chart.update();
 | 
				
			||||||
 | 
					                isClicked = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (options.onClick) {
 | 
					                if (options.onClick) {
 | 
				
			||||||
                    options.onClick(chart, e);
 | 
					                    options.onClick(chart, e);
 | 
				
			||||||
@ -480,14 +489,13 @@ Chartist.plugins.legend = function (options: any) {
 | 
				
			|||||||
            });
 | 
					            });
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        chart.on('created', function (data: any) {
 | 
					        appendLegendToDOM(legendElement);
 | 
				
			||||||
            appendLegendToDOM(legendElement);
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (options.clickable) {
 | 
					        if (options.clickable) {
 | 
				
			||||||
            setSeriesClassNames();
 | 
					            setSeriesClassNames();
 | 
				
			||||||
            addClickHandler(legendElement, legends, seriesMetadata, useLabels);
 | 
					            addClickHandler(legendElement, legends, seriesMetadata, useLabels);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user