Skip to content

Commit

Permalink
Merge pull request #2 from cicirello/add-logo
Browse files Browse the repository at this point in the history
Added Scholar logo to two upper corners
  • Loading branch information
cicirello authored Jun 10, 2022
2 parents fbfa3fc + 4e74e5f commit 2a0b04f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion images/bibliometrics.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion images/bibliometrics2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 13 additions & 4 deletions src/bibliometrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
{9}
{10}
{11}
{12}
{13}
</g></g></svg>
"""

Expand All @@ -57,23 +59,28 @@

urlTemplate = "https://scholar.google.com/citations?user={0}&pagesize=100"

scholarLogoTemplate = """
<svg x="{0}" y="{1}" width="{2}" height="{2}" viewBox="0 0 512 512"><path fill="#4285f4" d="M256 411.12L0 202.667 256 0z"/><path fill="#356ac3" d="M256 411.12l256-208.453L256 0z"/><circle fill="#a0c3ff" cx="256" cy="362.667" r="149.333"/><path fill="#76a7fa" d="M121.037 298.667c23.968-50.453 75.392-85.334 134.963-85.334s110.995 34.881 134.963 85.334H121.037z"/></svg>
"""

def generateBibliometricsImage(metrics, colors, titleText) :
"""Generates the bibliometrics image as an SVG.
Keyword arguments:
metrics - dictionary with the stats
colors - dictionary with colors
"""
titleSize = 20
titleSize = 18
titleLineHeight = 2 * titleSize + 1
textSize = 16
textSize = 14
smallSize = 12
margin = 15
scale = round(0.75 * titleSize / 110, 3)
stroke = 4
radius = 6
lineHeight = round(textSize * 1.5)
drop = round(textSize * 12.5 / 14, 1)
scholarLogoDimensions = 32

stats = [
("Total citations", "total"),
Expand All @@ -88,7 +95,7 @@ def generateBibliometricsImage(metrics, colors, titleText) :
lastUpdatedLength = calculateTextLength(lastUpdatedText, smallSize, True, 600)

titleLength = round(calculateTextLength110Weighted(titleText, 600))
minWidth = calculateTextLength(titleText, titleSize, True, 600) + 2*margin
minWidth = calculateTextLength(titleText, titleSize, True, 600) + 4*margin + 2*scholarLogoDimensions
minWidth = max(minWidth, lastUpdatedLength + 2*margin)
for label, key in stats :
minWidth = max(minWidth, 2 * calculateTextLength(label, textSize, True, 600) + 2*margin)
Expand Down Expand Up @@ -156,7 +163,9 @@ def generateBibliometricsImage(metrics, colors, titleText) :
colors["background"], #8
title, #9
''.join(formattedStats), #10
lastUpdated #11
lastUpdated, #11
scholarLogoTemplate.format(margin, margin, scholarLogoDimensions), #12
scholarLogoTemplate.format(minWidth - margin - scholarLogoDimensions, margin, scholarLogoDimensions) #13
)
return image.replace("\n", "")

Expand Down
16 changes: 14 additions & 2 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

class TestBibiometrics(unittest.TestCase) :

# To have tests output to standard out a sample image,
# To have tests generate sample images (to files),
# change this to True.
printSampleImage = False

Expand Down Expand Up @@ -67,5 +67,17 @@ def test_generate_image(self) :
colors,
"Bibliometrics"
)
colors2 = {
"background": "#f6f0bb",
"border": "#862d2d",
"text": "#305030",
"title": "#862d2d"
}
image2 = bib.generateBibliometricsImage(
metrics,
colors2,
"Bibliometrics"
)
if TestBibiometrics.printSampleImage :
print(image)
bib.outputImage(image, "images/bibliometrics2.svg")
bib.outputImage(image2, "images/bibliometrics.svg")

0 comments on commit 2a0b04f

Please sign in to comment.