7116ca660bd7a40b5436762d0cca8f9a922f8146.svn-base 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. if (!dojo._hasResource["dojox.charting.plot2d.common"]) { // _hasResource
  2. // checks added by
  3. // build. Do not use
  4. // _hasResource
  5. // directly in your
  6. // code.
  7. dojo._hasResource["dojox.charting.plot2d.common"] = true;
  8. dojo.provide("dojox.charting.plot2d.common");
  9. dojo.require("dojo.colors");
  10. dojo.require("dojox.gfx");
  11. dojo.require("dojox.lang.functional");
  12. (function() {
  13. var df = dojox.lang.functional, dc = dojox.charting.plot2d.common;
  14. dojo.mixin(dojox.charting.plot2d.common, {
  15. makeStroke : function(stroke) {
  16. if (!stroke) {
  17. return stroke;
  18. }
  19. if (typeof stroke == "string" || stroke instanceof dojo.Color) {
  20. stroke = {
  21. color : stroke
  22. };
  23. }
  24. return dojox.gfx
  25. .makeParameters(dojox.gfx.defaultStroke, stroke);
  26. },
  27. augmentColor : function(target, color) {
  28. var t = new dojo.Color(target), c = new dojo.Color(color);
  29. c.a = t.a;
  30. return c;
  31. },
  32. augmentStroke : function(stroke, color) {
  33. var s = dc.makeStroke(stroke);
  34. if (s) {
  35. s.color = dc.augmentColor(s.color, color);
  36. }
  37. return s;
  38. },
  39. augmentFill : function(fill, color) {
  40. var fc, c = new dojo.Color(color);
  41. if (typeof fill == "string" || fill instanceof dojo.Color) {
  42. return dc.augmentColor(fill, color);
  43. }
  44. return fill;
  45. },
  46. defaultStats : {
  47. hmin : Number.POSITIVE_INFINITY,
  48. hmax : Number.NEGATIVE_INFINITY,
  49. vmin : Number.POSITIVE_INFINITY,
  50. vmax : Number.NEGATIVE_INFINITY
  51. },
  52. collectSimpleStats : function(series) {
  53. var stats = dojo.clone(dc.defaultStats);
  54. for (var i = 0; i < series.length; ++i) {
  55. var run = series[i];
  56. if (!run.data.length) {
  57. continue;
  58. }
  59. if (typeof run.data[0] == "number") {
  60. // 1D case
  61. var old_vmin = stats.vmin, old_vmax = stats.vmax;
  62. if (!("ymin" in run) || !("ymax" in run)) {
  63. dojo.forEach(run.data, function(val, i) {
  64. var x = i + 1, y = val;
  65. if (isNaN(y)) {
  66. y = 0;
  67. }
  68. stats.hmin = Math.min(stats.hmin, x);
  69. stats.hmax = Math.max(stats.hmax, x);
  70. stats.vmin = Math.min(stats.vmin, y);
  71. stats.vmax = Math.max(stats.vmax, y);
  72. });
  73. }
  74. if ("ymin" in run) {
  75. stats.vmin = Math.min(old_vmin, run.ymin);
  76. }
  77. if ("ymax" in run) {
  78. stats.vmax = Math.max(old_vmax, run.ymax);
  79. }
  80. } else {
  81. // 2D case
  82. var old_hmin = stats.hmin, old_hmax = stats.hmax, old_vmin = stats.vmin, old_vmax = stats.vmax;
  83. if (!("xmin" in run) || !("xmax" in run)
  84. || !("ymin" in run) || !("ymax" in run)) {
  85. dojo.forEach(run.data, function(val, i) {
  86. var x = val.x, y = val.y;
  87. if (isNaN(x)) {
  88. x = 0;
  89. }
  90. if (isNaN(y)) {
  91. y = 0;
  92. }
  93. stats.hmin = Math.min(stats.hmin, x);
  94. stats.hmax = Math.max(stats.hmax, x);
  95. stats.vmin = Math.min(stats.vmin, y);
  96. stats.vmax = Math.max(stats.vmax, y);
  97. });
  98. }
  99. if ("xmin" in run) {
  100. stats.hmin = Math.min(old_hmin, run.xmin);
  101. }
  102. if ("xmax" in run) {
  103. stats.hmax = Math.max(old_hmax, run.xmax);
  104. }
  105. if ("ymin" in run) {
  106. stats.vmin = Math.min(old_vmin, run.ymin);
  107. }
  108. if ("ymax" in run) {
  109. stats.vmax = Math.max(old_vmax, run.ymax);
  110. }
  111. }
  112. }
  113. return stats;
  114. },
  115. collectStackedStats : function(series) {
  116. // collect statistics
  117. var stats = dojo.clone(dc.defaultStats);
  118. if (series.length) {
  119. // 1st pass: find the maximal length of runs
  120. stats.hmin = Math.min(stats.hmin, 1);
  121. stats.hmax = df.foldl(series,
  122. "seed, run -> Math.max(seed, run.data.length)",
  123. stats.hmax);
  124. // 2nd pass: stack values
  125. for (var i = 0; i < stats.hmax; ++i) {
  126. var v = series[0].data[i];
  127. if (isNaN(v)) {
  128. v = 0;
  129. }
  130. stats.vmin = Math.min(stats.vmin, v);
  131. for (var j = 1; j < series.length; ++j) {
  132. var t = series[j].data[i];
  133. if (isNaN(t)) {
  134. t = 0;
  135. }
  136. v += t;
  137. }
  138. stats.vmax = Math.max(stats.vmax, v);
  139. }
  140. }
  141. return stats;
  142. }
  143. });
  144. })();
  145. }