| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659 |
- // version: 2014-06-26
- /**
- * o--------------------------------------------------------------------------------o
- * | This file is part of the RGraph package. RGraph is Free Software, licensed |
- * | under the MIT license - so it's free to use for all purposes. If you want to |
- * | donate to help keep the project going then you can do so here: |
- * | |
- * | http://www.rgraph.net/donate |
- * o--------------------------------------------------------------------------------o
- */
- RGraph = window.RGraph || {isRGraph: true};
- RGraph.Effects = RGraph.Effects || {};
- RGraph.Effects.Rose = RGraph.Effects.Rose || {};
- /**
- * The rose chart constuctor
- *
- * @param object canvas
- * @param array data
- */
- RGraph.Rose = function (id, data)
- {
- var tmp = RGraph.getCanvasTag(id);
- // Get the canvas and context objects
- this.id = tmp[0];
- this.canvas = tmp[1];
- this.context = this.canvas.getContext ? this.canvas.getContext("2d", {alpha: (typeof id === 'object' && id.alpha === false) ? false : true}) : null;
- this.data = data;
- this.canvas.__object__ = this;
- this.type = 'rose';
- this.isRGraph = true;
- this.uid = RGraph.CreateUID();
- this.canvas.uid = this.canvas.uid ? this.canvas.uid : RGraph.CreateUID();
- this.colorsParsed = false;
- this.coordsText = [];
- this.original_colors = [];
- this.firstDraw = true; // After the first draw this will be false
- /**
- * Compatibility with older browsers
- */
- //RGraph.OldBrowserCompat(this.context);
- this.centerx = 0;
- this.centery = 0;
- this.radius = 0;
- this.max = 0;
- this.angles = [];
- this.angles2 = [];
-
- this.properties =
- {
- 'chart.background.axes': true,
- 'chart.background.axes.color': 'black',
- 'chart.background.grid': true,
- 'chart.background.grid.color': '#ccc',
- 'chart.background.grid.size': null,
- 'chart.background.grid.spokes': null,
- 'chart.background.grid.count': 5,
- 'chart.centerx': null,
- 'chart.centery': null,
- 'chart.radius': null,
- 'chart.angles.start': 0,
- 'chart.colors': ['rgba(255,0,0,0.5)', 'rgba(255,255,0,0.5)', 'rgba(0,255,255,0.5)', 'rgb(0,255,0)', 'gray', 'blue', 'rgb(255,128,255)','green', 'pink', 'gray', 'aqua'],
- 'chart.linewidth': 1,
- 'chart.colors.sequential': false,
- 'chart.colors.alpha': null,
- 'chart.margin': 0,
- 'chart.strokestyle': '#aaa',
- 'chart.gutter.left': 25,
- 'chart.gutter.right': 25,
- 'chart.gutter.top': 25,
- 'chart.gutter.bottom': 25,
- 'chart.title': '',
- 'chart.title.background': null,
- 'chart.title.hpos': null,
- 'chart.title.vpos': null,
- 'chart.title.bold': true,
- 'chart.title.font': null,
- 'chart.title.x': null,
- 'chart.title.y': null,
- 'chart.title.halign': null,
- 'chart.title.valign': null,
- 'chart.labels': null,
- 'chart.labels.position': 'center',
- 'chart.labels.axes': 'nsew',
- 'chart.labels.offset': 0,
- 'chart.text.color': 'black',
- 'chart.text.font': 'Arial',
- 'chart.text.size': 10,
- 'chart.key': null,
- 'chart.key.background': 'white',
- 'chart.key.position': 'graph',
- 'chart.key.halign': 'right',
- 'chart.key.shadow': false,
- 'chart.key.shadow.color': '#666',
- 'chart.key.shadow.blur': 3,
- 'chart.key.shadow.offsetx': 2,
- 'chart.key.shadow.offsety': 2,
- 'chart.key.position.gutter.boxed': false,
- 'chart.key.position.x': null,
- 'chart.key.position.y': null,
- 'chart.key.color.shape': 'square',
- 'chart.key.rounded': true,
- 'chart.key.linewidth': 1,
- 'chart.key.colors': null,
- 'chart.key.interactive': false,
- 'chart.key.interactive.highlight.chart.stroke': 'black',
- 'chart.key.interactive.highlight.chart.fill': 'rgba(255,255,255,0.7)',
- 'chart.key.interactive.highlight.label': 'rgba(255,0,0,0.2)',
- 'chart.key.text.color': 'black',
- 'chart.contextmenu': null,
- 'chart.tooltips': null,
- 'chart.tooltips.event': 'onclick',
- 'chart.tooltips.effect': 'fade',
- 'chart.tooltips.css.class': 'RGraph_tooltip',
- 'chart.tooltips.highlight': true,
- 'chart.highlight.stroke': 'rgba(0,0,0,0)',
- 'chart.highlight.fill': 'rgba(255,255,255,0.7)',
- 'chart.annotatable': false,
- 'chart.annotate.color': 'black',
- 'chart.zoom.factor': 1.5,
- 'chart.zoom.fade.in': true,
- 'chart.zoom.fade.out': true,
- 'chart.zoom.hdir': 'right',
- 'chart.zoom.vdir': 'down',
- 'chart.zoom.frames': 25,
- 'chart.zoom.delay': 16.666,
- 'chart.zoom.shadow': true,
- 'chart.zoom.background': true,
- 'chart.zoom.action': 'zoom',
- 'chart.resizable': false,
- 'chart.resize.handle.adjust': [0,0],
- 'chart.resize.handle.background': null,
- 'chart.adjustable': false,
- 'chart.ymax': null,
- 'chart.ymin': 0,
- 'chart.scale.decimals': null,
- 'chart.scale.point': '.',
- 'chart.scale.thousand': ',',
- 'chart.variant': 'stacked',
- 'chart.exploded': 0,
- 'chart.events.mousemove': null,
- 'chart.events.click': null,
- 'chart.animation.roundrobin.factor': 1,
- 'chart.animation.roundrobin.radius': true,
- 'chart.animation.grow.multiplier': 1,
- 'chart.labels.count': 5
- }
- /**
- * Create the $ objects. In the case of non-equi-angular rose charts it actually creates too many $ objects,
- * but it doesn't matter.
- */
- var linear_data = RGraph.array_linearize(this.data);
- for (var i=0; i<linear_data.length; ++i) {
- this["$" + i] = {}
- }
- /**
- * Translate half a pixel for antialiasing purposes - but only if it hasn't beeen
- * done already
- */
- if (!this.canvas.__rgraph_aa_translated__) {
- this.context.translate(0.5,0.5);
-
- this.canvas.__rgraph_aa_translated__ = true;
- }
- // Short variable names
- var RG = RGraph;
- var ca = this.canvas;
- var co = ca.getContext('2d');
- var prop = this.properties;
- var jq = jQuery;
- var pa = RG.Path;
- var win = window;
- var doc = document;
- var ma = Math;
-
-
-
- /**
- * "Decorate" the object with the generic effects if the effects library has been included
- */
- if (RG.Effects && typeof RG.Effects.decorate === 'function') {
- RG.Effects.decorate(this);
- }
- /**
- * A simple setter
- *
- * @param string name The name of the property to set
- * @param string value The value of the property
- */
- this.set =
- this.Set = function (name, value)
- {
- /**
- * This should be done first - prepend the propertyy name with "chart." if necessary
- */
- if (name.substr(0,6) != 'chart.') {
- name = 'chart.' + name;
- }
-
- prop[name.toLowerCase()] = value;
-
- return this;
- };
- /**
- * A simple getter
- *
- * @param string name The name of the property to get
- */
- this.get =
- this.Get = function (name)
- {
- /**
- * This should be done first - prepend the property name with "chart." if necessary
- */
- if (name.substr(0,6) != 'chart.') {
- name = 'chart.' + name;
- }
-
- return prop[name.toLowerCase()];
- };
- /**
- * This method draws the rose chart
- */
- this.draw =
- this.Draw = function ()
- {
- /**
- * Fire the onbeforedraw event
- */
- RG.FireCustomEvent(this, 'onbeforedraw');
-
-
-
- /**
- * This doesn't affect the chart, but is used for compatibility
- */
- this.gutterLeft = prop['chart.gutter.left'];
- this.gutterRight = prop['chart.gutter.right'];
- this.gutterTop = prop['chart.gutter.top'];
- this.gutterBottom = prop['chart.gutter.bottom'];
-
- // Calculate the radius
- this.radius = (Math.min(ca.width - this.gutterLeft - this.gutterRight, ca.height - this.gutterTop - this.gutterBottom) / 2);
- this.centerx = ((ca.width - this.gutterLeft - this.gutterRight) / 2) + this.gutterLeft;
- this.centery = ((ca.height - this.gutterTop - this.gutterBottom) / 2) + this.gutterTop;
- this.angles = [];
- this.angles2 = [];
- this.total = 0;
- this.startRadians = prop['chart.angles.start'];
- this.coordsText = [];
-
- /**
- * Change the centerx marginally if the key is defined
- */
- if (prop['chart.key'] && prop['chart.key'].length > 0 && prop['chart.key'].length >= 3) {
- this.centerx = this.centerx - this.gutterRight + 5;
- }
-
-
-
- // User specified radius, centerx and centery
- if (typeof(prop['chart.centerx']) == 'number') this.centerx = prop['chart.centerx'];
- if (typeof(prop['chart.centery']) == 'number') this.centery = prop['chart.centery'];
- if (typeof(prop['chart.radius']) == 'number') this.radius = prop['chart.radius'];
-
- /**
- * Parse the colors for gradients. Its down here so that the center X/Y can be used
- */
- if (!this.colorsParsed) {
-
- this.parseColors();
-
- // Don't want to do this again
- this.colorsParsed = true;
- }
-
- this.drawBackground();
- this.DrawRose();
- this.DrawLabels();
- /**
- * Set the strokestyle to transparent because of a strange double stroke bug
- *
- * DO NOT REMOVE
- */
- co.strokeStyle = 'rgba(0,0,0,0)'
- /**
- * Setup the context menu if required
- */
- if (prop['chart.contextmenu']) {
- RG.ShowContext(this);
- }
-
-
- /**
- * This function enables resizing
- */
- if (prop['chart.resizable']) {
- RG.AllowResizing(this);
- }
-
-
- /**
- * This function enables adjusting
- */
- if (prop['chart.adjustable']) {
- RG.AllowAdjusting(this);
- }
-
-
- /**
- * This installs the event listeners
- */
- RG.InstallEventListeners(this);
- /**
- * Fire the onfirstdraw event
- */
- if (this.firstDraw) {
- RG.fireCustomEvent(this, 'onfirstdraw');
- this.firstDrawFunc();
- this.firstDraw = false;
- }
- /**
- * Fire the RGraph ondraw event
- */
- RG.FireCustomEvent(this, 'ondraw');
-
- return this;
- };
- /**
- * This method draws the rose charts background
- */
- this.drawBackground =
- this.DrawBackground = function ()
- {
- co.lineWidth = 1;
-
-
- // Draw the background grey circles/spokes
- if (prop['chart.background.grid']) {
- if (typeof(prop['chart.background.grid.count']) == 'number') {
- prop['chart.background.grid.size'] = this.radius / prop['chart.background.grid.count'];
- }
-
- co.beginPath();
- co.strokeStyle = prop['chart.background.grid.color'];
-
- // Radius must be greater than 0 for Opera to work
- for (var i=prop['chart.background.grid.size']; i<=this.radius; i+=prop['chart.background.grid.size']) {
-
- // Hmmm... This is questionable
- co.moveTo(this.centerx + i, this.centery);
-
- // Radius must be greater than 0 for Opera to work
- co.arc(this.centerx,
- this.centery,
- i,
- 0,
- RG.TWOPI,
- false);
- }
- co.stroke();
-
-
-
-
-
-
- // Draw the background lines that go from the center outwards
- co.beginPath();
- if (typeof(prop['chart.background.grid.spokes']) == 'number') {
-
- var num = (360 / prop['chart.background.grid.spokes']);
-
- for (var i=num; i<=360; i+=num) {
-
- // Radius must be greater than 0 for Opera to work
- co.arc(this.centerx,
- this.centery,
- this.radius,
- ((i / (180 / RG.PI)) - RG.HALFPI) + this.startRadians,
- (((i + 0.0001) / (180 / RG.PI)) - RG.HALFPI) + this.startRadians,
- false);
-
- co.lineTo(this.centerx, this.centery);
- }
- } else {
- for (var i=15; i<=360; i+=15) {
-
- // Radius must be greater than 0 for Opera to work
- co.arc(this.centerx,
- this.centery,
- this.radius,
- (i / (180/ RG.PI)) - RG.HALFPI,
- ((i + 0.0001) / (180/ RG.PI)) - RG.HALFPI,
- false);
-
- co.lineTo(this.centerx, this.centery);
- }
- }
- co.stroke();
- }
-
-
-
- if (prop['chart.background.axes']) {
- co.beginPath();
- co.strokeStyle = prop['chart.background.axes.color'];
- // Draw the X axis
- co.moveTo(this.centerx - this.radius, Math.round(this.centery) );
- co.lineTo(this.centerx + this.radius, Math.round(this.centery) );
-
- // Draw the X ends
- co.moveTo(Math.round(this.centerx - this.radius), this.centery - 5);
- co.lineTo(Math.round(this.centerx - this.radius), this.centery + 5);
- co.moveTo(Math.round(this.centerx + this.radius), this.centery - 5);
- co.lineTo(Math.round(this.centerx + this.radius), this.centery + 5);
-
- // Draw the X check marks
- for (var i=(this.centerx - this.radius); i<(this.centerx + this.radius); i+=(this.radius / 5)) {
- co.moveTo(Math.round(i), this.centery - 3);
- co.lineTo(Math.round(i), this.centery + 3.5);
- }
-
- // Draw the Y check marks
- for (var i=(this.centery - this.radius); i<(this.centery + this.radius); i+=(this.radius / 5)) {
- co.moveTo(this.centerx - 3, Math.round(i));
- co.lineTo(this.centerx + 3, Math.round(i));
- }
-
- // Draw the Y axis
- co.moveTo(Math.round(this.centerx), this.centery - this.radius);
- co.lineTo(Math.round(this.centerx), this.centery + this.radius);
-
- // Draw the Y ends
- co.moveTo(this.centerx - 5, Math.round(this.centery - this.radius));
- co.lineTo(this.centerx + 5, Math.round(this.centery - this.radius));
-
- co.moveTo(this.centerx - 5, Math.round(this.centery + this.radius));
- co.lineTo(this.centerx + 5, Math.round(this.centery + this.radius));
-
- // Stroke it
- co.closePath();
- co.stroke();
- }
- };
- /**
- * This method draws the data on the graph
- */
- this.drawRose =
- this.DrawRose = function ()
- {
- var max = 0;
- var data = this.data;
- var margin = RGraph.degrees2Radians(prop['chart.margin']);
-
- co.lineWidth = prop['chart.linewidth'];
-
- // Must be at least two data points
- //if (data.length < 2) {
- // alert('[ROSE] Must be at least two data points! [' + data + ']');
- // return;
- //}
-
- // Work out the maximum value and the sum
- if (RG.is_null(prop['chart.ymax'])) {
-
- // Work out the max
- for (var i=0; i<data.length; ++i) {
- if (typeof(data[i]) == 'number') {
- max = Math.max(max, data[i]);
- } else if (typeof(data[i]) == 'object' && prop['chart.variant'] == 'non-equi-angular') {
- max = Math.max(max, data[i][0]);
-
- // Fallback is stacked
- } else {
- max = Math.max(max, RG.array_sum(data[i]));
- }
- }
-
- this.scale2 = RG.getScale2(this, {
- 'max':max,
- 'min':0,
- 'scale.thousand':prop['chart.scale.thousand'],
- 'scale.point':prop['chart.scale.point'],
- 'scale.decimals':prop['chart.scale.decimals'],
- 'ylabels.count':prop['chart.labels.count'],
- 'scale.round':prop['chart.scale.round'],
- 'units.pre': prop['chart.units.pre'],
- 'units.post': prop['chart.units.post']
- });
- this.max = this.scale2.max;
-
- } else {
-
- var ymax = prop['chart.ymax'];
-
-
-
- this.scale2 = RG.getScale2(this, {
- 'max':ymax,
- 'strict':true,
- 'scale.thousand':prop['chart.scale.thousand'],
- 'scale.point':prop['chart.scale.point'],
- 'scale.decimals':prop['chart.scale.decimals'],
- 'ylabels.count':prop['chart.labels.count'],
- 'scale.round':prop['chart.scale.round'],
- 'units.pre': prop['chart.units.pre'],
- 'units.post': prop['chart.units.post']
- });
- this.max = this.scale2.max
- }
-
- this.sum = RG.array_sum(data);
-
- // Move to the centre
- co.moveTo(this.centerx, this.centery);
-
- co.stroke(); // Stroke the background so it stays grey
-
- // Transparency
- if (prop['chart.colors.alpha']) {
- co.globalAlpha = prop['chart.colors.alpha'];
- }
-
- /*******************************************************
- * A non-equi-angular Rose chart
- *******************************************************/
- if (typeof(prop['chart.variant']) == 'string' && prop['chart.variant'] == 'non-equi-angular') {
- /*******************************************************
- * NON-EQUI-ANGULAR GOES HERE
- *******************************************************/
- var total=0;
- for (var i=0; i<data.length; ++i) {
- total += data[i][1];
- }
-
-
- for (var i=0; i<this.data.length; ++i) {
-
- var segmentRadians = ((this.data[i][1] / total) * RG.TWOPI);
- var radius = ((this.data[i][0] - prop['chart.ymin']) / (this.max - prop['chart.ymin'])) * this.radius;
- radius = radius * prop['chart.animation.grow.multiplier'];
-
- co.strokeStyle = prop['chart.strokestyle'];
- co.fillStyle = prop['chart.colors'][0];
-
- if (prop['chart.colors.sequential']) {
- co.fillStyle = prop['chart.colors'][i];
- }
-
- co.beginPath(); // Begin the segment
-
- var startAngle = (this.startRadians * prop['chart.animation.roundrobin.factor']) - RG.HALFPI + margin;
- var endAngle = ((this.startRadians + segmentRadians) * prop['chart.animation.roundrobin.factor']) - RG.HALFPI - margin;
-
- var exploded = this.getexploded(i, startAngle, endAngle, prop['chart.exploded']);
- var explodedX = exploded[0];
- var explodedY = exploded[1];
-
-
- co.arc(this.centerx + explodedX,
- this.centery + explodedY,
- prop['chart.animation.roundrobin.radius'] ? radius * prop['chart.animation.roundrobin.factor'] : radius,
- startAngle,
- endAngle,
- 0);
- co.lineTo(this.centerx + explodedX, this.centery + explodedY);
- co.closePath(); // End the segment
-
- co.stroke();
- co.fill();
-
- // Store the start and end angles
-
- this.angles.push(gg = [
- startAngle,
- endAngle,
- 0,
- radius,
- this.centerx + explodedX,
- this.centery + explodedY
- ]);
-
- this.startRadians += segmentRadians;
- }
- } else {
-
- var sequentialColorIndex = 0;
- /*******************************************************
- * Draw regular segments here
- *******************************************************/
- for (var i=0; i<this.data.length; ++i) {
-
- var segmentRadians = (1 / this.data.length) * RG.TWOPI;
- if (typeof(this.data[i]) == 'number') {
- co.beginPath(); // Begin the segment
-
- co.strokeStyle = prop['chart.strokestyle'];
- co.fillStyle = prop['chart.colors'][0];
-
- /*******************************************************
- * This allows sequential colors
- *******************************************************/
- if (prop['chart.colors.sequential']) {
- co.fillStyle = prop['chart.colors'][i];
- }
-
- var radius = ((this.data[i] - prop['chart.ymin']) / (this.max - prop['chart.ymin'])) * this.radius;
- radius = radius * prop['chart.animation.grow.multiplier'];
-
- var startAngle = (this.startRadians * prop['chart.animation.roundrobin.factor']) - RG.HALFPI + margin;
- var endAngle = (this.startRadians * prop['chart.animation.roundrobin.factor']) + (segmentRadians * prop['chart.animation.roundrobin.factor']) - RG.HALFPI - margin;
-
- var exploded = this.getexploded(i, startAngle, endAngle, prop['chart.exploded']);
- var explodedX = exploded[0];
- var explodedY = exploded[1];
-
- co.arc(this.centerx + explodedX,
- this.centery + explodedY,
- prop['chart.animation.roundrobin.radius'] ? radius * prop['chart.animation.roundrobin.factor'] : radius,
- startAngle,
- endAngle,
- 0);
- co.lineTo(this.centerx + explodedX, this.centery + explodedY);
- co.closePath(); // End the segment
- co.stroke();
- co.fill();
- // This skirts a double-stroke bug
- co.beginPath();
- if (endAngle == 0) {
- //endAngle = RG.TWOPI;
- }
- // Store the start and end angles
- this.angles.push([
- startAngle,
- endAngle,
- 0,
- radius * prop['chart.animation.roundrobin.factor'],
- this.centerx + explodedX,
- this.centery + explodedY
- ]);
-
- /*******************************************************
- * Draw a stacked segment
- *******************************************************/
- } else if (typeof(this.data[i]) == 'object') {
-
- var margin = prop['chart.margin'] / (180 / RG.PI);
-
- // Initialise the angles2 array so there's no undefined error
- if (!this.angles2[i]) {
- this.angles2[i] = [];
- }
-
-
- for (var j=0; j<this.data[i].length; ++j) {
-
- var startAngle = (this.startRadians * prop['chart.animation.roundrobin.factor']) - RG.HALFPI + margin;
- var endAngle = (this.startRadians * prop['chart.animation.roundrobin.factor'])+ (segmentRadians * prop['chart.animation.roundrobin.factor']) - RG.HALFPI - margin;
-
- var exploded = this.getexploded(i, startAngle, endAngle, prop['chart.exploded']);
- var explodedX = exploded[0];
- var explodedY = exploded[1];
-
- co.strokeStyle = prop['chart.strokestyle'];
- co.fillStyle = prop['chart.colors'][j];
-
- // This facilitates sequential color support
- if (prop['chart.colors.sequential']) {
- co.fillStyle = prop['chart.colors'][sequentialColorIndex++];
- }
-
- if (j == 0) {
- co.beginPath(); // Begin the segment
- var startRadius = 0;
- var endRadius = ((this.data[i][j] - prop['chart.ymin']) / (this.max - prop['chart.ymin'])) * this.radius;
- endRadius = endRadius * prop['chart.animation.grow.multiplier'];
-
- co.arc(this.centerx + explodedX,
- this.centery + explodedY,
- prop['chart.animation.roundrobin.radius'] ? endRadius * prop['chart.animation.roundrobin.factor'] : endRadius,
- startAngle,
- endAngle,
- 0);
- co.lineTo(this.centerx + explodedX, this.centery + explodedY);
- co.closePath(); // End the segment
- co.stroke();
- co.fill();
-
- this.angles.push([
- startAngle,
- endAngle,
- 0,
- endRadius * prop['chart.animation.roundrobin.factor'],
- this.centerx + explodedX,
- this.centery + explodedY
- ]);
-
- this.angles2[i].push([
- startAngle,
- endAngle,
- 0,
- endRadius * prop['chart.animation.roundrobin.factor'],
- this.centerx + explodedX,
- this.centery + explodedY
- ]);
-
- } else {
-
- co.beginPath(); // Begin the segment
-
- var startRadius = endRadius; // This comes from the prior iteration of this loop
- var endRadius = (((this.data[i][j] - prop['chart.ymin']) / (this.max - prop['chart.ymin'])) * this.radius) + startRadius;
- endRadius = endRadius * prop['chart.animation.grow.multiplier'];
-
- co.arc(this.centerx + explodedX,
- this.centery + explodedY,
- startRadius * prop['chart.animation.roundrobin.factor'],
- startAngle,
- endAngle,
- 0);
-
- co.arc(this.centerx + explodedX,
- this.centery + explodedY,
- endRadius * prop['chart.animation.roundrobin.factor'],
- endAngle,
- startAngle,
- true);
-
- co.closePath(); // End the segment
- co.stroke();
- co.fill();
-
- this.angles.push([
- startAngle,
- endAngle,
- startRadius * prop['chart.animation.roundrobin.factor'],
- endRadius * prop['chart.animation.roundrobin.factor'],
- this.centerx + explodedX,
- this.centery + explodedY
- ]);
-
- this.angles2[i].push([
- startAngle,
- endAngle,
- startRadius * prop['chart.animation.roundrobin.factor'],
- endRadius * prop['chart.animation.roundrobin.factor'],
- this.centerx + explodedX,
- this.centery + explodedY
- ]);
- }
- }
- }
-
- this.startRadians += segmentRadians;
- }
- }
-
- // Turn off the transparency
- if (prop['chart.colors.alpha']) {
- co.globalAlpha = 1;
- }
-
- // Draw the title if any has been set
- if (prop['chart.title']) {
- RG.DrawTitle(this,
- prop['chart.title'],
- (ca.height / 2) - this.radius,
- this.centerx,
- prop['chart.title.size'] ? prop['chart.title.size'] : prop['chart.text.size'] + 2);
- }
- };
- /**
- * Unsuprisingly, draws the labels
- */
- this.drawLabels =
- this.DrawLabels = function ()
- {
- co.lineWidth = 1;
- var key = prop['chart.key'];
-
- if (key && key.length) {
- RG.DrawKey(this, key, prop['chart.colors']);
- }
-
- // Set the color to black
- co.fillStyle = prop['chart.text.color'];
- co.strokeStyle = 'black';
-
- var radius = this.radius;
- var font = prop['chart.text.font'];
- var size = prop['chart.text.size'];
- var axes = prop['chart.labels.axes'].toLowerCase();
- var decimals = prop['chart.scale.decimals'];
- var units_pre = prop['chart.units.pre'];
- var units_post = prop['chart.units.post'];
- var centerx = this.centerx;
- var centery = this.centery;
-
- // Draw any circular labels
- if (typeof(prop['chart.labels']) == 'object' && prop['chart.labels']) {
- this.DrawCircularLabels(co, prop['chart.labels'], font, size, radius + 10);
- }
-
-
- // Size can be specified seperately for the scale now
- if (typeof(prop['chart.text.size.scale']) == 'number') {
- size = prop['chart.text.size.scale'];
- }
-
-
- var color = 'rgba(255,255,255,0.8)';
-
- // The "North" axis labels
- if (axes.indexOf('n') > -1) {
- for (var i=0; i<prop['chart.labels.count']; ++i) {
- RG.Text2(this, {'font':font,
- 'size':size,
- 'x':centerx,
- 'y':centery - (radius * ((i+1) / prop['chart.labels.count'])),
- 'text':this.scale2.labels[i],
- 'valign':'center',
- 'halign':'center',
- 'bounding':true,
- 'boundingFill':color,
- 'tag': 'scale'
- });
- }
- }
-
- // The "South" axis labels
- if (axes.indexOf('s') > -1) {
- for (var i=0; i<prop['chart.labels.count']; ++i) {
- RG.Text2(this, {'font':font,
- 'size':size,
- 'x':centerx,
- 'y':centery + (radius * ((i+1) / prop['chart.labels.count'])),
- 'text':this.scale2.labels[i],
- 'valign':'center',
- 'halign':'center',
- 'bounding':true,
- 'boundingFill':color,
- 'tag': 'scale'
- });
- }
- }
-
- // The "East" axis labels
- if (axes.indexOf('e') > -1) {
- for (var i=0; i<prop['chart.labels.count']; ++i) {
- RG.Text2(this, {'font':font,
- 'size':size,
- 'x':centerx + (radius * ((i+1) / prop['chart.labels.count'])),
- 'y':centery,
- 'text':this.scale2.labels[i],
- 'valign':'center',
- 'halign':'center',
- 'bounding':true,
- 'boundingFill':color,
- 'tag': 'scale'
- });
- }
- }
-
- // The "West" axis labels
- if (axes.indexOf('w') > -1) {
- for (var i=0; i<prop['chart.labels.count']; ++i) {
- RG.Text2(this, {'font':font,
- 'size':size,
- 'x':centerx - (radius * ((i+1) / prop['chart.labels.count'])),
- 'y':centery,
- 'text':this.scale2.labels[i],
- 'valign':'center',
- 'halign':'center',
- 'bounding':true,
- 'boundingFill':color,
- 'tag': 'scale'
- });
- }
- }
-
- if (axes.length > 0) {
- RG.Text2(this, {'font':font,
- 'size':size,
- 'x':centerx,
- 'y':centery,
- 'text':typeof(prop['chart.ymin']) == 'number' ? RG.number_format(this, Number(prop['chart.ymin']).toFixed(prop['chart.scale.decimals']), units_pre, units_post) : '0',
- 'valign':'center',
- 'halign':'center',
- 'bounding':true,
- 'boundingFill':color,
- 'tag': 'scale'
- });
- }
- };
- /**
- * Draws the circular labels that go around the charts
- *
- * @param labels array The labels that go around the chart
- */
- this.drawCircularLabels =
- this.DrawCircularLabels = function (co, labels, font, size, radius)
- {
- var variant = prop['chart.variant'];
- var position = prop['chart.labels.position'];
- var radius = radius + 5 + prop['chart.labels.offset'];
- var centerx = this.centerx;
- var centery = this.centery;
-
- for (var i=0; i<labels.length; ++i) {
- if (typeof(variant) == 'string' && variant == 'non-equi-angular') {
- var a = Number(this.angles[i][0]) + ((this.angles[i][1] - this.angles[i][0]) / 2);
- } else {
- var a = (RG.TWOPI / labels.length) * (i + 1) - (RG.TWOPI / (labels.length * 2));
- var a = a - RG.HALFPI + (prop['chart.labels.position'] == 'edge' ? ((RG.TWOPI / labels.length) / 2) : 0);
- }
-
- var x = centerx + (Math.cos(a) * radius);
- var y = centery + (Math.sin(a) * radius);
-
- // Horizontal alignment
- if (x > centerx) {
- halign = 'left';
- } else if (Math.round(x) == centerx) {
- halign = 'center';
- } else {
- halign = 'right';
- }
-
- RG.Text2(this, {'font':font,
- 'size':size,
- 'x':x,
- 'y':y,
- 'text':String(labels[i]),
- 'halign':halign,
- 'valign':'center',
- 'tag': 'labels'
- });
- }
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- /**
- * This function is for use with circular graph types, eg the Pie or Rose. Pass it your event object
- * and it will pass you back the corresponding segment details as an array:
- *
- * [x, y, r, startAngle, endAngle]
- *
- * Angles are measured in degrees, and are measured from the "east" axis (just like the canvas).
- *
- * @param object e Your event object
- */
- this.getShape =
- this.getSegment = function (e)
- {
- RG.FixEventObject(e);
-
- var angles = this.angles;
- var ret = [];
-
- /**
- * Go through all of the angles checking each one
- */
- for (var i=0; i<angles.length ; ++i) {
-
- var angleStart = angles[i][0];
- var angleEnd = angles[i][1];
- var radiusStart = angles[i][2];
- var radiusEnd = angles[i][3];
- var centerX = angles[i][4];
- var centerY = angles[i][5];
- var mouseXY = RG.getMouseXY(e);
- var mouseX = mouseXY[0] - centerX;
- var mouseY = mouseXY[1] - centerY;
-
- // New click testing (the 0.01 is there because Opera doesn't like 0 as the radius)
- co.beginPath();
- co.arc(centerX, centerY, radiusStart ? radiusStart : 0.01, angleStart, angleEnd, false);
- co.arc(centerX, centerY, radiusEnd, angleEnd, angleStart, true);
- co.closePath();
-
- // No stroke() or fill()
-
-
- if (co.isPointInPath(mouseXY[0], mouseXY[1])) {
-
- angles[i][6] = i;
-
- if (RG.parseTooltipText) {
- var tooltip = RG.parseTooltipText(prop['chart.tooltips'], angles[i][6]);
- }
-
- // Add the textual keys
- angles[i]['object'] = this;
- angles[i]['x'] = angles[i][4];
- angles[i]['y'] = angles[i][5];
- angles[i]['angle.start'] = angles[i][0];
- angles[i]['angle.end'] = angles[i][1];
- angles[i]['radius.start'] = angles[i][2];
- angles[i]['radius.end'] = angles[i][3];
- angles[i]['index'] = angles[i][6];
- angles[i]['tooltip'] = tooltip ? tooltip : null;
-
- return angles[i];
- }
- }
-
- return null;
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- /**
- * Returns any exploded for a particular segment
- */
- this.getExploded =
- this.getexploded = function (index, startAngle, endAngle, exploded)
- {
- var explodedx, explodedy;
-
- /**
- * Retrieve any exploded - the exploded can be an array of numbers or a single number
- * (which is applied to all segments)
- */
- if (typeof(exploded) == 'object' && typeof(exploded[index]) == 'number') {
- explodedx = Math.cos(((endAngle - startAngle) / 2) + startAngle) * exploded[index];
- explodedy = Math.sin(((endAngle - startAngle) / 2) + startAngle) * exploded[index];
-
- } else if (typeof(exploded) == 'number') {
- explodedx = Math.cos(((endAngle - startAngle) / 2) + startAngle) * exploded;
- explodedy = Math.sin(((endAngle - startAngle) / 2) + startAngle) * exploded;
-
- } else {
- explodedx = 0;
- explodedy = 0;
- }
-
- return [explodedx, explodedy];
- };
- /**
- * This function facilitates the installation of tooltip event listeners if
- * tooltips are defined.
- */
- this.allowTooltips =
- this.AllowTooltips = function ()
- {
- // Preload any tooltip images that are used in the tooltips
- RG.PreLoadTooltipImages(this);
-
-
- /**
- * This installs the window mousedown event listener that lears any
- * highlight that may be visible.
- */
- RG.InstallWindowMousedownTooltipListener(this);
-
-
- /**
- * This installs the canvas mousemove event listener. This function
- * controls the pointer shape.
- */
- RG.InstallCanvasMousemoveTooltipListener(this);
-
-
- /**
- * This installs the canvas mouseup event listener. This is the
- * function that actually shows the appropriate tooltip (if any).
- */
- RG.InstallCanvasMouseupTooltipListener(this);
- };
- /**
- * Each object type has its own Highlight() function which highlights the appropriate shape
- *
- * @param object shape The shape to highlight
- */
- this.highlight =
- this.Highlight = function (shape)
- {
- if (prop['chart.tooltips.highlight']) {
- // Add the new segment highlight
- co.beginPath();
-
- co.strokeStyle = prop['chart.highlight.stroke'];
- co.fillStyle = prop['chart.highlight.fill'];
-
- co.arc(shape['x'], shape['y'], shape['radius.end'], shape['angle.start'], shape['angle.end'], false);
- if (shape['radius.start'] > 0) {
- co.arc(shape['x'], shape['y'], shape['radius.start'], shape['angle.end'], shape['angle.start'], true);
- } else {
- co.lineTo(shape['x'], shape['y']);
- }
- co.closePath();
-
- co.stroke();
- co.fill();
- }
- };
- /**
- * The getObjectByXY() worker method. Don't call this call:
- *
- * RGraph.ObjectRegistry.getObjectByXY(e)
- *
- * @param object e The event object
- */
- this.getObjectByXY = function (e)
- {
- var mouseXY = RGraph.getMouseXY(e);
-
- // Work out the radius
- var radius = RG.getHypLength(this.centerx, this.centery, mouseXY[0], mouseXY[1]);
-
- if (
- mouseXY[0] > (this.centerx - this.radius)
- && mouseXY[0] < (this.centerx + this.radius)
- && mouseXY[1] > (this.centery - this.radius)
- && mouseXY[1] < (this.centery + this.radius)
- && radius <= this.radius
- ) {
-
- return this;
- }
- };
- /**
- * This function positions a tooltip when it is displayed
- *
- * @param obj object The chart object
- * @param int x The X coordinate specified for the tooltip
- * @param int y The Y coordinate specified for the tooltip
- * @param objec tooltip The tooltips DIV element
- */
- this.positionTooltip = function (obj, x, y, tooltip, idx)
- {
- var coordX = obj.angles[idx][4];
- var coordY = obj.angles[idx][5];
- var angleStart = obj.angles[idx][0];
- var angleEnd = obj.angles[idx][1];
- var radius = ((obj.angles[idx][3] - obj.angles[idx][2]) / 2) + obj.angles[idx][2];
-
- var angleCenter = ((angleEnd - angleStart) / 2) + angleStart;
- var canvasXY = RG.getCanvasXY(obj.canvas);
- var gutterLeft = this.gutterLeft;
- var gutterTop = this.gutterTop;
- var width = tooltip.offsetWidth;
- var height = tooltip.offsetHeight;
-
-
- // By default any overflow is hidden
- tooltip.style.overflow = '';
-
- // The arrow
- var img = new Image();
- img.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAFCAYAAACjKgd3AAAARUlEQVQYV2NkQAN79+797+RkhC4M5+/bd47B2dmZEVkBCgcmgcsgbAaA9GA1BCSBbhAuA/AagmwQPgMIGgIzCD0M0AMMAEFVIAa6UQgcAAAAAElFTkSuQmCC';
- img.style.position = 'absolute';
- img.id = '__rgraph_tooltip_pointer__';
- img.style.top = (tooltip.offsetHeight - 2) + 'px';
- tooltip.appendChild(img);
-
- // Reposition the tooltip if at the edges:
-
- // LEFT edge
- if ((canvasXY[0] + coordX + (Math.cos(angleCenter) * radius) - (width / 2)) < 10) {
- tooltip.style.left = (canvasXY[0] + coordX + (Math.cos(angleCenter) * radius)- (width * 0.1)) + 'px';
- tooltip.style.top = (canvasXY[1] + coordY + (Math.sin(angleCenter) * radius)- height - 5) + 'px';
- img.style.left = ((width * 0.1) - 8.5) + 'px';
-
- // RIGHT edge
- } else if ((canvasXY[0] + coordX + (Math.cos(angleCenter) * radius) + (width / 2)) > (doc.body.offsetWidth - 10) ) {
- tooltip.style.left = (canvasXY[0] + coordX + (Math.cos(angleCenter) * radius) - (width * 0.9)) + 'px';
- tooltip.style.top = (canvasXY[1] + coordY + (Math.sin(angleCenter) * radius)- height - 5) + 'px';
- img.style.left = ((width * 0.9) - 8.5) + 'px';
-
- // Default positioning - CENTERED
- } else {
- tooltip.style.left = (canvasXY[0] + coordX + (Math.cos(angleCenter) * radius)- (width / 2)) + 'px';
- tooltip.style.top = (canvasXY[1] + coordY + (Math.sin(angleCenter) * radius)- height - 5) + 'px';
- img.style.left = ((width * 0.5) - 8.5) + 'px';
- }
- };
- /**
- * This method gives you the relevant radius for a particular value
- *
- * @param number value The relevant value to get the radius for
- */
- this.getRadius = function (value)
- {
- // Range checking (the Rose minimum is always 0)
- if (value < 0 || value > this.max) {
- return null;
- }
-
- var r = (value / this.max) * this.radius;
-
- return r;
- };
- /**
- * This allows for easy specification of gradients
- */
- this.parseColors = function ()
- {
- // Save the original colors so that they can be restored when the canvas is reset
- if (this.original_colors.length === 0) {
- this.original_colors['chart.colors'] = RG.array_clone(prop['chart.colors']);
- this.original_colors['chart.key.colors'] = RG.array_clone(prop['chart.key.colors']);
- this.original_colors['chart.text.color'] = RG.array_clone(prop['chart.text.color']);
- this.original_colors['chart.title.color'] = RG.array_clone(prop['chart.title.color']);
- this.original_colors['chart.highlight.stroke'] = RG.array_clone(prop['chart.highlight.stroke']);
- this.original_colors['chart.highlight.fill'] = RG.array_clone(prop['chart.highlight.fill']);
- }
- for (var i=0; i<prop['chart.colors'].length; ++i) {
- prop['chart.colors'][i] = this.parseSingleColorForGradient(prop['chart.colors'][i]);
- }
-
- /**
- * Key colors
- */
- if (!RG.is_null(prop['chart.key.colors'])) {
- for (var i=0; i<prop['chart.key.colors'].length; ++i) {
- prop['chart.key.colors'][i] = this.parseSingleColorForGradient(prop['chart.key.colors'][i]);
- }
- }
-
- prop['chart.text.color'] = this.parseSingleColorForGradient(prop['chart.text.color']);
- prop['chart.title.color'] = this.parseSingleColorForGradient(prop['chart.title.color']);
- prop['chart.highlight.fill'] = this.parseSingleColorForGradient(prop['chart.highlight.fill']);
- prop['chart.highlight.stroke'] = this.parseSingleColorForGradient(prop['chart.highlight.stroke']);
- };
- /**
- * This parses a single color value
- */
- this.parseSingleColorForGradient = function (color)
- {
- if (!color || typeof(color) != 'string') {
- return color;
- }
-
- if (color.match(/^gradient\((.*)\)$/i)) {
-
- var parts = RegExp.$1.split(':');
-
- // Create the gradient
- //var grad = context.createLinearGradient(0,0,canvas.width,0);
- var grad = co.createRadialGradient(this.centerx, this.centery, 0, this.centerx, this.centery, this.radius);
-
- var diff = 1 / (parts.length - 1);
-
- grad.addColorStop(0, RG.trim(parts[0]));
-
- for (var j=1; j<parts.length; ++j) {
- grad.addColorStop(j * diff, RG.trim(parts[j]));
- }
- }
- return grad ? grad : color;
- };
- /**
- * This function handles highlighting an entire data-series for the interactive
- * key
- *
- * @param int index The index of the data series to be highlighted
- */
- this.interactiveKeyHighlight = function (index)
- {
- var segments = this.angles2;
-
- for (var i=0; i<this.angles2.length; i+=1) {
- co.beginPath();
- co.lineWidth = 2;
- co.fillStyle = prop['chart.key.interactive.highlight.chart.fill'];
- co.strokeStyle = prop['chart.key.interactive.highlight.chart.stroke'];
- co.arc(segments[i][index][4], segments[i][index][5], segments[i][index][2], segments[i][index][0], segments[i][index][1], false);
- co.arc(segments[i][index][4], segments[i][index][5], segments[i][index][3], segments[i][index][1], segments[i][index][0], true);
- co.closePath();
- co.fill();
- co.stroke();
- }
- return/*
- if (segments) {
- for (var i=0; i<segments.length; i+=1) {
- }
- }
- */
- };
- /**
- * Using a function to add events makes it easier to facilitate method chaining
- *
- * @param string type The type of even to add
- * @param function func
- */
- this.on = function (type, func)
- {
- if (type.substr(0,2) !== 'on') {
- type = 'on' + type;
- }
-
- this[type] = func;
-
- return this;
- };
- /**
- * This function runs once only
- * (put at the end of the file (before any effects))
- */
- this.firstDrawFunc = function ()
- {
- };
- /**
- * Rose chart explode
- *
- * Explodes the Rose chart - gradually incrementing the size of the chart.explode property
- *
- * @param object Optional options for the effect. You can pass in frames here - such as:
- * myRose.roundRobin({frames: 60}; function () {alert('Done!');})
- * @param function A callback function which is called when the effect is finished
- */
- this.explode = function ()
- {
- var obj = this;
- var opt = arguments[0] || {};
- var callback = arguments[1] || function (){};
- var frames = opt.frames ? opt.frames : 30;
- var frame = 0;
- var explodedMax = ma.max(ca.width, ca.height);
- var exploded = Number(this.Get('exploded'));
-
-
-
-
- function iterator ()
- {
- exploded = (frame / frames) * explodedMax;
- // Set the new value
- obj.Set('exploded', exploded);
-
- RG.clear(ca);
- RG.redrawCanvas(ca);
-
- if (frame++ < frames) {
- RG.Effects.updateCanvas(iterator);
- } else {
- callback(obj);
- }
- }
- iterator();
-
- return this;
- };
- /**
- * RoundRobin
- *
- * This effect is similar to the Pie chart RoundRobin effect
- *
- * @param object Optional options for the effect. You can pass in frames here - such as:
- * myRose.roundRobin({frames: 60}; function () {alert('Done!');})
- * @param function A callback function which is called when the effect is finished
- */
- this.roundrobin =
- this.roundRobin = function ()
- {
- var obj = this;
- var opt = arguments[0] || {}
- var frames = opt.frames || 30;
- var frame = 0;
- var original_margin = prop['chart.margin'];
- var margin = (360 / this.data.length) / 2;
- var callback = arguments[1] || function () {};
-
- this.Set('chart.margin', margin);
- this.Set('chart.animation.roundrobin.factor', 0);
-
- function iterator ()
- {
- RG.clear(obj.canvas);
- RG.redrawCanvas(obj.canvas);
- if (frame++ < frames) {
- obj.set('animation.roundrobin.factor', frame / frames);
- obj.set('margin', (frame / frames) * original_margin);
- RG.Effects.updateCanvas(iterator);
- } else {
- obj.set('animation.roundrobin.factor', 1);
- obj.set('margin', original_margin);
-
- callback(obj);
- }
- }
-
- iterator();
-
- return this;
- };
- /**
- * Rose chart implode
- *
- * Implodes the Rose chart - gradually decreasing the size of the chart.explode property. It starts at the largest of
- * the canvas width./height
- *
- * @param object Optional options for the effect. You can pass in frames here - such as:
- * myRose.implode({frames: 60}; function () {alert('Done!');})
- * @param function A callback function which is called when the effect is finished
- */
- this.implode = function ()
- {
- var obj = this;
- var opt = arguments[0] || {};
- var callback = arguments[1] || function (){};
- var frames = opt.frames || 30;
- var frame = 0;
- var explodedMax = ma.max(ca.width, ca.height);
- var exploded = explodedMax;
-
-
-
- function iterator ()
- {
- exploded = explodedMax - ((frame / frames) * explodedMax);
- // Set the new value
- obj.Set('exploded', exploded);
-
- RG.clear(ca);
- RG.redrawCanvas(ca);
- if (frame++ < frames) {
- RG.Effects.updateCanvas(iterator);
- } else {
- RG.clear(obj.canvas);
- RG.redrawCanvas(obj.canvas);
- callback(obj);
- }
- }
-
- iterator();
- return this;
- };
- /**
- * Rose chart Grow
- *
- * This effect gradually increases the size of the Rose chart
- *
- * @param object Optional options for the effect. You can pass in frames here - such as:
- * myRose.grow({frames: 60}; function () {alert('Done!');})
- * @param function A callback function which is called when the effect is finished
- */
- this.grow = function ()
- {
- var obj = this;
- var opt = arguments[0] || {};
- var callback = arguments[1] || function (){};
- var frames = opt.frames || 30;
- var frame = 0;
- function iterator ()
- {
- obj.Set('animation.grow.multiplier', frame / frames);
-
- RG.clear(ca);
- RG.redrawCanvas(ca);
- if (frame < frames) {
- frame++;
- RG.Effects.updateCanvas(iterator);
- } else {
- callback(obj);
- }
- }
-
- iterator();
- return this;
- };
- /**
- * Register this object
- */
- RG.Register(this);
- };
|