Hopkins-Plugin-HMI
view release on metacpan or search on metacpan
share/root/static/yui/build/profilerviewer/profilerviewer.js view on Meta::CPAN
if (arguments.length == 1 && !YAHOO.lang.isString(el) && !el.nodeName) {
attr = el;
el = attr.element || null;
}
if (!el && !attr.element) {
el = this._createProfilerViewerElement();
}
YAHOO.widget.ProfilerViewer.superclass.constructor.call(this, el, attr);
this._init();
};
YAHOO.extend(YAHOO.widget.ProfilerViewer, YAHOO.util.Element);
// Static members of YAHOO.widget.ProfilerViewer:
YAHOO.lang.augmentObject(YAHOO.widget.ProfilerViewer, {
/**
* Classname for ProfilerViewer containing element.
* @static
* @property CLASS
* @type string
* @public
* @default "yui-pv"
*/
CLASS: 'yui-pv',
/**
* Classname for ProfilerViewer button dashboard.
* @static
* @property CLASS_DASHBOARD
* @type string
* @public
* @default "yui-pv-dashboard"
*/
CLASS_DASHBOARD: 'yui-pv-dashboard',
/**
* Classname for the "refresh data" button.
* @static
* @property CLASS_REFRESH
* @type string
* @public
* @default "yui-pv-refresh"
*/
CLASS_REFRESH: 'yui-pv-refresh',
/**
* Classname for busy indicator in the dashboard.
* @static
* @property CLASS_BUSY
* @type string
* @public
* @default "yui-pv-busy"
*/
CLASS_BUSY: 'yui-pv-busy',
/**
* Classname for element containing the chart and chart
* legend elements.
* @static
* @property CLASS_CHART_CONTAINER
* @type string
* @public
* @default "yui-pv-chartcontainer"
*/
CLASS_CHART_CONTAINER: 'yui-pv-chartcontainer',
/**
* Classname for element containing the chart.
* @static
* @property CLASS_CHART
* @type string
* @public
* @default "yui-pv-chart"
*/
CLASS_CHART: 'yui-pv-chart',
/**
* Classname for element containing the chart's legend.
* @static
* @property CLASS_CHART_LEGEND
* @type string
* @public
* @default "yui-pv-chartlegend"
*/
CLASS_CHART_LEGEND: 'yui-pv-chartlegend',
/**
* Classname for element containing the datatable.
* @static
* @property CLASS_TABLE
* @type string
* @public
* @default "yui-pv-table"
*/
CLASS_TABLE: 'yui-pv-table',
/**
* Strings used in the UI.
* @static
* @property STRINGS
* @object
* @public
* @default English language strings for UI.
*/
STRINGS: {
title: "YUI Profiler (beta)",
buttons: {
viewprofiler: "View Profiler Data",
hideprofiler: "Hide Profiler Report",
showchart: "Show Chart",
hidechart: "Hide Chart",
refreshdata: "Refresh Data"
},
colHeads: {
//key: [column head label, width in pixels]
fn: ["Function/Method", null], //must auto-size
calls: ["Calls", 40],
avg: ["Average", 80],
min: ["Shortest", 70],
max: ["Longest", 70],
total: ["Total Time", 70],
pct: ["Percent", 70]
},
millisecondsAbbrev: "ms",
initMessage: "initialiazing chart...",
installFlashMessage: "Unable to load Flash content. The YUI Charts Control requires Flash Player 9.0.45 or higher. You can download the latest version of Flash Player from the <a href='http://www.adobe.com/go/getflashplayer'>Adobe Flash Player Dow...
},
/**
* Function used to format numbers in milliseconds
* for chart; must be publicly accessible, per Charts spec.
* @static
* @property timeAxisLabelFunction
* @type function
* @private
*/
timeAxisLabelFunction: function(n) {
var a = (n === Math.floor(n)) ? n : (Math.round(n*1000))/1000;
return (a + " " + YAHOO.widget.ProfilerViewer.STRINGS.millisecondsAbbrev);
},
/**
* Function used to format percent numbers for chart; must
* be publicly accessible, per Charts spec.
* @static
share/root/static/yui/build/profilerviewer/profilerviewer.js view on Meta::CPAN
* @private
**/
proto._sortedByChange = function(o) {
if(o.newValue && o.newValue.key) {
this.set("sortedBy", {key: o.newValue.key, dir:o.newValue.dir});
}
};
/**
* Proxy the render event in DataTable into the ProfilerViewer
* attribute.
* @method _dataTableRenderHandler
* @private
**/
proto._dataTableRenderHandler = function(o) {
this._setBusyState(false);
};
/**
* Event handler for clicks on the DataTable's sortable column
* heads.
* @method _thClickHandler
* @private
**/
proto._thClickHandler = function(o) {
this._setBusyState(true);
};
/**
* Refresh DataTable, getting new data from Profiler.
* @method _refreshDataTable
* @private
**/
proto._refreshDataTable = function(args) {
var dt = this._dataTable;
dt.getDataSource().sendRequest("", dt.onDataReturnInitializeTable, dt);
};
/**
* Refresh chart, getting new data from table.
* @method _refreshChart
* @private
**/
proto._refreshChart = function() {
switch (this.get("sortedBy").key) {
case "fn":
/*Keep the same data on the chart, but force update to
reflect new sort order on function/method name: */
this._chart.set("dataSource", this._chart.get("dataSource"));
/*no further action necessary; chart redraws*/
return;
case "calls":
/*Null out the xAxis formatting before redrawing chart.*/
this._chart.set("xAxis", this._chartAxisDefinitionPlain);
break;
case "pct":
this._chart.set("xAxis", this._chartAxisDefinitionPercent);
break;
default:
/*Set the default xAxis; redraw legend; set the new series definition.*/
this._chart.set("xAxis", this._chartAxisDefinitionTime);
break;
}
this._drawChartLegend();
this._chart.set("series", this._getSeriesDef(this.get("sortedBy").key));
};
/**
* Get data for the Chart from DataTable recordset
* @method _getChartData
* @private
*/
proto._getChartData = function() {
//var records = this._getProfilerData();
var records = this._dataTable.getRecordSet().getRecords(0, this.get("maxChartFunctions"));
var arr = [];
for (var i = 0, j = records.length; i<j; i++) {
arr.push(records[i].getData());
}
return arr;
};
/**
* Build series definition based on current configuration attributes.
* @method _getSeriesDef
* @private
*/
proto._getSeriesDef = function(field) {
var sd = this.get("chartSeriesDefinitions")[field];
var arr = [];
for(var i = 0, j = sd.group.length; i<j; i++) {
var c = this.get("chartSeriesDefinitions")[sd.group[i]];
arr.push(
{displayName:c.displayName,
xField:c.xField,
style: {color:c.style.color, size:c.style.size}
}
);
}
return arr;
};
/**
* Set up the Chart.
* @method _initChart
* @private
*/
proto._initChart = function() {
this._sizeChartCanvas();
YAHOO.widget.Chart.SWFURL = this.get("swfUrl");
var self = this;
//Create DataSource based on records currently displayed
//at the top of the sort list in the DataTable.
var ds = new YAHOO.util.DataSource(
//force the jsfunction DataSource to run in the scope of
//the ProfilerViewer, not in the YAHOO.util.DataSource scope:
function() {
return self._getChartData.call(self);
},
{
responseType: YAHOO.util.DataSource.TYPE_JSARRAY,
maxCacheEntries: 0
}
);
ds.responseSchema =
{
fields: [ "fn", "avg", "calls", "max", "min", "total", "pct" ]
};
ds.subscribe('responseEvent', this._sizeChartCanvas, this, true);
//Set up the chart itself.
this._chartAxisDefinitionTime = new YAHOO.widget.NumericAxis();
this._chartAxisDefinitionTime.labelFunction = "YAHOO.widget.ProfilerViewer.timeAxisLabelFunction";
this._chartAxisDefinitionPercent = new YAHOO.widget.NumericAxis();
this._chartAxisDefinitionPercent.labelFunction = "YAHOO.widget.ProfilerViewer.percentAxisLabelFunction";
this._chartAxisDefinitionPlain = new YAHOO.widget.NumericAxis();
this._chart = new YAHOO.widget.BarChart( this._chartEl, ds,
{
yField: "fn",
series: this._getSeriesDef(this.get("sortedBy").key),
style: this.get("chartStyle"),
xAxis: this._chartAxisDefinitionTime
} );
this._drawChartLegend();
this._chartInitialized = true;
this._dataTable.unsubscribe("initEvent", this._initChart, this);
this._dataTable.subscribe("initEvent", this._refreshChart, this, true);
};
/**
* Set up the Chart's legend
* @method _drawChartLegend
* @private
**/
proto._drawChartLegend = function() {
var seriesDefs = this.get("chartSeriesDefinitions");
var currentDef = seriesDefs[this.get("sortedBy").key];
var l = this._chartLegendEl;
l.innerHTML = "";
for(var i = 0, j = currentDef.group.length; i<j; i++) {
var c = seriesDefs[currentDef.group[i]];
var dt = document.createElement("dt");
Dom.setStyle(dt, "backgroundColor", "#" + c.style.color);
var dd = document.createElement("dd");
dd.innerHTML = c.displayName;
l.appendChild(dt);
l.appendChild(dd);
}
};
/**
* Resize the chart's canvas if based on number of records
* returned from the chart's datasource.
* @method _sizeChartCanvas
* @private
**/
proto._sizeChartCanvas = function(o) {
var bars = (o) ? o.response.length : this.get("maxChartFunctions");
var s = (bars * 36) + 34;
if (s != parseInt(this._chartElHeight, 10)) {
this._chartElHeight = s;
Dom.setStyle(this._chartEl, "height", s + "px");
}
};
/**
* setAttributeConfigs TabView specific properties.
* @method initAttributes
* @param {Object} attr Hash of initial attributes
* @method initAttributes
* @private
*/
proto.initAttributes = function(attr) {
YAHOO.widget.ProfilerViewer.superclass.initAttributes.call(this, attr);
/**
* The YUI Loader base path from which to pull YUI files needed
* in the rendering of the ProfilerViewer canvas. Passed directly
* to YUI Loader. Leave blank to draw files from
* yui.yahooapis.com.
* @attribute base
* @type string
* @default ""
*/
this.setAttributeConfig('base', {
value: attr.base
});
/**
* The height of the DataTable. The table will scroll
* vertically if the content overflows the specified
* height.
( run in 1.759 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )