Archive for the ‘Adobe AIR’ Category

Hide Chart Elements

Sunday, August 24th, 2008

First of all, a visual chart, generated via Flex-Charting framework, is constructed with many layers of elements. They are series(data) layer, axis layer, background elements and annotation elements. Besides, you are able to create your own chart elements by implementing IChartElement2 interface.

Here are some quick tips:

  • To kill the grid lines behind charts:
    backgroundElements=[]
  • To make the grid lines drawn with larger interval:
    GridLines#horizontalChangeCount = larger_number;
  • hide elements of axises
    AxisRenderer#showLabels = false;
    AxisRenderer#showLine = false;
    AxisRenderer#tickPlacements = "none";

提昇Flex圖表效能

Friday, July 25th, 2008

提昇Flex圖表元件 (Charting Components) 的效能,當你遇到圖表元件的繪製速度慢到想殺人的時候,建議你先從資料開始檢查,再看看圖表元件本身。

  • 如果可以,移除掉圖表效果,像是陰影
    ChartBase.seriesFilters=[]

  • 圖表的data-provider別餵太複雜的物件,尤其是很肥大的XML應該盡量避免,真的必要,可以作adapter物件來繪製之。
  • 當需要畫出很多條不同的資料線時,不要來一筆資料餵一次series (chartBase.series),能的話,讀完了再一次餵,因為一旦執行
    ChartBase.series = your_new_series_list

    會逼迫ChartBase重繪*所有的*的視覺元件,包含標籤、矩陣線、圖表線、軸線…等,很恐怖唷!尤其是你的資料又長到個不行時,老闆不開心、自己也難過。

  • 作線性圖( Line Chart )時,別輕易地變更線的樣式,尤其”form”, “miter”, “joint”這幾個,你可以看看官方的原始碼,對於這些屬性有非常不同的繪製演算法。用預設值吧,我相信Flex開發團隊已經先最佳化過了。
  • Gutter (gutter top, left, right, bottom) 能的話先給預設值,可以省下運算時間
  • 小心使用軸線的單位(unit),針對你的資料多寡,給予適當的單位值,如果你的資料有一千年,把單位切成秒數就不是個明智的作法。

以下是本文的英文版:

Enhance Flex Charting Components Performance

  • Clear the beautiful shadows or any other filters.
    ChartBase.seriesFilters=[]
  • Optimize your data objects to be rendered. Do not pass a bunch of huge, complex objects to the data-provider.
  • While building a line chart, do NOT change the lineStroke attributes such as “miter”, “joint” if not necessary. Flex Data-Visualization components has optimized the drawing performance to default renderers. To change these attributes may bring up a terrible risk.
  • You can remove the grid lines.
  • Set explicit gutter values while defining a chart base object.
  • If you have to render multiple series in a single chart, try to finish loading all data-providers before you assign series list to chart. Calling this method:
    ChartBase.series = your_list

    will force the chart to remove *ALL* chart elements( label, grid, axis, series items…) and re-create them. It is really time consuming to refresh the chart if re-assign the series objects again and again.

  • Set a lower quality of your flash movie( not available for AIR)
  • Mind your axis units. Be very careful while showing up a time-based data set. It is very possible to be the key to skew up your chart performance if the unit is set too small. Given an appropriate unit is highly recommended.

SQLite語法列表

Tuesday, July 22nd, 2008

寫AIR要用SQLite,可惜手冊上沒寫SQL syntax,加上我不會寫SQL,只有去找官方的語法了,如下:
SQL As Understood By SQLite

HTML與AIR之間的溝通

Wednesday, April 23rd, 2008

首先要熟記這張圖:

還有重要的官方注腳:
The JavaScript environment has its own Document and Window objects. JavaScript code can interact with the AIR run-time environment through the runtime, nativeWindow, and htmlLoader properties. ActionScript code can interact with the JavaScript environment through the window property of an HTMLLoader object, which is a reference to the JavaScript Window object. In addition, both ActionScript and JavaScript objects can listen for events disptached by both AIR and JavaScript objects.

例子: (在JS中讓AIR的native window發出事件)
[js]
//似乎不能用自定事件, 可惜可惜,
//不然就可以直接利用事件處理把資料傳遞到AIR runtime了
var e = new air.Event(”foobar”);
window.nativeWindow.dispatchEvent( e );
[/js]

例子2: ( 在AIR中監聽 Javascript DOM 事件)
[as]
//只能監聽DOM預設事件//
HTML#htmlLoader.window.document.addEventListener(”click” , onClick );
[/as]

例子3: ( sandbox bridge , 取得不同sandbox的資料)
[js]
//在child html定義bridge
var interface = {};
interface.foobar = “blahblah….”;
window.childSandboxBridge = interface;
[/js]

[js]
//parent html裡頭, 取得定義好的bridge
var childInterface = {};
childInterface = document.getElementById(”myDIV”).contentWindow.childSandboxBridge;
air.trace( childInterface.foobar )
//as console output: blahblah…//
[/js]

速記: Javascript@AIR

Wednesday, April 23rd, 2008

安全性解釋文件
AIR 是個跨越各種環境的應用程式,看起來很簡單,要處理的事情多很多,目前第一個遇到的問題: sandbox
sandbox 像是程式碼的“活動空間“,基本上處於不同活動空間的程式碼理當無法互相溝通,但是,必要的時候,要想辦法讓他們可以交流, ex:
sandboxBridge
sandboxRoot, documentRoot…

有關在AIR使用Javascript有一個先天上的限制,
官方手冊提到:

Loading script files from outside the application sandbox is not permitted. No security error is generated. All script files that run in the application sandbox must be installed in the application directory. To use external scripts in a page, you must map the page to a different sandbox.

想利用js作為mash-up的根基,需要許多sandbox溝通和對照的程式碼。