Commit 564dc914fb6d6ae83f52f4ad74ef7d024dd349bf

  • avatar
  • arvind
  • Sat Aug 30 20:36:58 IST 2014
Fix render issues with tag clouds. Tag cloud were off, set full width
and height for svg.
  
118118.nav-btn {
119119 margin-left: 10px;
120120}
121#tag-cloud {
122 height:768px;
123}
124#tags-tag-cloud svg {
125 position: absolute;
126 left:100px;
127 top: 0;
128 height:100%;
129 width: 100%;
130}
131#user-tag-cloud svg {
132 position: absolute;
133 height:100%;
134 top: 40em;
135 left:100px;
136 width: 100%
137}
  
709709 var TagCloudView = Backbone.View.extend({
710710 el: $('#tag-cloud'),
711711 events: {
712 "click g": "test"
712 "click #user-tag-cloud g": "userTagClicked",
713 "click #tags-tag-cloud g": "tagsTagClicked"
713714 },
714715 initialize: function() {
715716 this.user_tag_el = $('#user-tag-cloud');
718718 this.render();
719719
720720 },
721 test: function(e) {
721 userTagClicked: function(e) {
722722 console.log(e);
723723 },
724 tagsTagClicked: function(e) {
725 console.log('tags ',e);
726 },
724727 render: function() {
725728 this.renderUserTagCloud();
726729 this.renderTagsTagCloud();
727730 },
728731 renderUserTagCloud: function() {
729 var fill = d3.scale.category20();
730732 var words = _.uniq(swtr.LDs.pluck('who'));
731733 var weight = swtr.LDs.countBy('who');
732 d3.layout.cloud().size([300, 300])
734 d3.layout.cloud().size([1000, 1000])
733735 .words(words.map(function(d) {
734 return {text: d, size: weight[d]};
736 return {text: d, size: 5};
735737 }))
736738 .padding(5)
737 .rotate(function() { return ~~(Math.random() * 2) * 90; })
738739 .font("Impact")
739740 .fontSize(function(d) { return d.size; })
740741 .on("end", this.draw)
743743
744744 },
745745 draw: function (words) {
746 var fill = d3.scale.category20();
746747 d3.select("#user-tag-cloud").append("svg")
747 .attr("width", 300)
748 .attr("height", 300)
749748 .append("g")
750 .attr("transform", "translate(150,150)")
749 .attr("transform", "translate(370,180)")
751750 .selectAll("text")
752751 .data(words)
753752 .enter().append("text")
754753 .style("font-size", function(d) { return "16px"; })
755754 .style("font-family", "Impact")
756 .style("fill", function(d, i) {console.log(i); return 'red'; })
755 .style("fill", function(d, i) { return fill(i); })
757756 .attr("text-anchor", "middle")
758757 .attr("transform", function(d) {
759 return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
760 })
761 .text(function(d) {console.log(d); return d.text; });
758 return "translate(" + [d.x, d.y] + ")";})
759 .text(function(d) { return d.text; });
760
762761 },
763762 renderTagsTagCloud: function() {
764 var fill = d3.scale.category20();
765763 var sweetsWithTags = swtr.LDs.filter(function(k) {
766764 if(k.get('how').tags) {
767765 return k;
769769 _.each(sweetsWithTags, function(sweet) {
770770 tags.push(sweet.get('how').tags);
771771 });
772 tags = _.flatten(tags);
773 d3.layout.cloud().size([300, 300])
772 tags = _.uniq(_.flatten(tags));
773 d3.layout.cloud().size([500, 500])
774774 .words(tags.map(function(d) {
775775 return {text: d, size: 10};
776776 }))
777 .padding(5)
778 .rotate(function() { return ~~(Math.random() * 2) * 90; })
777 .padding(7)
779778 .font("Impact")
780779 .fontSize(function(d) { return d.size; })
781780 .on("end", this.drawTags)
782782
783783 },
784784 drawTags: function(words) {
785 var fill = d3.scale.category20();
785786 d3.select("#tags-tag-cloud").append("svg")
786 .attr("width", 300)
787 .attr("height", 300)
788787 .append("g")
789 .attr("transform", "translate(150,150)")
788 .attr("transform", "translate(700,300)")
790789 .selectAll("text")
791790 .data(words)
792791 .enter().append("text")
793 .style("font-size", function(d) { return "16px"; })
792 .style("font-size", function(d) { return "20px"; })
794793 .style("font-family", "Impact")
795 .style("fill", function(d, i) {console.log(i); return 'red'; })
794 .style("fill", function(d, i) { return fill(i); })
796795 .attr("text-anchor", "middle")
797796 .attr("transform", function(d) {
798 return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
797 return "translate(" + [d.x, d.y] + ")";
799798 })
800799 .text(function(d) {console.log(d); return d.text; });
801800 }
  
144144 </div>
145145 <div id="linked-data-page" class="page">
146146 <div id="tag-cloud">
147 <div id="user-tag-cloud" class="row"></div>
148 <div id="tags-tag-cloud" class="row"></div>
147 <div id="tags-tag-cloud"></div>
148 <div id="user-tag-cloud"></div>
149149 </div>
150150 </div>
151151 <!-- the search page -->