Applying color to the rotator in a transformer using konva.js

Adding an icon to my transformer rotator is the goal, but first I need to add a fill to understand how it works.

  var rot = transformer.findOne('.rotater');
  console.log(rot); //This code is executing correctly
  rot.fill('orange'); //However, this line is not working. The fill-priority should not be necessary  
  layer.batchDraw();

Answer №1

<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a1cacecfd7c0e1968f918f95">[email protected]</a>
does not provide an API for customizing specific anchors on a Konva.Transformer.

The code you have written may not work as expected, as the Konva.Transformer can reset its style using the internal tr.update() function at any time.

To address this issue, you can override the update method and apply your own styles:

const tr = new Konva.Transformer({
  nodes: [shape]
})

tr.update = function() {
  Konva.Transformer.prototype.update.call(tr);
  var rot = this.findOne('.rotater');
  rot.fill('orange');
}

tr.forceUpdate();

layer.add(tr);

Check out the demo here: https://jsbin.com/lumisacayo/1/edit?html,js,output

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

Expanding the reach of the navigation bar

Hello Everyone, Is there a way to stretch my navigation bar so that the links are evenly spaced out across the browser window instead of being clustered together? I want it to be responsive rather than fixed in size. This is my HTML code: <div class= ...

MongooseServerSelectionError: Connection timed out

Recently, I encountered an issue while attempting to run my Node.js application. An error message popped up stating MongooseServerSelectionError: connect ETIMEDOUT, along with type: 'ReplicaSetNoPrimary'. Surprisingly, everything had been functio ...

AccessMediaStream - camera direction

My current setup involves using an Android tablet and GetUserMedia to capture images in my program. It seems that by default, GetUserMedia uses the front camera. How can I set the rear camera as the default instead? Below is the code snippet I am using w ...

What could possibly be causing my app to exhaust CPU resources on Mozilla Firefox?

I have created a unique game application for Facebook. Currently, the app is not optimized with AJAX technology, resulting in multiple server requests causing high CPU usage (specifically in Firefox) which slows down the overall performance of the app. Alt ...

Executing a script within an ASP.NET MVC Project

Currently, I'm in the process of developing a project in MVC that requires using AJAX to fetch XML from an external source. However, I have encountered a challenge where I am unable to directly make the AJAX call due to a XMLHttpRequest same domain po ...

Custom range-slider in Angular with flexible min/max values

I am currently working with the angular ui-slider and I am looking to dynamically load the min- and max values for the slider from an external source. This will allow me to set them in a structured way, similar to the following: $scope.minMaxValues = { ...

Controller Receives Null Parameter Following an Ajax Request

Let's set the scene: Imagine a user clicks on the Details button, triggering the JavaScript function, getPersonId to fetch the personId as intended. Identifying the problem: Upon selecting the personId, I pass it into an ajax call. The Id is passed ...

Enhance user experience by implementing a feature in AngularJS that highlights anchor

As I am in the process of developing a chat application using Angular, I have encountered an issue with switching between views. One view, named 'chat.html', displays the list of available users while another view, 'chatMessages.html', ...

Although Sequelize has the capability to generate tables, it lacks the ability to perform insertions or selections of data

Currently, I am in the process of developing an express app that incorporates basic MVC functionality with Sequelize. At this stage, my focus is on creating a route to insert a single row of student data into the database. Upon starting the server, Sequel ...

Can config values be dynamically set from an Excel file in Protractor?

I am currently working on parameterizing capabilities using an Excel sheet. For this task, I am utilizing the npm exceljs package for both reading and writing data. Below is a snippet of the code that demonstrates how I am trying to achieve this: //This f ...

Using TypeScript in Node.js to iterate through an asynchronous forEach loop

I attempted to integrate a database operation within an async forEach loop with the following code snippet: let successCounter = 0; let failureCounter = 0; let myData = [101, 102, 104, 105]; myData.forEach(async data => { let response = awai ...

Showing or hiding child content based on the selected state of a radio button

This is a follow-up question from a previous one on changing check boxes to radio buttons. Now, I need to display child radio buttons and change the background color when the parent radio button is active. The child radio buttons should be hidden and the b ...

Refresh page upon clicking the same state link in AngularJS using ui.router

Just received an interesting request from our QA team that seems a bit out there. Let's dive in: imagine you are already on the 'about' state/page within an angular-based app, and when you click on the 'about' state URL again from ...

What is the best way to retrieve data from app.post within react.js?

//server.js app.post('/trip', function(req,res){ var params = "something"; getResult(params).then((db)=>{ // I am trying to access the variable called "db" in my App.js(React) file, but I am unsure of how to do so. res.s ...

Modifying content in Infragistics WebTextEdit using a JavaScript function

Currently, I am utilizing the Infragistics component set for .Net 2.0 in Visual Studio 2005 with C#. Below is a snippet of javascript code (variable declarations are located elsewhere): ***alert(box[select].value); text.value(box[select].value); alert(te ...

Determining the XY position of the wheel data

In my attempt to develop a lucky draw wheel using reactjs, I needed to position all the input data at specific XY coordinates. Below is an example of the expected output XY positions that I require. var renderData = ["1", "2", "3", "4", "5", "6", "7", " ...

Puppeteer refuses to interact with Facebook's cookie banner, no matter the circumstances

I'm currently working on a script that automates the login process for Facebook by loading the website, entering an email and password, and logging in automatically. However, I've run into an issue where a cookie notice pops up after about 0.5 se ...

What are some clever ways to handle the transition of the display property?

While transitions for the display property may not work, I am exploring alternatives. I attempted using the visibility property but it didn't quite fit my needs. In my current setup, different text is displayed when hovering over an anchor tag by sett ...

Encountered an error while using NPM Bootstrap Carousel: Uncaught TypeError - Super expression must be either null or a function

Currently using the NPM build of Bootstrap (with Gulp) for a custom WordPress theme, and I seem to be facing some issues. While I am new to Bootstrap, I have previous experience with WordPress and Gulp (primarily with Foundation). Below is how I am includ ...

Utilizing vue.js router guards with asynchronous user information retrieval

Currently, I am developing a Vue.js application that requires the implementation of router guards to restrict access based on user roles and prevent unauthorized users from accessing the application. The login process involves integrating an external appli ...