Skip to content

Commit

Permalink
Merge pull request #397 from SchmidtDSE/main
Browse files Browse the repository at this point in the history
Fast forward deploy
  • Loading branch information
sampottinger authored Aug 31, 2024
2 parents b986c31 + d9a3a41 commit 88249d9
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 72 deletions.
23 changes: 17 additions & 6 deletions image_gen/plastics_sankey/const.pde
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
final float COLUMN_BODY_WIDTH = 200;
final float COLUMN_BODY_WIDTH = 170;

final boolean SHOW_WARNING_TEXT = false;

Expand All @@ -9,6 +9,7 @@ Map<String, Integer> CONNECT_COLORS;
Map<String, Integer> FONT_COLORS;

Map<String, String> STRINGS;
Map<String, Float> VAL_OVERRIDES;

Pattern LONGITUDINAL_PATTERN = Pattern.compile("^[A-Za-z]+20[0-9]+$");

Expand Down Expand Up @@ -76,10 +77,10 @@ void loadSemiconstants() {
FONT_COLORS.put("Textile", #FFFFFF);
FONT_COLORS.put("Other", #FFFFFF);

HEADER_FONT = loadFont("Lato-Medium-20.vlw");
SUBHEADER_FONT = loadFont("Lato-Medium-15.vlw");
BODY_FONT = loadFont("Lato-Medium-13.vlw");
DETAIL_FONT = loadFont("Lato-Medium-11.vlw");
HEADER_FONT = loadFont("PublicSans-Regular-20.vlw");
SUBHEADER_FONT = loadFont("PublicSans-Regular-20.vlw");
BODY_FONT = loadFont("PublicSans-Regular-18.vlw");
DETAIL_FONT = loadFont("PublicSans-Regular-15.vlw");

STRINGS = new HashMap<>();
STRINGS.put("china", "China");
Expand All @@ -106,9 +107,19 @@ void loadSemiconstants() {
STRINGS.put("taxVirgin", "Packaging consumption tax");
STRINGS.put("minimumRecyclingRate", "40% recycled rate");
STRINGS.put("banSingleUse", "Ban single use");
STRINGS.put("capVirgin", "Cap virgin to 2025");
STRINGS.put("capVirgin", "Cap virgin to 2020");
STRINGS.put("recyclingInvestment", "$100B recycling invest");
STRINGS.put("minimumRecycledContent", "40% recycled content");
STRINGS.put("minimumPackagingReuse", "80% packaging reuse");
STRINGS.put("wasteInvestment", "$50B waste invest");

VAL_OVERRIDES = new HashMap<>();
VAL_OVERRIDES.put("minimumRecycledContent", 8.0);
VAL_OVERRIDES.put("wasteInvestment", 7.0);
VAL_OVERRIDES.put("capVirgin", 6.0);
VAL_OVERRIDES.put("recyclingInvestment", 5.0);
VAL_OVERRIDES.put("minimumRecyclingRate", 4.0);
VAL_OVERRIDES.put("taxVirgin", 3.0);
VAL_OVERRIDES.put("banSingleUse", 2.0);
VAL_OVERRIDES.put("minimumPackagingReuse", 1.0);
}
Binary file removed image_gen/plastics_sankey/data/Lato-Medium-11.vlw
Binary file not shown.
Binary file removed image_gen/plastics_sankey/data/Lato-Medium-13.vlw
Binary file not shown.
Binary file removed image_gen/plastics_sankey/data/Lato-Medium-15.vlw
Binary file not shown.
Binary file removed image_gen/plastics_sankey/data/Lato-Medium-20.vlw
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
69 changes: 36 additions & 33 deletions image_gen/plastics_sankey/draw.pde
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void drawUnsafe() {

drawAxis();
drawSubheaders();
drawHeader();
//drawHeader();
drawCaption();

popStyle();
Expand Down Expand Up @@ -54,42 +54,45 @@ void drawStage(String column, Stage stage, ColorGetter colorGetter, boolean thin
textAlign(thin ? LEFT : CENTER, CENTER);
fill(FONT_COLORS.getOrDefault(groupName, #333333));

String roundedStr = "" + round(stage.get(groupName));

if (thin) {
textFont(BODY_FONT);
text(STRINGS.getOrDefault(groupName, groupName), thin ? 12 : COLUMN_BODY_WIDTH / 2, midY - 7);
text(STRINGS.getOrDefault(groupName, groupName), thin ? 12 : COLUMN_BODY_WIDTH / 2, midY - 12);

textFont(DETAIL_FONT);
text(nfc(stage.get(groupName), 1) + " Mt Plastic", thin ? 12 : COLUMN_BODY_WIDTH / 2, midY + 7);
text(roundedStr + " Mt Plastic", thin ? 12 : COLUMN_BODY_WIDTH / 2, midY + 6);
} else if (barHeight < 25) {
textFont(BODY_FONT);
text(STRINGS.getOrDefault(groupName, groupName), thin ? 12 : COLUMN_BODY_WIDTH / 2, midY);
textFont(DETAIL_FONT);
text(STRINGS.getOrDefault(groupName, groupName) + ": " + roundedStr + " Mt", thin ? 12 : COLUMN_BODY_WIDTH / 2, midY);
} else {
textFont(BODY_FONT);
text(STRINGS.getOrDefault(groupName, groupName), thin ? 12 : COLUMN_BODY_WIDTH / 2, midY - 7);
text(STRINGS.getOrDefault(groupName, groupName), thin ? 12 : COLUMN_BODY_WIDTH / 2, midY - 10);

textFont(DETAIL_FONT);
text(nfc(stage.get(groupName), 1) + " Mt", thin ? 12 : COLUMN_BODY_WIDTH / 2, midY + 7);
text(roundedStr + " Mt", thin ? 12 : COLUMN_BODY_WIDTH / 2, midY + 12);
}

if (thin) {
if (thin) {
float ghgDelta = stage.getGhgDelta(groupName);
String ghgValueStr = (ghgDelta > 0 ? "+" : "") + nfc(ghgDelta, 1) + " Megaton CO2e";
String ghgStr = "" + round(ghgDelta / 10) * 10;
String ghgValueStr = (ghgDelta > 0 ? "+" : "") + ghgStr + " Mt CO2e";

fill(#757575);
textFont(DETAIL_FONT);
text(ghgValueStr, thin ? 12 : COLUMN_BODY_WIDTH / 2, midY + 20);
text(ghgValueStr, thin ? 12 : COLUMN_BODY_WIDTH / 2, midY + 22);

noFill();
stroke(#757575);
strokeWeight(2);
float startX = map(0, -400, 400, 12, COLUMN_BODY_WIDTH - 24);
line(startX, midY + 29, startX, midY + 36);
float startX = map(0, -400, 400, 12, COLUMN_BODY_WIDTH - 10);
line(startX, midY + 30, startX, midY + 39);

rectMode(CORNERS);
noStroke();
fill(#757575);
float endX = map(ghgDelta, -400, 400, 12, COLUMN_BODY_WIDTH - 24);
rect(startX, midY + 30, endX, midY + 35);
float endX = map(ghgDelta, -400, 400, 12, COLUMN_BODY_WIDTH - 10);
rect(startX, midY + 32, endX, midY + 37);
}
});

Expand Down Expand Up @@ -129,8 +132,8 @@ void drawRegions(String column, Map<String, Region> regions) {
text(STRINGS.get(regionName), COLUMN_BODY_WIDTH / 2, midY - 13);

textFont(DETAIL_FONT);
text(nfc(region.getConsumption(), 1) + " Mt consumption", COLUMN_BODY_WIDTH / 2, midY + 1);
text(nfc(region.getWaste(), 1) + " Mt waste", COLUMN_BODY_WIDTH / 2, midY + 14);
text(round(region.getConsumption()) + " Mt consumption", COLUMN_BODY_WIDTH / 2, midY + 4);
text(round(region.getWaste()) + " Mt waste", COLUMN_BODY_WIDTH / 2, midY + 21);

for (String sector : SECTORS) {
fill(FILL_COLORS.get(sector));
Expand Down Expand Up @@ -259,23 +262,23 @@ void drawSubheaders() {

textAlign(CENTER, CENTER);
text(
"Consumption",
"(A) Consumption",
(layoutManager.getXStart("consumption") + layoutManager.getXEnd("consumption")) / 2,
52
22
);
text(
"Regions",
"(B) Regions",
(layoutManager.getXStart("regions") + layoutManager.getXEnd("regions")) / 2,
52
22
);
text(
"End of Life",
"(C) End of Life",
(layoutManager.getXStart("waste") + layoutManager.getXEnd("waste")) / 2,
52
22
);

textAlign(LEFT, CENTER);
text("Policy", layoutManager.getXStart("policy") + 12, 52);
text("(D) Policy", layoutManager.getXStart("policy") + 12, 22);

popStyle();
popMatrix();
Expand Down Expand Up @@ -331,37 +334,37 @@ void drawCaption() {
text(
"-400 Mt",
layoutManager.getXStart("policy") + 12,
height - 70
height - 70 - 200
);

textAlign(RIGHT, CENTER);
text(
"+400 Mt",
layoutManager.getXEnd("policy") - 24,
height - 70
layoutManager.getXEnd("policy") - 10,
height - 70 - 200
);

textAlign(CENTER, TOP);
text(
"Plastics GHG Impact",
(layoutManager.getXStart("policy") + layoutManager.getXEnd("policy")) / 2,
height - 60
height - 60 - 200
);

noFill();
stroke(#757575);
strokeWeight(1);
line(
layoutManager.getXStart("policy") + 12,
height - 78,
layoutManager.getXEnd("policy") - 24,
height - 78
height - 78 - 200,
layoutManager.getXEnd("policy") - 10,
height - 78 - 200
);
line(
layoutManager.getXStart("policy") + 12,
height - 62,
layoutManager.getXEnd("policy") - 24,
height - 62
height - 62 - 200,
layoutManager.getXEnd("policy") - 10,
height - 62 - 200
);

popStyle();
Expand Down
26 changes: 14 additions & 12 deletions image_gen/plastics_sankey/model.pde
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,21 @@ List<Record> loadRecords(String csvLoc) {
for (TableRow row : mainTable.rows()) {
String region = row.getString("region");
String scenario = row.getString("scenario");
MutableRecord newRecord = new MutableRecord(region, scenario);

for (String sector : SECTORS) {
float value = row.getFloat("consumption" + sector + "MT");
newRecord.addConsumption(sector, value);
}

for (String fate : EOL_FATES) {
float value = row.getFloat("eol" + fate + "MT");
newRecord.addWaste(fate, value);
if (!scenario.equals("selectPackage")) {
MutableRecord newRecord = new MutableRecord(region, scenario);

for (String sector : SECTORS) {
float value = row.getFloat("consumption" + sector + "MT");
newRecord.addConsumption(sector, value);
}

for (String fate : EOL_FATES) {
float value = row.getFloat("eol" + fate + "MT");
newRecord.addWaste(fate, value);
}

retList.add(newRecord);
}

retList.add(newRecord);
}

return retList;
Expand Down
24 changes: 15 additions & 9 deletions image_gen/plastics_sankey/plastics_sankey.pde
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import java.util.*;
import java.util.regex.*;
import java.util.stream.*;

// import processing.svg.*;

List<Record> rawRecords;
Stage consumptionStage;
Map<String, Region> regions;
Expand All @@ -11,7 +13,8 @@ LayoutManager layoutManager;


void setup() {
size(1700, 900);
// size(1550, 900, SVG, "sankey.svg");
size(1550, 900);
try {
runSketch();
} catch (Exception e) {
Expand All @@ -21,28 +24,31 @@ void setup() {


void draw() {
//runSketch();
exit();
}


void runSketch() {
loadSemiconstants();

String csvLoc;
String outputDirectory;

if (args == null || args.length != 2) {
println("USAGE: processing-java --sketch=plastics_sankey --output=/tmp/sankeybuild --force --run [CSV] [output directory]");
exit();
return;
csvLoc = "scenarios_overview.csv";
outputDirectory = "";
} else {
csvLoc = args[0];
outputDirectory = args[1] + "/";
}

background(#FFFFFF);

String csvLoc = args[0];
String outputDirectory = args[1];

loadState(csvLoc);
drawUnsafe();

save(outputDirectory + "/sankey.png");
save(outputDirectory + "sankey.png");
}


Expand All @@ -53,7 +59,7 @@ void loadState(String csvLoc) {
policyStage = buildPolicyStage(rawRecords);
wasteStage = buildWasteStage(rawRecords, policyStage);

layoutManager = new LayoutManager(60, width - 10, 70, height - 50);
layoutManager = new LayoutManager(60, width - 100, 50, height - 70);
layoutManager.add("consumption", consumptionStage, 2);
layoutManager.add("regions", regions, 2);
layoutManager.add("waste", wasteStage, 2);
Expand Down
13 changes: 13 additions & 0 deletions image_gen/plastics_sankey/struct.pde
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface Stage {
public boolean getIsShadow(String group, String connection);
public float get(String group);
public float get(String group, String connection);
public float get(String group, String connection, boolean allowOverride);
public Stream<String> getGroups();
public Stream<String> getConnections(String group);
public Stream<String> getShadowConnections(String group);
Expand Down Expand Up @@ -50,6 +51,14 @@ class MutableStage implements Stage {
}
return connections.get(group).get(connection);
}

public float get(String group, String connection, boolean allowOverride) {
if (!allowOverride || !VAL_OVERRIDES.containsKey(group)) {
return get(group, connection);
} else {
return VAL_OVERRIDES.get(group);
}
}

public Stream<String> getGroups() {
return totals.keySet()
Expand Down Expand Up @@ -252,6 +261,10 @@ Stage buildPolicyStage(List<Record> records) {
.filter((x) -> !x.getScenario().equals("businessAsUsual"))
.filter((x) -> !x.getScenario().equals("lowAmbition"))
.filter((x) -> !x.getScenario().equals("highAmbition"))
.filter((x) -> !x.getScenario().equals("banPsPackaging"))
.filter((x) -> !x.getScenario().equals("banWasteTrade"))
.filter((x) -> !x.getScenario().equals("reducedAdditives"))
.filter((x) -> !x.getScenario().equals("selectPackage"))
.filter((x) -> !LONGITUDINAL_PATTERN.matcher(x.getScenario()).matches())
.collect(Collectors.toMap(x -> x.getScenario(), x -> totalMismanagedBau - x.getWaste("Mismanaged")));

Expand Down
2 changes: 1 addition & 1 deletion js/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20240623
20240830
Loading

0 comments on commit 88249d9

Please sign in to comment.