123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917 |
- (function($) {
-
- $.jqplot.ThemeEngine = function(){
-
-
-
-
-
- this.themes = {};
-
-
- this.activeTheme=null;
-
- };
-
-
- $.jqplot.ThemeEngine.prototype.init = function() {
-
- var th = new $.jqplot.Theme({_name:'Default'});
- var n, i, nn;
-
- for (n in th.target) {
- if (n == "textColor") {
- th.target[n] = this.target.css('color');
- }
- else {
- th.target[n] = this.target.css(n);
- }
- }
-
- if (this.title.show && this.title._elem) {
- for (n in th.title) {
- if (n == "textColor") {
- th.title[n] = this.title._elem.css('color');
- }
- else {
- th.title[n] = this.title._elem.css(n);
- }
- }
- }
-
- for (n in th.grid) {
- th.grid[n] = this.grid[n];
- }
- if (th.grid.backgroundColor == null && this.grid.background != null) {
- th.grid.backgroundColor = this.grid.background;
- }
- if (this.legend.show && this.legend._elem) {
- for (n in th.legend) {
- if (n == 'textColor') {
- th.legend[n] = this.legend._elem.css('color');
- }
- else {
- th.legend[n] = this.legend._elem.css(n);
- }
- }
- }
- var s;
-
- for (i=0; i<this.series.length; i++) {
- s = this.series[i];
- if (s.renderer.constructor == $.jqplot.LineRenderer) {
- th.series.push(new LineSeriesProperties());
- }
- else if (s.renderer.constructor == $.jqplot.BarRenderer) {
- th.series.push(new BarSeriesProperties());
- }
- else if (s.renderer.constructor == $.jqplot.PieRenderer) {
- th.series.push(new PieSeriesProperties());
- }
- else if (s.renderer.constructor == $.jqplot.DonutRenderer) {
- th.series.push(new DonutSeriesProperties());
- }
- else if (s.renderer.constructor == $.jqplot.FunnelRenderer) {
- th.series.push(new FunnelSeriesProperties());
- }
- else if (s.renderer.constructor == $.jqplot.MeterGaugeRenderer) {
- th.series.push(new MeterSeriesProperties());
- }
- else {
- th.series.push({});
- }
- for (n in th.series[i]) {
- th.series[i][n] = s[n];
- }
- }
- var a, ax;
- for (n in this.axes) {
- ax = this.axes[n];
- a = th.axes[n] = new AxisProperties();
- a.borderColor = ax.borderColor;
- a.borderWidth = ax.borderWidth;
- if (ax._ticks && ax._ticks[0]) {
- for (nn in a.ticks) {
- if (ax._ticks[0].hasOwnProperty(nn)) {
- a.ticks[nn] = ax._ticks[0][nn];
- }
- else if (ax._ticks[0]._elem){
- a.ticks[nn] = ax._ticks[0]._elem.css(nn);
- }
- }
- }
- if (ax._label && ax._label.show) {
- for (nn in a.label) {
-
- if (ax._label[nn]) {
- a.label[nn] = ax._label[nn];
- }
- else if (ax._label._elem){
- if (nn == 'textColor') {
- a.label[nn] = ax._label._elem.css('color');
- }
- else {
- a.label[nn] = ax._label._elem.css(nn);
- }
- }
- }
- }
- }
- this.themeEngine._add(th);
- this.themeEngine.activeTheme = this.themeEngine.themes[th._name];
- };
-
-
- $.jqplot.ThemeEngine.prototype.get = function(name) {
- if (!name) {
-
- return this.activeTheme;
- }
- else {
- return this.themes[name];
- }
- };
-
- function numericalOrder(a,b) { return a-b; }
-
-
-
- $.jqplot.ThemeEngine.prototype.getThemeNames = function() {
- var tn = [];
- for (var n in this.themes) {
- tn.push(n);
- }
- return tn.sort(numericalOrder);
- };
-
-
- $.jqplot.ThemeEngine.prototype.getThemes = function() {
- var tn = [];
- var themes = [];
- for (var n in this.themes) {
- tn.push(n);
- }
- tn.sort(numericalOrder);
- for (var i=0; i<tn.length; i++) {
- themes.push(this.themes[tn[i]]);
- }
- return themes;
- };
-
- $.jqplot.ThemeEngine.prototype.activate = function(plot, name) {
-
- var redrawPlot = false;
- if (!name && this.activeTheme && this.activeTheme._name) {
- name = this.activeTheme._name;
- }
- if (!this.themes.hasOwnProperty(name)) {
- throw new Error("No theme of that name");
- }
- else {
- var th = this.themes[name];
- this.activeTheme = th;
- var val, checkBorderColor = false, checkBorderWidth = false;
- var arr = ['xaxis', 'x2axis', 'yaxis', 'y2axis'];
-
- for (i=0; i<arr.length; i++) {
- var ax = arr[i];
- if (th.axesStyles.borderColor != null) {
- plot.axes[ax].borderColor = th.axesStyles.borderColor;
- }
- if (th.axesStyles.borderWidth != null) {
- plot.axes[ax].borderWidth = th.axesStyles.borderWidth;
- }
- }
-
- for (var axname in plot.axes) {
- var axis = plot.axes[axname];
- if (axis.show) {
- var thaxis = th.axes[axname] || {};
- var thaxstyle = th.axesStyles;
- var thax = $.jqplot.extend(true, {}, thaxis, thaxstyle);
- val = (th.axesStyles.borderColor != null) ? th.axesStyles.borderColor : thax.borderColor;
- if (thax.borderColor != null) {
- axis.borderColor = thax.borderColor;
- redrawPlot = true;
- }
- val = (th.axesStyles.borderWidth != null) ? th.axesStyles.borderWidth : thax.borderWidth;
- if (thax.borderWidth != null) {
- axis.borderWidth = thax.borderWidth;
- redrawPlot = true;
- }
- if (axis._ticks && axis._ticks[0]) {
- for (var nn in thax.ticks) {
-
-
-
-
-
-
-
- val = thax.ticks[nn];
- if (val != null) {
- axis.tickOptions[nn] = val;
- axis._ticks = [];
- redrawPlot = true;
- }
- }
- }
- if (axis._label && axis._label.show) {
- for (var nn in thax.label) {
-
-
-
-
-
-
-
- val = thax.label[nn];
- if (val != null) {
- axis.labelOptions[nn] = val;
- redrawPlot = true;
- }
- }
- }
-
- }
- }
-
- for (var n in th.grid) {
- if (th.grid[n] != null) {
- plot.grid[n] = th.grid[n];
- }
- }
- if (!redrawPlot) {
- plot.grid.draw();
- }
-
- if (plot.legend.show) {
- for (n in th.legend) {
- if (th.legend[n] != null) {
- plot.legend[n] = th.legend[n];
- }
- }
- }
- if (plot.title.show) {
- for (n in th.title) {
- if (th.title[n] != null) {
- plot.title[n] = th.title[n];
- }
- }
- }
-
- var i;
- for (i=0; i<th.series.length; i++) {
- var opts = {};
- var redrawSeries = false;
- for (n in th.series[i]) {
- val = (th.seriesStyles[n] != null) ? th.seriesStyles[n] : th.series[i][n];
- if (val != null) {
- opts[n] = val;
- if (n == 'color') {
- plot.series[i].renderer.shapeRenderer.fillStyle = val;
- plot.series[i].renderer.shapeRenderer.strokeStyle = val;
- plot.series[i][n] = val;
- }
- else if ((n == 'lineWidth') || (n == 'linePattern')) {
- plot.series[i].renderer.shapeRenderer[n] = val;
- plot.series[i][n] = val;
- }
- else if (n == 'markerOptions') {
- merge (plot.series[i].markerOptions, val);
- merge (plot.series[i].markerRenderer, val);
- }
- else {
- plot.series[i][n] = val;
- }
- redrawPlot = true;
- }
- }
- }
-
- if (redrawPlot) {
- plot.target.empty();
- plot.draw();
- }
-
- for (n in th.target) {
- if (th.target[n] != null) {
- plot.target.css(n, th.target[n]);
- }
- }
- }
-
- };
-
- $.jqplot.ThemeEngine.prototype._add = function(theme, name) {
- if (name) {
- theme._name = name;
- }
- if (!theme._name) {
- theme._name = Date.parse(new Date());
- }
- if (!this.themes.hasOwnProperty(theme._name)) {
- this.themes[theme._name] = theme;
- }
- else {
- throw new Error("jqplot.ThemeEngine Error: Theme already in use");
- }
- };
-
-
-
-
-
- $.jqplot.ThemeEngine.prototype.remove = function(name) {
- if (name == 'Default') {
- return false;
- }
- return delete this.themes[name];
- };
-
- $.jqplot.ThemeEngine.prototype.newTheme = function(name, obj) {
- if (typeof(name) == 'object') {
- obj = obj || name;
- name = null;
- }
- if (obj && obj._name) {
- name = obj._name;
- }
- else {
- name = name || Date.parse(new Date());
- }
-
- var th = this.copy(this.themes['Default']._name, name);
- $.jqplot.extend(th, obj);
- return th;
- };
-
-
-
-
-
- function clone(obj){
- if(obj == null || typeof(obj) != 'object'){
- return obj;
- }
-
- var temp = new obj.constructor();
- for(var key in obj){
- temp[key] = clone(obj[key]);
- }
- return temp;
- }
-
- $.jqplot.clone = clone;
-
- function merge(obj1, obj2) {
- if (obj2 == null || typeof(obj2) != 'object') {
- return;
- }
- for (var key in obj2) {
- if (key == 'highlightColors') {
- obj1[key] = clone(obj2[key]);
- }
- if (obj2[key] != null && typeof(obj2[key]) == 'object') {
- if (!obj1.hasOwnProperty(key)) {
- obj1[key] = {};
- }
- merge(obj1[key], obj2[key]);
- }
- else {
- obj1[key] = obj2[key];
- }
- }
- }
-
- $.jqplot.merge = merge;
-
-
- $.jqplot.extend = function() {
-
- var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
-
- if ( typeof target === "boolean" ) {
- deep = target;
- target = arguments[1] || {};
-
- i = 2;
- }
-
- if ( typeof target !== "object" && !toString.call(target) === "[object Function]" ) {
- target = {};
- }
- for ( ; i < length; i++ ){
-
- if ( (options = arguments[ i ]) != null ) {
-
- for ( var name in options ) {
- var src = target[ name ], copy = options[ name ];
-
- if ( target === copy ) {
- continue;
- }
-
- if ( deep && copy && typeof copy === "object" && !copy.nodeType ) {
- target[ name ] = $.jqplot.extend( deep,
-
- src || ( copy.length != null ? [ ] : { } )
- , copy );
- }
-
- else if ( copy !== undefined ) {
- target[ name ] = copy;
- }
- }
- }
- }
-
- return target;
- };
-
- $.jqplot.ThemeEngine.prototype.rename = function (oldName, newName) {
- if (oldName == 'Default' || newName == 'Default') {
- throw new Error ("jqplot.ThemeEngine Error: Cannot rename from/to Default");
- }
- if (this.themes.hasOwnProperty(newName)) {
- throw new Error ("jqplot.ThemeEngine Error: New name already in use.");
- }
- else if (this.themes.hasOwnProperty(oldName)) {
- var th = this.copy (oldName, newName);
- this.remove(oldName);
- return th;
- }
- throw new Error("jqplot.ThemeEngine Error: Old name or new name invalid");
- };
-
- $.jqplot.ThemeEngine.prototype.copy = function (sourceName, targetName, obj) {
- if (targetName == 'Default') {
- throw new Error ("jqplot.ThemeEngine Error: Cannot copy over Default theme");
- }
- if (!this.themes.hasOwnProperty(sourceName)) {
- var s = "jqplot.ThemeEngine Error: Source name invalid";
- throw new Error(s);
- }
- if (this.themes.hasOwnProperty(targetName)) {
- var s = "jqplot.ThemeEngine Error: Target name invalid";
- throw new Error(s);
- }
- else {
- var th = clone(this.themes[sourceName]);
- th._name = targetName;
- $.jqplot.extend(true, th, obj);
- this._add(th);
- return th;
- }
- };
-
-
- $.jqplot.Theme = function(name, obj) {
- if (typeof(name) == 'object') {
- obj = obj || name;
- name = null;
- }
- name = name || Date.parse(new Date());
- this._name = name;
- this.target = {
- backgroundColor: null
- };
- this.legend = {
- textColor: null,
- fontFamily: null,
- fontSize: null,
- border: null,
- background: null
- };
- this.title = {
- textColor: null,
- fontFamily: null,
- fontSize: null,
- textAlign: null
- };
- this.seriesStyles = {};
- this.series = [];
- this.grid = {
- drawGridlines: null,
- gridLineColor: null,
- gridLineWidth: null,
- backgroundColor: null,
- borderColor: null,
- borderWidth: null,
- shadow: null
- };
- this.axesStyles = {label:{}, ticks:{}};
- this.axes = {};
- if (typeof(obj) == 'string') {
- this._name = obj;
- }
- else if(typeof(obj) == 'object') {
- $.jqplot.extend(true, this, obj);
- }
- };
-
- var AxisProperties = function() {
- this.borderColor = null;
- this.borderWidth = null;
- this.ticks = new AxisTicks();
- this.label = new AxisLabel();
- };
-
- var AxisTicks = function() {
- this.show = null;
- this.showGridline = null;
- this.showLabel = null;
- this.showMark = null;
- this.size = null;
- this.textColor = null;
- this.whiteSpace = null;
- this.fontSize = null;
- this.fontFamily = null;
- };
-
- var AxisLabel = function() {
- this.textColor = null;
- this.whiteSpace = null;
- this.fontSize = null;
- this.fontFamily = null;
- this.fontWeight = null;
- };
-
- var LineSeriesProperties = function() {
- this.color=null;
- this.lineWidth=null;
- this.linePattern=null;
- this.shadow=null;
- this.fillColor=null;
- this.showMarker=null;
- this.markerOptions = new MarkerOptions();
- };
-
- var MarkerOptions = function() {
- this.show = null;
- this.style = null;
- this.lineWidth = null;
- this.size = null;
- this.color = null;
- this.shadow = null;
- };
-
- var BarSeriesProperties = function() {
- this.color=null;
- this.seriesColors=null;
- this.lineWidth=null;
- this.shadow=null;
- this.barPadding=null;
- this.barMargin=null;
- this.barWidth=null;
- this.highlightColors=null;
- };
-
- var PieSeriesProperties = function() {
- this.seriesColors=null;
- this.padding=null;
- this.sliceMargin=null;
- this.fill=null;
- this.shadow=null;
- this.startAngle=null;
- this.lineWidth=null;
- this.highlightColors=null;
- };
-
- var DonutSeriesProperties = function() {
- this.seriesColors=null;
- this.padding=null;
- this.sliceMargin=null;
- this.fill=null;
- this.shadow=null;
- this.startAngle=null;
- this.lineWidth=null;
- this.innerDiameter=null;
- this.thickness=null;
- this.ringMargin=null;
- this.highlightColors=null;
- };
-
- var FunnelSeriesProperties = function() {
- this.color=null;
- this.lineWidth=null;
- this.shadow=null;
- this.padding=null;
- this.sectionMargin=null;
- this.seriesColors=null;
- this.highlightColors=null;
- };
-
- var MeterSeriesProperties = function() {
- this.padding=null;
- this.backgroundColor=null;
- this.ringColor=null;
- this.tickColor=null;
- this.ringWidth=null;
- this.intervalColors=null;
- this.intervalInnerRadius=null;
- this.intervalOuterRadius=null;
- this.hubRadius=null;
- this.needleThickness=null;
- this.needlePad=null;
- };
-
- })(jQuery);
|