You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2006/08/19 00:37:35 UTC
svn commit: r432759 [2/2] - in
/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/widget:
html/ svg/
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/widget/html/TimePicker.js
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/widget/html/TimePicker.js?rev=432759&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/widget/html/TimePicker.js (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/widget/html/TimePicker.js Fri Aug 18 15:37:34 2006
@@ -0,0 +1,249 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.widget.html.TimePicker");
+dojo.require("dojo.widget.*");
+dojo.require("dojo.widget.HtmlWidget");
+dojo.require("dojo.widget.TimePicker");
+dojo.require("dojo.event.*");
+dojo.require("dojo.date");
+dojo.require("dojo.html");
+
+dojo.widget.html.TimePicker = function(){
+ dojo.widget.TimePicker.call(this);
+ dojo.widget.HtmlWidget.call(this);
+
+
+ var _this = this;
+ // selected time, JS Date object
+ this.time = "";
+ // set following flag to true if a default time should be set
+ this.useDefaultTime = false;
+ // set the following to true to set default minutes to current time, false to // use zero
+ this.useDefaultMinutes = false;
+ // rfc 3339 date
+ this.storedTime = "";
+ // time currently selected in the UI, stored in hours, minutes, seconds in the format that will be actually displayed
+ this.currentTime = {};
+ this.classNames = {
+ selectedTime: "selectedItem"
+ }
+ this.any = "any"
+ // dom node indecies for selected hour, minute, amPm, and "any time option"
+ this.selectedTime = {
+ hour: "",
+ minute: "",
+ amPm: "",
+ anyTime: false
+ }
+
+ // minutes are ordered as follows: ["12", "6", "1", "7", "2", "8", "3", "9", "4", "10", "5", "11"]
+ this.hourIndexMap = ["", 2, 4, 6, 8, 10, 1, 3, 5, 7, 9, 11, 0];
+ // minutes are ordered as follows: ["00", "30", "05", "35", "10", "40", "15", "45", "20", "50", "25", "55"]
+ this.minuteIndexMap = [0, 2, 4, 6, 8, 10, 1, 3, 5, 7, 9, 11];
+
+ this.templatePath = dojo.uri.dojoUri("src/widget/templates/HtmlTimePicker.html");
+ this.templateCssPath = dojo.uri.dojoUri("src/widget/templates/HtmlTimePicker.css");
+
+ this.fillInTemplate = function(){
+ this.initData();
+ this.initUI();
+ }
+
+ this.initData = function() {
+ // FIXME: doesn't currently validate the time before trying to set it
+ // Determine the date/time from stored info, or by default don't
+ // have a set time
+ // FIXME: should normalize against whitespace on storedTime... for now
+ // just a lame hack
+ if(this.storedTime.indexOf("T")!=-1 && this.storedTime.split("T")[1] && this.storedTime!=" " && this.storedTime.split("T")[1]!="any") {
+ this.time = dojo.widget.TimePicker.util.fromRfcDateTime(this.storedTime, this.useDefaultMinutes, this.selectedTime.anyTime);
+ } else if (this.useDefaultTime) {
+ this.time = dojo.widget.TimePicker.util.fromRfcDateTime("", this.useDefaultMinutes, this.selectedTime.anyTime);
+ } else {
+ this.selectedTime.anyTime = true;
+ this.time = dojo.widget.TimePicker.util.fromRfcDateTime("", 0, 1);
+ }
+ }
+
+ this.initUI = function() {
+ // set UI to match the currently selected time
+ if(!this.selectedTime.anyTime && this.time) {
+ var amPmHour = dojo.widget.TimePicker.util.toAmPmHour(this.time.getHours());
+ var hour = amPmHour[0];
+ var isAm = amPmHour[1];
+ var minute = this.time.getMinutes();
+ var minuteIndex = parseInt(minute/5);
+ this.onSetSelectedHour(this.hourIndexMap[hour]);
+ this.onSetSelectedMinute(this.minuteIndexMap[minuteIndex]);
+ this.onSetSelectedAmPm(isAm);
+ } else {
+ this.onSetSelectedAnyTime();
+ }
+ }
+
+ this.setDateTime = function(rfcDate) {
+ this.storedTime = rfcDate;
+ }
+
+ this.onClearSelectedHour = function(evt) {
+ this.clearSelectedHour();
+ }
+
+ this.onClearSelectedMinute = function(evt) {
+ this.clearSelectedMinute();
+ }
+
+ this.onClearSelectedAmPm = function(evt) {
+ this.clearSelectedAmPm();
+ }
+
+ this.onClearSelectedAnyTime = function(evt) {
+ this.clearSelectedAnyTime();
+ if(this.selectedTime.anyTime) {
+ this.selectedTime.anyTime = false;
+ this.time = dojo.widget.TimePicker.util.fromRfcDateTime("", this.useDefaultMinutes);
+ this.initUI();
+ }
+ }
+
+ this.clearSelectedHour = function() {
+ var hourNodes = this.hourContainerNode.getElementsByTagName("td");
+ for (var i=0; i<hourNodes.length; i++) {
+ dojo.html.setClass(hourNodes.item(i), "");
+ }
+ }
+
+ this.clearSelectedMinute = function() {
+ var minuteNodes = this.minuteContainerNode.getElementsByTagName("td");
+ for (var i=0; i<minuteNodes.length; i++) {
+ dojo.html.setClass(minuteNodes.item(i), "");
+ }
+ }
+
+ this.clearSelectedAmPm = function() {
+ var amPmNodes = this.amPmContainerNode.getElementsByTagName("td");
+ for (var i=0; i<amPmNodes.length; i++) {
+ dojo.html.setClass(amPmNodes.item(i), "");
+ }
+ }
+
+ this.clearSelectedAnyTime = function() {
+ dojo.html.setClass(this.anyTimeContainerNode, "anyTimeContainer");
+ }
+
+ this.onSetSelectedHour = function(evt) {
+ this.onClearSelectedAnyTime();
+ this.onClearSelectedHour();
+ this.setSelectedHour(evt);
+ this.onSetTime();
+ }
+
+ this.setSelectedHour = function(evt) {
+ if(evt && evt.target) {
+ dojo.html.setClass(evt.target, this.classNames.selectedTime);
+ this.selectedTime["hour"] = evt.target.innerHTML;
+ } else if (!isNaN(evt)) {
+ var hourNodes = this.hourContainerNode.getElementsByTagName("td");
+ if(hourNodes.item(evt)) {
+ dojo.html.setClass(hourNodes.item(evt), this.classNames.selectedTime);
+ this.selectedTime["hour"] = hourNodes.item(evt).innerHTML;
+ }
+ }
+ this.selectedTime.anyTime = false;
+ }
+
+ this.onSetSelectedMinute = function(evt) {
+ this.onClearSelectedAnyTime();
+ this.onClearSelectedMinute();
+ this.setSelectedMinute(evt);
+ this.selectedTime.anyTime = false;
+ this.onSetTime();
+ }
+
+ this.setSelectedMinute = function(evt) {
+ if(evt && evt.target) {
+ dojo.html.setClass(evt.target, this.classNames.selectedTime);
+ this.selectedTime["minute"] = evt.target.innerHTML;
+ } else if (!isNaN(evt)) {
+ var minuteNodes = this.minuteContainerNode.getElementsByTagName("td");
+ if(minuteNodes.item(evt)) {
+ dojo.html.setClass(minuteNodes.item(evt), this.classNames.selectedTime);
+ this.selectedTime["minute"] = minuteNodes.item(evt).innerHTML;
+ }
+ }
+ }
+
+ this.onSetSelectedAmPm = function(evt) {
+ this.onClearSelectedAnyTime();
+ this.onClearSelectedAmPm();
+ this.setSelectedAmPm(evt);
+ this.selectedTime.anyTime = false;
+ this.onSetTime();
+ }
+
+ this.setSelectedAmPm = function(evt) {
+ if(evt && evt.target) {
+ dojo.html.setClass(evt.target, this.classNames.selectedTime);
+ this.selectedTime["amPm"] = evt.target.innerHTML;
+ } else {
+ evt = evt ? 0 : 1;
+ var amPmNodes = this.amPmContainerNode.getElementsByTagName("td");
+ if(amPmNodes.item(evt)) {
+ dojo.html.setClass(amPmNodes.item(evt), this.classNames.selectedTime);
+ this.selectedTime["amPm"] = amPmNodes.item(evt).innerHTML;
+ }
+ }
+ }
+
+ this.onSetSelectedAnyTime = function(evt) {
+ this.onClearSelectedHour();
+ this.onClearSelectedMinute();
+ this.onClearSelectedAmPm();
+ this.setSelectedAnyTime();
+ this.onSetTime();
+ }
+
+ this.setSelectedAnyTime = function(evt) {
+ this.selectedTime.anyTime = true;
+ dojo.html.setClass(this.anyTimeContainerNode, this.classNames.selectedTime + " " + "anyTimeContainer");
+ }
+
+ this.onClick = function(evt) {
+ dojo.event.browser.stopEvent(evt)
+ }
+
+ this.onSetTime = function() {
+ if(this.selectedTime.anyTime) {
+ this.time = new Date();
+ var tempDateTime = dojo.widget.TimePicker.util.toRfcDateTime(this.time);
+ this.setDateTime(tempDateTime.split("T")[0]);
+ } else {
+ var hour = 12;
+ var minute = 0;
+ var isAm = false;
+ if(this.selectedTime["hour"]) {
+ hour = parseInt(this.selectedTime["hour"], 10);
+ }
+ if(this.selectedTime["minute"]) {
+ minute = parseInt(this.selectedTime["minute"], 10);
+ }
+ if(this.selectedTime["amPm"]) {
+ isAm = (this.selectedTime["amPm"].toLowerCase() == "am");
+ }
+ this.time = new Date();
+ this.time.setHours(dojo.widget.TimePicker.util.fromAmPmHour(hour, isAm));
+ this.time.setMinutes(minute);
+ this.setDateTime(dojo.widget.TimePicker.util.toRfcDateTime(this.time));
+ }
+ }
+
+}
+dojo.inherits(dojo.widget.html.TimePicker, dojo.widget.HtmlWidget);
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/widget/html/Tooltip.js
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/widget/html/Tooltip.js?rev=432759&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/widget/html/Tooltip.js (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/widget/html/Tooltip.js Fri Aug 18 15:37:34 2006
@@ -0,0 +1,183 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.widget.html.Tooltip");
+dojo.require("dojo.widget.html.ContentPane");
+dojo.require("dojo.widget.Tooltip");
+dojo.require("dojo.uri");
+dojo.require("dojo.widget.*");
+dojo.require("dojo.event");
+dojo.require("dojo.style");
+dojo.require("dojo.html");
+
+dojo.widget.defineWidget(
+ "dojo.widget.html.Tooltip",
+ dojo.widget.html.ContentPane,
+ {
+ widgetType: "Tooltip",
+ isContainer: true,
+
+ // Constructor arguments
+ caption: "",
+ showDelay: 500,
+ hideDelay: 100,
+ connectId: "",
+
+ templatePath: dojo.uri.dojoUri("src/widget/templates/HtmlTooltipTemplate.html"),
+ templateCssPath: dojo.uri.dojoUri("src/widget/templates/HtmlTooltipTemplate.css"),
+
+ connectNode: null,
+
+ // Tooltip has the following possible states:
+ // erased - nothing on screen
+ // displaying - currently being faded in (partially displayed)
+ // displayed - fully displayed
+ // erasing - currently being faded out (partially erased)
+ state: "erased",
+
+ fillInTemplate: function(args, frag){
+ if(this.caption != ""){
+ this.domNode.appendChild(document.createTextNode(this.caption));
+ }
+ this.connectNode = dojo.byId(this.connectId);
+ dojo.widget.html.Tooltip.superclass.fillInTemplate.call(this, args, frag);
+ },
+
+ postCreate: function(args, frag){
+ // The domnode was appended to my parent widget's domnode, but the positioning
+ // only works if the domnode is a child of document.body
+ document.body.appendChild(this.domNode);
+
+ dojo.event.connect(this.connectNode, "onmouseover", this, "onMouseOver");
+ dojo.widget.html.Tooltip.superclass.postCreate.call(this, args, frag);
+ },
+
+ onMouseOver: function(e) {
+ this.mouse = {x: e.pageX, y: e.pageY};
+
+ if(!this.showTimer){
+ this.showTimer = setTimeout(dojo.lang.hitch(this, "show"), this.showDelay);
+ dojo.event.connect(document.documentElement, "onmousemove", this, "onMouseMove");
+ }
+ },
+
+ onMouseMove: function(e) {
+ this.mouse = {x: e.pageX, y: e.pageY};
+
+ if(dojo.html.overElement(this.connectNode, e) || dojo.html.overElement(this.domNode, e)) {
+ // If the tooltip has been scheduled to be erased, cancel that timer
+ // since we are hovering over element/tooltip again
+ if(this.hideTimer) {
+ clearTimeout(this.hideTimer);
+ delete this.hideTimer;
+ }
+ } else {
+ // mouse has been moved off the element/tooltip
+ // note: can't use onMouseOut to detect this because the "explode" effect causes
+ // spurious onMouseOut/onMouseOver events (due to interference from outline)
+ if(this.showTimer){
+ clearTimeout(this.showTimer);
+ delete this.showTimer;
+ }
+ if((this.state=="displaying"||this.state=="displayed") && !this.hideTimer){
+ this.hideTimer = setTimeout(dojo.lang.hitch(this, "hide"), this.hideDelay);
+ }
+ }
+ },
+
+ show: function() {
+ if(this.state=="erasing"){
+ // we are in the process of erasing; when that is finished, display it.
+ this.displayScheduled=true;
+ return;
+ }
+ if ( this.state=="displaying" || this.state=="displayed" ) { return; }
+
+ // prevent IE bleed through (iframe creation is deferred until first show()
+ // call because apparently it takes a long time)
+ if(!this.bgIframe){
+ this.bgIframe = new dojo.html.BackgroundIframe(this.domNode);
+ }
+
+ this.position();
+
+ // if rendering using explosion effect, need to set explosion source
+ this.explodeSrc = [this.mouse.x, this.mouse.y];
+
+ this.state="displaying";
+
+ dojo.widget.html.Tooltip.superclass.show.call(this);
+ },
+
+ onShow: function() {
+ dojo.widget.html.Tooltip.superclass.onShow.call(this);
+
+ this.state="displayed";
+
+ // in the corner case where the user has moved his mouse away
+ // while the tip was fading in
+ if(this.eraseScheduled){
+ this.hide();
+ this.eraseScheduled=false;
+ }
+ },
+
+ hide: function() {
+ if(this.state=="displaying"){
+ // in the process of fading in. wait until that is finished and then fade out
+ this.eraseScheduled=true;
+ return;
+ }
+ if ( this.state=="displayed" ) {
+ this.state="erasing";
+ if ( this.showTimer ) {
+ clearTimeout(this.showTimer);
+ delete this.showTimer;
+ }
+ if ( this.hideTimer ) {
+ clearTimeout(this.hideTimer);
+ delete this.hideTimer;
+ }
+ dojo.event.disconnect(document.documentElement, "onmousemove", this, "onMouseMove");
+ dojo.widget.html.Tooltip.superclass.hide.call(this);
+ }
+ },
+
+ onHide: function(){
+ this.state="erased";
+
+ // in the corner case where the user has moved his mouse back
+ // while the tip was fading out
+ if(this.displayScheduled){
+ this.display();
+ this.displayScheduled=false;
+ }
+ },
+
+ position: function(){
+ dojo.html.placeOnScreenPoint(this.domNode, this.mouse.x, this.mouse.y, [10,15], true);
+ this.bgIframe.onResized();
+ },
+
+ onLoad: function(){
+ if(this.isShowing()){
+ // the tooltip has changed size due to downloaded contents, so reposition it
+ dojo.lang.setTimeout(this, this.position, 50);
+ dojo.widget.html.Tooltip.superclass.onLoad.apply(this, arguments);
+ }
+ },
+
+ checkSize: function() {
+ // checkSize() is called when the user has resized the browser window,
+ // but that doesn't affect this widget (or this widget's children)
+ // so it can be safely ignored
+ }
+ }
+);
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/widget/html/stabile.js
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/widget/html/stabile.js?rev=432759&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/widget/html/stabile.js (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/widget/html/stabile.js Fri Aug 18 15:37:34 2006
@@ -0,0 +1,213 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+// Maintain state of widgets when user hits back/forward button
+
+dojo.provide("dojo.widget.html.stabile");
+
+dojo.widget.html.stabile = {
+ // Characters to quote in single-quoted regexprs
+ _sqQuotables: new RegExp("([\\\\'])", "g"),
+
+ // Current depth.
+ _depth: 0,
+
+ // Set to true when calling v.toString, to sniff for infinite
+ // recursion.
+ _recur: false,
+
+ // Levels of nesting of Array and object displays.
+ // If when >= depth, no display or array or object internals.
+ depthLimit: 2
+};
+
+
+
+
+
+//// PUBLIC METHODS
+
+// Get the state stored for the widget with the given ID, or undefined
+// if none.
+//
+dojo.widget.html.stabile.getState = function(id){
+ dojo.widget.html.stabile.setup();
+ return dojo.widget.html.stabile.widgetState[id];
+}
+
+
+// Set the state stored for the widget with the given ID. If isCommit
+// is true, commits all widget state to more stable storage.
+//
+dojo.widget.html.stabile.setState = function(id, state, isCommit){
+ dojo.widget.html.stabile.setup();
+ dojo.widget.html.stabile.widgetState[id] = state;
+ if(isCommit){
+ dojo.widget.html.stabile.commit(dojo.widget.html.stabile.widgetState);
+ }
+}
+
+
+// Sets up widgetState: a hash keyed by widgetId, maps to an object
+// or array writable with "describe". If there is data in the widget
+// storage area, use it, otherwise initialize an empty object.
+//
+dojo.widget.html.stabile.setup = function(){
+ if(!dojo.widget.html.stabile.widgetState){
+ var text = dojo.widget.html.stabile.getStorage().value;
+ dojo.widget.html.stabile.widgetState = text ? dj_eval("("+text+")") : {};
+ }
+}
+
+
+// Commits all widget state to more stable storage, so if the user
+// navigates away and returns, it can be restored.
+//
+dojo.widget.html.stabile.commit = function(state){
+ dojo.widget.html.stabile.getStorage().value = dojo.widget.html.stabile.description(state);
+}
+
+// Return a JSON "description string" for the given value.
+// Supports only core JavaScript types with literals, plus Date,
+// and cyclic structures are unsupported.
+// showAll defaults to false -- if true, this becomes a simple symbolic
+// object dumper, but you cannot "eval" the output.
+//
+dojo.widget.html.stabile.description = function(v, showAll){
+ // Save and later restore dojo.widget.html.stabile._depth;
+ var depth = dojo.widget.html.stabile._depth;
+
+ var describeThis = function() {
+ return this.description(this, true);
+ }
+
+ try {
+
+ if(v===void(0)){
+ return "undefined";
+ }
+ if(v===null){
+ return "null";
+ }
+ if(typeof(v)=="boolean" || typeof(v)=="number"
+ || v instanceof Boolean || v instanceof Number){
+ return v.toString();
+ }
+
+ if(typeof(v)=="string" || v instanceof String){
+ // Quote strings and their contents as required.
+ // Replacing by $& fails in IE 5.0
+ var v1 = v.replace(dojo.widget.html.stabile._sqQuotables, "\\$1");
+ v1 = v1.replace(/\n/g, "\\n");
+ v1 = v1.replace(/\r/g, "\\r");
+ // Any other important special cases?
+ return "'"+v1+"'";
+ }
+
+ if(v instanceof Date){
+ // Create a data constructor.
+ return "new Date("+d.getFullYear+","+d.getMonth()+","+d.getDate()+")";
+ }
+
+ var d;
+ if(v instanceof Array || v.push){
+ // "push" test needed for KHTML/Safari, don't know why -cp
+
+ if(depth>=dojo.widget.html.stabile.depthLimit)
+ return "[ ... ]";
+
+ d = "[";
+ var first = true;
+ dojo.widget.html.stabile._depth++;
+ for(var i=0; i<v.length; i++){
+ // Skip functions and undefined values
+ // if(v[i]==undef || typeof(v[i])=="function")
+ // continue;
+ if(first){
+ first = false;
+ }else{
+ d += ",";
+ }
+ d+=arguments.callee(v[i], showAll);
+ }
+ return d+"]";
+ }
+
+ if(v.constructor==Object
+ || v.toString==describeThis){
+ if(depth>=dojo.widget.html.stabile.depthLimit)
+ return "{ ... }";
+
+ // Instanceof Hash is good, or if we just use Objects,
+ // we can say v.constructor==Object.
+ // IE (5?) lacks hasOwnProperty, but perhaps objects do not always
+ // have prototypes??
+ if(typeof(v.hasOwnProperty)!="function" && v.prototype){
+ throw new Error("description: "+v+" not supported by script engine");
+ }
+ var first = true;
+ d = "{";
+ dojo.widget.html.stabile._depth++;
+ for(var key in v){
+ // Skip values that are functions or undefined.
+ if(v[key]==void(0) || typeof(v[key])=="function")
+ continue;
+ if(first){
+ first = false;
+ }else{
+ d += ", ";
+ }
+ var kd = key;
+ // If the key is not a legal identifier, use its description.
+ // For strings this will quote the stirng.
+ if(!kd.match(/^[a-zA-Z_][a-zA-Z0-9_]*$/)){
+ kd = arguments.callee(key, showAll);
+ }
+ d += kd+": "+arguments.callee(v[key], showAll);
+ }
+ return d+"}";
+ }
+
+ if(showAll){
+ if(dojo.widget.html.stabile._recur){
+ // Save the original definitions of toString;
+ var objectToString = Object.prototype.toString;
+ return objectToString.apply(v, []);
+ }else{
+ dojo.widget.html.stabile._recur = true;
+ return v.toString();
+ }
+ }else{
+ // log("Description? "+v.toString()+", "+typeof(v));
+ throw new Error("Unknown type: "+v);
+ return "'unknown'";
+ }
+
+ } finally {
+ // Always restore the global current depth.
+ dojo.widget.html.stabile._depth = depth;
+ }
+
+}
+
+
+
+//// PRIVATE TO MODULE
+
+// Gets an object (form field) with a read/write "value" property.
+//
+dojo.widget.html.stabile.getStorage = function(){
+ if (dojo.widget.html.stabile.dataField) {
+ return dojo.widget.html.stabile.dataField;
+ }
+ var form = document.forms._dojo_form;
+ return dojo.widget.html.stabile.dataField = form ? form.stabile : {value: ""};
+}
+
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/widget/svg/Chart.js
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/widget/svg/Chart.js?rev=432759&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/widget/svg/Chart.js (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/widget/svg/Chart.js Fri Aug 18 15:37:34 2006
@@ -0,0 +1,531 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.widget.svg.Chart");
+
+dojo.require("dojo.widget.HtmlWidget");
+dojo.require("dojo.widget.Chart");
+dojo.require("dojo.math");
+dojo.require("dojo.html");
+dojo.require("dojo.svg");
+dojo.require("dojo.graphics.color");
+
+dojo.widget.svg.Chart=function(){
+ dojo.widget.Chart.call(this);
+ dojo.widget.HtmlWidget.call(this);
+};
+dojo.inherits(dojo.widget.svg.Chart, dojo.widget.HtmlWidget);
+dojo.lang.extend(dojo.widget.svg.Chart, {
+ // widget props
+ templatePath:null,
+ templateCssPath:null,
+
+ // state
+ _isInitialized:false,
+ hasData:false,
+
+ // chart props
+ vectorNode:null,
+ plotArea:null,
+ dataGroup:null,
+ axisGroup:null,
+
+ properties:{
+ height:400, // defaults, will resize to the domNode.
+ width:600,
+ plotType:null,
+ padding:{
+ top:10,
+ bottom:2,
+ left:60,
+ right:30
+ },
+ axes:{
+ x:{
+ plotAt:0,
+ label:"",
+ unitLabel:"",
+ unitType:Number,
+ nUnitsToShow:10,
+ range:{
+ min:0,
+ max:200
+ }
+ },
+ y:{
+ plotAt:0,
+ label:"",
+ unitLabel:"",
+ unitType:Number,
+ nUnitsToShow:10,
+ range:{
+ min:0,
+ max:200
+ }
+ }
+ }
+ },
+
+ fillInTemplate:function(args,frag){
+ this.initialize();
+ this.render();
+ },
+ parseData:function(){
+ },
+ initialize:function(){
+ this.parseData();
+
+ // begin by grabbing the table, and reading it in.
+ var table=this.domNode.getElementsByTagName("table")[0];
+ if (!table) return;
+
+ var bRangeX=false;
+ var bRangeY=false;
+
+ // properties off the table
+ if (table.getAttribute("width")) this.properties.width=table.getAttribute("width");
+ if (table.getAttribute("height")) this.properties.height=table.getAttribute("height");
+ if (table.getAttribute("plotType")) this.properties.plotType=table.getAttribute("plotType");
+ if (table.getAttribute("padding")){
+ if (table.getAttribute("padding").indexOf(",") > -1)
+ var p=table.getAttribute("padding").split(",");
+ else var p=table.getAttribute("padding").split(" ");
+ if (p.length==1){
+ var pad=parseFloat(p[0]);
+ this.properties.padding.top=pad;
+ this.properties.padding.right=pad;
+ this.properties.padding.bottom=pad;
+ this.properties.padding.left=pad;
+ } else if(p.length==2){
+ var padV=parseFloat(p[0]);
+ var padH=parseFloat(p[1]);
+ this.properties.padding.top=padV;
+ this.properties.padding.right=padH;
+ this.properties.padding.bottom=padV;
+ this.properties.padding.left=padH;
+ } else if(p.length==4){
+ this.properties.padding.top=parseFloat(p[0]);
+ this.properties.padding.right=parseFloat(p[1]);
+ this.properties.padding.bottom=parseFloat(p[2]);
+ this.properties.padding.left=parseFloat(p[3]);
+ }
+ }
+ if (table.getAttribute("rangeX")){
+ var p=table.getAttribute("rangeX");
+ if (p.indexOf(",")>-1) p=p.split(",");
+ else p=p.split(" ");
+ this.properties.axes.x.range.min=parseFloat(p[0]);
+ this.properties.axes.x.range.max=parseFloat(p[1]);
+ bRangeX=true;
+ }
+ if (table.getAttribute("rangeY")){
+ var p=table.getAttribute("rangeY");
+ if (p.indexOf(",")>-1) p=p.split(",");
+ else p=p.split(" ");
+ this.properties.axes.y.range.min=parseFloat(p[0]);
+ this.properties.axes.y.range.max=parseFloat(p[1]);
+ bRangeY=true;
+ }
+
+ var thead=table.getElementsByTagName("thead")[0];
+ var tbody=table.getElementsByTagName("tbody")[0];
+ if(!(thead&&tbody)) dojo.raise("dojo.widget.Chart: supplied table must define a head and a body.");
+
+ // set up the series.
+ var columns=thead.getElementsByTagName("tr")[0].getElementsByTagName("th"); // should be <tr><..>
+
+ // assume column 0 == X
+ for (var i=1; i<columns.length; i++){
+ var key="column"+i;
+ var label=columns[i].innerHTML;
+ var plotType=columns[i].getAttribute("plotType")||"line";
+ var color=columns[i].getAttribute("color");
+ var ds=new dojo.widget.Chart.DataSeries(key,label,plotType,color);
+ this.series.push(ds);
+ }
+
+ // ok, get the values.
+ var rows=tbody.getElementsByTagName("tr");
+ var xMin=Number.MAX_VALUE,xMax=Number.MIN_VALUE;
+ var yMin=Number.MAX_VALUE,yMax=Number.MIN_VALUE;
+ var ignore = [
+ "accesskey","align","bgcolor","class",
+ "colspan","height","id","nowrap",
+ "rowspan","style","tabindex","title",
+ "valign","width"
+ ];
+
+ for(var i=0; i<rows.length; i++){
+ var row=rows[i];
+ var cells=row.getElementsByTagName("td");
+ var x=Number.MIN_VALUE;
+ for (var j=0; j<cells.length; j++){
+ if (j==0){
+ x=parseFloat(cells[j].innerHTML);
+ xMin=Math.min(xMin, x);
+ xMax=Math.max(xMax, x);
+ } else {
+ var ds=this.series[j-1];
+ var y=parseFloat(cells[j].innerHTML);
+ yMin=Math.min(yMin,y);
+ yMax=Math.max(yMax,y);
+ var o={x:x, value:y};
+ var attrs=cells[j].attributes;
+ for(var k=0; k<attrs.length; k++){
+ var attr=attrs.item(k);
+ var bIgnore=false;
+ for (var l=0; l<ignore.length; l++){
+ if (attr.nodeName.toLowerCase()==ignore[l]){
+ bIgnore=true;
+ break;
+ }
+ }
+ if(!bIgnore) o[attr.nodeName]=attr.nodeValue;
+ }
+ ds.add(o);
+ }
+ }
+ }
+
+ // fix the axes
+ if(!bRangeX){
+ this.properties.axes.x.range={min:xMin, max:xMax};
+ }
+ if(!bRangeY){
+ this.properties.axes.y.range={min:yMin, max:yMax};
+ }
+
+ // where to plot the axes
+ if (table.getAttribute("axisAt")){
+ var p=table.getAttribute("axisAt");
+ if (p.indexOf(",")>-1) p=p.split(",");
+ else p=p.split(" ");
+
+ // x axis
+ if (!isNaN(parseFloat(p[0]))){
+ this.properties.axes.x.plotAt=parseFloat(p[0]);
+ } else if (p[0].toLowerCase()=="ymin"){
+ this.properties.axes.x.plotAt=this.properties.axes.y.range.min;
+ } else if (p[0].toLowerCase()=="ymax"){
+ this.properties.axes.x.plotAt=this.properties.axes.y.range.max;
+ }
+
+ // y axis
+ if (!isNaN(parseFloat(p[1]))){
+ this.properties.axes.y.plotAt=parseFloat(p[1]);
+ } else if (p[1].toLowerCase()=="xmin"){
+ this.properties.axes.y.plotAt=this.properties.axes.x.range.min;
+ } else if (p[1].toLowerCase()=="xmax"){
+ this.properties.axes.y.plotAt=this.properties.axes.x.range.max;
+ }
+ } else {
+ this.properties.axes.x.plotAt=this.properties.axes.y.range.min;
+ this.properties.axes.y.plotAt=this.properties.axes.x.range.min;
+ }
+
+ // table values should be populated, now pop it off.
+ this.domNode.removeChild(table);
+
+ // get the width and the height.
+// this.properties.width=dojo.html.getInnerWidth(this.domNode);
+// this.properties.height=dojo.html.getInnerHeight(this.domNode);
+
+ // ok, lets create the chart itself.
+ dojo.svg.g.suspend();
+ if(this.vectorNode) this.destroy();
+ this.vectorNode=document.createElementNS(dojo.svg.xmlns.svg, "svg");
+ this.vectorNode.setAttribute("width", this.properties.width);
+ this.vectorNode.setAttribute("height", this.properties.height);
+
+ // set up the clip path for the plot area.
+ var defs = document.createElementNS(dojo.svg.xmlns.svg, "defs");
+ var clip = document.createElementNS(dojo.svg.xmlns.svg, "clipPath");
+ clip.setAttribute("id","plotClip"+this.widgetId);
+ var rect = document.createElementNS(dojo.svg.xmlns.svg, "rect");
+ rect.setAttribute("x", this.properties.padding.left);
+ rect.setAttribute("y", this.properties.padding.top);
+ rect.setAttribute("width", this.properties.width-this.properties.padding.left-this.properties.padding.right);
+ rect.setAttribute("height", this.properties.height-this.properties.padding.bottom-this.properties.padding.bottom);
+ clip.appendChild(rect);
+ defs.appendChild(clip);
+ this.vectorNode.appendChild(defs);
+
+ // the plot background.
+ this.plotArea = document.createElementNS(dojo.svg.xmlns.svg, "g");
+ this.vectorNode.appendChild(this.plotArea);
+ var rect = document.createElementNS(dojo.svg.xmlns.svg, "rect");
+ rect.setAttribute("x", this.properties.padding.left);
+ rect.setAttribute("y", this.properties.padding.top);
+ rect.setAttribute("width", this.properties.width-this.properties.padding.left-this.properties.padding.right);
+ rect.setAttribute("height", this.properties.height-this.properties.padding.bottom-this.properties.padding.bottom);
+ rect.setAttribute("fill", "#fff");
+ this.plotArea.appendChild(rect);
+
+ // data group
+ this.dataGroup = document.createElementNS(dojo.svg.xmlns.svg, "g");
+ this.dataGroup.setAttribute("style","clip-path:url(#plotClip"+this.widgetId+");");
+ this.plotArea.appendChild(this.dataGroup);
+
+ // axis group
+ this.axisGroup = document.createElementNS(dojo.svg.xmlns.svg, "g");
+ this.plotArea.appendChild(this.axisGroup);
+
+ // x axis
+ var stroke=1;
+ var line = document.createElementNS(dojo.svg.xmlns.svg, "line");
+ var y=dojo.widget.svg.Chart.Plotter.getY(this.properties.axes.x.plotAt, this);
+ line.setAttribute("y1", y);
+ line.setAttribute("y2", y);
+ line.setAttribute("x1",this.properties.padding.left-stroke);
+ line.setAttribute("x2",this.properties.width-this.properties.padding.right);
+ line.setAttribute("style","stroke:#000;stroke-width:"+stroke+";");
+ this.axisGroup.appendChild(line);
+
+ // x axis units.
+ // (min and max)
+ var textSize=10;
+ var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
+ text.setAttribute("x", this.properties.padding.left);
+ text.setAttribute("y", this.properties.height-this.properties.padding.bottom+textSize+2);
+ text.setAttribute("style", "text-anchor:middle;font-size:"+textSize+"px;fill:#000;");
+ text.appendChild(document.createTextNode(dojo.math.round(parseFloat(this.properties.axes.x.range.min),2)));
+ this.axisGroup.appendChild(text);
+
+ var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
+ text.setAttribute("x", this.properties.width-this.properties.padding.right-(textSize/2));
+ text.setAttribute("y", this.properties.height-this.properties.padding.bottom+textSize+2);
+ text.setAttribute("style", "text-anchor:middle;font-size:"+textSize+"px;fill:#000;");
+ text.appendChild(document.createTextNode(dojo.math.round(parseFloat(this.properties.axes.x.range.max),2)));
+ this.axisGroup.appendChild(text);
+
+ // y axis
+ var line=document.createElementNS(dojo.svg.xmlns.svg, "line");
+ var x=dojo.widget.svg.Chart.Plotter.getX(this.properties.axes.y.plotAt, this);
+ line.setAttribute("x1", x);
+ line.setAttribute("x2", x);
+ line.setAttribute("y1", this.properties.padding.top);
+ line.setAttribute("y2", this.properties.height-this.properties.padding.bottom);
+ line.setAttribute("style", "stroke:#000;stroke-width:"+stroke+";");
+ this.axisGroup.appendChild(line);
+
+ // y axis units
+ var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
+ text.setAttribute("x", this.properties.padding.left-4);
+ text.setAttribute("y", this.properties.height-this.properties.padding.bottom);
+ text.setAttribute("style", "text-anchor:end;font-size:"+textSize+"px;fill:#000;");
+ text.appendChild(document.createTextNode(dojo.math.round(parseFloat(this.properties.axes.y.range.min),2)));
+ this.axisGroup.appendChild(text);
+
+ var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
+ text.setAttribute("x", this.properties.padding.left-4);
+ text.setAttribute("y", this.properties.padding.top+(textSize/2));
+ text.setAttribute("style", "text-anchor:end;font-size:"+textSize+"px;fill:#000;");
+ text.appendChild(document.createTextNode(dojo.math.round(parseFloat(this.properties.axes.y.range.max),2)));
+ this.axisGroup.appendChild(text);
+
+ this.domNode.appendChild(this.vectorNode);
+ dojo.svg.g.resume();
+
+ // this is last.
+ this.assignColors();
+ this._isInitialized=true;
+ },
+ destroy:function(){
+ while(this.domNode.childNodes.length>0){
+ this.domNode.removeChild(this.domNode.childNodes.item(0));
+ }
+ this.vectorNode=this.plotArea=this.dataGroup=this.axisGroup=null;
+ },
+ render:function(){
+ dojo.svg.g.suspend();
+
+ if (this.dataGroup){
+ while(this.dataGroup.childNodes.length>0){
+ this.dataGroup.removeChild(this.dataGroup.childNodes.item(0));
+ }
+ } else {
+ this.initialize();
+ }
+
+ // the remove/append is an attempt to streamline the rendering, it's totally optional
+// var p=this.dataGroup.parentNode;
+// p.removeChild(this.dataGroup);
+ for(var i=0; i<this.series.length; i++){
+ dojo.widget.svg.Chart.Plotter.plot(this.series[i], this);
+ }
+// p.appendChild(this.dataGroup);
+
+ dojo.svg.g.resume();
+ }
+});
+
+dojo.widget.svg.Chart.Plotter=new function(){
+ var _this=this;
+ var plotters = {};
+ var types=dojo.widget.Chart.PlotTypes;
+
+ this.getX=function(value, chart){
+ var v=parseFloat(value);
+ var min=chart.properties.axes.x.range.min;
+ var max=chart.properties.axes.x.range.max;
+ var ofst=0-min;
+ min+=ofst; max+=ofst; v+=ofst;
+
+ var xmin=chart.properties.padding.left;
+ var xmax=chart.properties.width-chart.properties.padding.right;
+ var x=(v*((xmax-xmin)/max))+xmin;
+ return x;
+ };
+ this.getY=function(value, chart){
+ var v=parseFloat(value);
+ var max=chart.properties.axes.y.range.max;
+ var min=chart.properties.axes.y.range.min;
+ var ofst=0;
+ if(min<0)ofst+=Math.abs(min);
+ min+=ofst; max+=ofst; v+=ofst;
+
+ var ymin=chart.properties.height-chart.properties.padding.bottom;
+ var ymax=chart.properties.padding.top;
+ var y=(((ymin-ymax)/(max-min))*(max-v))+ymax;
+ return y;
+ };
+
+ this.addPlotter=function(name, func){
+ plotters[name]=func;
+ };
+ this.plot=function(series, chart){
+ if (series.values.length==0) return;
+ if (series.plotType && plotters[series.plotType]){
+ return plotters[series.plotType](series, chart);
+ }
+ else if (chart.plotType && plotters[chart.plotType]){
+ return plotters[chart.plotType](series, chart);
+ }
+ };
+
+ // plotting
+ plotters[types.Bar]=function(series, chart){
+ var space=1;
+ var lastW = 0;
+ for (var i=0; i<series.values.length; i++){
+ var x=_this.getX(series.values[i].x, chart);
+ var w;
+ if (i==series.values.length-1){
+ w=lastW;
+ } else{
+ w=_this.getX(series.values[i+1].x, chart)-x-space;
+ lastW=w;
+ }
+ x-=(w/2);
+
+ var yA=_this.getY(chart.properties.axes.x.plotAt, chart);
+ var y=_this.getY(series.values[i].value, chart);
+ var h=Math.abs(yA-y);
+ if (parseFloat(series.values[i].value)<chart.properties.axes.x.plotAt){
+ var oy=yA;
+ yA=y;
+ y=oy;
+ }
+
+ var bar=document.createElementNS(dojo.svg.xmlns.svg, "rect");
+ bar.setAttribute("fill", series.color);
+ bar.setAttribute("title", series.label + ": " + series.values[i].value);
+ bar.setAttribute("stroke-width", "0");
+ bar.setAttribute("x", x);
+ bar.setAttribute("y", y);
+ bar.setAttribute("width", w);
+ bar.setAttribute("height", h);
+ bar.setAttribute("fill-opacity", "0.9");
+ chart.dataGroup.appendChild(bar);
+ }
+ };
+ plotters[types.Line]=function(series, chart){
+ var tension=3;
+ var line = document.createElementNS(dojo.svg.xmlns.svg, "path");
+ line.setAttribute("fill", "none");
+ line.setAttribute("stroke", series.color);
+ line.setAttribute("stroke-width", "2");
+ line.setAttribute("stroke-opacity", "0.85");
+ line.setAttribute("title", series.label);
+ chart.dataGroup.appendChild(line);
+
+ var path = [];
+ for (var i=0; i<series.values.length; i++){
+ var x = _this.getX(series.values[i].x, chart)
+ var y = _this.getY(series.values[i].value, chart);
+
+ var dx = chart.properties.padding.left+1;
+ var dy = chart.properties.height-chart.properties.padding.bottom;
+ if (i>0){
+ dx=x-_this.getX(series.values[i-1].x, chart);
+ dy=_this.getY(series.values[i-1].value, chart);
+ }
+
+ if (i==0) path.push("M");
+ else {
+ path.push("C");
+ var cx=x-(tension-1)*(dx/tension);
+ path.push(cx+","+dy);
+ cx=x-(dx/tension);
+ path.push(cx+","+y);
+ }
+ path.push(x+","+y);
+ }
+ line.setAttribute("d", path.join(" "));
+ };
+ plotters[types.Scatter]=function(series, chart){
+ var r=7;
+ for (var i=0; i<series.values.length; i++){
+ var x=_this.getX(series.values[i].x, chart);
+ var y=_this.getY(series.values[i].value, chart);
+ var point = document.createElementNS(dojo.svg.xmlns.svg, "path");
+ point.setAttribute("fill", series.color);
+ point.setAttribute("stroke-width", "0");
+ point.setAttribute("title", series.label + ": " + series.values[i].value);
+ point.setAttribute("d",
+ "M " + x + "," + (y-r) + " " +
+ "Q " + x + "," + y + " " + (x+r) + "," + y + " " +
+ "Q " + x + "," + y + " " + x + "," + (y+r) + " " +
+ "Q " + x + "," + y + " " + (x-r) + "," + y + " " +
+ "Q " + x + "," + y + " " + x + "," + (y-r) + " " +
+ "Z"
+ );
+ chart.dataGroup.appendChild(point);
+ }
+ };
+ plotters[types.Bubble]=function(series, chart){
+ // added param for series[n].value: size
+ var minR=1;
+
+ // do this off the x axis?
+ var min=chart.properties.axes.x.range.min;
+ var max=chart.properties.axes.x.range.max;
+ var ofst=0-min;
+ min+=ofst; max+=ofst;
+
+ var xmin=chart.properties.padding.left;
+ var xmax=chart.properties.width-chart.properties.padding.right;
+ var factor=(max-min)/(xmax-xmin)*25;
+
+ for (var i=0; i<series.values.length; i++){
+ var size = series.values[i].size;
+ if (isNaN(parseFloat(size))) size=minR;
+ var point=document.createElementNS(dojo.svg.xmlns.svg, "circle");
+ point.setAttribute("stroke-width", 0);
+ point.setAttribute("fill", series.color);
+ point.setAttribute("fill-opacity", "0.8");
+ point.setAttribute("r", (parseFloat(size)*factor)/2);
+ point.setAttribute("cx", _this.getX(series.values[i].x, chart));
+ point.setAttribute("cy", _this.getY(series.values[i].value, chart));
+ point.setAttribute("title", series.label + ": " + series.values[i].value + " (" + size + ")");
+ chart.dataGroup.appendChild(point);
+ }
+ };
+}();