How to include angular JS expressions inside an SVG circle

Sooraj

I have the following html code to create concentric circles.

<div id="delightmeter">

  {{delightScore}}
    <svg width='500px' height='300px' version='1.1' xmlns='http://www.w3.org/2000/svg'>


            <g class=''>


                <circle class='' cx='200' cy='60' r='20'></circle>
                <circle class="" cx='200' cy='60' r='17' ></circle>


        </g>

    </svg>

</div>

I have another JS file in which i do some operations using angular JS and i have the value in a $scope variable. Is there any way to access the variable from the other file and show it inside the svg circle

Update:

'use strict';

angular.module('delightMeterApp', [

])
    .directive('delightMeter', function () {
        function link($scope, $element, $attrs) {


            document.getElementById("arc1").setAttribute("d", describeArc(200, 200, 100, -90, -56));
            document.getElementById("arc2").setAttribute("d", describeArc(200, 200, 100, -54, -20));
            document.getElementById("arc3").setAttribute("d", describeArc(200, 200, 100, -18, 16));
            document.getElementById("arc4").setAttribute("d", describeArc(200, 200, 100, 18, 52));
            document.getElementById("arc5").setAttribute("d", describeArc(200, 200, 100, 54, 90));



            function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
                var angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0;

                return {
                    x: centerX + (radius * Math.cos(angleInRadians)),
                    y: centerY + (radius * Math.sin(angleInRadians))
                };
            }
            /* Function to draw single arcs recieving (start co-ordinateX,start co-ordinateY,radius,start angle, end angle) */
            function describeArc(x, y, radius, startAngle, endAngle) {

                var start = polarToCartesian(x, y, radius, endAngle);
                var end = polarToCartesian(x, y, radius, startAngle);
                var arcSweep = endAngle - startAngle <= 180 ? "0" : "1";
                var d = [
                    "M", start.x, start.y,
                    "A", radius, radius, 0, arcSweep, 0, end.x, end.y
                ].join(" ");
                return d;
            }


            function ScoreRotateNeedle(delightScore) {
                $('.needleset').css({
                    "transform": "rotate(" + delightScore + "deg)",
                    "transform-origin": "50% 95%"
                });
            }

            $scope.$watch('score', function () {
                ScoreRotateNeedle($scope.score);
            });

        }

        return {
            restrict: 'E',
            templateUrl: 'svgmeter.html',
            scope: {
                score: '=ngModel'
            },
            link: link
        };
    })
    .controller('delightMeterController', function ($scope) {
$scope.delightScore = 0;



    })

I need to access the delightScore variable from inside custom directive in my html template.

shivas

I have updated the plunker so that the delight score shows up as text in the SVG.

http://plnkr.co/edit/tWeNjM0H7F6npc2mM9L2?p=preview

Since you already have the value of delightScore in your directives scope called "score" you can use that in your SVG template as {{score}}

    <svg width='500px' height='300px' version='1.1' xmlns='http://www.w3.org/2000/svg'>

    <g>
        <text x='100' y='220' fill='black'>0</text>
        **<text x='195' y='220' fill='black'>{{score}}</text>**
        <text x='300' y='220' fill='black'>100</text>
        <path class='arc' id='arc1' d='' />
        <path class='arc' id='arc2' d='' />
        <path class='arc' id='arc3' d='' />
        <path class='arc' id='arc4' d='' />
        <path class='arc' id='arc5' d='' />
        <g class='needleset'>
            <circle class='needle-center' cx='200' cy='200' r='5'></circle>
            <path class='needle' d='M 195 198 L 200 100 L 205 202'></path>
            <circle class='needle-center' cx='200' cy='200' r='5'></circle>
        </g>
    </g>

</svg>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I place text inside an SVG circle with React JS?

From Dev

How to add a link inside an svg circle

From Dev

SVG image inside circle

From Dev

SVG path inside circle

From Dev

How do I perfectly center a single character inside an SVG circle?

From Dev

How to draw a number centered inside a circle with inline svg?

From Dev

Google Chart Calendar how to mark date with circle inside -svg

From Dev

Find elements inside circle in svg

From Dev

Angular JS: include partial HTML inside another ng-include

From Java

How to rotate svg circle

From Dev

How to center a circle in an svg

From Dev

how to create a half bordered circle(only css, not js or even svg)?

From Dev

Include a png/svg inside a polygon?

From Dev

how to replace text inside an svg using js?

From Dev

How to Include marker in SVG Blinking Rectangular or circle Border image in google maps

From Dev

Trying to center an svg circle inside a div

From Dev

svg draw circle with curved text inside

From Dev

svg draw circle with curved text inside

From Dev

How to change size of SVG circle

From Dev

How to morph a SVG diamond into a circle

From Dev

How to add a circle to svg element

From Dev

How to change the size of circle in svg?

From Dev

How can I display an image inside SVG circle in html5?

From Dev

How to make angular load jquery inside ng-include?

From Java

How to create a circle with text inside

From Dev

How to bound a circle inside an ellipse?

From Dev

How to draw stroke inside a circle?

From Dev

How to include moment.js inside marionette application?

From Dev

Angular 1 how to properly include external component inside ng-include?

Related Related

HotTag

Archive