Skip to content
Browse files

Legend modified (Prealpha version [unsuable])

We don't allow the user to hide all the legends.
  • Loading branch information...
1 parent 490da14 commit ebd3a1d8b1e0166cee7c5150e4d4330a819dbf3a Jesús committed Jul 2, 2012
Showing with 83 additions and 0 deletions.
  1. +3 −0 img/palettes.txt
  2. +79 −0 js/jamcharts.js
  3. +1 −0 test/line.html
View
3 img/palettes.txt
@@ -0,0 +1,3 @@
+Goldfish: http://www.colourlovers.com/palette/92095/Giant_Goldfish
+105,210,231 243,134,48 167,219,216 250,105,0 224,228,204
+
View
79 js/jamcharts.js
@@ -37,8 +37,74 @@ var JAMChart = function (obj,graph){
m.appendStyle(".point"+num+", .line"+num+"{display:block}")
m.hideLegends.splice(m.hideLegends.indexOf(num),1)
}
+ if(m.hideLegends.length==m.graph.variables.length){ /*No permitimos que desactiven todas las leyendas*/
+ m.hideLegends=[]
+ for(p=0;p<m.graph.variables.length;p++){
+ m.appendStyle(".point"+p+", .line"+p+"{display:block}")
+ }
+ }
/*Restructuramos toda la plantilla*/
+ //Creamos una variable igual que graph.variables pero sólo con las variables que son visibles en este momento
+ m.activeVariables=[]
+ for(var p=0;p<m.graph['variables'].length;p++){
+ if(m.hideLegends.indexOf(p.toString())==-1){
+ m.activeVariables[m.activeVariables.length]=m.graph['variables'][p]
+ }
+ }
+ /*Decidimos la altura del gráfico*/
+ m.cont = m.grCont.lastChild.firstChild
+ /*Wich is going to be the biggest and the smallest data in the graph*/
+ m.biggestData = 0
+ m.smallestData = 0
+ for(var z=0;z<m.activeVariables.length;z++){
+ for(var y=0;y<m.activeVariables[z].data.length;y++){
+ if(m.activeVariables[z].data[y]>m.biggestData) {
+ m.biggestData = m.activeVariables[z].data[y]
+ }
+ if(m.activeVariables[z].data[y]<m.smallestData) {
+ m.smallestData = m.activeVariables[z].data[y]
+ }
+ }
+ }
+ /*We decide the scale of the graph*/
+ m.graphHeight = m.cont.offsetHeight
+ m.graphWidth = m.cont.offsetWidth
+ m.maxLines = parseInt(m.graphHeight/40,10)
+ m.amplitude = m.biggestData-m.smallestData
+ m.rang = parseInt((m.amplitude/m.maxLines)+0.99999,10)
+ m.rang = parseInt(((m.amplitude+m.rang)/m.maxLines)+0.99999,10)
+ /*Adaptamos el rango*/
+ if(m.rang>5&&m.rang<10){
+ m.rang = 10
+ }
+ if(m.rang>10){
+ m.rang = (parseInt(m.rang/5,10)+1)*5
+ }
+ if((m.rang+"").length>2){
+ m.rang = (parseInt(m.rang/Math.pow(10,(m.rang+"").length-2),10)+1)*Math.pow(10,(m.rang+"").length-2)
+ }
+
+ /*Definimos los límites del gráfico*/
+ if(m.smallestData < 0){
+ m.smallestData = (parseInt(m.smallestData/m.rang,10)-1)*m.rang
+ }
+ m.biggestData = (parseInt(m.biggestData/m.rang,10)+1)*m.rang
+ /*Definimos la distancia en píxeles entre una línea y la siguiente*/
+ m.pixelRang = parseInt((m.graphHeight/(m.biggestData-m.smallestData+1))*m.rang,10)
+ /*rang indica la amplitud entre una línea y la siguiente y pixelRang indica la diferencia de píxeles entre una línea y la siguiente*/
+
+ /*Definimos variables para situar las líneas de la plantilla en position:absolute*/
+ m.topRel = m.cont.offsetTop
+ m.leftRel = m.cont.offsetLeft
+ m.bottomRel = m.topRel + m.cont.offsetHeight
+ m.rightRel = m.leftRel + m.cont.offsetWidth
+
+ /*Definimos variables para la nivelación izquierda*/
+ m.leftData = {}
+ m.leftData.width = m.grCont.firstChild.offsetWidth
+ m.leftData.leftRel = m.grCont.firstChild.offsetLeft
+ m.leftData.template = []
}
}
@@ -161,6 +227,19 @@ var JAMChart = function (obj,graph){
m.bottomData.topRel = m.cont.offsetTop
m.bottomData.legendSpace = m.bottomData.width/m.graph['independent']['categories'].length
+ /*I'M HERE*/
+ /*I'M HERE*/
+ /*I'M HERE*/
+ /*I'M HERE*/
+ /*I'M HERE*/
+ /*I'M HERE*/
+ /*I'M HERE*/
+ /*I'M HERE*/
+ /*I'M HERE*/
+ /*I'M HERE*/
+ /*I'M HERE*/
+ /*Hay que añadir el*/
+
/*Creamos la plantilla inferior*/
for(w=0;w<m.graph['independent']['categories'].length;w++){
m.bottomData.template[w] = document.createElement("span")
View
1 test/line.html
@@ -43,6 +43,7 @@
chr = new JAMChart(document.getElementById("chartContainer"),graph)
}
</script>
+
</head>
<body onload="createChart()">

0 comments on commit ebd3a1d

Please sign in to comment.
Something went wrong with that request. Please try again.