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

Needle overrun #16

Open
HeiDJ65 opened this issue Oct 18, 2015 · 0 comments
Open

Needle overrun #16

HeiDJ65 opened this issue Oct 18, 2015 · 0 comments

Comments

@HeiDJ65
Copy link

HeiDJ65 commented Oct 18, 2015

When the angle between two values exceeds 180, the needle transition covers the area outside the gauge. This can be prevented by something like

         var lastAngle = 0;
         var onValueChanged = function (pValue, pPrecision, pValueUnit) {
             if (typeof pValue === 'undefined' || pValue == null) return;

             if (needle && pValue >= minLimit && pValue <= maxLimit) {
                 var needleAngle = getNewAngle(pValue);
                 var diff = needleAngle - lastAngle; //avoid overrun
                 lastAngle = needleAngle;
                 var n = needle, t = transitionMs;
                 if (Math.abs(diff) >= 180) {
                     t = transitionMs / 2;
                     n = needle.transition()
                         .duration(t)
                         .ease('linear')
                         .attr('transform', 'rotate(' + (needleAngle - diff / 2) + ')');
                 }
                 n.transition()
                     .duration(t)
                     .ease('bounce-in')
                     .attr('transform', 'rotate(' + needleAngle + ')');
                 svg.selectAll('.mtt-graduationValueText')
                 .text('[ ' + pValue.toFixed(pPrecision) + pValueUnit + ' ]');
             } else {
                 svg.selectAll('.mtt-graduation-needle').remove();
                 svg.selectAll('.mtt-graduationValueText').remove();
                 svg.selectAll('.mtt-graduation-needle-center').attr("fill", inactiveColor);
             }
         };

With other words - splitting the transition in two and making sure that the intermediate value is inside the range.

Regards,

HeiDJ65

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

1 participant