]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix multi-dataset bar highlighting and bar highlight color logic
authorDavid Cochrum <dcochrum@sonnysdirect.com>
Fri, 11 Mar 2016 16:41:09 +0000 (11:41 -0500)
committerDavid Cochrum <dcochrum@sonnysdirect.com>
Fri, 11 Mar 2016 17:16:43 +0000 (12:16 -0500)
Chart.js
src/Chart.Bar.js
src/Chart.Doughnut.js
src/Chart.PolarArea.js

index 8a518d883bf2ced100280fcf6550b0581c723a60..21edb16a8b4a7be89bae28dbd48ca552e7c9bf85 100644 (file)
--- a/Chart.js
+++ b/Chart.js
                        if (reflow){
                                this.reflow();
                        }
-                       
+
                        if (this.options.animation && !reflow){
                                var animation = new Chart.Animation();
                                animation.numSteps = this.options.animationSteps;
                                animation.easing = this.options.animationEasing;
-                               
+
                                // render function
                                animation.render = function(chartInstance, animationObject) {
                                        var easingFunction = helpers.easingEffects[animationObject.easing];
                                        var stepDecimal = animationObject.currentStep / animationObject.numSteps;
                                        var easeDecimal = easingFunction(stepDecimal);
-                                       
+
                                        chartInstance.draw(easeDecimal, stepDecimal, animationObject.currentStep);
                                };
-                               
+
                                // user events
                                animation.onAnimationProgress = this.options.onAnimationProgress;
                                animation.onAnimationComplete = this.options.onAnimationComplete;
-                               
+
                                Chart.animationService.addAnimation(this, animation);
                        }
                        else{
                numSteps: 60, // default number of steps
                easing: "", // the easing to use for this animation
                render: null, // render function used by the animation service
-               
-               onAnimationProgress: null, // user specified callback to fire on each step of the animation 
+
+               onAnimationProgress: null, // user specified callback to fire on each step of the animation
                onAnimationComplete: null, // user specified callback to fire when the animation finishes
        });
-       
+
        Chart.Tooltip = Chart.Element.extend({
                draw : function(){
 
                                        return;
                                }
                        }
-                       
+
                        this.animations.push({
                                chartInstance: chartInstance,
                                animationObject: animationObject
                        var index = helpers.findNextWhere(this.animations, function(animationWrapper) {
                                return animationWrapper.chartInstance === chartInstance;
                        });
-                       
+
                        if (index)
                        {
                                this.animations.splice(index, 1);
                                if(this.animations[i].animationObject.currentStep > this.animations[i].animationObject.numSteps){
                                        this.animations[i].animationObject.currentStep = this.animations[i].animationObject.numSteps;
                                }
-                               
+
                                this.animations[i].animationObject.render(this.animations[i].chartInstance, this.animations[i].animationObject);
-                               
+
                                // Check if executed the last frame.
                                if (this.animations[i].animationObject.currentStep == this.animations[i].animationObject.numSteps){
                                        // Call onAnimationComplete
                                                bar.restore(['fillColor', 'strokeColor']);
                                        });
                                        helpers.each(activeBars, function(activeBar){
-                                               activeBar.fillColor = activeBar.highlightFill;
-                                               activeBar.strokeColor = activeBar.highlightStroke;
+                                               if (activeBar) {
+                                                       activeBar.fillColor = activeBar.highlightFill;
+                                                       activeBar.strokeColor = activeBar.highlightStroke;
+                                               }
                                        });
                                        this.showTooltip(activeBars);
                                });
                        var index = atIndex !== undefined ? atIndex : this.segments.length;
                        if ( typeof(segment.color) === "undefined" ) {
                                segment.color = Chart.defaults.global.segmentColorDefault[index % Chart.defaults.global.segmentColorDefault.length];
-                               segment.highlight = Chart.defaults.global.segmentHighlightColorDefaults[index % Chart.defaults.global.segmentHighlightColorDefaults.length];                            
+                               segment.highlight = Chart.defaults.global.segmentHighlightColorDefaults[index % Chart.defaults.global.segmentHighlightColorDefaults.length];
                        }
                        this.segments.splice(index, 0, new this.SegmentArc({
                                value : segment.value,
                        helpers.each(this.segments,function(segment){
                                segment.save();
                        });
-                       
+
                        this.reflow();
                        this.render();
                },
index c38d2525c0cb1777c880f35c72a8de362d43034f..7820a320bb9cc22395e3bd8e8bc9b37d08d58fb7 100644 (file)
                                                bar.restore(['fillColor', 'strokeColor']);
                                        });
                                        helpers.each(activeBars, function(activeBar){
-                                               activeBar.fillColor = activeBar.highlightFill;
-                                               activeBar.strokeColor = activeBar.highlightStroke;
+                                               if (activeBar) {
+                                                       activeBar.fillColor = activeBar.highlightFill;
+                                                       activeBar.strokeColor = activeBar.highlightStroke;
+                                               }
                                        });
                                        this.showTooltip(activeBars);
                                });
                                                datasetLabel: dataset.label,
                                                strokeColor : (typeof dataset.strokeColor != 'string') ? dataset.strokeColor[index] : dataset.strokeColor,
                                                fillColor : (typeof dataset.fillColor != 'string') ? dataset.fillColor[index] : dataset.fillColor,
-                                               highlightFill : (dataset.highlightFill && typeof dataset.highlightFill != 'string') ? dataset.highlightFill[index] || dataset.highlightFill : (typeof dataset.fillColor != 'string') ? dataset.fillColor[index] : dataset.fillColor,
-                                               highlightStroke : (dataset.highlightStroke && typeof dataset.highlightStroke != 'string') ? dataset.highlightStroke[index] || dataset.highlightStroke : (typeof dataset.strokeColor != 'string') ? dataset.strokeColor[index] : dataset.strokeColor
+                                               highlightFill : (dataset.highlightFill) ? (typeof dataset.highlightFill != 'string') ? dataset.highlightFill[index] : dataset.highlightFill : (typeof dataset.fillColor != 'string') ? dataset.fillColor[index] : dataset.fillColor,
+                                               highlightStroke : (dataset.highlightStroke) ? (typeof dataset.highlightStroke != 'string') ? dataset.highlightStroke[index] : dataset.highlightStroke : (typeof dataset.strokeColor != 'string') ? dataset.strokeColor[index] : dataset.strokeColor
                                        }));
                                },this);
 
index 90d886b79219ed1caa21221e0a07f341f75c7ff6..4769305caf1969e752237486da4403e62c08aae2 100644 (file)
@@ -39,7 +39,7 @@
        Chart.Type.extend({
                //Passing in a name registers this chart in the Chart namespace
                name: "Doughnut",
-               //Providing a defaults will also register the deafults in the chart namespace
+               //Providing a defaults will also register the defaults in the chart namespace
                defaults : defaultConfig,
                //Initialize is fired when the chart is initialized - Data is passed in as a parameter
                //Config is automatically merged by the core of Chart.js, and is available at this.options
index d1802f5d61754f3ead44d64ba8b053314cc39979..bf03f102b8f14a3cdfd410868883a001ce72da87 100644 (file)
@@ -54,7 +54,7 @@
        Chart.Type.extend({
                //Passing in a name registers this chart in the Chart namespace
                name: "PolarArea",
-               //Providing a defaults will also register the deafults in the chart namespace
+               //Providing a defaults will also register the defaults in the chart namespace
                defaults : defaultConfig,
                //Initialize is fired when the chart is initialized - Data is passed in as a parameter
                //Config is automatically merged by the core of Chart.js, and is available at this.options