diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/VisVOContainer.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/VisVOContainer.java new file mode 100644 index 000000000..254ab5eed --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/VisVOContainer.java @@ -0,0 +1,84 @@ +package edu.cornell.mannlib.vitro.webapp.visualization.personpubcount; + +public class VisVOContainer { + + /* + * For now sparklineNumPublicationsText & sparklinePublicationRangeText is left + * as empty but later on we would want to leverage the granularity that this + * provides. + * */ + private String sparklineNumPublicationsText = ""; + private String sparklinePublicationRangeText = ""; + + private Integer earliestRenderedPublicationYear; + private Integer latestRenderedPublicationYear; + + private String table = ""; + + private String downloadDataLink = ""; + private String fullTimelineNetworkLink = ""; + + private String sparklineContent; + private String sparklineContext; + + public String getSparklineNumPublicationsText() { + return sparklineNumPublicationsText; + } + public void setSparklineNumPublicationsText(String sparklineNumPublicationsText) { + this.sparklineNumPublicationsText = sparklineNumPublicationsText; + } + public String getSparklinePublicationRangeText() { + return sparklinePublicationRangeText; + } + public void setSparklinePublicationRangeText( + String sparklinePublicationRangeText) { + this.sparklinePublicationRangeText = sparklinePublicationRangeText; + } + public Integer getEarliestRenderedPublicationYear() { + return earliestRenderedPublicationYear; + } + public void setEarliestRenderedPublicationYear( + Integer earliestRenderedPublicationYear) { + this.earliestRenderedPublicationYear = earliestRenderedPublicationYear; + } + public Integer getLatestRenderedPublicationYear() { + return latestRenderedPublicationYear; + } + public void setLatestRenderedPublicationYear( + Integer latestRenderedPublicationYear) { + this.latestRenderedPublicationYear = latestRenderedPublicationYear; + } + public String getTable() { + return table; + } + public void setTable(String table) { + this.table = table; + } + public String getDownloadDataLink() { + return downloadDataLink; + } + public void setDownloadDataLink(String downloadDataLink) { + this.downloadDataLink = downloadDataLink; + } + public String getFullTimelineNetworkLink() { + return fullTimelineNetworkLink; + } + public void setFullTimelineNetworkLink(String fullTimelineNetworkLink) { + this.fullTimelineNetworkLink = fullTimelineNetworkLink; + } + + public String getSparklineContent() { + return sparklineContent; + } + public void setSparklineContent(String shortSparklineContent) { + this.sparklineContent = shortSparklineContent; + } + + public String getSparklineContext() { + return sparklineContext; + } + public void setSparklineContext(String shortSparklineContext) { + this.sparklineContext = shortSparklineContext; + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/VisualizationCodeGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/VisualizationCodeGenerator.java index 340da51ef..7c198b817 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/VisualizationCodeGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/VisualizationCodeGenerator.java @@ -5,6 +5,7 @@ import java.net.URLEncoder; import java.util.Calendar; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; @@ -35,24 +36,74 @@ public class VisualizationCodeGenerator { private static final String SHORT_SPARKLINE_MODE_URL_HANDLE = "short"; private static final String FULL_SPARKLINE_MODE_URL_HANDLE = "full"; - + private Map yearToPublicationCount; private Log log; - public VisualizationCodeGenerator(Map yearToPublicationCount, Log log) { + private VisVOContainer valueObjectContainer; + + public VisualizationCodeGenerator(String requestURI, + String individualURIParam, + String visMode, + String visContainer, + List authorDocuments, + Map yearToPublicationCount, + VisVOContainer valueObjectContainer, + Log log) { + this.yearToPublicationCount = yearToPublicationCount; + this.valueObjectContainer = valueObjectContainer; this.log = log; + + generateVisualizationCode(requestURI, + individualURIParam, + visMode, + visContainer, + authorDocuments); + + } - public String getMainVisualizationCode(List authorDocuments, - Set publishedYears, + + private void generateVisualizationCode(String requestURI, + String individualURIParam, String visMode, - String providedVisContainerID) { + String visContainer, + List authorDocuments) { + + valueObjectContainer.setSparklineContent(getMainVisualizationCode(authorDocuments, + visMode, + visContainer)); + + + valueObjectContainer.setSparklineContext(getVisualizationContextCode(requestURI, + individualURIParam, + visMode)); + + } + +// public VisVOContainer getValueObjectContainer() { +// +// +// +// return valueObjectContainer; +// } + + private String getMainVisualizationCode(List authorDocuments, + String visMode, + String providedVisContainerID) { int numOfYearsToBeRendered = 0; int currentYear = Calendar.getInstance().get(Calendar.YEAR); int shortSparkMinYear = currentYear - 10 + 1; + /* + * This is required because when deciding the range of years over which the vis + * was rendered we dont want to be influenced by the "DEFAULT_PUBLICATION_YEAR". + * */ + Set publishedYears = new HashSet(yearToPublicationCount.keySet()); + publishedYears.remove(VOConstants.DEFAULT_PUBLICATION_YEAR); + /* * We are setting the default value of minPublishedYear to be 10 years before * the current year (which is suitably represented by the shortSparkMinYear), @@ -157,6 +208,14 @@ public class VisualizationCodeGenerator { } + /* + * By default these represents the range of the rendered sparks. Only in case of + * "short" sparkline mode we will set the Earliest RenderedPublication year to + * "currentYear - 10". + * */ + valueObjectContainer.setEarliestRenderedPublicationYear(minPublishedYear); + valueObjectContainer.setLatestRenderedPublicationYear(currentYear); + /* * The Full Sparkline will be rendered by default. Only if the url has specific mention of * SHORT_SPARKLINE_MODE_URL_HANDLE then we render the short sparkline and not otherwise. @@ -169,6 +228,8 @@ public class VisualizationCodeGenerator { * They both side-effect "visualizationCode" * */ if (SHORT_SPARKLINE_MODE_URL_HANDLE.equalsIgnoreCase(visMode)) { + + valueObjectContainer.setEarliestRenderedPublicationYear(shortSparkMinYear); generateShortSparklineVisualizationContent(currentYear, shortSparkMinYear, visContainerID, @@ -184,6 +245,9 @@ public class VisualizationCodeGenerator { } + + + // System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); log.debug(visualizationCode); @@ -231,6 +295,8 @@ public class VisualizationCodeGenerator { "renderedShortSparks += data.getValue(value, 1);" + "});\n"); + + /* * Generate the text introducing the vis. * */ @@ -303,7 +369,7 @@ public class VisualizationCodeGenerator { "\n"; } - public String getVisualizationContextCode(String uri, String individualURI, String visMode) { + private String getVisualizationContextCode(String uri, String individualURI, String visMode) { String visualizationContextCode = ""; if (SHORT_SPARKLINE_MODE_URL_HANDLE.equalsIgnoreCase(visMode)) { @@ -333,27 +399,33 @@ public class VisualizationCodeGenerator { String downloadFileCode; if (yearToPublicationCount.size() > 0) { - downloadFileCode = "Download data as .csv file.
"; + + + String downloadURL = uri.toString() + + "?" + VisualizationFrameworkConstants.INDIVIDUAL_URI_URL_HANDLE + + "=" + URLEncoder.encode(individualURI, + VisualizationController.URL_ENCODING_SCHEME).toString() + + "&" + VisualizationFrameworkConstants.VIS_TYPE_URL_HANDLE + + "=" + URLEncoder.encode(VisualizationController + .PERSON_PUBLICATION_COUNT_VIS_URL_VALUE, + VisualizationController.URL_ENCODING_SCHEME).toString() + + "&" + VisualizationFrameworkConstants.RENDER_MODE_URL_HANDLE + + "=" + URLEncoder.encode(VisualizationFrameworkConstants.DATA_RENDER_MODE_URL_VALUE, + VisualizationController.URL_ENCODING_SCHEME).toString(); + downloadFileCode = "Download data as .csv file.
"; + + valueObjectContainer.setDownloadDataLink(downloadURL); } else { downloadFileCode = "No data available to export.
"; - + valueObjectContainer.setDownloadDataLink("#"); } - divContextCode.append("

" + generateDataTable() + + String tableCode = generateDataTable(); + + divContextCode.append("

" + tableCode + downloadFileCode + "

"); + + valueObjectContainer.setTable(tableCode); } catch (UnsupportedEncodingException e) { e.printStackTrace(); @@ -373,22 +445,27 @@ public class VisualizationCodeGenerator { String fullTimelineLink; if (yearToPublicationCount.size() > 0) { - fullTimelineLink = "View full timeline and network.
"; + String fullTimelineNetworkURL = uri.toString() + "?" + + VisualizationFrameworkConstants.INDIVIDUAL_URI_URL_HANDLE + + "=" + URLEncoder.encode(individualURI, + VisualizationController.URL_ENCODING_SCHEME).toString() + + "&" + + "vis" + + "=" + URLEncoder.encode(VisualizationController + .PERSON_PUBLICATION_COUNT_VIS_URL_VALUE, + VisualizationController.URL_ENCODING_SCHEME).toString() + + "&" + + VisualizationFrameworkConstants.RENDER_MODE_URL_HANDLE + + "=" + URLEncoder.encode(VisualizationFrameworkConstants.STANDALONE_RENDER_MODE_URL_VALUE, + VisualizationController.URL_ENCODING_SCHEME).toString(); + fullTimelineLink = "View full timeline and network.
"; + + valueObjectContainer.setFullTimelineNetworkLink(fullTimelineNetworkURL); + } else { + fullTimelineLink = "No data available to render full timeline.
"; + valueObjectContainer.setFullTimelineNetworkLink("#"); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/VisualizationRequestHandler.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/VisualizationRequestHandler.java index a470b1a44..b9df2417b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/VisualizationRequestHandler.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/visualization/personpubcount/VisualizationRequestHandler.java @@ -109,26 +109,28 @@ public class VisualizationRequestHandler { * Computations required to generate HTML for the sparklines & related context. * */ - /* - * This is required because when deciding the range of years over which the vis - * was rendered we dont want to be influenced by the "DEFAULT_PUBLICATION_YEAR". - * */ - Set publishedYears = new HashSet(yearToPublicationCount.keySet()); - publishedYears.remove(VOConstants.DEFAULT_PUBLICATION_YEAR); + VisVOContainer valueObjectContainer = new VisVOContainer(); VisualizationCodeGenerator visualizationCodeGenerator = - new VisualizationCodeGenerator(yearToPublicationCount, log); + new VisualizationCodeGenerator(vitroRequest.getRequestURI(), + individualURIParam, + visMode, + visContainer, + authorDocuments, + yearToPublicationCount, + valueObjectContainer, + log); - String visContentCode = visualizationCodeGenerator - .getMainVisualizationCode(authorDocuments, - publishedYears, - visMode, - visContainer); + + String visContentCode = valueObjectContainer.getSparklineContent(); - String visContextCode = visualizationCodeGenerator - .getVisualizationContextCode(vitroRequest.getRequestURI(), - individualURIParam, - visMode); + String visContextCode = valueObjectContainer.getSparklineContext(); + + System.out.println("ft url - " + valueObjectContainer.getFullTimelineNetworkLink()); + System.out.println("dnld fl - " + valueObjectContainer.getDownloadDataLink()); + System.out.println("table - " + valueObjectContainer.getTable()); + System.out.println("min - " + valueObjectContainer.getEarliestRenderedPublicationYear()); + System.out.println("max - " + valueObjectContainer.getLatestRenderedPublicationYear()); /* diff --git a/webapp/web/js/visualization/coauthorship/co_authorship.js b/webapp/web/js/visualization/coauthorship/co_authorship.js index e3f9b3ebe..2fea4016f 100644 --- a/webapp/web/js/visualization/coauthorship/co_authorship.js +++ b/webapp/web/js/visualization/coauthorship/co_authorship.js @@ -30,7 +30,6 @@ function getWellFormedURLs(given_uri, type) { dataType: "text", async: false, success:function(data){ - console.log("PROF - " + data); } }).responseText; @@ -44,33 +43,123 @@ function getWellFormedURLs(given_uri, type) { dataType: "text", async: false, success:function(data){ - console.log("IMAGE - " + data); } }).responseText; - return contextPath + finalURL; -// return finalURL; + return finalURL; + + } else if (type == "profile_info") { + + var profileInfoJSON = $.ajax({ + url: contextPath + "/admin/visQuery", + data: ({vis: "utilities", vis_mode: "PROFILE_INFO", uri: given_uri}), + dataType: "json", + async: false, + success:function(data){ + } + }).responseText; + + return profileInfoJSON; } - + // }); - } $.fn.image = function(src, successFunc, failureFunc){ return this.each(function(){ - var i = new Image(); - i.src = src; - i.onerror = failureFunc; - i.onload = successFunc; - - // console.dir(i); - // this.appendChild(i); - - return i; + var profileImage = new Image(); + profileImage.src = src; + profileImage.width = 150; + profileImage.onerror = failureFunc; + profileImage.onload = successFunc; + + + return profileImage; }); } +function setProfileImage(imageContainerID, rawPath, contextPath) { + + if (imageContainerID == "") { + return; + } + + + var imageLink = contextPath + rawPath; + + var imageContainer = $("#" + imageContainerID); + imageContainer.image(imageLink, + function(){ + imageContainer.empty().append(this); + }, + function(){ + //For performing any action on failure to + //find the image. + imageContainer.empty(); + } + ); + +} + +function setProfileMoniker(monikerContainerID, moniker) { + + if (monikerContainerID == "") { + return; + } + + $("#" + monikerContainerID).empty().text(moniker); + +} + +function setProfileName(nameContainerID, name) { + + if (nameContainerID == "") { + return; + } + + $("#" + nameContainerID).empty().text(name); + + +} + +function processProfileInformation(nameContainerID, + monikerContainerID, + imageContainerID, + profileInfoJSON) { + + + var name, imageRawPath, imageContextPath, moniker; + + $.each(profileInfoJSON, function(key, set){ + + if (key.search(/imageThumb/i) > -1) { + + imageRawPath = set[0]; + + } else if (key.search(/imageContextPath/i) > -1) { + + imageContextPath = set[0]; + + } else if (key.search(/moniker/i) > -1) { + + moniker = set[0]; + + } else if (key.search(/label/i) > -1) { + + name = set[0]; + + } + + }); + + setProfileName(nameContainerID, name); + setProfileMoniker(monikerContainerID, moniker); + setProfileImage(imageContainerID, imageRawPath, imageContextPath); + +} + + function nodeClickedJS(obj){ @@ -84,28 +173,17 @@ function nodeClickedJS(obj){ if(obj[7]){ $("#profileUrl").attr("href", getWellFormedURLs(obj[7], "profile")); $("#coAuthorshipVisUrl").attr("href", getWellFormedURLs(obj[7], "coauthorship")); - var imageLink = getWellFormedURLs(obj[7], "image"); + processProfileInformation("", + "profileMoniker", + "profileImage", + jQuery.parseJSON(getWellFormedURLs(obj[7], "profile_info"))); } else{ $("#profileUrl").attr("href","#"); $("#coAuthorshipVisUrl").attr("href","#"); } - var imageContainer = $("#profileImage"); - imageContainer.image(imageLink, - function(){ - imageContainer.append(this); - }, - function(){ - /* - * For performing any action on failure to - * find the image. - */ - } - ); - - - $("#coAuthorName").empty().append(obj[name]); + $("#coAuthorName").empty().append(obj[0]); $("#coAuthors").empty().append(obj[5]); $("#firstPublication").empty().append((obj[3])?obj[3]+" First Publication":""); @@ -115,7 +193,27 @@ function nodeClickedJS(obj){ } -function renderVisualization() { +function renderSparklineVisualization(visualizationURL) { + + $(document).ready(function() { + + //$("#ego_sparkline").empty().html(''); + + $.ajax({ + url: visualizationURL, + dataType: "html", + success:function(data){ + $("#ego_sparkline").html(data); + + } + }); + + + }); + +} + +function renderCoAuthorshipVisualization() { //Version check for the Flash Player that has the ability to start Player //Product Install (6.0r65) diff --git a/webapp/web/templates/visualization/co_authorship.jsp b/webapp/web/templates/visualization/co_authorship.jsp index d6e036944..5b2b8dd8d 100644 --- a/webapp/web/templates/visualization/co_authorship.jsp +++ b/webapp/web/templates/visualization/co_authorship.jsp @@ -1,6 +1,7 @@ <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> + @@ -16,17 +17,23 @@ + + + + + + + + + - - - - - + + + + + + + @@ -62,20 +69,66 @@ var contextPath = "${contextPath}"; + - + + -
-

Co-Author Network

-
+ + +<%-- Label --%> +
+
+ +
+
+ +<%-- Moniker--%> +
+
+
+ +
+
+
+ +<%-- Image --%> +
+
+
+
+
+
+ +<%-- Sparkline --%> +
+
+
+ + ${requestScope.egoURIParam} + +
+
+
+ +

@@ -84,7 +137,7 @@ var contextPath = "${contextPath}"; @@ -104,9 +157,7 @@ renderVisualization(); -

-
+ +Download co-authorship newtwork as .graphml file. +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Publications per year
YearPublications
20044
20052
11
Unknown1
+ +Download data as .csv file. + + + + + + + + + + + + + + + + + + + + + + + + + + +
Co - Authorhips
NamePublications
20044
20052
11
Unknown1
+ + + + -