123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827 |
- 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.dom.safe');
- goog.require('goog.events.Event');
- goog.require('goog.string');
- goog.require('goog.ui.Component');
- goog.ui.ServerChart = function(
- type, opt_width, opt_height, opt_domHelper, opt_uri) {
- goog.ui.Component.call(this, opt_domHelper);
-
- this.uri_ = new goog.Uri(
- opt_uri || goog.ui.ServerChart.CHART_SERVER_SCHEME_INDEPENDENT_URI);
-
- this.encodingType_ = goog.ui.ServerChart.EncodingType.AUTOMATIC;
-
- this.dataSets_ = [];
-
- this.setColors_ = [];
-
- this.setLegendTexts_ = [];
-
- this.xLabels_ = [];
-
- this.leftLabels_ = [];
-
- this.rightLabels_ = [];
-
- this.multiAxisType_ = [];
-
- this.multiAxisLabelText_ = {};
-
- this.multiAxisLabelPosition_ = {};
-
- this.multiAxisRange_ = {};
-
- this.multiAxisLabelStyle_ = {};
- this.setType(type);
- this.setSize(opt_width, opt_height);
-
- this.minValue_ = this.isPieChart() ? 0 : Infinity;
- };
- goog.inherits(goog.ui.ServerChart, goog.ui.Component);
- goog.ui.ServerChart.CHART_SERVER_SCHEME_INDEPENDENT_URI =
- '//chart.googleapis.com/chart';
- goog.ui.ServerChart.CHART_SERVER_HTTP_URI = 'http://chart.googleapis.com/chart';
- goog.ui.ServerChart.CHART_SERVER_HTTPS_URI =
- 'https://chart.googleapis.com/chart';
- goog.ui.ServerChart.CHART_SERVER_URI =
- goog.ui.ServerChart.CHART_SERVER_HTTP_URI;
- goog.ui.ServerChart.DEFAULT_NORMALIZATION = 0.5;
- goog.ui.ServerChart.prototype.uriLengthLimit_ = 2048;
- goog.ui.ServerChart.prototype.gridX_ = 0;
- goog.ui.ServerChart.prototype.gridY_ = 0;
- goog.ui.ServerChart.prototype.maxValue_ = -Infinity;
- goog.ui.ServerChart.prototype.title_ = null;
- goog.ui.ServerChart.prototype.titleSize_ = 13.5;
- goog.ui.ServerChart.prototype.titleColor_ = '333333';
- goog.ui.ServerChart.prototype.legend_ = null;
- goog.ui.ServerChart.prototype.numVisibleDataSets_ = null;
- 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]
- }));
- };
- goog.ui.ServerChart.prototype.decorateInternal = function(img) {
- goog.dom.safe.setImageSrc(
- (img), this.getUri().toString());
- this.setElementInternal(img);
- };
- goog.ui.ServerChart.prototype.updateChart = function() {
- if (this.getElement()) {
- goog.dom.safe.setImageSrc(
- (this.getElement()),
- this.getUri().toString());
- }
- };
- goog.ui.ServerChart.prototype.setUri = function(uri) {
- this.uri_ = uri;
- };
- goog.ui.ServerChart.prototype.getUri = function() {
- this.computeDataString_();
- return this.uri_;
- };
- goog.ui.ServerChart.prototype.getUriLengthLimit = function() {
- return this.uriLengthLimit_;
- };
- goog.ui.ServerChart.prototype.setUriLengthLimit = function(uriLengthLimit) {
- this.uriLengthLimit_ = uriLengthLimit;
- };
- goog.ui.ServerChart.prototype.setGridParameter = function(value) {
- this.uri_.setParameterValue(goog.ui.ServerChart.UriParam.GRID, value);
- };
- goog.ui.ServerChart.prototype.getGridParameter = function() {
- return (
- this.uri_.getParameterValue(goog.ui.ServerChart.UriParam.GRID));
- };
- goog.ui.ServerChart.prototype.setMarkerParameter = function(value) {
- this.uri_.setParameterValue(goog.ui.ServerChart.UriParam.MARKERS, value);
- };
- goog.ui.ServerChart.prototype.getMarkerParameter = function() {
- return (
- this.uri_.getParameterValue(goog.ui.ServerChart.UriParam.MARKERS));
- };
- goog.ui.ServerChart.prototype.setMiscParameter = function(value) {
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.MISC_PARAMS, String(value));
- };
- goog.ui.ServerChart.prototype.getMiscParameter = function() {
- return (
- this.uri_.getParameterValue(goog.ui.ServerChart.UriParam.MISC_PARAMS));
- };
- goog.ui.ServerChart.EncodingType = {
- AUTOMATIC: '',
- EXTENDED: 'e',
- SIMPLE: 's',
- TEXT: 't'
- };
- 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'
- };
- goog.ui.ServerChart.MultiAxisType = {
- X_AXIS: 'x',
- LEFT_Y_AXIS: 'y',
- RIGHT_Y_AXIS: 'r',
- TOP_AXIS: 't'
- };
- goog.ui.ServerChart.MultiAxisAlignment = {
- ALIGN_LEFT: -1,
- ALIGN_CENTER: 0,
- ALIGN_RIGHT: 1
- };
- goog.ui.ServerChart.LegendPosition = {
- TOP: 't',
- BOTTOM: 'b',
- LEFT: 'l',
- RIGHT: 'r'
- };
- goog.ui.ServerChart.AxisDisplayType = {
- LINE_AND_TICKS: 'lt',
- LINE: 'l',
- TICKS: 't'
- };
- goog.ui.ServerChart.MaximumValue = {
- WIDTH: 1000,
- HEIGHT: 1000,
- MAP_WIDTH: 440,
- MAP_HEIGHT: 220,
- TOTAL_AREA: 300000
- };
- 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'
- };
- goog.ui.ServerChart.prototype.setBackgroundFill = function(fill) {
- var value = [];
- goog.array.forEach(fill, function(spec) {
- spec.area = spec.area || 'bg';
- spec.effect = spec.effect || 's';
- value.push([spec.area, spec.effect, spec.color].join(','));
- });
- value = value.join('|');
- this.setParameterValue(goog.ui.ServerChart.UriParam.BACKGROUND_FILL, value);
- };
- goog.ui.ServerChart.prototype.getBackgroundFill = function() {
- var value =
- this.uri_.getParameterValue(goog.ui.ServerChart.UriParam.BACKGROUND_FILL);
- var result = [];
- if (goog.isDefAndNotNull(value)) {
- var fillSpecifications = value.split('|');
- var valid = true;
- goog.array.forEach(fillSpecifications, function(spec) {
- var parts = spec.split(',');
- if (valid && parts[1] == 's') {
- result.push({area: parts[0], effect: parts[1], color: parts[2]});
- } else {
-
- result = [];
- valid = false;
- }
- });
- }
- return result;
- };
- goog.ui.ServerChart.prototype.setEncodingType = function(type) {
- this.encodingType_ = type;
- };
- goog.ui.ServerChart.prototype.getEncodingType = function() {
- return this.encodingType_;
- };
- goog.ui.ServerChart.prototype.setType = function(type) {
- this.uri_.setParameterValue(goog.ui.ServerChart.UriParam.TYPE, type);
- };
- goog.ui.ServerChart.prototype.getType = function() {
- return (
- this.uri_.getParameterValue(goog.ui.ServerChart.UriParam.TYPE));
- };
- goog.ui.ServerChart.prototype.setSize = function(opt_width, opt_height) {
- var sizeString = [opt_width || 300, opt_height || 150].join('x');
- this.uri_.setParameterValue(goog.ui.ServerChart.UriParam.SIZE, sizeString);
- };
- goog.ui.ServerChart.prototype.getSize = function() {
- var sizeStr = this.uri_.getParameterValue(goog.ui.ServerChart.UriParam.SIZE);
- return sizeStr.split('x');
- };
- goog.ui.ServerChart.prototype.setMinValue = function(minValue) {
- this.minValue_ = minValue;
- };
- goog.ui.ServerChart.prototype.getMinValue = function() {
- return this.minValue_;
- };
- goog.ui.ServerChart.prototype.setMaxValue = function(maxValue) {
- this.maxValue_ = maxValue;
- };
- goog.ui.ServerChart.prototype.getMaxValue = function() {
- return this.maxValue_;
- };
- goog.ui.ServerChart.prototype.setMargins = function(
- leftMargin, rightMargin, topMargin, bottomMargin) {
- var margins = [leftMargin, rightMargin, topMargin, bottomMargin].join(',');
- var UriParam = goog.ui.ServerChart.UriParam;
- this.uri_.setParameterValue(UriParam.MARGINS, margins);
- };
- goog.ui.ServerChart.prototype.setGridX = function(gridlines) {
-
- this.gridX_ = gridlines;
- this.setGrids_(this.gridX_, this.gridY_);
- };
- goog.ui.ServerChart.prototype.getGridX = function() {
- return this.gridX_;
- };
- goog.ui.ServerChart.prototype.setGridY = function(gridlines) {
-
- this.gridY_ = gridlines;
- this.setGrids_(this.gridX_, this.gridY_);
- };
- goog.ui.ServerChart.prototype.getGridY = function() {
- return this.gridY_;
- };
- goog.ui.ServerChart.prototype.setGrids_ = function(x, y) {
- var gridArray = [x == 0 ? 0 : 100 / x, y == 0 ? 0 : 100 / y];
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.GRID, gridArray.join(','));
- };
- goog.ui.ServerChart.prototype.setXLabels = function(labels) {
- this.xLabels_ = labels;
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.X_LABELS, this.xLabels_.join('|'));
- };
- goog.ui.ServerChart.prototype.getXLabels = function() {
- return this.xLabels_;
- };
- goog.ui.ServerChart.prototype.isBarChart = function() {
- var type = this.getType();
- return type == goog.ui.ServerChart.ChartType.BAR ||
- type == goog.ui.ServerChart.ChartType.HORIZONTAL_GROUPED_BAR ||
- type == goog.ui.ServerChart.ChartType.HORIZONTAL_STACKED_BAR ||
- type == goog.ui.ServerChart.ChartType.VERTICAL_GROUPED_BAR ||
- type == goog.ui.ServerChart.ChartType.VERTICAL_STACKED_BAR;
- };
- goog.ui.ServerChart.prototype.isPieChart = function() {
- var type = this.getType();
- return type == goog.ui.ServerChart.ChartType.PIE ||
- type == goog.ui.ServerChart.ChartType.PIE3D ||
- type == goog.ui.ServerChart.ChartType.CONCENTRIC_PIE;
- };
- goog.ui.ServerChart.prototype.isGroupedBarChart = function() {
- var type = this.getType();
- return type == goog.ui.ServerChart.ChartType.HORIZONTAL_GROUPED_BAR ||
- type == goog.ui.ServerChart.ChartType.VERTICAL_GROUPED_BAR;
- };
- goog.ui.ServerChart.prototype.isHorizontalBarChart = function() {
- var type = this.getType();
- return type == goog.ui.ServerChart.ChartType.BAR ||
- type == goog.ui.ServerChart.ChartType.HORIZONTAL_GROUPED_BAR ||
- type == goog.ui.ServerChart.ChartType.HORIZONTAL_STACKED_BAR;
- };
- goog.ui.ServerChart.prototype.isLineChart = function() {
- var type = this.getType();
- return type == goog.ui.ServerChart.ChartType.FILLEDLINE ||
- type == goog.ui.ServerChart.ChartType.LINE ||
- type == goog.ui.ServerChart.ChartType.SPARKLINE ||
- type == goog.ui.ServerChart.ChartType.XYLINE;
- };
- goog.ui.ServerChart.prototype.isMap = function() {
- var type = this.getType();
- return type == goog.ui.ServerChart.ChartType.MAP ||
- type == goog.ui.ServerChart.ChartType.MAPUSA ||
- type == goog.ui.ServerChart.ChartType.MAPWORLD;
- };
- goog.ui.ServerChart.prototype.isStackedBarChart = function() {
- var type = this.getType();
- return type == goog.ui.ServerChart.ChartType.BAR ||
- type == goog.ui.ServerChart.ChartType.HORIZONTAL_STACKED_BAR ||
- type == goog.ui.ServerChart.ChartType.VERTICAL_STACKED_BAR;
- };
- goog.ui.ServerChart.prototype.isVerticalBarChart = function() {
- var type = this.getType();
- return type == goog.ui.ServerChart.ChartType.VERTICAL_GROUPED_BAR ||
- type == goog.ui.ServerChart.ChartType.VERTICAL_STACKED_BAR;
- };
- goog.ui.ServerChart.prototype.setLeftLabels = function(labels) {
- this.leftLabels_ = labels;
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.LEFT_Y_LABELS,
- this.leftLabels_.reverse().join('|'));
- };
- goog.ui.ServerChart.prototype.getLeftLabels = function() {
- return this.leftLabels_;
- };
- goog.ui.ServerChart.prototype.setParameterValue = function(key, value) {
- this.uri_.setParameterValue(key, value);
- };
- goog.ui.ServerChart.prototype.removeParameter = function(key) {
- this.uri_.removeParameter(key);
- };
- goog.ui.ServerChart.prototype.setRightLabels = function(labels) {
- this.rightLabels_ = labels;
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.RIGHT_LABELS,
- this.rightLabels_.reverse().join('|'));
- };
- goog.ui.ServerChart.prototype.getRightLabels = function() {
- return this.rightLabels_;
- };
- goog.ui.ServerChart.prototype.setLegendPosition = function(value) {
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.LEGEND_POSITION, value);
- };
- goog.ui.ServerChart.prototype.getLegendPosition = function() {
- return (
- this.uri_.getParameterValue(
- goog.ui.ServerChart.UriParam.LEGEND_POSITION));
- };
- goog.ui.ServerChart.prototype.setNumVisibleDataSets = function(n) {
- this.numVisibleDataSets_ = n;
- };
- goog.ui.ServerChart.prototype.getNumVisibleDataSets = function() {
- return this.numVisibleDataSets_;
- };
- goog.ui.ServerChart.prototype.setVennSeries = function(
- weights, opt_legendText, opt_colors) {
- if (this.getType() != goog.ui.ServerChart.ChartType.VENN) {
- throw Error('Can only set a weight function for a Venn diagram.');
- }
- var dataMin = this.arrayMin_(weights);
- if (dataMin < this.minValue_) {
- this.minValue_ = dataMin;
- }
- var dataMax = this.arrayMax_(weights);
- if (dataMax > this.maxValue_) {
- this.maxValue_ = dataMax;
- }
- if (goog.isDef(opt_legendText)) {
- goog.array.forEach(opt_legendText, goog.bind(function(legend) {
- this.setLegendTexts_.push(legend);
- }, this));
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.LEGEND_TEXTS,
- this.setLegendTexts_.join('|'));
- }
-
-
-
- if (weights.length == 3) {
- weights[3] = weights[2];
- weights[2] = 0.0;
- }
- this.dataSets_.push(weights);
- if (goog.isDef(opt_colors)) {
- goog.array.forEach(opt_colors, goog.bind(function(color) {
- this.setColors_.push(color);
- }, this));
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.DATA_COLORS, this.setColors_.join(','));
- }
- };
- goog.ui.ServerChart.prototype.setTitle = function(title) {
- this.title_ = title;
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.TITLE, this.title_.replace(/\n/g, '|'));
- };
- goog.ui.ServerChart.prototype.setTitleSize = function(size) {
- this.titleSize_ = size;
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.TITLE_FORMAT,
- this.titleColor_ + ',' + this.titleSize_);
- };
- goog.ui.ServerChart.prototype.getTitleSize = function() {
- return this.titleSize_;
- };
- goog.ui.ServerChart.prototype.setTitleColor = function(color) {
- this.titleColor_ = color;
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.TITLE_FORMAT,
- this.titleColor_ + ',' + this.titleSize_);
- };
- goog.ui.ServerChart.prototype.getTitleColor = function() {
- return this.titleColor_;
- };
- goog.ui.ServerChart.prototype.setLegend = function(legend) {
- this.legend_ = legend;
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.LEGEND, this.legend_.join('|'));
- };
- goog.ui.ServerChart.prototype.setDataScaling = function(minimum, maximum) {
- this.encodingType_ = goog.ui.ServerChart.EncodingType.TEXT;
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.DATA_SCALING, minimum + ',' + maximum);
- };
- goog.ui.ServerChart.prototype.setBarSpaceWidths = function(
- barWidth, opt_spaceBars, opt_spaceGroups) {
- var widths = [barWidth];
- if (goog.isDef(opt_spaceBars)) {
- widths.push(opt_spaceBars);
- }
- if (goog.isDef(opt_spaceGroups)) {
- widths.push(opt_spaceGroups);
- }
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.BAR_HEIGHT, widths.join(','));
- };
- goog.ui.ServerChart.prototype.setAutomaticBarWidth = function(
- opt_spaceBars, opt_spaceGroups) {
- var widths = ['a'];
- if (goog.isDef(opt_spaceBars)) {
- widths.push(opt_spaceBars);
- }
- if (goog.isDef(opt_spaceGroups)) {
- widths.push(opt_spaceGroups);
- }
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.BAR_HEIGHT, widths.join(','));
- };
- goog.ui.ServerChart.prototype.addMultiAxis = function(axisType) {
- this.multiAxisType_.push(axisType);
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.MULTI_AXIS_TYPES,
- this.multiAxisType_.join(','));
- return this.multiAxisType_.length - 1;
- };
- goog.ui.ServerChart.prototype.getMultiAxisType = function(opt_axisNumber) {
- if (goog.isDef(opt_axisNumber)) {
- return this.multiAxisType_[opt_axisNumber];
- }
- return this.multiAxisType_;
- };
- goog.ui.ServerChart.prototype.setMultiAxisLabelText = function(
- axisNumber, labelText) {
- this.multiAxisLabelText_[axisNumber] = labelText;
- var axisString = this.computeMultiAxisDataString_(
- this.multiAxisLabelText_, ':|', '|', '|');
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.MULTI_AXIS_LABEL_TEXT, axisString);
- };
- goog.ui.ServerChart.prototype.getMultiAxisLabelText = function(opt_axisNumber) {
- if (goog.isDef(opt_axisNumber)) {
- return this.multiAxisLabelText_[opt_axisNumber];
- }
- return this.multiAxisLabelText_;
- };
- goog.ui.ServerChart.prototype.setMultiAxisLabelPosition = function(
- axisNumber, labelPosition) {
- this.multiAxisLabelPosition_[axisNumber] = labelPosition;
- var positionString = this.computeMultiAxisDataString_(
- this.multiAxisLabelPosition_, ',', ',', '|');
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.MULTI_AXIS_LABEL_POSITION, positionString);
- };
- goog.ui.ServerChart.prototype.getMultiAxisLabelPosition = function(
- opt_axisNumber) {
- if (goog.isDef(opt_axisNumber)) {
- return this.multiAxisLabelPosition_[opt_axisNumber];
- }
- return this.multiAxisLabelPosition_;
- };
- goog.ui.ServerChart.prototype.setMultiAxisRange = function(
- axisNumber, rangeStart, rangeEnd, opt_interval) {
- goog.asserts.assert(
- rangeStart != rangeEnd, 'Range start and end cannot be the same value.');
- goog.asserts.assert(
- isFinite(rangeStart) && isFinite(rangeEnd),
- 'Range start and end must be finite numbers.');
- this.multiAxisRange_[axisNumber] = [rangeStart, rangeEnd];
- if (goog.isDef(opt_interval)) {
- this.multiAxisRange_[axisNumber].push(opt_interval);
- }
- var rangeString =
- this.computeMultiAxisDataString_(this.multiAxisRange_, ',', ',', '|');
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.MULTI_AXIS_RANGE, rangeString);
- };
- goog.ui.ServerChart.prototype.getMultiAxisRange = function(opt_axisNumber) {
- if (goog.isDef(opt_axisNumber)) {
- return this.multiAxisRange_[opt_axisNumber];
- }
- return this.multiAxisRange_;
- };
- goog.ui.ServerChart.prototype.setMultiAxisLabelStyle = function(
- axisNumber, color, opt_fontSize, opt_alignment, opt_axisDisplay) {
- var style = [color];
- if (goog.isDef(opt_fontSize) || goog.isDef(opt_alignment)) {
- style.push(opt_fontSize || '');
- }
- if (goog.isDef(opt_alignment)) {
- style.push(opt_alignment);
- }
- if (opt_axisDisplay) {
- style.push(opt_axisDisplay);
- }
- this.multiAxisLabelStyle_[axisNumber] = style;
- var styleString = this.computeMultiAxisDataString_(
- this.multiAxisLabelStyle_, ',', ',', '|');
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.MULTI_AXIS_STYLE, styleString);
- };
- goog.ui.ServerChart.prototype.getMultiAxisLabelStyle = function(
- opt_axisNumber) {
- if (goog.isDef(opt_axisNumber)) {
- return this.multiAxisLabelStyle_[opt_axisNumber];
- }
- return this.multiAxisLabelStyle_;
- };
- goog.ui.ServerChart.prototype.addDataSet = function(
- data, color, opt_legendText) {
- var dataMin = this.arrayMin_(data);
- if (dataMin < this.minValue_) {
- this.minValue_ = dataMin;
- }
- var dataMax = this.arrayMax_(data);
- if (dataMax > this.maxValue_) {
- this.maxValue_ = dataMax;
- }
- if (goog.isDef(opt_legendText)) {
- if (this.setLegendTexts_.length < this.dataSets_.length) {
- throw Error('Cannot start adding legends text after first element.');
- }
- this.setLegendTexts_.push(opt_legendText);
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.LEGEND_TEXTS,
- this.setLegendTexts_.join('|'));
- }
- this.dataSets_.push(data);
- this.setColors_.push(color);
- this.uri_.setParameterValue(
- goog.ui.ServerChart.UriParam.DATA_COLORS, this.setColors_.join(','));
- };
- goog.ui.ServerChart.prototype.clearDataSets = function() {
- var queryData = this.uri_.getQueryData();
- queryData.remove(goog.ui.ServerChart.UriParam.LEGEND_TEXTS);
- queryData.remove(goog.ui.ServerChart.UriParam.DATA_COLORS);
- queryData.remove(goog.ui.ServerChart.UriParam.DATA);
- this.setLegendTexts_.length = 0;
- this.setColors_.length = 0;
- this.dataSets_.length = 0;
- };
- goog.ui.ServerChart.prototype.getData = function(opt_setNumber) {
- if (goog.isDef(opt_setNumber)) {
- return this.dataSets_[opt_setNumber];
- }
- return this.dataSets_;
- };
- goog.ui.ServerChart.prototype.computeDataString_ = function() {
- var ok;
- if (this.encodingType_ != goog.ui.ServerChart.EncodingType.AUTOMATIC) {
- ok = this.computeDataStringForEncoding_(this.encodingType_);
- } else {
- ok = this.computeDataStringForEncoding_(
- goog.ui.ServerChart.EncodingType.EXTENDED);
- if (!ok) {
- ok = this.computeDataStringForEncoding_(
- goog.ui.ServerChart.EncodingType.SIMPLE);
- }
- }
- if (!ok) {
- this.dispatchEvent(
- new goog.ui.ServerChart.UriTooLongEvent(this.uri_.toString()));
- }
- };
- goog.ui.ServerChart.prototype.computeDataStringForEncoding_ = function(
- encoding) {
- var dataStrings = [];
- for (var i = 0, setLen = this.dataSets_.length; i < setLen; ++i) {
- dataStrings[i] = this.getChartServerValues_(
- this.dataSets_[i], this.minValue_, this.maxValue_, encoding);
- }
- var delimiter = encoding == goog.ui.ServerChart.EncodingType.TEXT ? '|' : ',';
- dataStrings = dataStrings.join(delimiter);
- var data;
- if (this.numVisibleDataSets_ == null) {
- data = goog.string.buildString(encoding, ':', dataStrings);
- } else {
- data = goog.string.buildString(
- encoding, this.numVisibleDataSets_, ':', dataStrings);
- }
- this.uri_.setParameterValue(goog.ui.ServerChart.UriParam.DATA, data);
- return this.uri_.toString().length < this.uriLengthLimit_;
- };
- goog.ui.ServerChart.prototype.computeMultiAxisDataString_ = function(
- data, indexSeparator, elementSeparator, axisSeparator) {
- var elementStrings = [];
- for (var i = 0, setLen = this.multiAxisType_.length; i < setLen; ++i) {
- if (data[i]) {
- elementStrings.push(i + indexSeparator + data[i].join(elementSeparator));
- }
- }
- return elementStrings.join(axisSeparator);
- };
- goog.ui.ServerChart.CHART_VALUES = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
- 'abcdefghijklmnopqrstuvwxyz' +
- '0123456789';
- goog.ui.ServerChart.CHART_VALUES_EXTENDED =
- goog.ui.ServerChart.CHART_VALUES + '-.';
- goog.ui.ServerChart.EXTENDED_UPPER_BOUND =
- Math.pow(goog.ui.ServerChart.CHART_VALUES_EXTENDED.length, 2) - 1;
- goog.ui.ServerChart.prototype.getConvertedValue_ = function(
- value, minValue, maxValue, encoding) {
- goog.asserts.assert(
- minValue <= maxValue,
- 'minValue should be less than or equal to maxValue');
- var isExtended = (encoding == goog.ui.ServerChart.EncodingType.EXTENDED);
- if (goog.isNull(value) || !goog.isDef(value) || isNaN(value) ||
- value < minValue || value > maxValue) {
- return isExtended ? '__' : '_';
- }
- if (encoding == goog.ui.ServerChart.EncodingType.TEXT) {
- return String(value);
- }
- var frac = goog.ui.ServerChart.DEFAULT_NORMALIZATION;
- if (maxValue > minValue) {
- frac = (value - minValue) / (maxValue - minValue);
-
- }
- if (isExtended) {
- var maxIndex = goog.ui.ServerChart.CHART_VALUES_EXTENDED.length;
- var upperBound = goog.ui.ServerChart.EXTENDED_UPPER_BOUND;
- var index1 = Math.floor(frac * upperBound / maxIndex);
- var index2 = Math.floor((frac * upperBound) % maxIndex);
- var extendedVals = goog.ui.ServerChart.CHART_VALUES_EXTENDED;
- return extendedVals.charAt(index1) + extendedVals.charAt(index2);
- }
- var index = Math.round(frac * (goog.ui.ServerChart.CHART_VALUES.length - 1));
- return goog.ui.ServerChart.CHART_VALUES.charAt(index);
- };
- goog.ui.ServerChart.prototype.getChartServerValues_ = function(
- values, minValue, maxValue, encoding) {
- var s = [];
- for (var i = 0, valuesLen = values.length; i < valuesLen; ++i) {
- s.push(this.getConvertedValue_(values[i], minValue, maxValue, encoding));
- }
- return s.join(
- this.encodingType_ == goog.ui.ServerChart.EncodingType.TEXT ? ',' : '');
- };
- goog.ui.ServerChart.prototype.arrayMin_ = function(ary) {
- var min = Infinity;
- for (var i = 0, aryLen = ary.length; i < aryLen; ++i) {
- var value = ary[i];
- if (value != null && value < min) {
- min = value;
- }
- }
- return min;
- };
- goog.ui.ServerChart.prototype.arrayMax_ = function(ary) {
- var max = -Infinity;
- for (var i = 0, aryLen = ary.length; i < aryLen; ++i) {
- var value = ary[i];
- if (value != null && value > max) {
- max = value;
- }
- }
- return max;
- };
- goog.ui.ServerChart.prototype.disposeInternal = function() {
- goog.ui.ServerChart.superClass_.disposeInternal.call(this);
- delete this.xLabels_;
- delete this.leftLabels_;
- delete this.rightLabels_;
- delete this.gridX_;
- delete this.gridY_;
- delete this.setColors_;
- delete this.setLegendTexts_;
- delete this.dataSets_;
- this.uri_ = null;
- delete this.minValue_;
- delete this.maxValue_;
- this.title_ = null;
- delete this.multiAxisType_;
- delete this.multiAxisLabelText_;
- delete this.multiAxisLabelPosition_;
- delete this.multiAxisRange_;
- delete this.multiAxisLabelStyle_;
- this.legend_ = null;
- };
- goog.ui.ServerChart.Event = {
-
- URI_TOO_LONG: 'uritoolong'
- };
- goog.ui.ServerChart.UriTooLongEvent = function(uri) {
- goog.events.Event.call(this, goog.ui.ServerChart.Event.URI_TOO_LONG);
-
- this.uri = uri;
- };
- goog.inherits(goog.ui.ServerChart.UriTooLongEvent, goog.events.Event);
|