serverchart_test.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. // Copyright 2007 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. goog.provide('goog.ui.ServerChartTest');
  15. goog.setTestOnly('goog.ui.ServerChartTest');
  16. goog.require('goog.Uri');
  17. goog.require('goog.events');
  18. goog.require('goog.testing.jsunit');
  19. goog.require('goog.ui.ServerChart');
  20. function testSchemeIndependentBarChartRequest() {
  21. var bar = new goog.ui.ServerChart(
  22. goog.ui.ServerChart.ChartType.BAR, 180, 104, null);
  23. tryToCreateBarChart(bar);
  24. var uri = bar.getUri();
  25. var schemeIndependentUri =
  26. new goog.Uri(goog.ui.ServerChart.CHART_SERVER_SCHEME_INDEPENDENT_URI);
  27. assertEquals('', uri.getScheme());
  28. assertEquals(schemeIndependentUri.getDomain(), uri.getDomain());
  29. }
  30. function testHttpBarChartRequest() {
  31. var bar = new goog.ui.ServerChart(
  32. goog.ui.ServerChart.ChartType.BAR, 180, 104, null,
  33. goog.ui.ServerChart.CHART_SERVER_HTTP_URI);
  34. tryToCreateBarChart(bar);
  35. var uri = bar.getUri();
  36. var httpUri = new goog.Uri(goog.ui.ServerChart.CHART_SERVER_HTTP_URI);
  37. assertEquals('http', uri.getScheme());
  38. assertEquals(httpUri.getDomain(), uri.getDomain());
  39. }
  40. function testHttpsBarChartRequest() {
  41. var bar = new goog.ui.ServerChart(
  42. goog.ui.ServerChart.ChartType.BAR, 180, 104, null,
  43. goog.ui.ServerChart.CHART_SERVER_HTTPS_URI);
  44. tryToCreateBarChart(bar);
  45. var uri = bar.getUri();
  46. var httpsUri = new goog.Uri(goog.ui.ServerChart.CHART_SERVER_HTTPS_URI);
  47. assertEquals('https', uri.getScheme());
  48. assertEquals(httpsUri.getDomain(), uri.getDomain());
  49. }
  50. function testMinValue() {
  51. var pie =
  52. new goog.ui.ServerChart(goog.ui.ServerChart.ChartType.PIE3D, 180, 104);
  53. pie.addDataSet([1, 2, 3], '000000');
  54. assertEquals(pie.getMinValue(), 0);
  55. var line =
  56. new goog.ui.ServerChart(goog.ui.ServerChart.ChartType.LINE, 180, 104);
  57. line.addDataSet([1, 2, 3], '000000');
  58. assertEquals(line.getMinValue(), 1);
  59. }
  60. function testMargins() {
  61. var pie =
  62. new goog.ui.ServerChart(goog.ui.ServerChart.ChartType.PIE3D, 180, 104);
  63. pie.setMargins(1, 2, 3, 4);
  64. assertEquals(
  65. '1,2,3,4',
  66. pie.getUri().getParameterValue(goog.ui.ServerChart.UriParam.MARGINS));
  67. }
  68. function testSetParameterValue() {
  69. var scatter =
  70. new goog.ui.ServerChart(goog.ui.ServerChart.ChartType.SCATTER, 180, 104);
  71. var key = goog.ui.ServerChart.UriParam.DATA_COLORS;
  72. var value = '000000,FF0000|00FF00|0000FF';
  73. scatter.setParameterValue(key, value);
  74. assertEquals(
  75. 'unexpected parameter value', value,
  76. scatter.getUri().getParameterValue(key));
  77. scatter.removeParameter(key);
  78. assertUndefined(
  79. 'parameter not removed', scatter.getUri().getParameterValue(key));
  80. }
  81. function testTypes() {
  82. var chart;
  83. chart = new goog.ui.ServerChart(
  84. goog.ui.ServerChart.ChartType.CONCENTRIC_PIE, 180, 104);
  85. assertTrue(chart.isPieChart());
  86. assertFalse(chart.isBarChart());
  87. assertFalse(chart.isMap());
  88. assertFalse(chart.isLineChart());
  89. chart = new goog.ui.ServerChart(
  90. goog.ui.ServerChart.ChartType.HORIZONTAL_GROUPED_BAR, 180, 104);
  91. assertFalse(chart.isPieChart());
  92. assertTrue(chart.isBarChart());
  93. assertTrue(chart.isHorizontalBarChart());
  94. assertTrue(chart.isGroupedBarChart());
  95. assertFalse(chart.isVerticalBarChart());
  96. assertFalse(chart.isStackedBarChart());
  97. chart = new goog.ui.ServerChart(goog.ui.ServerChart.ChartType.BAR, 180, 104);
  98. assertTrue(chart.isBarChart());
  99. assertTrue(chart.isStackedBarChart());
  100. assertFalse(chart.isGroupedBarChart());
  101. chart =
  102. new goog.ui.ServerChart(goog.ui.ServerChart.ChartType.XYLINE, 180, 104);
  103. assertTrue('I thought lxy was a line chart', chart.isLineChart());
  104. assertFalse('lxy is definitely not a pie chart', chart.isPieChart());
  105. }
  106. function testBarChartRequest() {
  107. var bar =
  108. new goog.ui.ServerChart(goog.ui.ServerChart.ChartType.BAR, 180, 104);
  109. tryToCreateBarChart(bar);
  110. var httpUri = new goog.Uri(goog.ui.ServerChart.CHART_SERVER_URI);
  111. var uri = bar.getUri();
  112. assertEquals(httpUri.getDomain(), uri.getDomain());
  113. }
  114. function tryToCreateBarChart(bar) {
  115. bar.addDataSet([8, 23, 7], '008000');
  116. bar.addDataSet([31, 11, 7], 'ffcc33');
  117. bar.addDataSet([2, 43, 70, 3, 43, 74], '3072f3');
  118. bar.setLeftLabels(['', '20K', '', '60K', '', '100K']);
  119. bar.setXLabels(['O', 'N', 'D']);
  120. bar.setMaxValue(100);
  121. var uri = bar.getUri();
  122. assertEquals('br', uri.getParameterValue(goog.ui.ServerChart.UriParam.TYPE));
  123. assertEquals(
  124. '180x104', uri.getParameterValue(goog.ui.ServerChart.UriParam.SIZE));
  125. assertEquals(
  126. 'e:D6NtDQ,S7F4DQ,AAaxsZApaxvA',
  127. uri.getParameterValue(goog.ui.ServerChart.UriParam.DATA));
  128. assertEquals(
  129. '008000,ffcc33,3072f3',
  130. uri.getParameterValue(goog.ui.ServerChart.UriParam.DATA_COLORS));
  131. assertEquals(
  132. '100K||60K||20K|',
  133. uri.getParameterValue(goog.ui.ServerChart.UriParam.LEFT_Y_LABELS));
  134. assertEquals(
  135. 'O|N|D', uri.getParameterValue(goog.ui.ServerChart.UriParam.X_LABELS));
  136. }
  137. function testClearDataSets() {
  138. var chart =
  139. new goog.ui.ServerChart(goog.ui.ServerChart.ChartType.BAR, 180, 104);
  140. tryToCreateBarChart(chart);
  141. var uriBefore = chart.getUri();
  142. chart.clearDataSets();
  143. var chart =
  144. new goog.ui.ServerChart(goog.ui.ServerChart.ChartType.BAR, 180, 104);
  145. tryToCreateBarChart(chart);
  146. var uriAfter = chart.getUri();
  147. assertEquals(uriBefore.getScheme(), uriAfter.getScheme());
  148. assertEquals(uriBefore.getDomain(), uriAfter.getDomain());
  149. assertEquals(uriBefore.getPath(), uriAfter.getPath());
  150. }
  151. function testMultipleDatasetsTextEncoding() {
  152. var chart =
  153. new goog.ui.ServerChart(goog.ui.ServerChart.ChartType.BAR, 180, 104);
  154. chart.setEncodingType(goog.ui.ServerChart.EncodingType.TEXT);
  155. chart.addDataSet([0, 25, 100], '008000');
  156. chart.addDataSet([12, 2, 7.1], '112233');
  157. chart.addDataSet([82, 16, 2], '3072f3');
  158. var uri = chart.getUri();
  159. assertEquals(
  160. 't:0,25,100|12,2,7.1|82,16,2',
  161. uri.getParameterValue(goog.ui.ServerChart.UriParam.DATA));
  162. }
  163. function testVennDiagramRequest() {
  164. var venn =
  165. new goog.ui.ServerChart(goog.ui.ServerChart.ChartType.VENN, 300, 200);
  166. venn.setTitle('Google Employees');
  167. var weights = [
  168. 80, // Size of circle A
  169. 60, // Size of circle B
  170. 40, // Size of circle C
  171. 20, // Overlap of A and B
  172. 20, // Overlap of A and C
  173. 20, // Overlap of B and C
  174. 5
  175. ]; // Overlap of A, B and C
  176. var labels = [
  177. 'C Hackers', // Label for A
  178. 'LISP Gurus', // Label for B
  179. 'Java Jockeys'
  180. ]; // Label for C
  181. venn.setVennSeries(weights, labels);
  182. var uri = venn.getUri();
  183. var httpUri = new goog.Uri(goog.ui.ServerChart.CHART_SERVER_URI);
  184. assertEquals(httpUri.getDomain(), uri.getDomain());
  185. assertEquals('v', uri.getParameterValue(goog.ui.ServerChart.UriParam.TYPE));
  186. assertEquals(
  187. '300x200', uri.getParameterValue(goog.ui.ServerChart.UriParam.SIZE));
  188. assertEquals(
  189. 'e:..u7d3MzMzMzAA',
  190. uri.getParameterValue(goog.ui.ServerChart.UriParam.DATA));
  191. assertEquals(
  192. 'Google Employees',
  193. uri.getParameterValue(goog.ui.ServerChart.UriParam.TITLE));
  194. assertEquals(
  195. labels.join('|'),
  196. uri.getParameterValue(goog.ui.ServerChart.UriParam.LEGEND_TEXTS));
  197. }
  198. function testSparklineChartRequest() {
  199. var chart = new goog.ui.ServerChart(
  200. goog.ui.ServerChart.ChartType.SPARKLINE, 300, 200);
  201. chart.addDataSet([8, 23, 7], '008000');
  202. chart.addDataSet([31, 11, 7], 'ffcc33');
  203. chart.addDataSet([2, 43, 70, 3, 43, 74], '3072f3');
  204. chart.setLeftLabels(['', '20K', '', '60K', '', '100K']);
  205. chart.setXLabels(['O', 'N', 'D']);
  206. chart.setMaxValue(100);
  207. var uri = chart.getUri();
  208. assertEquals('ls', uri.getParameterValue(goog.ui.ServerChart.UriParam.TYPE));
  209. assertEquals(
  210. '300x200', uri.getParameterValue(goog.ui.ServerChart.UriParam.SIZE));
  211. assertEquals(
  212. 'e:D6NtDQ,S7F4DQ,AAaxsZApaxvA',
  213. uri.getParameterValue(goog.ui.ServerChart.UriParam.DATA));
  214. assertEquals(
  215. '008000,ffcc33,3072f3',
  216. uri.getParameterValue(goog.ui.ServerChart.UriParam.DATA_COLORS));
  217. assertEquals(
  218. '100K||60K||20K|',
  219. uri.getParameterValue(goog.ui.ServerChart.UriParam.LEFT_Y_LABELS));
  220. assertEquals(
  221. 'O|N|D', uri.getParameterValue(goog.ui.ServerChart.UriParam.X_LABELS));
  222. }
  223. function testLegendPositionRequest() {
  224. var chart = new goog.ui.ServerChart(
  225. goog.ui.ServerChart.ChartType.SPARKLINE, 300, 200);
  226. chart.addDataSet([0, 100], '008000', 'foo');
  227. chart.setLegendPosition(goog.ui.ServerChart.LegendPosition.TOP);
  228. assertEquals('t', chart.getLegendPosition());
  229. var uri = chart.getUri();
  230. assertEquals(
  231. 't', uri.getParameterValue(goog.ui.ServerChart.UriParam.LEGEND_POSITION));
  232. }
  233. function testSetGridParameter() {
  234. var gridArg = '20,20,4,4';
  235. var chart = new goog.ui.ServerChart(
  236. goog.ui.ServerChart.ChartType.SPARKLINE, 300, 200);
  237. chart.addDataSet([0, 100], '008000', 'foo');
  238. chart.setGridParameter(gridArg);
  239. assertEquals(gridArg, chart.getGridParameter());
  240. var uri = chart.getUri();
  241. assertEquals(
  242. gridArg, uri.getParameterValue(goog.ui.ServerChart.UriParam.GRID));
  243. }
  244. function testSetMarkerParameter() {
  245. var markerArg = 's,FF0000,0,-1,5';
  246. var chart = new goog.ui.ServerChart(
  247. goog.ui.ServerChart.ChartType.SPARKLINE, 300, 200);
  248. chart.addDataSet([0, 100], '008000', 'foo');
  249. chart.setMarkerParameter(markerArg);
  250. assertEquals(markerArg, chart.getMarkerParameter());
  251. var uri = chart.getUri();
  252. assertEquals(
  253. markerArg, uri.getParameterValue(goog.ui.ServerChart.UriParam.MARKERS));
  254. }
  255. function testNullDataPointRequest() {
  256. var chart = new goog.ui.ServerChart(
  257. goog.ui.ServerChart.ChartType.SPARKLINE, 300, 200);
  258. chart.addDataSet([40, null, 10], '008000');
  259. assertEquals(10, chart.getMinValue());
  260. assertEquals(40, chart.getMaxValue());
  261. var uri = chart.getUri();
  262. assertEquals(
  263. 'e:..__AA', uri.getParameterValue(goog.ui.ServerChart.UriParam.DATA));
  264. chart = new goog.ui.ServerChart(
  265. goog.ui.ServerChart.ChartType.SPARKLINE, 300, 200);
  266. chart.addDataSet([-5, null, -1], '008000');
  267. assertEquals(-5, chart.getMinValue());
  268. assertEquals(-1, chart.getMaxValue());
  269. uri = chart.getUri();
  270. assertEquals(
  271. 'e:AA__..', uri.getParameterValue(goog.ui.ServerChart.UriParam.DATA));
  272. }
  273. function testSetBarSpaceWidths() {
  274. var noSpaceBetweenBarsSpecified = '20';
  275. var noSpaceBetweenBarsChart = new goog.ui.ServerChart(
  276. goog.ui.ServerChart.ChartType.VERTICAL_STACKED_BAR);
  277. noSpaceBetweenBarsChart.setBarSpaceWidths(20);
  278. var uri = noSpaceBetweenBarsChart.getUri();
  279. assertEquals(
  280. noSpaceBetweenBarsSpecified,
  281. uri.getParameterValue(goog.ui.ServerChart.UriParam.BAR_HEIGHT));
  282. var spaceBetweenBarsSpecified = '20,5';
  283. var spaceBetweenBarsChart = new goog.ui.ServerChart(
  284. goog.ui.ServerChart.ChartType.HORIZONTAL_STACKED_BAR);
  285. spaceBetweenBarsChart.setBarSpaceWidths(20, 5);
  286. var uri = spaceBetweenBarsChart.getUri();
  287. assertEquals(
  288. spaceBetweenBarsSpecified,
  289. uri.getParameterValue(goog.ui.ServerChart.UriParam.BAR_HEIGHT));
  290. var spaceBetweenGroupsSpecified = '20,5,6';
  291. var spaceBetweenGroupsChart = new goog.ui.ServerChart(
  292. goog.ui.ServerChart.ChartType.HORIZONTAL_STACKED_BAR);
  293. spaceBetweenGroupsChart.setBarSpaceWidths(20, 5, 6);
  294. var uri = spaceBetweenGroupsChart.getUri();
  295. assertEquals(
  296. spaceBetweenGroupsSpecified,
  297. uri.getParameterValue(goog.ui.ServerChart.UriParam.BAR_HEIGHT));
  298. var groupsButNotBarsSpecified = '20,6';
  299. var groupsButNotBarsChart = new goog.ui.ServerChart(
  300. goog.ui.ServerChart.ChartType.HORIZONTAL_STACKED_BAR);
  301. groupsButNotBarsChart.setBarSpaceWidths(20, undefined, 6);
  302. var uri = groupsButNotBarsChart.getUri();
  303. assertEquals(
  304. groupsButNotBarsSpecified,
  305. uri.getParameterValue(goog.ui.ServerChart.UriParam.BAR_HEIGHT));
  306. }
  307. function testSetAutomaticBarWidth() {
  308. var noSpaceBetweenBarsSpecified = 'a';
  309. var noSpaceBetweenBarsChart = new goog.ui.ServerChart(
  310. goog.ui.ServerChart.ChartType.VERTICAL_STACKED_BAR);
  311. noSpaceBetweenBarsChart.setAutomaticBarWidth();
  312. var uri = noSpaceBetweenBarsChart.getUri();
  313. assertEquals(
  314. noSpaceBetweenBarsSpecified,
  315. uri.getParameterValue(goog.ui.ServerChart.UriParam.BAR_HEIGHT));
  316. var spaceBetweenBarsSpecified = 'a,5';
  317. var spaceBetweenBarsChart = new goog.ui.ServerChart(
  318. goog.ui.ServerChart.ChartType.HORIZONTAL_STACKED_BAR);
  319. spaceBetweenBarsChart.setAutomaticBarWidth(5);
  320. uri = spaceBetweenBarsChart.getUri();
  321. assertEquals(
  322. spaceBetweenBarsSpecified,
  323. uri.getParameterValue(goog.ui.ServerChart.UriParam.BAR_HEIGHT));
  324. var spaceBetweenGroupsSpecified = 'a,5,6';
  325. var spaceBetweenGroupsChart = new goog.ui.ServerChart(
  326. goog.ui.ServerChart.ChartType.HORIZONTAL_STACKED_BAR);
  327. spaceBetweenGroupsChart.setAutomaticBarWidth(5, 6);
  328. uri = spaceBetweenGroupsChart.getUri();
  329. assertEquals(
  330. spaceBetweenGroupsSpecified,
  331. uri.getParameterValue(goog.ui.ServerChart.UriParam.BAR_HEIGHT));
  332. var groupsButNotBarsSpecified = 'a,6';
  333. var groupsButNotBarsChart = new goog.ui.ServerChart(
  334. goog.ui.ServerChart.ChartType.HORIZONTAL_STACKED_BAR);
  335. groupsButNotBarsChart.setAutomaticBarWidth(undefined, 6);
  336. uri = groupsButNotBarsChart.getUri();
  337. assertEquals(
  338. groupsButNotBarsSpecified,
  339. uri.getParameterValue(goog.ui.ServerChart.UriParam.BAR_HEIGHT));
  340. }
  341. function testSetDataScaling() {
  342. var dataScalingArg = '0,160';
  343. var dataArg = 't:0,50,100,130';
  344. var chart = new goog.ui.ServerChart(
  345. goog.ui.ServerChart.ChartType.VERTICAL_STACKED_BAR, 300, 200);
  346. chart.addDataSet([0, 50, 100, 130], '008000');
  347. chart.setDataScaling(0, 160);
  348. var uri = chart.getUri();
  349. assertEquals(
  350. dataScalingArg,
  351. uri.getParameterValue(goog.ui.ServerChart.UriParam.DATA_SCALING));
  352. assertEquals(
  353. dataArg, uri.getParameterValue(goog.ui.ServerChart.UriParam.DATA));
  354. }
  355. function testSetMultiAxisLabelStyle() {
  356. var noFontSizeChart = new goog.ui.ServerChart(
  357. goog.ui.ServerChart.ChartType.HORIZONTAL_STACKED_BAR, 300, 200);
  358. noFontSizeChart.addDataSet([0, 50, 100, 130], '008000');
  359. var axisNumber = noFontSizeChart.addMultiAxis(
  360. goog.ui.ServerChart.MultiAxisType.LEFT_Y_AXIS);
  361. var noFontSizeArgs = axisNumber + ',009000';
  362. noFontSizeChart.setMultiAxisLabelStyle(axisNumber, '009000');
  363. var noFontSizeUri = noFontSizeChart.getUri();
  364. assertEquals(
  365. noFontSizeArgs, noFontSizeUri.getParameterValue(
  366. goog.ui.ServerChart.UriParam.MULTI_AXIS_STYLE));
  367. var noAlignChart = new goog.ui.ServerChart(
  368. goog.ui.ServerChart.ChartType.HORIZONTAL_STACKED_BAR, 300, 200);
  369. noAlignChart.addDataSet([0, 50, 100, 130], '008000');
  370. var xAxisNumber =
  371. noAlignChart.addMultiAxis(goog.ui.ServerChart.MultiAxisType.X_AXIS);
  372. var yAxisNumber =
  373. noAlignChart.addMultiAxis(goog.ui.ServerChart.MultiAxisType.LEFT_Y_AXIS);
  374. var noAlignArgs = xAxisNumber + ',009000,12|' + yAxisNumber + ',007000,14';
  375. noAlignChart.setMultiAxisLabelStyle(xAxisNumber, '009000', 12);
  376. noAlignChart.setMultiAxisLabelStyle(yAxisNumber, '007000', 14);
  377. var noAlignUri = noAlignChart.getUri();
  378. assertEquals(
  379. noAlignArgs, noAlignUri.getParameterValue(
  380. goog.ui.ServerChart.UriParam.MULTI_AXIS_STYLE));
  381. var noLineTicksChart = new goog.ui.ServerChart(
  382. goog.ui.ServerChart.ChartType.HORIZONTAL_STACKED_BAR, 300, 200);
  383. noLineTicksChart.addDataSet([0, 50, 100, 130], '008000');
  384. axisNumber = noLineTicksChart.addMultiAxis(
  385. goog.ui.ServerChart.MultiAxisType.LEFT_Y_AXIS);
  386. var noLineTicksArgs = axisNumber + ',009000,12,0';
  387. noLineTicksChart.setMultiAxisLabelStyle(
  388. axisNumber, '009000', 12,
  389. goog.ui.ServerChart.MultiAxisAlignment.ALIGN_CENTER);
  390. var noLineTicksUri = noLineTicksChart.getUri();
  391. assertEquals(
  392. noLineTicksArgs, noLineTicksUri.getParameterValue(
  393. goog.ui.ServerChart.UriParam.MULTI_AXIS_STYLE));
  394. var allParamsChart = new goog.ui.ServerChart(
  395. goog.ui.ServerChart.ChartType.HORIZONTAL_STACKED_BAR, 300, 200);
  396. allParamsChart.addDataSet([0, 50, 100, 130], '008000');
  397. axisNumber = allParamsChart.addMultiAxis(
  398. goog.ui.ServerChart.MultiAxisType.LEFT_Y_AXIS);
  399. var allParamsArgs = axisNumber + ',009000,12,0,lt';
  400. allParamsChart.setMultiAxisLabelStyle(
  401. axisNumber, '009000', 12,
  402. goog.ui.ServerChart.MultiAxisAlignment.ALIGN_CENTER,
  403. goog.ui.ServerChart.AxisDisplayType.LINE_AND_TICKS);
  404. var allParamsUri = allParamsChart.getUri();
  405. assertEquals(
  406. allParamsArgs, allParamsUri.getParameterValue(
  407. goog.ui.ServerChart.UriParam.MULTI_AXIS_STYLE));
  408. }
  409. function testSetBackgroundFill() {
  410. var chart = new goog.ui.ServerChart(
  411. goog.ui.ServerChart.ChartType.HORIZONTAL_STACKED_BAR, 300, 200);
  412. assertEquals(0, chart.getBackgroundFill().length);
  413. chart.setBackgroundFill([{color: '00ff00'}]);
  414. assertObjectEquals(
  415. {area: 'bg', effect: 's', color: '00ff00'}, chart.getBackgroundFill()[0]);
  416. chart.setBackgroundFill([{color: '00ff00'}, {area: 'c', color: '00ff00'}]);
  417. assertObjectEquals(
  418. {area: 'bg', effect: 's', color: '00ff00'}, chart.getBackgroundFill()[0]);
  419. assertObjectEquals(
  420. {area: 'c', effect: 's', color: '00ff00'}, chart.getBackgroundFill()[1]);
  421. chart.setParameterValue(
  422. goog.ui.ServerChart.UriParam.BACKGROUND_FILL,
  423. 'bg,s,00ff00|c,lg,45,ff00ff|bg,s,ff00ff');
  424. assertEquals(0, chart.getBackgroundFill().length);
  425. }
  426. function testSetMultiAxisRange() {
  427. var chart = new goog.ui.ServerChart(
  428. goog.ui.ServerChart.ChartType.HORIZONTAL_STACKED_BAR, 300, 200);
  429. var x = chart.addMultiAxis(goog.ui.ServerChart.MultiAxisType.X_AXIS);
  430. var top = chart.addMultiAxis(goog.ui.ServerChart.MultiAxisType.TOP_AXIS);
  431. chart.setMultiAxisRange(x, -500, 500, 100);
  432. chart.setMultiAxisRange(top, 0, 10);
  433. var range = chart.getMultiAxisRange();
  434. assertArrayEquals(range[x], [-500, 500, 100]);
  435. assertArrayEquals(range[top], [0, 10]);
  436. }
  437. function testGetConvertedValue() {
  438. var chart = new goog.ui.ServerChart(
  439. goog.ui.ServerChart.ChartType.VERTICAL_STACKED_BAR);
  440. assertThrows('No exception thrown when minValue > maxValue', function() {
  441. var result = chart.getConvertedValue_(
  442. 90, 24, 3, goog.ui.ServerChart.EncodingType.SIMPLE);
  443. });
  444. assertEquals(
  445. '_', chart.getConvertedValue_(
  446. 90, 100, 101, goog.ui.ServerChart.EncodingType.SIMPLE));
  447. assertEquals(
  448. '_', chart.getConvertedValue_(
  449. null, 0, 5, goog.ui.ServerChart.EncodingType.SIMPLE));
  450. assertEquals(
  451. '__', chart.getConvertedValue_(
  452. null, 0, 150, goog.ui.ServerChart.EncodingType.EXTENDED));
  453. assertEquals(
  454. '24', chart.getConvertedValue_(
  455. 24, 1, 200, goog.ui.ServerChart.EncodingType.TEXT));
  456. assertEquals(
  457. 'H', chart.getConvertedValue_(
  458. 24, 1, 200, goog.ui.ServerChart.EncodingType.SIMPLE));
  459. assertEquals(
  460. 'HZ', chart.getConvertedValue_(
  461. 24, 1, 200, goog.ui.ServerChart.EncodingType.EXTENDED));
  462. // Out-of-range values should give a missing data point, not an empty string.
  463. assertEquals(
  464. '__', chart.getConvertedValue_(
  465. 0, 1, 200, goog.ui.ServerChart.EncodingType.EXTENDED));
  466. assertEquals(
  467. '__', chart.getConvertedValue_(
  468. 201, 1, 200, goog.ui.ServerChart.EncodingType.EXTENDED));
  469. assertEquals(
  470. '_', chart.getConvertedValue_(
  471. 0, 1, 200, goog.ui.ServerChart.EncodingType.SIMPLE));
  472. assertEquals(
  473. '_', chart.getConvertedValue_(
  474. 201, 1, 200, goog.ui.ServerChart.EncodingType.SIMPLE));
  475. assertEquals(
  476. '_', chart.getConvertedValue_(
  477. 0, 1, 200, goog.ui.ServerChart.EncodingType.TEXT));
  478. assertEquals(
  479. '_', chart.getConvertedValue_(
  480. 201, 1, 200, goog.ui.ServerChart.EncodingType.TEXT));
  481. }
  482. function testGetChartServerValues() {
  483. var chart = new goog.ui.ServerChart(
  484. goog.ui.ServerChart.ChartType.HORIZONTAL_STACKED_BAR);
  485. var values = [0, 1, 2, 56, 90, 120];
  486. var minValue = 0;
  487. var maxValue = 140;
  488. var expectedSimple = 'AABYn0';
  489. assertEquals(
  490. expectedSimple, chart.getChartServerValues_(values, minValue, maxValue));
  491. var expectedText = '0,1,2,56,90,120';
  492. assertEquals(
  493. expectedSimple, chart.getChartServerValues_(values, minValue, maxValue));
  494. }
  495. function testUriLengthLimit() {
  496. var chart = new goog.ui.ServerChart(
  497. goog.ui.ServerChart.ChartType.SPARKLINE, 300, 200);
  498. var longUri = null;
  499. goog.events.listen(
  500. chart, goog.ui.ServerChart.Event.URI_TOO_LONG,
  501. function(e) { longUri = e.uri; });
  502. assertEquals(
  503. goog.ui.ServerChart.EncodingType.AUTOMATIC, chart.getEncodingType());
  504. chart.addDataSet(
  505. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], '008000');
  506. assertEquals(
  507. 'e:AAHHOOVVccjjqqxx44..AAHHOOVVccjjqqxx44..',
  508. chart.getUri().getParameterValue(goog.ui.ServerChart.UriParam.DATA));
  509. chart.setUriLengthLimit(100);
  510. assertEquals(
  511. 's:AHOUbipv29AHOUbipv29',
  512. chart.getUri().getParameterValue(goog.ui.ServerChart.UriParam.DATA));
  513. chart.setUriLengthLimit(80);
  514. assertEquals(null, longUri);
  515. chart.getUri();
  516. assertNotEquals(null, longUri);
  517. }
  518. function testVisibleDataSets() {
  519. var uri;
  520. var bar =
  521. new goog.ui.ServerChart(goog.ui.ServerChart.ChartType.BAR, 180, 104);
  522. bar.addDataSet([8, 23, 7], '008000');
  523. bar.addDataSet([31, 11, 7], 'ffcc33');
  524. bar.addDataSet([2, 43, 70, 3, 43, 74], '3072f3');
  525. bar.setMaxValue(100);
  526. bar.setNumVisibleDataSets(0);
  527. uri = bar.getUri();
  528. assertEquals(
  529. 'e0:D6NtDQ,S7F4DQ,AAaxsZApaxvA',
  530. uri.getParameterValue(goog.ui.ServerChart.UriParam.DATA));
  531. bar.setNumVisibleDataSets(1);
  532. uri = bar.getUri();
  533. assertEquals(
  534. 'e1:D6NtDQ,S7F4DQ,AAaxsZApaxvA',
  535. uri.getParameterValue(goog.ui.ServerChart.UriParam.DATA));
  536. bar.setNumVisibleDataSets(2);
  537. uri = bar.getUri();
  538. assertEquals(
  539. 'e2:D6NtDQ,S7F4DQ,AAaxsZApaxvA',
  540. uri.getParameterValue(goog.ui.ServerChart.UriParam.DATA));
  541. bar.setNumVisibleDataSets(null);
  542. uri = bar.getUri();
  543. assertEquals(
  544. 'e:D6NtDQ,S7F4DQ,AAaxsZApaxvA',
  545. uri.getParameterValue(goog.ui.ServerChart.UriParam.DATA));
  546. }
  547. function testTitle() {
  548. var chart =
  549. new goog.ui.ServerChart(goog.ui.ServerChart.ChartType.BAR, 180, 104);
  550. assertEquals('Default title size', 13.5, chart.getTitleSize());
  551. assertEquals('Default title color', '333333', chart.getTitleColor());
  552. chart.setTitle('Test title');
  553. chart.setTitleSize(7);
  554. chart.setTitleColor('ff0000');
  555. var uri = chart.getUri();
  556. assertEquals(
  557. 'Changing chart title failed', 'Test title',
  558. uri.getParameterValue(goog.ui.ServerChart.UriParam.TITLE));
  559. assertEquals(
  560. 'Changing title size and color failed', 'ff0000,7',
  561. uri.getParameterValue(goog.ui.ServerChart.UriParam.TITLE_FORMAT));
  562. assertEquals('New title size', 7, chart.getTitleSize());
  563. assertEquals('New title color', 'ff0000', chart.getTitleColor());
  564. }