Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Copyright 2007 The Closure Library Authors. All Rights Reserved.
//
// Licensed 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.
/**
* @fileoverview Component for generating chart PNGs using Google Chart Server.
*
* @deprecated Google Chart Images service (the server-side component of this
* class) has been deprecated. See
* https://developers.google.com/chart/ for alternatives.
*
* @see ../demos/serverchart.html
*/
/**
* Namespace for chart functions
*/
goog.provide('goog.ui.ServerChart');
goog.provide('goog.ui.ServerChart.AxisDisplayType');
goog.provide('goog.ui.ServerChart.ChartType');
goog.provide('goog.ui.ServerChart.EncodingType');
goog.provide('goog.ui.ServerChart.Event');
goog.provide('goog.ui.ServerChart.LegendPosition');
goog.provide('goog.ui.ServerChart.MaximumValue');
goog.provide('goog.ui.ServerChart.MultiAxisAlignment');
goog.provide('goog.ui.ServerChart.MultiAxisType');
goog.provide('goog.ui.ServerChart.UriParam');
goog.provide('goog.ui.ServerChart.UriTooLongEvent');
goog.require('goog.Uri');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.dom.TagName');
goog.require('goog.events.Event');
goog.require('goog.string');
goog.require('goog.ui.Component');
/**
* Will construct a chart using Google's chartserver.
*
* @param {goog.ui.ServerChart.ChartType} type The chart type.
* @param {number=} opt_width The width of the chart.
* @param {number=} opt_height The height of the chart.
* @param {goog.dom.DomHelper=} opt_domHelper Optional DOM Helper.
* @param {string=} opt_uri Optional uri used to connect to the chart server, if
* different than goog.ui.ServerChart.CHART_SERVER_SCHEME_INDEPENDENT_URI.
* @constructor
* @extends {goog.ui.Component}
*
* @deprecated Google Chart Server has been deprecated. See
* https://developers.google.com/chart/image/ for details.
* @final
*/
goog.ui.ServerChart = function(
type, opt_width, opt_height, opt_domHelper, opt_uri) {
goog.ui.Component.call(this, opt_domHelper);
/**
* Image URI.
* @type {goog.Uri}
* @private
*/
this.uri_ = new goog.Uri(
opt_uri || goog.ui.ServerChart.CHART_SERVER_SCHEME_INDEPENDENT_URI);
/**
* Encoding method for the URI data format.
* @type {goog.ui.ServerChart.EncodingType}
* @private
*/
this.encodingType_ = goog.ui.ServerChart.EncodingType.AUTOMATIC;
/**
* Two-dimensional array of the data sets on the chart.
* @type {Array>}
* @private
*/
this.dataSets_ = [];
/**
* Colors for each data set.
* @type {Array}
* @private
*/
this.setColors_ = [];
/**
* Legend texts for each data set.
* @type {Array}
* @private
*/
this.setLegendTexts_ = [];
/**
* Labels on the X-axis.
* @type {Array}
* @private
*/
this.xLabels_ = [];
/**
* Labels on the left along the Y-axis.
* @type {Array}
* @private
*/
this.leftLabels_ = [];
/**
* Labels on the right along the Y-axis.
* @type {Array}
* @private
*/
this.rightLabels_ = [];
/**
* Axis type for each multi-axis in the chart. The indices into this array
* also work as the reference index for all other multi-axis properties.
* @type {Array}
* @private
*/
this.multiAxisType_ = [];
/**
* Axis text for each multi-axis in the chart, indexed by the indices from
* multiAxisType_ in a sparse array.
* @type {Object}
* @private
*/
this.multiAxisLabelText_ = {};
/**
* Axis position for each multi-axis in the chart, indexed by the indices
* from multiAxisType_ in a sparse array.
* @type {Object}
* @private
*/
this.multiAxisLabelPosition_ = {};
/**
* Axis range for each multi-axis in the chart, indexed by the indices from
* multiAxisType_ in a sparse array.
* @type {Object}
* @private
*/
this.multiAxisRange_ = {};
/**
* Axis style for each multi-axis in the chart, indexed by the indices from
* multiAxisType_ in a sparse array.
* @type {Object}
* @private
*/
this.multiAxisLabelStyle_ = {};
this.setType(type);
this.setSize(opt_width, opt_height);
/**
* Minimum value for the chart (used for normalization). By default,
* this is set to infinity, and is eventually updated to the lowest given
* value in the data. The minimum value is then subtracted from all other
* values. For a pie chart, subtracting the minimum value does not make
* sense, so minValue_ is set to zero because 0 is the additive identity.
* @type {number}
* @private
*/
this.minValue_ = this.isPieChart() ? 0 : Infinity;
};
goog.inherits(goog.ui.ServerChart, goog.ui.Component);
/**
* Base scheme-independent URI for the chart renderer.
* @type {string}
*/
goog.ui.ServerChart.CHART_SERVER_SCHEME_INDEPENDENT_URI =
'//chart.googleapis.com/chart';
/**
* Base HTTP URI for the chart renderer.
* @type {string}
*/
goog.ui.ServerChart.CHART_SERVER_HTTP_URI = 'http://chart.googleapis.com/chart';
/**
* Base HTTPS URI for the chart renderer.
* @type {string}
*/
goog.ui.ServerChart.CHART_SERVER_HTTPS_URI =
'https://chart.googleapis.com/chart';
/**
* Base URI for the chart renderer.
* @type {string}
* @deprecated Use
* {@link goog.ui.ServerChart.CHART_SERVER_SCHEME_INDEPENDENT_URI},
* {@link goog.ui.ServerChart.CHART_SERVER_HTTP_URI} or
* {@link goog.ui.ServerChart.CHART_SERVER_HTTPS_URI} instead.
*/
goog.ui.ServerChart.CHART_SERVER_URI =
goog.ui.ServerChart.CHART_SERVER_HTTP_URI;
/**
* The 0 - 1.0 ("fraction of the range") value to use when getMinValue() ==
* getMaxValue(). This determines, for example, the vertical position
* of the line in a flat line-chart.
* @type {number}
*/
goog.ui.ServerChart.DEFAULT_NORMALIZATION = 0.5;
/**
* The upper limit on the length of the chart image URI, after encoding.
* If the URI's length equals or exceeds it, goog.ui.ServerChart.UriTooLongEvent
* is dispatched on the goog.ui.ServerChart object.
* @type {number}
* @private
*/
goog.ui.ServerChart.prototype.uriLengthLimit_ = 2048;
/**
* Number of gridlines along the X-axis.
* @type {number}
* @private
*/
goog.ui.ServerChart.prototype.gridX_ = 0;
/**
* Number of gridlines along the Y-axis.
* @type {number}
* @private
*/
goog.ui.ServerChart.prototype.gridY_ = 0;
/**
* Maximum value for the chart (used for normalization). The minimum is
* declared in the constructor.
* @type {number}
* @private
*/
goog.ui.ServerChart.prototype.maxValue_ = -Infinity;
/**
* Chart title.
* @type {?string}
* @private
*/
goog.ui.ServerChart.prototype.title_ = null;
/**
* Chart title size.
* @type {number}
* @private
*/
goog.ui.ServerChart.prototype.titleSize_ = 13.5;
/**
* Chart title color.
* @type {string}
* @private
*/
goog.ui.ServerChart.prototype.titleColor_ = '333333';
/**
* Chart legend.
* @type {Array?}
* @private
*/
goog.ui.ServerChart.prototype.legend_ = null;
/**
* ChartServer supports using data sets to position markers. A data set
* that is being used for positioning only can be made "invisible", in other
* words, the caller can indicate to ChartServer that ordinary chart elements
* (e.g. bars in a bar chart) should not be drawn on the data points of the
* invisible data set. Such data sets must be provided at the end of the
* chd parameter, and if invisible data sets are being used, the chd
* parameter must indicate the number of visible data sets.
* @type {?number}
* @private
*/
goog.ui.ServerChart.prototype.numVisibleDataSets_ = null;
/**
* Creates the DOM node (image) needed for the Chart
* @override
*/
goog.ui.ServerChart.prototype.createDom = function() {
var size = this.getSize();
this.setElementInternal(this.getDomHelper().createDom(goog.dom.TagName.IMG, {
'src': this.getUri(),
'class': goog.getCssName('goog-serverchart-image'),
'width': size[0],
'height': size[1]
}));
};
/**
* Decorate an image already in the DOM.
* Expects the following structure:
*
* - img
*
*
* @param {Element} img Image to decorate.
* @override
*/
goog.ui.ServerChart.prototype.decorateInternal = function(img) {
img.src = this.getUri();
this.setElementInternal(img);
};
/**
* Updates the image if any of the data or settings have changed.
*/
goog.ui.ServerChart.prototype.updateChart = function() {
if (this.getElement()) {
this.getElement().src = this.getUri();
}
};
/**
* Sets the URI of the chart.
*
* @param {goog.Uri} uri The chart URI.
*/
goog.ui.ServerChart.prototype.setUri = function(uri) {
this.uri_ = uri;
};
/**
* Returns the URI of the chart.
*
* @return {goog.Uri} The chart URI.
*/
goog.ui.ServerChart.prototype.getUri = function() {
this.computeDataString_();
return this.uri_;
};
/**
* Returns the upper limit on the length of the chart image URI, after encoding.
* If the URI's length equals or exceeds it, goog.ui.ServerChart.UriTooLongEvent
* is dispatched on the goog.ui.ServerChart object.
*
* @return {number} The chart URI length limit.
*/
goog.ui.ServerChart.prototype.getUriLengthLimit = function() {
return this.uriLengthLimit_;
};
/**
* Sets the upper limit on the length of the chart image URI, after encoding.
* If the URI's length equals or exceeds it, goog.ui.ServerChart.UriTooLongEvent
* is dispatched on the goog.ui.ServerChart object.
*
* @param {number} uriLengthLimit The chart URI length limit.
*/
goog.ui.ServerChart.prototype.setUriLengthLimit = function(uriLengthLimit) {
this.uriLengthLimit_ = uriLengthLimit;
};
/**
* Sets the 'chg' parameter of the chart Uri.
* This is used by various types of charts to specify Grids.
*
* @param {string} value Value for the 'chg' parameter in the chart Uri.
*/
goog.ui.ServerChart.prototype.setGridParameter = function(value) {
this.uri_.setParameterValue(goog.ui.ServerChart.UriParam.GRID, value);
};
/**
* Returns the 'chg' parameter of the chart Uri.
* This is used by various types of charts to specify Grids.
*
* @return {string|undefined} The 'chg' parameter of the chart Uri.
*/
goog.ui.ServerChart.prototype.getGridParameter = function() {
return /** @type {string} */ (
this.uri_.getParameterValue(goog.ui.ServerChart.UriParam.GRID));
};
/**
* Sets the 'chm' parameter of the chart Uri.
* This is used by various types of charts to specify Markers.
*
* @param {string} value Value for the 'chm' parameter in the chart Uri.
*/
goog.ui.ServerChart.prototype.setMarkerParameter = function(value) {
this.uri_.setParameterValue(goog.ui.ServerChart.UriParam.MARKERS, value);
};
/**
* Returns the 'chm' parameter of the chart Uri.
* This is used by various types of charts to specify Markers.
*
* @return {string|undefined} The 'chm' parameter of the chart Uri.
*/
goog.ui.ServerChart.prototype.getMarkerParameter = function() {
return /** @type {string} */ (
this.uri_.getParameterValue(goog.ui.ServerChart.UriParam.MARKERS));
};
/**
* Sets the 'chp' parameter of the chart Uri.
* This is used by various types of charts to specify certain options.
* e.g., finance charts use this to designate which line is the 0 axis.
*
* @param {string|number} value Value for the 'chp' parameter in the chart Uri.
*/
goog.ui.ServerChart.prototype.setMiscParameter = function(value) {
this.uri_.setParameterValue(
goog.ui.ServerChart.UriParam.MISC_PARAMS, String(value));
};
/**
* Returns the 'chp' parameter of the chart Uri.
* This is used by various types of charts to specify certain options.
* e.g., finance charts use this to designate which line is the 0 axis.
*
* @return {string|undefined} The 'chp' parameter of the chart Uri.
*/
goog.ui.ServerChart.prototype.getMiscParameter = function() {
return /** @type {string} */ (
this.uri_.getParameterValue(goog.ui.ServerChart.UriParam.MISC_PARAMS));
};
/**
* Enum of chart data encoding types
*
* @enum {string}
*/
goog.ui.ServerChart.EncodingType = {
AUTOMATIC: '',
EXTENDED: 'e',
SIMPLE: 's',
TEXT: 't'
};
/**
* Enum of chart types with their short names used by the chartserver.
*
* @enum {string}
*/
goog.ui.ServerChart.ChartType = {
BAR: 'br',
CLOCK: 'cf',
CONCENTRIC_PIE: 'pc',
FILLEDLINE: 'lr',
FINANCE: 'lfi',
GOOGLEOMETER: 'gom',
HORIZONTAL_GROUPED_BAR: 'bhg',
HORIZONTAL_STACKED_BAR: 'bhs',
LINE: 'lc',
MAP: 't',
MAPUSA: 'tuss',
MAPWORLD: 'twoc',
PIE: 'p',
PIE3D: 'p3',
RADAR: 'rs',
SCATTER: 's',
SPARKLINE: 'ls',
VENN: 'v',
VERTICAL_GROUPED_BAR: 'bvg',
VERTICAL_STACKED_BAR: 'bvs',
XYLINE: 'lxy'
};
/**
* Enum of multi-axis types.
*
* @enum {string}
*/
goog.ui.ServerChart.MultiAxisType = {
X_AXIS: 'x',
LEFT_Y_AXIS: 'y',
RIGHT_Y_AXIS: 'r',
TOP_AXIS: 't'
};
/**
* Enum of multi-axis alignments.
*
* @enum {number}
*/
goog.ui.ServerChart.MultiAxisAlignment = {
ALIGN_LEFT: -1,
ALIGN_CENTER: 0,
ALIGN_RIGHT: 1
};
/**
* Enum of legend positions.
*
* @enum {string}
*/
goog.ui.ServerChart.LegendPosition = {
TOP: 't',
BOTTOM: 'b',
LEFT: 'l',
RIGHT: 'r'
};
/**
* Enum of line and tick options for an axis.
*
* @enum {string}
*/
goog.ui.ServerChart.AxisDisplayType = {
LINE_AND_TICKS: 'lt',
LINE: 'l',
TICKS: 't'
};
/**
* Enum of chart maximum values in pixels, as listed at:
* http://code.google.com/apis/chart/basics.html
*
* @enum {number}
*/
goog.ui.ServerChart.MaximumValue = {
WIDTH: 1000,
HEIGHT: 1000,
MAP_WIDTH: 440,
MAP_HEIGHT: 220,
TOTAL_AREA: 300000
};
/**
* Enum of ChartServer URI parameters.
*
* @enum {string}
*/
goog.ui.ServerChart.UriParam = {
BACKGROUND_FILL: 'chf',
BAR_HEIGHT: 'chbh',
DATA: 'chd',
DATA_COLORS: 'chco',
DATA_LABELS: 'chld',
DATA_SCALING: 'chds',
DIGITAL_SIGNATURE: 'sig',
GEOGRAPHICAL_REGION: 'chtm',
GRID: 'chg',
LABEL_COLORS: 'chlc',
LEFT_Y_LABELS: 'chly',
LEGEND: 'chdl',
LEGEND_POSITION: 'chdlp',
LEGEND_TEXTS: 'chdl',
LINE_STYLES: 'chls',
MARGINS: 'chma',
MARKERS: 'chm',
MISC_PARAMS: 'chp',
MULTI_AXIS_LABEL_POSITION: 'chxp',
MULTI_AXIS_LABEL_TEXT: 'chxl',
MULTI_AXIS_RANGE: 'chxr',
MULTI_AXIS_STYLE: 'chxs',
MULTI_AXIS_TYPES: 'chxt',
RIGHT_LABELS: 'chlr',
RIGHT_LABEL_POSITIONS: 'chlrp',
SIZE: 'chs',
TITLE: 'chtt',
TITLE_FORMAT: 'chts',
TYPE: 'cht',
X_AXIS_STYLE: 'chx',
X_LABELS: 'chl'
};
/**
* Sets the background fill.
*
* @param {Array