The size of the SVG <g> element remains zero even though it contains children

I inserted some elements into an SVG with one large group. The basic code for the group is as follows:

<svg ng-attr-view-box="{{getViewbox()}}"
     width="100%" height="100%">

    <!-- This will be the global group element I reference below -->
    <g ng-transclude></g>    
</svg>

Right after the page loads, it requests a list of elements (actually several lists) to display and then adds them to the page. Each element looks something like this:

<g class="element-view">
    <circle ng-attr-cx="{{model.x}}"
            ng-attr-cy="{{model.y}}"
            style="fill:blue"
            r="4">
    </circle>
    <path ng-attr-d="....">
    </path>
</g>

In Chrome, sometimes the upper group has zero size despite all elements being correctly loaded and added to the DOM. And nothing is displayed. The second list of elements is not displayed at all, but all the elements are in place, and all <g> elements of the second list also have a size of zero despite child SVG tags properly set with coordinates and sizes.

In Firefox, the global group size is always zero.

Does anyone know why browsers do not set the proper size of the <g> element?

P.S. My guess is that the reason for this could be that the parent element or SVG view-box is initially set to zero and then to some value during the layout setup, and for some reason, the <g> element is not resized afterward. But I'm unsure how to debug this.

Answer №1

If you want to use svg elements in the angular template, make sure to specify the proper template namespace for each template. This can be achieved by using the templateNamespace directive parameter as shown below:

.directive('cuiPluginview', function () {
    return {
        restrict: 'E',
        templateUrl: '/components/views/module/view.html',
        templateNamespace: 'svg',
        replace: true,

For more information on this topic, refer to this question: Including SVG template in Angularjs directive

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What allows code to still execute beyond 'return res.send()'

I'm confused as to why the code keeps running even after calling return and res.send(). To gain a better understanding, check out this GIST. UPDATE: Thanks to the community's help, I now realize that the issue is that return res.send(); happens ...

JSZip on Repeat: Exploring the Possibilities!

Can JSZip be used to generate multiple zip folders and files in a loop? If so, how can this be accomplished? For example: const JSZip = require("jszip"); const saveAs = require('file-saver'); const fs = require("fs"); for(let i = 0; i < 5; ...

Angular JS does not acknowledge null values

Within my controller, the variable $scope.test is assigned a value from the server. When this value is null, line 1 of the code below prints 'null', however it still enters the else condition. I have attempted to use $scope.test != null and $scop ...

Ways to assign dynamic widths to inner divs within a parent div automatically

I am working with divs <div id='top' > <div id='top-border' > </div> <div id='top-menu' > <jdoc:include type="modules" name="top-menu" style="well" /></div> </div> and adjust ...

Arranging five divs within one main div horizontally with equal margins between them

I am currently working on a website system where I need to place 5 divs within 1 main div horizontally. However, I want the spacing between the 5 divs to be equal and fixed within the main div. Below is how my current page looks: https://i.stack.imgur.com ...

Displaying PDF files on the internet without allowing them to be downloaded

How can I display PDF files on my website without allowing them to be saved or downloaded? Is there a way to prevent browsers from saving or downloading the PDF files? ...

Sending a request from JavaScript to C# methods using AJAX, with no expected response, within an ASP.NET MVC framework

Setting up the Environment: <package id="jQuery" version="3.2.1" targetFramework="net45" /> <package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" /> Recently, I encountered an issue while trying to send a request from one ...

Pass JavaScript variables to a PHP file with the help of AJAX

Hey there, I'm new to developing web-based applications and currently learning about AJAX. I've run into a problem while trying to make an AJAX request with user inputs as variables and fetching the same variables in a PHP file. Below is the code ...

What is causing the extra whitespace on the right side with container-fluid?

Could someone assist me with an issue I'm experiencing when using the container-fluid in Bootstrap? It seems to be leaving some space on the right side of my web page, and as a newcomer to Bootstrap, any help would be greatly appreciated. <link ...

Tips for positioning a label at the top of a table row in an asp.net C# application

I am facing an alignment issue in my asp.net page with a table that contains a label and a textbox. Despite trying various methods, the label consistently displays at the bottom of the row. How can I ensure that the label is aligned to either the center or ...

Position the background in CSS according to the class name

There are a total of 8 icons, with 4 in blue and 4 in grey. Therefore, product 1 has both a blue icon and a grey icon. When the user has product 1, they will see the blue icon (with an added class on the container called .gotProduct), and when they don&ap ...

The word "await" is a special reserved keyword used to call functions within an async

Currently utilizing async-await: Whenever the function run invokes findLateastVersion, even though run function is marked as async, an error message pops up stating await is a reserved word. The findLateastVersion method returns a promise and based on va ...

Resetting CSS animations in Vue is a simple process that can be achieved

Here is a sample list: var v = new Vue({ 'el' : '#app', 'data' : { 'list' : [1,2,3,4,5,6,7,8,9,10] }, methods: { activateClass($event){ $event.target.classList.remove('animate'); ...

JavaScript array does not support iteration

Last night, I encountered an unusual issue while working with a basic JavaScript array. In my React Native app connected to Firebase's real-time database through the SDK, I came across something unexpected. Here's the piece of code: var app ...

How can we ensure that href/src values are "absolutized" when utilizing server rendering?

Imagine having an element with its href/src set as a root path like this: href="/abc/def". There is also a function written like this: function absolutizeHREF(href) { const URLBase = new URL(`http://${process.env.HOST}:${process.env.PORT}/`); ...

Attempting to eliminate the parent container of a slide generated by the Slick Slider Plugin

I have developed a filter mechanism that hides specific classes within a slick slider based on the data-tag associated with the objects and the value of checkboxes. However, when these classes are hidden, they still occupy space because I should be hiding ...

Troubleshooting: My Bootstrap collapse navbar refuses to cooperate

Hi there! I'm working on creating a responsive navbar with Bootstrap, but I'm having trouble getting the collapse feature to work. Can someone please assist me? Here are the lines of code I have: <nav class="navbar navbar-expand-md navba ...

Halt the adhesion of the Bootstrap column when it hits the div section

I have a simple bootstrap row containing two columns: <div class="row"> <div class="col-xs-7"> <p>Walking together</p> </div> <div class="col-xs-5" id="stay"> <p>Joyful journey</p> </div ...

text breaks free from the flex container when zooming in

Hi, I am attempting to design a user card-type div that includes images on the left and the username on the right. I have managed to create the layout, but when zooming in, the text is overflowing and escaping the flex container. Here is my code snippet. Y ...

Update the blue glow effect on checkbox inputs within Bootstrap 4 to create a unique visual experience

This query has been asked repeatedly, and I have exhaustively attempted numerous solutions. Here is my code snippet: <div class="btn-group" id="btn-container" data-toggle="buttons"> <label class="btn classic-design"> <input type ...