source: main/trunk/model-sites-dev/von-sparql/js/von-sparql-comparison-setup.js@ 29423

Last change on this file since 29423 was 29423, checked in by ak19, 9 years ago

Changes made to some functions that were deleted in new version of jquery

File size: 7.9 KB
Line 
1///////////////////////////////////////////////
2// //
3// Setup for comparisons //
4// Query generation code is messy, watch out!//
5// //
6///////////////////////////////////////////////
7
8//SPARQL endpoint location
9var sparqlEndpoint= location.protocol + '//' + location.hostname + ":3030/greenstone/query" ;
10//Contains the query built
11var comparisonQuery;
12//Hard limit for results returned from a query
13var hardLimit = 2000;
14//sgvizler chart width/height
15var defaultChartWidth = 468;
16var defaultChartHeight = 200;
17//just to keep track of amount of queries running
18var currentQueries = 0;
19
20//collection names
21var leftCollection = "";
22var rightCollection = "";
23
24// ComparisonQuery object contains details about a comparison to be made between 2 datasets
25// page Page number
26// datsetSelection Left or right dataset
27// pred_L Left predicate
28// predval_L Left predicate value (if restricting to a specific value)
29// refine_L Left predicate to use for comparison after restriction
30// pred_R Right predicate
31// predval_R Right predicate value (if restricting to a specific value)
32// refine_R Right predicate to use for comparison after restriction
33function ComparisonQuery(){
34 this.page = 1;
35 this.datasetSelection = "";
36 this.type = "intersection";
37 this.pred_L = $('#sel_leftPredicate').val();
38 this.predval_L = $('#sel_leftPredicateValue').val();
39 this.refine_L = "";
40 if($('#cb_leftRefineSearch').is(':checked'))
41 this.refine_L = " <" + $('#sel_leftVisualizePredicate').val() + "> ";// + "> ?common";
42
43 this.pred_R = $('#sel_rightPredicate').val();
44 this.predval_R = $('#sel_rightPredicateValue').val();
45 this.refine_R = "";
46 if($('#cb_rightRefineSearch').is(':checked'))
47 this.refine_R = " <" + $('#sel_rightVisualizePredicate').val() + "> ";// + "> ?common";
48 $('#span_PageNum').text("1");
49}
50
51function setupPage(){
52 sgvizler_setup();
53 //Load collection names from dropdown boxes
54 leftCollection = $('#sel_leftCollection').val();
55 rightCollection = $('#sel_rightCollection').val();
56
57 //Draw buttons, etc for each side of page
58 drawSide("left",leftCollection);
59 apply_functions("left",leftCollection);
60 drawSide("right",rightCollection);
61 apply_functions("right",rightCollection);
62
63 //apply css to generated objects
64 apply_styles();
65
66 //populates predicate dropdown boxes
67 populatePredicateSelector("all", "sel_comparisonPredicate");
68}
69
70//Redraw a side, given the collection name
71function drawSide(side, collectionName){
72 $('#span_' + side + 'Name').html(collectionName);
73 drawOverview(collectionName, ("div_" + side + "Overview"));
74 populatePredicateSelector(collectionName, ("sel_" + side + "Predicate"));
75}
76
77//Draw predicates available for dataset
78function drawOverview(collection, container){
79 var Q = new sgvizler.Query();
80 Q.query(createOverviewQuery(collection))
81 .endpointURL(sparqlEndpoint)
82 .endpointOutputFormat("json")
83 .chartFunction("google.visualization.Table")
84 .draw(container);
85}
86
87//Return a query that searches for all uses of predicates in a graph
88function createOverviewQuery(collection){
89 var Query = "PREFIX gsdl: <http://localhost:3030/greenstone/data/>"
90 +"SELECT (?p as ?Predicate) (COUNT (?s) as ?Total)WHERE\n"
91 + "{\n";
92 if(collection=="all")
93 Query += "?s ?p ?o ";
94 else
95 Query += "GRAPH gsdl:" + collection + "{"
96 + " ?s ?p ?o "
97 + "}";
98 Query += "}"
99 + "GROUP BY ?p "
100 + "ORDER BY DESC(?Predicate)";
101 return Query;
102}
103
104function sgvizler_setup(){
105 sgvizler
106 .defaultEndpointOutputFormat('jsonp')
107 .defaultChartWidth(defaultChartWidth)
108 .defaultChartHeight(defaultChartHeight)
109 .prefix('dc', "http://purl.org/dc/elements/1.1/")
110 .prefix('xsd', "http://www.w3.org/2001/XMLSchema#")
111 .prefix('gsdl', "http://localhost:3030/greenstone/data/")
112}
113
114function apply_styles(){
115 $('.basicControls tbody tr td:first-child').addClass("alignRight");
116 $('.refineControls tbody tr td:first-child').addClass("alignRight");
117 $('.refineControls').toggle();
118 $('#txt_comparisonPredicate').val("http://purl.org/dc/elements/1.1/Title");
119 $('#div_resultPredicates').toggle();
120 $('#cb_showOnlyCommonObjects').attr('checked','checked');
121 $('#cb_showOnlyCommonObjects').on('click', function(){
122 $('#div_resultPredicates').toggle();
123 });
124
125 $('#btn_submitComparison').on('click',function(){
126 drawComparisonTable();
127 });
128
129 $('#btn_comparisonPagePrev').on('click',function(){
130 if(comparisonQuery.page <= 1)
131 return;
132 $('#span_PageNum').text(--comparisonQuery.page)
133 drawComparisonTable();
134 });
135
136 $('#btn_comparisonPageNext').on('click',function(){
137 $('#span_PageNum').text(++comparisonQuery.page)
138 drawComparisonTable();
139 });
140
141 $('#btn_exportCSV').on('click',function(){
142 var csv = $('#div_combinedResultsVisualization table').table2CSV({
143 delivery: 'value'
144 });
145 var vendorName = window.navigator.vendor;
146 if(vendorName == "Google Inc.") {
147 // is Google chrome
148 window.location.href = 'data:text/csv;charset=UTF-8,' + encodeURIComponent(csv);
149 }
150 else{
151 alert("-----Use Google Chrome to save file to disk.-----\n\n" + csv);
152 }
153 });
154}
155
156//Apply functions to various elements
157function apply_functions(side, collection){
158
159 //Create jquery UI comboboxes
160 $('#div_' + side + 'RefineControls select').combobox({
161 select: function(event, ui) {
162 var id = event.target.id;
163 if(id == "sel_" + side + "Predicate")
164 updateValueSelector(this.value,"sel_"+ side + "PredicateValue", collection);
165 }
166 });
167
168 $('#btn_' + side + 'ShowChart').on('click',function(){
169 hardLimit=2000;
170 drawFilteredDataset(side, collection);
171 });
172
173 $('#btn_' + side + 'ShowQuery').on('click',function(){
174 hardLimit=2000;
175 alert(generateQuery(side,collection));
176 });
177
178 $('#btn_' + side + 'SubmitQuery').on('click',function(){
179 paper.install(window);
180 var color = updateCircle(side);
181 comparisonQuery = new ComparisonQuery();
182 $('#div_' + side + 'Indicator').css("background-color",color);
183 });
184
185 //When a <tr> in overview table is selected, select in predicate dropdown
186$(document).on("click", "#div_" + side + "Overview.overview tr", function(){
187 var clickedText = tidyPredicate($(this).children(":first").text());
188 $('#sel_' + side + 'Predicate option[text="' + clickedText + '"]').attr('selected','selected');
189 $('#sel_' + side + 'Predicate option').filter(function(){
190 return $(this).text() == clickedText;
191 }).attr('selected', true);
192
193 $('#sel_' + side + 'Predicate').siblings('.custom-combobox').find('.custom-combobox-input').val(clickedText);
194 updateValueSelector($('#sel_' + side + 'Predicate option:selected').val(),"sel_"+ side + "PredicateValue", collection);
195
196 if($('#cb_quickSearch').is(':checked')) {
197 hardLimit=500;
198 drawFilteredDataset(side, collection);
199 }
200
201 //When TD is selected, highlight similar TD's in opposite table
202 showSimilarPredicates(side,$(this).children(":first").text());
203 });
204
205 $('#cb_' + side + 'RefineSearch').on('click', function(){
206 //$('#table_' + side + 'RefineControls').toggle();
207 $('#table_' + side + 'RefineControls').toggle("slide", { direction: "up" });
208 });
209
210 $('#sel_' + side + 'Collection').on('change',function(){
211 if(side=="left")
212 leftCollection = $('#sel_' + side + 'Collection').val();
213 else
214 rightCollection = $('#sel_' + side + 'Collection').val();
215
216 drawSide(side, $('#sel_' + side + 'Collection').val());
217 });
218}
219
220// When a predicate is clicked on one side, makes the same predicate on
221// the opposite side bold, to stand out
222function showSimilarPredicates(side,clickedText){
223 var oppositeSide;
224 if(side == "left")
225 oppositeSide = "right";
226 else
227 oppositeSide = "left";
228
229 $('#div_' + oppositeSide + 'Overview.overview tr').each(function(){
230 if($(this).children(":first").text() == clickedText)
231 $(this).children(":first").addClass("bold");
232 else
233 $(this).children(":first").removeClass("bold");
234
235 });
236
237 $('#div_' + side + 'Overview.overview tr').each(function(){
238 if($(this).children(":first").text() == clickedText)
239 $(this).children(":first").addClass("bold");
240 else
241 $(this).children(":first").removeClass("bold");
242 });
243}
Note: See TracBrowser for help on using the repository browser.