Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to set the horizontal origin of transformation of IText using FabricJS?
In this tutorial, we are going to learn how to set the horizontal origin of transformation of IText using FabricJS. The IText class was introduced in FabricJS version 1.4, extends fabric.Text and is used to create IText instances. An IText instance gives us the freedom to select, cut, paste or add new text without additional configurations. There are also various supported key combinations and mouse/touch combinations which make text interactive which are not provided in Text. Textbox, however, which is based on IText allows us to resize the text rectangle and wraps lines automatically. This is not true for ...
Read MoreFabricJS – Check if a Polygon Object is Fully Contained within Another Object?
We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. We use the isContainedWithinObject method to find whether a polygon object is fully contained within the area of another object. This method returns a boolean value indicating if the polygon is completely inside the boundaries of another fabric object. Syntax isContainedWithinObject(other: Object, ...
Read MoreGroup a JavaScript Array
Grouping JavaScript arrays by a specific property is a common requirement when working with complex data structures. In this tutorial, we'll learn how to group array elements by the tableName property and restructure the data. Problem Statement Suppose we have a JavaScript array with objects containing table data: const data = [ { "dataId": "1", "tableName": "table1", "column": "firstHeader", "rows": ...
Read MoreGroup a sorted array based on the difference between current and previous elements in JavaScript
In JavaScript, grouping a sorted array based on the difference between consecutive elements is a common problem where we need to create separate groups whenever the difference exceeds a certain threshold (typically 1). This technique is useful for analyzing sequences and identifying continuous ranges in data. Understanding the Problem Given a sorted array, we need to group elements where consecutive elements have a difference of 1 or less. When the difference between current and previous elements exceeds 1, we start a new group. For example, the array [1, 2, ...
Read MoreCounting the number of IP addresses present between two IP addresses in JavaScript
We are required to write a JavaScript function that takes in two IPv4 addresses, and returns the number of addresses between them (including the first one, excluding the last one). This can be done by converting them to decimal and finding their absolute difference. How IP Address Conversion Works An IPv4 address consists of 4 octets (0-255). To convert to decimal, we use the formula: IP: a.b.c.d converts to: Decimal = a×256³ + b×256² + c×256¹ + d×256⁰ Example: 20.0.0.10 = 20×16777216 + 0×65536 + 0×256 + 10×1 ...
Read MoreRearranging cards into groups in JavaScript
We are required to write a JavaScript function that takes in an array of numbers, arr, as the first argument and a number, num, as the second argument. The numbers in the array are in the range [1, 13], limits inclusive, representing the 1-based index of playing cards. Our function should determine whether there exists a way to rearrange the cards into groups so that each group is size num, and consists of num consecutive cards. Problem Example For example, if the input to the function is: const arr = [1, 4, 3, 2]; ...
Read MoreHow to create a canvas with a background color using FabricJS?
In this article, we are going to create a canvas with a given background color using FabricJS. The default background color provided by the FabricJS API is white and it can be customized using the backgroundColor option. Syntax new fabric.Canvas(element: HTMLElement|String, { backgroundColor: String }: Object) Parameters element − This parameter is the element itself which can be derived using document.getElementById() or the id of the element itself. The FabricJS canvas will be initialized on this element. ...
Read MoreHow to set the border opacity of a Circle while moving using FabricJS?
In this tutorial, we are going to set the border opacity of Circle while moving using FabricJS. Circle is one of the various shapes provided by FabricJS. In order to create a circle, we will have to create an instance of fabric.Circle class and add it to the canvas. We can change the opacity of circle while moving it around in the canvas by using the borderOpacityWhenMoving property. Syntax new fabric.Circle({ borderOpacityWhenMoving: Number }: Object) Parameters options (optional) − This parameter is an ...
Read MoreHow to maintain stroke width of a Triangle while scaling using FabricJS?
In this tutorial, we are going to learn how we can maintain the stroke width of Triangle while scaling using FabricJS. By default, the stroke width increases or decreases with respect to the object's scale values. However, we can disable this behaviour by using the strokeUniform property. Syntax new fabric.Triangle({ strokeUniform: Boolean }: Object) Parameters Options (optional) − This parameter is an Object which provides additional customizations to our triangle. Using this parameter, properties such as colour, cursor, stroke width, and a lot ...
Read MoreHow to set the offset amount for text path in IText using FabricJS?
In this tutorial, we are going to learn about how to set the offset amount for text in IText using FabricJS. The IText class was introduced in FabricJS version 1.4, extends fabric.Text and is used to create IText instances. An IText instance gives us the freedom to select, cut, paste or add new text without additional configurations. There are also various supported key combinations and mouse/touch combinations which make text interactive which are not provided in Text. Textbox, however, which is based on IText allows us to resize the text rectangle and wraps lines automatically. This is not true ...
Read More