CN111240675B - Multi-terminal drawing method based on Canvas API - Google Patents
Multi-terminal drawing method based on Canvas API Download PDFInfo
- Publication number
- CN111240675B CN111240675B CN202010027928.4A CN202010027928A CN111240675B CN 111240675 B CN111240675 B CN 111240675B CN 202010027928 A CN202010027928 A CN 202010027928A CN 111240675 B CN111240675 B CN 111240675B
- Authority
- CN
- China
- Prior art keywords
- terminal
- native
- canvas api
- canvas
- command set
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/38—Creation or generation of source code for implementing user interfaces
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Human Computer Interaction (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Image Generation (AREA)
Abstract
The invention discloses a multi-terminal drawing method based on Canvas API, which draws by calling the drawing method defined by Canvas API, simultaneously generates a plurality of drawing logics, then converts the drawing logics into corresponding drawing commands, constructs command sets by all the drawing commands, and finally transmits the command sets to a native terminal so as to enable the native terminal to draw and complete drawing according to the command sets.
Description
Technical Field
The invention relates to the technical field of data processing, in particular to a multi-terminal drawing method based on Canvas API.
Background
The real Native framework is an open source framework developed and used by Facebook corporation to write Native mobile applications based on JavaScript and real. The basic UI component used by the real Native is completely consistent with the Native application, so that a set of codes can be developed into iOS and Android multi-terminal applications simultaneously.
A chart is an expression of data visualization associated with various graphics. In securities APP, various financial products, stock quotation K lines and securities analysis products are displayed by charts.
Canvas API is a Web development technology, and the method and implementation specification of graphics rendering are defined by W3C (World Wide Web Consortium ). The Canvas API focuses mainly on 2D graphics, defining various graphics rendering methods. Drawing using Canvas API is a way to write imperative code and calls.
In the real Native framework, for the technical choice of complex charts, there are mainly two common schemes that can select WebView and Native end component schemes, and the WebView scheme uses a Web chart library to draw charts in Web pages, and then uses WebView to display the Web pages in the real Native framework. The method is simple, and the Web mature chart library such as echarts, highCharts and the like can be directly used after being packaged by a WebView component. The original terminal (iOS and Android) scheme is that the Android and the iOS terminal respectively realize the chart function, so that the JS terminal directly calls and displays.
However, the two common solutions have the following technical problems:
(1) Although the WebView scheme has low use cost, the WebView scheme has the performance problems of low first loading speed, high memory occupation and the like because of loading and analyzing the webpage.
(2) The scheme of the original terminal implementation needs to write codes at two ends to be respectively responsible for drawing logic, and has high development and maintenance cost.
Disclosure of Invention
The embodiment of the invention aims to provide a multi-terminal drawing method based on Canvas API, which can improve drawing performance and usability and reduce development and maintenance cost.
In order to achieve the above object, an embodiment of the present invention provides a multi-terminal drawing method based on Canvas API, including the steps of:
calling a drawing method defined by a Canvas API to draw, and generating a plurality of drawing logics at the same time;
converting the drawing logics into corresponding drawing commands, and constructing a command set by using all the drawing commands;
transmitting the command set to a native terminal, so that the native terminal triggers view drawing and completes drawing according to the command set.
Further, the drawing command includes a drawing method and drawing parameters.
Further, after receiving the command set, the originating terminal calls a corresponding Canvas API method to complete drawing by adopting a reflection dynamic call technology according to a drawing method and drawing parameters in the command set.
Further, data transmission is performed with the native terminal through React Native bridge.
Further, the native terminal comprises an iOS terminal and an Android terminal.
Further, the iOS terminal triggers view drawing and completes drawing through a Core Graphics graphic drawing library.
Further, the Android terminal triggers view drawing and completes drawing through a graphics Canvas graphic drawing package.
The embodiment of the invention has the following beneficial effects:
the invention provides a multi-terminal drawing method based on Canvas API, which draws by calling the drawing method defined by Canvas API, simultaneously generates a plurality of drawing logics, then converts the drawing logics into corresponding drawing commands, constructs command sets by all drawing commands, and finally transmits the command sets to a native terminal, so that the native terminal can trigger the drawing of a view and complete drawing according to the command sets.
Compared with the prior art, the embodiment provided by the invention has the following advantages:
(1) Performance aspects: compared with a WebView chart drawing method, the embodiment provided by the scheme is characterized by less memory use and stable FPS at the iOS end, and is changed into a CPU with low use rate, less memory use and ideal performance at the Android end.
(2) Ease of use: the Canvas API of the Web development technical standard is realized, the graph library mature at the Web end is compatible, and the graph drawing logic realized at the JS end can be realized by using the existing graph library, so that the use cost is reduced.
(3) Development and maintenance costs: drawing business logic is only needed to be realized at the JS end, business logic is not needed to be realized at the original end, and development and maintenance cost is reduced.
Drawings
FIG. 1 is a flow chart of one embodiment of a Canvas API-based multi-port drawing method provided by the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Referring to fig. 1, fig. 1 is a schematic flow chart of an embodiment of a multi-terminal drawing method based on Canvas API according to the present invention.
As shown in fig. 1, the multi-terminal drawing method based on Canvas API includes steps S1 to S3, and the steps are as follows:
s1, calling a drawing method defined by a Canvas API to draw, and generating a plurality of drawing logics.
As a preferred embodiment of the invention, the invention uses Canvas API method to realize drawing logic of specific graph such as line graph.
S2, converting the drawing logics into corresponding drawing commands, and constructing a command set by using all the drawing commands.
As a preferred embodiment of the present invention, the drawing command includes a drawing method and drawing parameters, wherein the drawing parameters are specific information of color, coordinates, and the like.
It should be noted that these drawing commands are composed of corresponding method names and method parameters. Such as invoking a rendering method transform (50, 50), commands such as { "method": "transform", "parameters": [50,50] } are generated and added to the command set.
And S3, transmitting the command set to a native terminal, so that the native terminal triggers view drawing and completes drawing according to the command set.
As a preferred embodiment of the invention, after receiving the command set, the native terminal adopts a reflection dynamic calling technology to call a corresponding Canvas API method to complete drawing according to a drawing method and drawing parameters in the command set.
In this embodiment, the data transmission is performed with the native terminal through React Native bridge, so that the command set can be transmitted to the native terminal.
Preferably, the native terminal comprises an iOS terminal and an Android terminal, the iOS terminal triggers the drawing of the view and completes the drawing through a Core Graphics drawing library, and the Android terminal triggers the drawing of the view and completes the drawing through a Graphics Canvas Graphics drawing package.
In order to better illustrate the multi-terminal drawing method provided by the invention, the following is the working principle of the method of the invention: firstly, calling Canvas API methods through a JS end to draw, converting the methods into drawing commands, then transmitting the commands to a Native end through a communication means 'React Nativebridge' provided by a real Native, and calling the Canvas API drawing methods realized by the Native end to draw after the Native end receives the commands, thereby completing drawing of graphics.
In summary, the multi-terminal drawing method based on Canvas API provided by the invention draws by calling the drawing method defined by Canvas API, simultaneously generates a plurality of drawing logics, converts the drawing logics into corresponding drawing commands, constructs command sets by all drawing commands, and finally transmits the command sets to the original terminal, so that the original terminal can trigger the drawing of the view and complete the drawing according to the command sets.
Compared with the prior art, the embodiment provided by the invention has the following advantages:
(1) Performance aspects: compared with a WebView chart drawing method, the embodiment provided by the scheme is characterized by less memory use and stable FPS at the iOS end, and is changed into a CPU with low use rate, less memory use and ideal performance at the Android end.
(2) Ease of use: the Canvas API of the Web development technical standard is realized, the graph library mature at the Web end is compatible, and the graph drawing logic realized at the JS end can be realized by using the existing graph library, so that the use cost is reduced.
(3) Development and maintenance costs: drawing business logic is only needed to be realized at the JS end, business logic is not needed to be realized at the original end, and development and maintenance cost is reduced.
Those skilled in the art will appreciate that implementing all or part of the above-described methods in accordance with the embodiments may be accomplished by way of a computer program stored on a computer readable storage medium, which when executed may comprise the steps of the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), or the like.
While the foregoing is directed to the preferred embodiments of the present invention, it will be appreciated by those skilled in the art that changes and modifications may be made without departing from the principles of the invention, such changes and modifications are also intended to be within the scope of the invention.
Claims (4)
1. A Canvas API based multi-terminal drawing method comprising the steps of:
calling a drawing method defined by a Canvas API to draw, and generating a plurality of drawing logics at the same time; the drawing logic includes a chart drawn using a Canvas API method;
converting the drawing logics into corresponding drawing commands, and constructing a command set by using all the drawing commands; the drawing command comprises a drawing method and drawing parameters;
transmitting the command set to a native terminal, so that the native terminal triggers view drawing and completes drawing according to the command set; data transmission is carried out with the original terminal through React Native bridge;
and after receiving the command set, the native terminal calls a corresponding Canvas API method to complete drawing by adopting a reflection dynamic call technology according to a drawing method and drawing parameters in the command set.
2. The Canvas API-based multi-terminal drawing method according to claim 1, wherein the native terminal comprises an iOS terminal and an Android terminal.
3. The multi-terminal drawing method based on Canvas API according to claim 2, wherein the iOS terminal triggers the drawing of the view and completes the drawing through the Core Graphics drawing library.
4. The Canvas API-based multi-terminal drawing method according to claim 2, wherein the Android terminal triggers view drawing and completes drawing through a graphics Canvas graphic drawing package.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010027928.4A CN111240675B (en) | 2020-01-10 | 2020-01-10 | Multi-terminal drawing method based on Canvas API |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010027928.4A CN111240675B (en) | 2020-01-10 | 2020-01-10 | Multi-terminal drawing method based on Canvas API |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111240675A CN111240675A (en) | 2020-06-05 |
CN111240675B true CN111240675B (en) | 2023-07-25 |
Family
ID=70870904
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010027928.4A Active CN111240675B (en) | 2020-01-10 | 2020-01-10 | Multi-terminal drawing method based on Canvas API |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111240675B (en) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114064017B (en) * | 2020-08-04 | 2024-08-30 | 腾讯科技(深圳)有限公司 | Drawing method and related equipment |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2012079049A1 (en) * | 2010-12-10 | 2012-06-14 | Wyse Technology Inc. | Methods and systems for facilitating a remote desktop session utilizing a remote desktop client common interface |
CN107749843A (en) * | 2017-10-13 | 2018-03-02 | 北京中教在线科技有限公司 | A kind of electronic drawing board sharing method |
CN110018812A (en) * | 2018-01-08 | 2019-07-16 | 搜游网络科技(北京)有限公司 | A kind of pattern drawing method and device |
CN110475141A (en) * | 2019-08-29 | 2019-11-19 | 深圳市网心科技有限公司 | Video broadcasting method, system and electronic equipment and storage medium based on RN |
-
2020
- 2020-01-10 CN CN202010027928.4A patent/CN111240675B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2012079049A1 (en) * | 2010-12-10 | 2012-06-14 | Wyse Technology Inc. | Methods and systems for facilitating a remote desktop session utilizing a remote desktop client common interface |
CN103403695A (en) * | 2010-12-10 | 2013-11-20 | 韦斯技术有限公司 | Methods and systems for facilitating a remote desktop session utilizing a remote desktop client common interface |
CN107749843A (en) * | 2017-10-13 | 2018-03-02 | 北京中教在线科技有限公司 | A kind of electronic drawing board sharing method |
CN110018812A (en) * | 2018-01-08 | 2019-07-16 | 搜游网络科技(北京)有限公司 | A kind of pattern drawing method and device |
CN110475141A (en) * | 2019-08-29 | 2019-11-19 | 深圳市网心科技有限公司 | Video broadcasting method, system and electronic equipment and storage medium based on RN |
Also Published As
Publication number | Publication date |
---|---|
CN111240675A (en) | 2020-06-05 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8988434B1 (en) | Text rendering for browsers and mobile based applications | |
CN106886544A (en) | A kind of data processing method and device | |
JP7538948B2 (en) | Image processing method and apparatus, and computer-readable storage medium | |
CN105094786A (en) | Method and system for customizing page based on JavaScript | |
US8656055B2 (en) | Protocol wrapper and serializer/deserializer for facilitating data exchanges | |
CN109254771A (en) | A kind of monitoring page generation method and device | |
US11004170B2 (en) | Converting flash content to HTML content by generating an instruction list | |
CN106354355A (en) | User interface layout method, device and system | |
CN107122398A (en) | A kind of data display chart generation method and system | |
CN112417343B (en) | Method for caching data based on front-end Angular frame | |
CN113110829B (en) | Multi-UI component library data processing method and device | |
CN111240675B (en) | Multi-terminal drawing method based on Canvas API | |
CN111476006B (en) | PDF file online annotation method, device, equipment and readable storage medium | |
CN117076811A (en) | Webpage export method, device, equipment and storage medium | |
CN107562325A (en) | The cursor accelerated method and system of cursor software are carried in a kind of virtual machine | |
KR101580605B1 (en) | Graphic model architecture with output method for fast output mobile application based HTML5 WebGL | |
CN112614210B (en) | Engineering drawing display method, system and related device | |
CN113760438A (en) | Page display method and device for webpage application | |
CN116049599A (en) | Self-adaptive rendering method, system and storage medium of data visualization page | |
CN109918598B (en) | Web page rendering method based on Android television browser | |
CN116579296A (en) | B/S architecture electronic document preview processing method, device, medium and equipment | |
CN115391692A (en) | Video processing method and device | |
CN113849164A (en) | Data processing method and device, electronic equipment and memory | |
CN115329720A (en) | Document display method, device, equipment and storage medium | |
CN106569816A (en) | Rendering method and apparatus |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |