SVG.js relocate group with symbol reference element

Incorporating the SVG.js library into my project, I am currently faced with a challenge. Specifically, I am attempting to shift a group that consists of multiple elements such as rect, text, and one use element in the x-direction:

// creating a symbol; this symbol can take any form
const symbol = svg.symbol().circle(10)  

//creating a group with various elements
const group = svg.group();
const rect = group.rect();
const text = group.plain('some text');
const symbolUse = svg.use(symbol);
group.add(symbolUse);

//at a later point...translate the group to a new x-coordinate (can be anything)
group.x(newX)

Currently, I have successfully managed to move all elements in the group in the desired manner along the x-axis except for the use element. Interestingly, the use element seems to shift not only horizontally but also vertically, which is unintended.

I wonder if this issue arises from a bug within the SVG.js library or if it could potentially be due to a misunderstanding on my part when handling the use element?

Answer №1

If you're looking to achieve this effect, consider using the transform() function.

For more information, visit:

var svg = SVG().addTo('body').size(300, 300)

const symbol = svg.symbol().circle(10)  

//create group with elements
const group = svg.group();
const rect = group.rect();
const text = group.plain('some text');
const symbolUse = svg.use(symbol);
group.add(symbolUse);

// Move the entire group right by 150 units
group.transform({translateX: 150});
<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="601316074e0a1320534e50">[email protected]</a>/dist/svg.min.js"></script>

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

Building a search API with Node.js and MongoDB: A step-by-step guide

I'm currently working on building a search API using nodejs and MongoDB. After doing some research online, I came across a helpful post Building a simple search api. However, when I tried to implement it, I encountered an error that I'm strugglin ...

Organizing Files and Creating Applications with Electron

Recently, I came across Electron and found it to be a fantastic tool for developing desktop applications. I created a basic Twitter Aggregator that functions when I execute nodemon app.js. Now, I want to package it with Atom in order to run it in its own w ...

The selected attribute does not function properly with the <option> tag in Angular

Currently, I am faced with a challenge involving dropdowns and select2. My task is to edit a product, which includes selecting a category that corresponds to the product. However, when I open the modal, the selected group/category is not displayed in the d ...

Embrace the power of npm package within the Nest Framework

Is there a way to integrate the celebrate NPM package with the Nest Framework? The documentation only mentions the use of the class-validator package, but I have experience using the celebrate middleware for request validation in Express and other framew ...

Locate all span elements with a specific class using jQuery and conceal the parent divs further up in

I'm currently attempting to identify a specific span element with a particular class and then move up the DOM to find the closest div with another specified class in order to hide it. Is there something I might be overlooking? Any insights as to why ...

Struggling to find a solution for your operating system issue?

We are currently attempting to utilize the markdown-yaml-metadata-parser package for our project. You can find more information about the package here. Within the package, it imports 'os' using the following syntax: const os = require('os ...

Display a modal as the first screen appears in a React Native application

Trying to implement a non-animating modal before the main screen loads on my react-native app. The goal is to display a login screen in a modal view if no user is logged in. Encountering an issue where the main screen briefly appears before the modal, ins ...

Show all span elements in a map except for the last one

Within my ReactJS application, I have implemented a mapping function to iterate through an Object. In between each element generated from the mapping process, I am including a span containing a simple care symbol. The following code snippet demonstrates t ...

What steps do I need to take in order for TypeScript source files to appear in the node inspector?

Currently developing a node express app with TypeScript 2.3. Compiling using tsc Interested in debugging TypeScript code using node-inspector (now included in node 6.3+) SourceMaps are enabled in my tsConfig.json file { "compilerOptions": { "targ ...

What are the steps to setting up SystemJS with Auth0?

I am having trouble configuring SystemJS for Auth0 (angular2-jwt) and Angular 2.0.0-beta.6 as I keep encountering the following error message: GET http://localhost:3000/angular2/http 404 (Not Found)fetchTextFromURL @ system.src.js:1068(anonymous function) ...

Is it possible for me to scrape an HTML code snippet directly from a browser?

How can I extract specific content from an HTML code block using only JS or jQuery on a browser? Below is the code I am working with: <ul> <li>New York</li> <li>London</li> <li>Madrid</li> <li&g ...

Is $timeout considered a questionable hack in Angular.js development practices?

Here's a question for you: I recently encountered a situation where I needed to edit the DOM on a Leaflet Map in order to manipulate the appearance of the legend. To workaround an issue where the map wasn't generating fast enough to access the n ...

Employ various iterations of the leaflet library

Creating a web application using React and various libraries, I encountered an issue with conflicting versions of the Leaflet library. Currently, I am incorporating the Windy API for weather forecast, which utilizes Leaflet library version 1.4.0. However ...

Unpredictable hue of text

Is it possible to fill text with a combination of 2-3 random colors? ...

Fixing the Bootstrap 4 Modal Hide Issue

Struggling with hiding a modal in bootstrap 4. Within my temporary function, I need to close the modal before utilizing the update_table(url) method. HTML and JS <div class="modal" id="Modal" tabindex="-1" role="dialog"></div> <script src ...

Is there a way to create an input field that accepts only numbers and behaves like a password field simultaneously?

I am attempting to develop an input field for entering a PIN. I would like the PIN to be masked on mobile devices, similar to how passwords are obscured in password input fields. I came across a suggestion on stackoverflow regarding this, but unfortunately ...

Trigger an event when the menu is outside the viewport and then lock the menu to the top of the viewport

I am trying to create a menu element that remains fixed at the top of the browser viewport as the user scrolls, ensuring it is always visible. In my webpage layout, the menu sits below some text in the header initially. Once the user scrolls past the heade ...

Angular 2 i18n: Localization of <option> values

I am in the process of transitioning my application from ng2-translate to native i18n support. I have encountered an issue when trying to translate a <md-select> element with multiple options: <md-select placeholder="Salutation" i18n-placeholder& ...

Make sure that the input for a function is a valid key within a specific interface, and that the corresponding value in the interface is

I'm a beginner in TypeScript and I've hit a roadblock with this issue. Despite searching extensively, I haven't found a solution yet. My goal is to create a well-typed sorting function that takes two parameters: an array of objects and the ...

Ways to integrate object-or-array with recursion in Typescript

I am striving to achieve the following: type Foo = ({bar: string} & Record<string, Foo>) | Foo[] However, I keep encountering issues such as circular references in type or the constraint that An interface can only extend an object type or inte ...