The Canvas widget behaves as a drawing board that allows you to draw shapes such as circles, polygons, lines, etc. on your app. Currently, you can only use Canvas widget to draw lines.
You can create Canvas widget only by using code.
You can draw shapes in a Canvas widget by using the shapesData property. In addition, you can append or remove multiple shapes in the Canvas widget by using the addShapes and removeShapes methods. Furthermore, you can update the configurations of the shapes by using the updateShapes method. You can also delete all the shapes that you have created in the Canvas widget by using the clear method.
The functionalities that can be implemented by using Canvas widget are as follows:
This property helps you access the parent of a Canvas widget.
Canvas Widget Basics
Canvas widget helps you to draw shapes such as lines (in any orientation), circles, and rectangles in your application.
Some real-world scenarios where you can use a Canvas widget are as follows:
To use as a line separator when a list of items is mentioned.
To display more than one focal point on a web-page, use dashed/ dotted lines to divide the page.
To highlight a feature newly introduced in an app such as coupons, and updates.
Create a Canvas Widget
You can create a Canvas widget is created by using a constructor with the following attributes.
basicConf: A JavaScript object that contains the basic properties of Canvas widget, including the shapesData property.
layoutConf: A JavaScript object that contains the layout properties of Canvas widget.
pspConf: A JavaScript object that contains the platform-specific properties of Canvas widget.
Example
// Sample code to create a Canvas widget with a red-dashed line.var basicConf ={"height":"200px","id":"canvasWidgetRef","isVisible":true,"left":"10%","skin":"skinCanvas","top":"10%","width":"200px","zIndex":1,//Code to add the configuration of the shape with shapeid:shape1. "shapesData":[{"shapeid":"shape1","shapeType": kony.canvas.SHAPE_TYPE_LINE,"lineStyle": kony.canvas.LINE_STYLE_DASHED,"lineStyleConfig":["1px","1px"],"thickness":"2px","points":[["10px","10px"],["100px","10px"]],
strokeColor:"ff000000",}]};var layoutConf ={"marginInPixel":false,};var pspConf ={};//Creating the Canvas widgetvar canvas =new kony.ui.Canvas(basicConf, layoutConf, pspConf);