]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fixes to show all lines but not all labels. Added a variable in the template function...
authorEvert Timberg <evert.timberg@gmail.com>
Tue, 15 Sep 2015 00:32:23 +0000 (20:32 -0400)
committerEvert Timberg <evert.timberg@gmail.com>
Tue, 15 Sep 2015 00:32:23 +0000 (20:32 -0400)
samples/scatter-logX.html
src/core/core.helpers.js
src/scales/scale.logarithmic.js

index 976684f5c31dbbb0668ff1a0def905b235296617..d8d00c85c71b3094f927ad57f4d4348d0adbefa7 100644 (file)
                                position: 'bottom',
                                labels: {
                                        userCallback: function(tick) {
-                                               return tick.toString() + "Hz";
+                                               var remain = tick / (Math.pow(10, Math.floor(Chart.helpers.log10(tick))));
+                                               if (remain === 1 || remain === 2 || remain === 5) {
+                                                       return tick.toString() + "Hz";
+                                               }
+                                               return '';
                                        }
                                }
                        }],
index 46ad752d88210a6e1ac3800737b9985f705fafb3..ab58b0789dc7b1bb7567447402318da639292370 100644 (file)
                                } else {
                                        // Generate a reusable function that will serve as a template
                                        // generator (and which will be cached).
-                                       fn = new Function("obj",
-                                               "var p=[],print=function(){p.push.apply(p,arguments);};" +
+                                       var functionCode = "var p=[],print=function(){p.push.apply(p,arguments);};" +
 
                                                // Introduce the data as local variables using with(){}
                                                "with(obj){p.push('" +
                                                .split("\t").join("');")
                                                .split("%>").join("p.push('")
                                                .split("\r").join("\\'") +
-                                               "');}return p.join('');"
-                                       );
+                                               "');}return p.join('');";
+                                       fn = new Function("obj", functionCode);
 
                                        // Cache the result
                                        templateStringCache[str] = fn;
index 7294cd522d493b89d0bdc2737d410d19fc149afe..a8d9706b937afbe6c3859846f12f94e091421d43 100644 (file)
@@ -30,7 +30,7 @@
                        show: true,
                        mirror: false,
                        padding: 10,
-                       template: "<%=value.toExponential()%>",
+                       template: "<%var remain = value / (Math.pow(10, Math.floor(Chart.helpers.log10(value))));if (remain === 1 || remain === 2 || remain === 5) {%><%=value.toExponential()%><%} else {%><%= null %><%}%>",
                        fontSize: 12,
                        fontStyle: "normal",
                        fontColor: "#666",
@@ -76,9 +76,7 @@
 
                                for (var exponent = minExponent; exponent < maxExponent; ++exponent) {
                                        for (var i = 1; i < 10; ++i) {
-                                               if (i === 1 || i === 2 || i === 3 || i === 5 || i === 7) {
-                                                       this.ticks.push(i * Math.pow(10, exponent));
-                                               }
+                                               this.ticks.push(i * Math.pow(10, exponent));
                                        }
                                }
 
                                        });
                                }
 
-                               this.labels.push(label ? label : ""); // empty string will not render so we're good
+                               this.labels.push(label); // empty string will not render so we're good
                        }, this);
                },
                // Get the correct value. If the value type is object get the x or y based on whether we are horizontal or not
 
                                                helpers.each(this.labels, function(label, index) {
                                                        var xValue = this.getPixelForValue(this.ticks[index]);
-                                                       this.ctx.fillText(label, xValue, labelStartY);
+                                                       if (label) {
+                                                               this.ctx.fillText(label, xValue, labelStartY);
+                                                       }
                                                }, this);
                                        }
                                } else {