Custom Elements Documentation
Getting Started
jqxDraw is a HTML Element which drawing svg, html5 and vml programming interface.Every UI element from jQWidgets toolkit needs its JavaScript files to be included in order to work properly.
The first step is to create html page and add links to the javascript files and
css dependencies to your project.
The jqxDraw element requires the following
files:
The next step is to add the html element within the body of the html page.<script type="text/javascript" src="../scripts/webcomponents-lite.min.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxcore.elements.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxdata.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxdraw.js"></script>
The last step is to initialize the element settings:<jqx-draw settings="elementSettings"></jqx-draw>
To call a function(method), you need to pass the method name and parameters(if any) in the jqxDraw's instance.<script type="text/javascript">
JQXElements.settings["elementSettings"] =
{
renderEngine:"HTML5"
}
</script>
To get the result of a function after calling it, you can use the following syntax:<script>
window.onload = function () {
var element = document.querySelector("jqx-draw");
element.attr(element, { fill: 'lightblue', stroke: 'darkblue' });
}
</script>
To set a property(option), you need to use the property name and value(s) along with the jqxDraw's instance.<script>
window.onload = function () {
var element = document.querySelector("jqx-draw");
var result = element.circle();
}
</script>
You can also set properties of HTML Elements by using Attributes. Traditionally, attributes are used to set the initial state of an element. Properties with camelCase naming have dash-based attributes. For example: A property "dataSource" will have an attribute called "data-source".window.onload = function() {
document.querySelector("jqx-draw").renderEngine = '''';
}
To get a property(option), you need to use the property name along with the jqxDraw's instance.
window.onload = function() {
var propertyValue = document.querySelector("jqx-draw").renderEngine;
}
Event binding can be defined in the HTML as an attribute. The syntax is: 'on-' and the event's name. Event Names with camelCase naming have dash-based attributes. The attribute's value is the event handler's name. The addEventListener
function can also be used for event binding.
{{EVENTEXAMPLE}}
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title id='Description'>Draw Custom Element Overview</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1 minimum-scale=1" />
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
<link rel="stylesheet" href="../../styles/demos.css" type="text/css" />
<script type="text/javascript" src="../../scripts/webcomponents-lite.min.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script><script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script><script type="text/javascript" src="../../jqwidgets/jqxcore.elements.js"></script><script type="text/javascript" src="../../jqwidgets/jqxdraw.js"></script><script type="text/javascript">JQXElements.settings["drawSettings"] ={renderEngine:"HTML5"}window.onload = function () {var renderer = document.querySelector('jqx-draw').getInstance();var size = renderer.getSize();// create a circle// params: cx, cy, radius, paramsvar circleElement = renderer.circle(250, 150, 50, {});// set the fill color and border color of the circle// params: element, attributesrenderer.attr(circleElement, { fill: 'lightblue', stroke: 'darkblue' });// draw a path// params: line command, attributesvar pathElement = renderer.path("M 100,100 L 150, 130 C 130,130 180,190 150,150", { stroke: '#777777', fill: 'red' });// draw an area// params: line command, attributesvar areaElement = renderer.path("M 300,300 L 350, 330 C 330,330 380,390 350,350 Z", { stroke: '#777777', fill: 'yellow' });// draw a line// params: x1, y1, x2, y2, attributesrenderer.line(600, 100, 600, 200, { stroke: 'blue', 'stroke-width': 6 });renderer.line(550, 50, 650, 90, { stroke: 'green', 'stroke-width': 6 });// draw text// params: text, x, y, width, height, angle, params, clip, halign, valign, rotateAroundrenderer.text("Drawing shapes", 50, 20, undefined, undefined, 0, { 'class': 'largeText', fill: 'yellow', stroke: 'orange' }, false, 'center', 'center', 'centermiddle');renderer.text("This is rotated text", 600, 300, undefined, undefined, 45, { 'class': 'smallText' }, false, 'center', 'center', 'centermiddle');// add an event handler to the circle elementvar circleUp = renderer.circle(50, 450, 30, { fill: '#DEDEDE', stroke: '#777777' });var pathUp = renderer.path("M30 460 L 70 460 L50 430 Z", { fill: 'transparent', stroke: '#777777', 'stroke-width': 1 });var circleDown = renderer.circle(120, 450, 30, { fill: '#DEDEDE', stroke: '#777777' });var pathDown = renderer.path("M100 440 L 140 440 L120 470 Z", { fill: 'transparent', stroke: '#777777', 'stroke-width': 1 });renderer.text("Click these buttons:", 20, 390);var moveCircle = function (moveUp) {var circleY = parseInt(renderer.getAttr(circleElement, 'cy'));renderer.attr(circleElement, { cy: circleY + (moveUp ? -10 : 10) });}renderer.on(circleUp, 'click', function () { moveCircle(true); });renderer.on(pathUp, 'click', function () { moveCircle(true); });renderer.on(circleDown, 'click', function () { moveCircle(false); });renderer.on(pathDown, 'click', function () { moveCircle(false); });renderer.refresh();}</script></head><body><div class="example-description">This demo illustrates the basic functionality of the Draw custom element.</div><jqx-draw settings="drawSettings"></jqx-draw></body></html>