Repository: flex-asjs Updated Branches: refs/heads/develop 892fd753b -> e28d38e86
Add new example FlexWebsiteStatsViewer. This examples fetches data from Google Analytics for the website: flex.apache.org, and parses the data into the required format. Then, via data binding, updates the dataprovider for a ColumnChart which renders the data. Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/e28d38e8 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/e28d38e8 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/e28d38e8 Branch: refs/heads/develop Commit: e28d38e8688877793108bc2d49a2eed558ab8996 Parents: 892fd75 Author: OmPrakash Muppirala <[email protected]> Authored: Mon Sep 21 04:16:16 2015 -0700 Committer: OmPrakash Muppirala <[email protected]> Committed: Mon Sep 21 04:16:16 2015 -0700 ---------------------------------------------------------------------- .../flexjs/FlexWebsiteStatsViewer/build.xml | 74 +++++++++++++++++ examples/flexjs/FlexWebsiteStatsViewer/pom.xml | 74 +++++++++++++++++ .../src/FlexWebsiteStatsViewer.mxml | 55 +++++++++++++ .../FlexWebsiteStatsViewer/src/README.txt | 23 ++++++ .../FlexWebsiteStatsViewer/src/StatsView.mxml | 86 ++++++++++++++++++++ .../src/controllers/GAJSONInputParser.as | 20 +++++ .../controllers/GAStatsDataJSONItemConverter.as | 41 ++++++++++ .../src/controllers/StatsController.as | 77 ++++++++++++++++++ .../src/models/StatsModel.as | 55 +++++++++++++ 9 files changed, 505 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e28d38e8/examples/flexjs/FlexWebsiteStatsViewer/build.xml ---------------------------------------------------------------------- diff --git a/examples/flexjs/FlexWebsiteStatsViewer/build.xml b/examples/flexjs/FlexWebsiteStatsViewer/build.xml new file mode 100644 index 0000000..20b4415 --- /dev/null +++ b/examples/flexjs/FlexWebsiteStatsViewer/build.xml @@ -0,0 +1,74 @@ +<?xml version="1.0"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> + + +<project name="chartexample" default="main" basedir="."> + <property name="FLEXJS_HOME" location="../../.."/> + <property name="example" value="ChartExample" /> + + <property file="${FLEXJS_HOME}/env.properties"/> + <property environment="env"/> + <property file="${FLEXJS_HOME}/build.properties"/> + <property name="FLEX_HOME" value="${FLEXJS_HOME}"/> + <available file="${env.FALCON_HOME}/lib/falcon-mxmlc.jar" + type="file" + property="FALCON_HOME" + value="${env.FALCON_HOME}"/> + + <available file="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk/lib/falcon-mxmlc.jar" + type="file" + property="FALCON_HOME" + value="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk"/> + + <available file="${env.FALCONJX_HOME}/lib/jsc.jar" + type="file" + property="FALCONJX_HOME" + value="${env.FALCONJX_HOME}"/> + + <available file="${FLEXJS_HOME}/../flex-falcon/compiler.jx/lib/jsc.jar" + type="file" + property="FALCONJX_HOME" + value="${FLEXJS_HOME}/../flex-falcon/compiler.jx"/> + + <available file="${env.GOOG_HOME}/closure/goog/base.js" + type="file" + property="GOOG_HOME" + value="${env.GOOG_HOME}"/> + + <available file="${FLEXJS_HOME}/js/lib/google/closure-library/closure/goog/base.js" + type="file" + property="GOOG_HOME" + value="${FLEXJS_HOME}/js/lib/google/closure-library"/> + + <include file="${basedir}/../../build_example.xml" /> + +<!-- temp remove build_example.compilejs --> + <target name="main" depends="clean,build_example.compile,build_example.compilejs" description="Clean build of ${example}"> + </target> + + <target name="clean"> + <delete dir="${basedir}/bin" failonerror="false" /> + <delete dir="${basedir}/bin-debug" failonerror="false" /> + <delete dir="${basedir}/bin-release" failonerror="false" /> + </target> + + + +</project> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e28d38e8/examples/flexjs/FlexWebsiteStatsViewer/pom.xml ---------------------------------------------------------------------- diff --git a/examples/flexjs/FlexWebsiteStatsViewer/pom.xml b/examples/flexjs/FlexWebsiteStatsViewer/pom.xml new file mode 100644 index 0000000..02414b8 --- /dev/null +++ b/examples/flexjs/FlexWebsiteStatsViewer/pom.xml @@ -0,0 +1,74 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flex.examples.flexjs</groupId> + <artifactId>examples</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>FlexWebsiteStatsViewer</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>swf</packaging> + + <build> + <sourceDirectory>src</sourceDirectory> + <plugins> + <plugin> + <groupId>net.flexmojos.oss</groupId> + <artifactId>flexmojos-maven-plugin</artifactId> + <version>7.1.0-SNAPSHOT</version> + <extensions>true</extensions> + <configuration> + <sourceFile>FlexWebsiteStatsViewer.mxml</sourceFile> + <compilerName>${flexmojos-compiler-name}</compilerName> + <debug>true</debug> + </configuration> + <dependencies> + <dependency> + <groupId>org.apache.flex.compiler</groupId> + <artifactId>falcon-jx-compiler</artifactId> + <version>0.5.0-SNAPSHOT</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>org.apache.flex.flexjs</groupId> + <artifactId>framework</artifactId> + <version>0.5.0-SNAPSHOT</version> + <type>pom</type> + </dependency> + <dependency> + <groupId>com.adobe.flash.framework</groupId> + <artifactId>playerglobal</artifactId> + <version>18.0</version> + <type>swc</type> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e28d38e8/examples/flexjs/FlexWebsiteStatsViewer/src/FlexWebsiteStatsViewer.mxml ---------------------------------------------------------------------- diff --git a/examples/flexjs/FlexWebsiteStatsViewer/src/FlexWebsiteStatsViewer.mxml b/examples/flexjs/FlexWebsiteStatsViewer/src/FlexWebsiteStatsViewer.mxml new file mode 100644 index 0000000..9aafac9 --- /dev/null +++ b/examples/flexjs/FlexWebsiteStatsViewer/src/FlexWebsiteStatsViewer.mxml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="utf-8"?> +<!--- +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +--> +<js:Application xmlns:fx="http://ns.adobe.com/mxml/2009" + xmlns:local="*" + xmlns:models="models.*" + xmlns:controllers="controllers.*" + xmlns:js="library://ns.apache.org/flexjs/basic" + initialize="trace('app initialized')" + > + <js:valuesImpl> + <js:SimpleCSSValuesImpl /> + </js:valuesImpl> + <js:initialView> + <local:StatsView /> + </js:initialView> + <js:model> + <models:StatsModel /> + </js:model> + <js:controller> + <controllers:StatsController /> + </js:controller> + <js:beads> + <js:BrowserScroller /> + <js:HTTPService id="service"> + <js:LazyCollection id="collection"> + <js:inputParser> + <controllers:GAJSONInputParser /> + </js:inputParser> + <js:itemConverter> + <controllers:GAStatsDataJSONItemConverter /> + </js:itemConverter> + </js:LazyCollection> + </js:HTTPService> + <js:CSSFontFaceBead /> + </js:beads> +</js:Application> + http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e28d38e8/examples/flexjs/FlexWebsiteStatsViewer/src/README.txt ---------------------------------------------------------------------- diff --git a/examples/flexjs/FlexWebsiteStatsViewer/src/README.txt b/examples/flexjs/FlexWebsiteStatsViewer/src/README.txt new file mode 100644 index 0000000..0b1e0f3 --- /dev/null +++ b/examples/flexjs/FlexWebsiteStatsViewer/src/README.txt @@ -0,0 +1,23 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +This examples fetches data from Google Analytics for the website: flex.apache.org, +and parses the data into the required format. Then, via data binding, updates +the dataprovider for a ColumnChart which renders the data. + http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e28d38e8/examples/flexjs/FlexWebsiteStatsViewer/src/StatsView.mxml ---------------------------------------------------------------------- diff --git a/examples/flexjs/FlexWebsiteStatsViewer/src/StatsView.mxml b/examples/flexjs/FlexWebsiteStatsViewer/src/StatsView.mxml new file mode 100644 index 0000000..a389c83 --- /dev/null +++ b/examples/flexjs/FlexWebsiteStatsViewer/src/StatsView.mxml @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +--> +<js:ViewBase xmlns:fx="http://ns.adobe.com/mxml/2009" + xmlns:js="library://ns.apache.org/flexjs/basic" + xmlns:local="*" + xmlns:models="models.*" + initComplete="testit()" + > + <fx:Script> + <![CDATA[ + + private function testit():void + { + trace(); + } + + private function refreshBtnClick(event:Event):void + { + var e:Event = new Event("refresh",true); + dispatchEvent(e); + } + + ]]> + </fx:Script> + + <fx:Style> + @namespace js "library://ns.apache.org/flexjs/basic"; + .AllCharts { + border-width: 0px; + padding-left: 2px; + padding-top: 10px; + padding-bottom: 2px; + padding-right: 10px; + } + </fx:Style> + + <js:beads> + <js:ViewBaseDataBinding /> + </js:beads> + + <js:Label text="Number of users on flex.apache.org for last 30 days" x="10" y="10" /> + <js:TextButton id="refreshButton" text="Refresh" x="300" y="10" click="refreshBtnClick(event)"/> + + <js:ColumnChart id="columnChart" x="40" y="40" width="1024" height="768" className="AllCharts"> + <js:beads> + <js:SimpleBinding + sourceID="applicationModel" + sourcePropertyName="lastThirtyDaysUsers" + destinationPropertyName="dataProvider" + eventName="lastThirtyDaysDataChanged" + /> + <js:HorizontalCategoryAxisBead categoryField="date" /> + <js:VerticalLinearAxisBead valueField="users" /> + </js:beads> + <js:series> + <js:ColumnSeries yField="users"> + <js:itemRenderer> + <fx:Component> + <js:BoxItemRenderer> + <js:fill> + <js:SolidColor color="#FF964D" alpha="1.0" /> + </js:fill> + </js:BoxItemRenderer> + </fx:Component> + </js:itemRenderer> + </js:ColumnSeries> + </js:series> + </js:ColumnChart> +</js:ViewBase> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e28d38e8/examples/flexjs/FlexWebsiteStatsViewer/src/controllers/GAJSONInputParser.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/FlexWebsiteStatsViewer/src/controllers/GAJSONInputParser.as b/examples/flexjs/FlexWebsiteStatsViewer/src/controllers/GAJSONInputParser.as new file mode 100644 index 0000000..bb2a09d --- /dev/null +++ b/examples/flexjs/FlexWebsiteStatsViewer/src/controllers/GAJSONInputParser.as @@ -0,0 +1,20 @@ +package controllers +{ + import org.apache.flex.collections.parsers.IInputParser; + + public class GAJSONInputParser implements IInputParser + { + public function GAJSONInputParser() + { + } + + public function parseItems(s:String):Array + { + var rowsArrayStartIndex:int = s.indexOf('"rows": [', 0); + var rowsArrayEndIndex:int = s.indexOf("]]", rowsArrayStartIndex); + var rowsArrayString:String = s.slice(rowsArrayStartIndex + 9,rowsArrayEndIndex); + var rowsArray:Array = rowsArrayString.split("],"); + return rowsArray; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e28d38e8/examples/flexjs/FlexWebsiteStatsViewer/src/controllers/GAStatsDataJSONItemConverter.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/FlexWebsiteStatsViewer/src/controllers/GAStatsDataJSONItemConverter.as b/examples/flexjs/FlexWebsiteStatsViewer/src/controllers/GAStatsDataJSONItemConverter.as new file mode 100644 index 0000000..608db8f --- /dev/null +++ b/examples/flexjs/FlexWebsiteStatsViewer/src/controllers/GAStatsDataJSONItemConverter.as @@ -0,0 +1,41 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package controllers +{ + import org.apache.flex.collections.converters.JSONItemConverter; + + public class GAStatsDataJSONItemConverter extends JSONItemConverter + { + public function GAStatsDataJSONItemConverter() + { + super(); + } + + override public function convertItem(data:String):Object + { + var obj:Object = {}; + var a:Array = data.split(","); + var dateStr:String = a[0]; + var usersStr:String = a[1]; + obj.date = dateStr.substring(dateStr.indexOf("[") + 2 , dateStr.lastIndexOf('"')); + obj.users = parseInt(usersStr.substring(usersStr.indexOf(' "') + 2, usersStr.lastIndexOf('"'))); + return obj; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e28d38e8/examples/flexjs/FlexWebsiteStatsViewer/src/controllers/StatsController.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/FlexWebsiteStatsViewer/src/controllers/StatsController.as b/examples/flexjs/FlexWebsiteStatsViewer/src/controllers/StatsController.as new file mode 100644 index 0000000..b4a054c --- /dev/null +++ b/examples/flexjs/FlexWebsiteStatsViewer/src/controllers/StatsController.as @@ -0,0 +1,77 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package controllers +{ + + import models.StatsModel; + + import org.apache.flex.core.Application; + import org.apache.flex.core.IDocument; + import org.apache.flex.events.Event; + + public class StatsController implements IDocument + { + public function StatsController(a:Application = null) + { + if (a) + { + this.app = a as FlexWebsiteStatsViewer; + this.app.addEventListener("viewChanged", viewChangeHandler); + } + } + + private var lastThirtyDaysUsers:String = 'https://apache-flex-dashboard.appspot.com/query?id=ahdzfmFwYWNoZS1mbGV4LWRhc2hib2FyZHIVCxIIQXBpUXVlcnkYgICAgICAgAoM&format=json' + + private var app:FlexWebsiteStatsViewer; + + private function viewChangeHandler(event:Event):void + { + app.initialView.addEventListener("refresh", buttonClickHandler); + } + + private function buttonClickHandler(event:Event):void + { + app.service.url = lastThirtyDaysUsers; + app.service.send(); + app.service.addEventListener("complete", completeHandler); + } + + private function completeHandler(event:Event):void + { + var lastThirtyDaysUsers:Array = []; + if(app.collection) + { + for (var i:int = 0; i < app.collection.length; i++) + { + lastThirtyDaysUsers.push(app.collection.getItemAt(i)) + } + + } + + StatsModel(app.model).lastThirtyDaysUsers = lastThirtyDaysUsers; + } + + public function setDocument(document:Object, id:String = null):void + { + this.app = document as FlexWebsiteStatsViewer; + app.addEventListener("viewChanged", viewChangeHandler); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e28d38e8/examples/flexjs/FlexWebsiteStatsViewer/src/models/StatsModel.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/FlexWebsiteStatsViewer/src/models/StatsModel.as b/examples/flexjs/FlexWebsiteStatsViewer/src/models/StatsModel.as new file mode 100644 index 0000000..d6d1254 --- /dev/null +++ b/examples/flexjs/FlexWebsiteStatsViewer/src/models/StatsModel.as @@ -0,0 +1,55 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package models +{ + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + + public class StatsModel extends EventDispatcher + { + private var _lastThirtyDaysUsers:Array; + public function StatsModel() + { + + } + + [Bindable("lastThirtyDaysDataChanged")] + public function get lastThirtyDaysUsers():Array + { + return _lastThirtyDaysUsers; + } + + public function set lastThirtyDaysUsers(v:Array):void + { + if(v != _lastThirtyDaysUsers) + { + _lastThirtyDaysUsers = v; + dispatchEvent(new Event("lastThirtyDaysDataChanged")); + } + } + + private var _labelFields:Array = [ "date", "users"]; + public function get labelFields():Array + { + return _labelFields; + } + + } + +}
