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

Insert additional text after the subText. #45

Open
mota57 opened this issue Apr 28, 2017 · 0 comments
Open

Insert additional text after the subText. #45

mota57 opened this issue Apr 28, 2017 · 0 comments

Comments

@mota57
Copy link

mota57 commented Apr 28, 2017

image

I was trying to insert text after the property "subText.text". In this case you can see that the value of this property is 'restantes' but if I want to add additional text that will not move and will stick to it, no matter the screen size I had to write a directive as follows. My question here...is there any standard way to do this?

I had the jsfiddle that shows that it works !! but is not a testable. I hope you guys let me know if my question is wrong and if it is please provide proper feedback.

export function KnobFormat($injector: any): angular.IDirective {

    return {
        restrict: 'A',
        link: function(scope: any, element: any, attrs: any){

            var svg = element.find('svg')[0];
            var $jq = angular.element; 
            var rows = $jq(element).find('text');
            var $filter = $injector.get('$filter')('filter');

            let pattern = {id: ''};
            var elements = $filter(rows, pattern, (a: any, e: any) => {  return (a !== 'text') ? true : false; });

            $jq(elements).css('font-size', '14px');
            $jq(elements).css('dominant-baseline', 'central');



            var text = svg.getElementsByClassName('sub-text')[0];
           

            var transform =  text.getAttribute('transform');
            var index1 = transform.indexOf('(') + 1;
            var index2 = transform.indexOf(')');
            var vals = transform.substring(index1, index2).split(',').map((n: string) => { return parseInt(n); });
            var x = vals[0];
            var y = vals[1] + 18;
            
            var newElement = document.createElementNS('http://www.w3.org/2000/svg', 'text');
            newElement.setAttribute('id', 'knob-text');
            newElement.setAttribute('class', 'sub-text');
            newElement.setAttribute('text-anchor', 'middle');
            newElement.setAttribute('font-size', 'bold italic large serifpx');

            var translate = 'translate(' + x + ',' + y + ')';
            newElement.setAttribute('transform', translate);
            newElement.style.fontSize = '12px';
            newElement.style.dominantBaseline = 'central';

            newElement.textContent = attrs.note;

            text.insertAdjacentElement('afterend', newElement);
        }
    };
}

@mota57 mota57 closed this as completed May 5, 2017
@mota57 mota57 reopened this May 5, 2017
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