| 1 |
define(["dojo/_base/lang", "dojo/_base/array","dojo/_base/declare","dojo/_base/Color", "dojox/lang/utils", "dojox/gfx/gradutils"], |
| 2 |
function(lang, arr, declare, Color, dlu, dgg){ |
| 3 |
|
| 4 |
var SimpleTheme = declare("dojox.charting.SimpleTheme", null, { |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
shapeSpaces: {shape: 1, shapeX: 1, shapeY: 1}, |
| 151 |
|
| 152 |
constructor: function(kwArgs){ |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
kwArgs = kwArgs || {}; |
| 157 |
|
| 158 |
|
| 159 |
var def = SimpleTheme.defaultTheme; |
| 160 |
arr.forEach(["chart", "plotarea", "axis", "grid", "series", "marker", "indicator"], function(name){ |
| 161 |
this[name] = lang.delegate(def[name], kwArgs[name]); |
| 162 |
}, this); |
| 163 |
|
| 164 |
|
| 165 |
if(kwArgs.seriesThemes && kwArgs.seriesThemes.length){ |
| 166 |
this.colors = null; |
| 167 |
this.seriesThemes = kwArgs.seriesThemes.slice(0); |
| 168 |
}else{ |
| 169 |
this.seriesThemes = null; |
| 170 |
this.colors = (kwArgs.colors || SimpleTheme.defaultColors).slice(0); |
| 171 |
} |
| 172 |
this.markerThemes = null; |
| 173 |
if(kwArgs.markerThemes && kwArgs.markerThemes.length){ |
| 174 |
this.markerThemes = kwArgs.markerThemes.slice(0); |
| 175 |
} |
| 176 |
this.markers = kwArgs.markers ? lang.clone(kwArgs.markers) : lang.delegate(SimpleTheme.defaultMarkers); |
| 177 |
|
| 178 |
|
| 179 |
this.noGradConv = kwArgs.noGradConv; |
| 180 |
this.noRadialConv = kwArgs.noRadialConv; |
| 181 |
if(kwArgs.reverseFills){ |
| 182 |
this.reverseFills(); |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
this._current = 0; |
| 187 |
this._buildMarkerArray(); |
| 188 |
}, |
| 189 |
|
| 190 |
clone: function(){ |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
var theme = new this.constructor({ |
| 196 |
|
| 197 |
chart: this.chart, |
| 198 |
plotarea: this.plotarea, |
| 199 |
axis: this.axis, |
| 200 |
grid: this.grid, |
| 201 |
series: this.series, |
| 202 |
marker: this.marker, |
| 203 |
|
| 204 |
colors: this.colors, |
| 205 |
markers: this.markers, |
| 206 |
indicator: this.indicator, |
| 207 |
seriesThemes: this.seriesThemes, |
| 208 |
markerThemes: this.markerThemes, |
| 209 |
|
| 210 |
noGradConv: this.noGradConv, |
| 211 |
noRadialConv: this.noRadialConv, |
| 212 |
pieInnerRadius: this.pieInnerRadius |
| 213 |
}); |
| 214 |
|
| 215 |
arr.forEach( |
| 216 |
["clone", "clear", "next", "skip", "addMixin", "post", "getTick"], |
| 217 |
function(name){ |
| 218 |
if(this.hasOwnProperty(name)){ |
| 219 |
theme[name] = this[name]; |
| 220 |
} |
| 221 |
}, |
| 222 |
this |
| 223 |
); |
| 224 |
return theme; |
| 225 |
}, |
| 226 |
|
| 227 |
clear: function(){ |
| 228 |
|
| 229 |
|
| 230 |
this._current = 0; |
| 231 |
}, |
| 232 |
|
| 233 |
next: function(elementType, mixin, doPost){ |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
var merge = dlu.merge, series, marker; |
| 245 |
if(this.colors){ |
| 246 |
series = lang.delegate(this.series); |
| 247 |
marker = lang.delegate(this.marker); |
| 248 |
var color = new Color(this.colors[this._current % this.colors.length]), old; |
| 249 |
|
| 250 |
if(series.stroke && series.stroke.color){ |
| 251 |
series.stroke = lang.delegate(series.stroke); |
| 252 |
old = new Color(series.stroke.color); |
| 253 |
series.stroke.color = new Color(color); |
| 254 |
series.stroke.color.a = old.a; |
| 255 |
}else{ |
| 256 |
series.stroke = {color: color}; |
| 257 |
} |
| 258 |
if(marker.stroke && marker.stroke.color){ |
| 259 |
marker.stroke = lang.delegate(marker.stroke); |
| 260 |
old = new Color(marker.stroke.color); |
| 261 |
marker.stroke.color = new Color(color); |
| 262 |
marker.stroke.color.a = old.a; |
| 263 |
}else{ |
| 264 |
marker.stroke = {color: color}; |
| 265 |
} |
| 266 |
|
| 267 |
if(!series.fill || series.fill.type){ |
| 268 |
series.fill = color; |
| 269 |
}else{ |
| 270 |
old = new Color(series.fill); |
| 271 |
series.fill = new Color(color); |
| 272 |
series.fill.a = old.a; |
| 273 |
} |
| 274 |
if(!marker.fill || marker.fill.type){ |
| 275 |
marker.fill = color; |
| 276 |
}else{ |
| 277 |
old = new Color(marker.fill); |
| 278 |
marker.fill = new Color(color); |
| 279 |
marker.fill.a = old.a; |
| 280 |
} |
| 281 |
}else{ |
| 282 |
series = this.seriesThemes ? |
| 283 |
merge(this.series, this.seriesThemes[this._current % this.seriesThemes.length]) : |
| 284 |
this.series; |
| 285 |
marker = this.markerThemes ? |
| 286 |
merge(this.marker, this.markerThemes[this._current % this.markerThemes.length]) : |
| 287 |
series; |
| 288 |
} |
| 289 |
|
| 290 |
var symbol = marker && marker.symbol || this._markers[this._current % this._markers.length]; |
| 291 |
|
| 292 |
var theme = {series: series, marker: marker, symbol: symbol}; |
| 293 |
|
| 294 |
|
| 295 |
++this._current; |
| 296 |
|
| 297 |
if(mixin){ |
| 298 |
theme = this.addMixin(theme, elementType, mixin); |
| 299 |
} |
| 300 |
if(doPost){ |
| 301 |
theme = this.post(theme, elementType); |
| 302 |
} |
| 303 |
|
| 304 |
return theme; |
| 305 |
}, |
| 306 |
|
| 307 |
skip: function(){ |
| 308 |
|
| 309 |
|
| 310 |
++this._current; |
| 311 |
}, |
| 312 |
|
| 313 |
addMixin: function(theme, elementType, mixin, doPost){ |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
if(lang.isArray(mixin)){ |
| 327 |
arr.forEach(mixin, function(m){ |
| 328 |
theme = this.addMixin(theme, elementType, m); |
| 329 |
}, this); |
| 330 |
}else{ |
| 331 |
var t = {}; |
| 332 |
if("color" in mixin){ |
| 333 |
if(elementType == "line" || elementType == "area"){ |
| 334 |
lang.setObject("series.stroke.color", mixin.color, t); |
| 335 |
lang.setObject("marker.stroke.color", mixin.color, t); |
| 336 |
}else{ |
| 337 |
lang.setObject("series.fill", mixin.color, t); |
| 338 |
} |
| 339 |
} |
| 340 |
arr.forEach(["stroke", "outline", "shadow", "fill", "filter", "font", "fontColor", "labelWiring"], function(name){ |
| 341 |
var markerName = "marker" + name.charAt(0).toUpperCase() + name.substr(1), |
| 342 |
b = markerName in mixin; |
| 343 |
if(name in mixin){ |
| 344 |
lang.setObject("series." + name, mixin[name], t); |
| 345 |
if(!b){ |
| 346 |
lang.setObject("marker." + name, mixin[name], t); |
| 347 |
} |
| 348 |
} |
| 349 |
if(b){ |
| 350 |
lang.setObject("marker." + name, mixin[markerName], t); |
| 351 |
} |
| 352 |
}); |
| 353 |
if("marker" in mixin){ |
| 354 |
t.symbol = mixin.marker; |
| 355 |
t.symbol = mixin.marker; |
| 356 |
} |
| 357 |
theme = dlu.merge(theme, t); |
| 358 |
} |
| 359 |
if(doPost){ |
| 360 |
theme = this.post(theme, elementType); |
| 361 |
} |
| 362 |
return theme; |
| 363 |
}, |
| 364 |
|
| 365 |
post: function(theme, elementType){ |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
var fill = theme.series.fill, t; |
| 375 |
if(!this.noGradConv && this.shapeSpaces[fill.space] && fill.type == "linear"){ |
| 376 |
if(elementType == "bar"){ |
| 377 |
|
| 378 |
t = { |
| 379 |
x1: fill.y1, |
| 380 |
y1: fill.x1, |
| 381 |
x2: fill.y2, |
| 382 |
y2: fill.x2 |
| 383 |
}; |
| 384 |
}else if(!this.noRadialConv && fill.space == "shape" && (elementType == "slice" || elementType == "circle")){ |
| 385 |
|
| 386 |
t = { |
| 387 |
type: "radial", |
| 388 |
cx: 0, |
| 389 |
cy: 0, |
| 390 |
r: 100 |
| 391 |
}; |
| 392 |
} |
| 393 |
if(t){ |
| 394 |
return dlu.merge(theme, {series: {fill: t}}); |
| 395 |
} |
| 396 |
} |
| 397 |
return theme; |
| 398 |
}, |
| 399 |
|
| 400 |
getTick: function(name, mixin){ |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
var tick = this.axis.tick, tickName = name + "Tick", |
| 408 |
merge = dlu.merge; |
| 409 |
if(tick){ |
| 410 |
if(this.axis[tickName]){ |
| 411 |
tick = merge(tick, this.axis[tickName]); |
| 412 |
} |
| 413 |
}else{ |
| 414 |
tick = this.axis[tickName]; |
| 415 |
} |
| 416 |
if(mixin){ |
| 417 |
if(tick){ |
| 418 |
if(mixin[tickName]){ |
| 419 |
tick = merge(tick, mixin[tickName]); |
| 420 |
} |
| 421 |
}else{ |
| 422 |
tick = mixin[tickName]; |
| 423 |
} |
| 424 |
} |
| 425 |
return tick; |
| 426 |
}, |
| 427 |
|
| 428 |
inspectObjects: function(f){ |
| 429 |
arr.forEach(["chart", "plotarea", "axis", "grid", "series", "marker", "indicator"], function(name){ |
| 430 |
f(this[name]); |
| 431 |
}, this); |
| 432 |
if(this.seriesThemes){ |
| 433 |
arr.forEach(this.seriesThemes, f); |
| 434 |
} |
| 435 |
if(this.markerThemes){ |
| 436 |
arr.forEach(this.markerThemes, f); |
| 437 |
} |
| 438 |
}, |
| 439 |
|
| 440 |
reverseFills: function(){ |
| 441 |
this.inspectObjects(function(o){ |
| 442 |
if(o && o.fill){ |
| 443 |
o.fill = dgg.reverse(o.fill); |
| 444 |
} |
| 445 |
}); |
| 446 |
}, |
| 447 |
|
| 448 |
addMarker:function( name, segment){ |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
this.markers[name] = segment; |
| 454 |
this._buildMarkerArray(); |
| 455 |
}, |
| 456 |
|
| 457 |
setMarkers:function( obj){ |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
this.markers = obj; |
| 465 |
this._buildMarkerArray(); |
| 466 |
}, |
| 467 |
|
| 468 |
_buildMarkerArray: function(){ |
| 469 |
this._markers = []; |
| 470 |
for(var p in this.markers){ |
| 471 |
this._markers.push(this.markers[p]); |
| 472 |
} |
| 473 |
} |
| 474 |
}); |
| 475 |
|
| 476 |
lang.mixin(SimpleTheme, { |
| 477 |
defaultMarkers: { |
| 478 |
CIRCLE: "m-3,0 c0,-4 6,-4 6,0 m-6,0 c0,4 6,4 6,0", |
| 479 |
SQUARE: "m-3,-3 l0,6 6,0 0,-6 z", |
| 480 |
DIAMOND: "m0,-3 l3,3 -3,3 -3,-3 z", |
| 481 |
CROSS: "m0,-3 l0,6 m-3,-3 l6,0", |
| 482 |
X: "m-3,-3 l6,6 m0,-6 l-6,6", |
| 483 |
TRIANGLE: "m-3,3 l3,-6 3,6 z", |
| 484 |
TRIANGLE_INVERTED: "m-3,-3 l3,6 3,-6 z" |
| 485 |
}, |
| 486 |
|
| 487 |
defaultColors:[ |
| 488 |
|
| 489 |
"#54544c", "#858e94", "#6e767a", "#948585", "#474747" |
| 490 |
], |
| 491 |
|
| 492 |
defaultTheme: { |
| 493 |
|
| 494 |
chart:{ |
| 495 |
stroke: null, |
| 496 |
fill: "white", |
| 497 |
pageStyle: null, |
| 498 |
titleGap: 20, |
| 499 |
titlePos: "top", |
| 500 |
titleFont: "normal normal bold 14pt Tahoma", |
| 501 |
titleFontColor: "#333", |
| 502 |
titleAlign: "middle" |
| 503 |
}, |
| 504 |
plotarea:{ |
| 505 |
stroke: null, |
| 506 |
fill: "white" |
| 507 |
}, |
| 508 |
|
| 509 |
axis:{ |
| 510 |
stroke: { |
| 511 |
color: "#333", |
| 512 |
width: 1 |
| 513 |
}, |
| 514 |
tick: { |
| 515 |
color: "#666", |
| 516 |
position: "center", |
| 517 |
font: "normal normal normal 7pt Tahoma", |
| 518 |
fontColor: "#333", |
| 519 |
labelGap: 4 |
| 520 |
}, |
| 521 |
majorTick: { |
| 522 |
width: 1, |
| 523 |
length: 6 |
| 524 |
}, |
| 525 |
minorTick: { |
| 526 |
width: 0.8, |
| 527 |
length: 3 |
| 528 |
}, |
| 529 |
microTick: { |
| 530 |
width: 0.5, |
| 531 |
length: 1 |
| 532 |
}, |
| 533 |
title: { |
| 534 |
gap: 15, |
| 535 |
font: "normal normal normal 11pt Tahoma", |
| 536 |
fontColor: "#333", |
| 537 |
orientation: "axis" |
| 538 |
} |
| 539 |
}, |
| 540 |
series: { |
| 541 |
|
| 542 |
stroke: {width: 1.5, color: "#333"}, |
| 543 |
outline: {width: 0.1, color: "#ccc"}, |
| 544 |
|
| 545 |
shadow: null, |
| 546 |
fill: "#ccc", |
| 547 |
font: "normal normal normal 8pt Tahoma", |
| 548 |
fontColor: "#000", |
| 549 |
labelWiring: {width: 1, color: "#ccc"} |
| 550 |
}, |
| 551 |
marker: { |
| 552 |
stroke: {width: 1.5, color: "#333"}, |
| 553 |
outline: {width: 0.1, color: "#ccc"}, |
| 554 |
|
| 555 |
shadow: null, |
| 556 |
fill: "#ccc", |
| 557 |
font: "normal normal normal 8pt Tahoma", |
| 558 |
fontColor: "#000" |
| 559 |
}, |
| 560 |
indicator: { |
| 561 |
lineStroke: {width: 1.5, color: "#333"}, |
| 562 |
lineOutline: {width: 0.1, color: "#ccc"}, |
| 563 |
lineShadow: null, |
| 564 |
lineFill: null, |
| 565 |
stroke: {width: 1.5, color: "#333"}, |
| 566 |
outline: {width: 0.1, color: "#ccc"}, |
| 567 |
shadow: null, |
| 568 |
fill : "#ccc", |
| 569 |
radius: 3, |
| 570 |
font: "normal normal normal 10pt Tahoma", |
| 571 |
fontColor: "#000", |
| 572 |
markerFill: "#ccc", |
| 573 |
markerSymbol: "m-3,0 c0,-4 6,-4 6,0 m-6,0 c0,4 6,4 6,0", |
| 574 |
markerStroke: {width: 1.5, color: "#333"}, |
| 575 |
markerOutline: {width: 0.1, color: "#ccc"}, |
| 576 |
markerShadow: null |
| 577 |
} |
| 578 |
} |
| 579 |
}); |
| 580 |
|
| 581 |
return SimpleTheme; |
| 582 |
}); |