From 58027077dd89fa852311fdba1fec3313476732a3 Mon Sep 17 00:00:00 2001 From: Jesse Kaczmarski Date: Fri, 19 Apr 2024 14:08:15 -0800 Subject: [PATCH] Tooltip improvements. Fixes #53 --- capacity.qmd | 17 +++++++++-------- consumption.qmd | 28 ++++++++++++++-------------- generation.qmd | 30 +++++++++++++++++------------- prices.qmd | 32 ++++++++++++++++---------------- 4 files changed, 56 insertions(+), 51 deletions(-) diff --git a/capacity.qmd b/capacity.qmd index 32fcf90..2a542df 100644 --- a/capacity.qmd +++ b/capacity.qmd @@ -72,7 +72,7 @@ Plot.plot({ { x: "year", y: "capacity", - fill: "prime_mover", + fill: "Prime Mover", order: ["Fossil Turbines", "Recip Engines", "Hydro", "Wind","Utility Solar","Rooftop Solar","Storage","Landfill Gas"], tip: {format: {x: "d"}} } @@ -127,7 +127,7 @@ Plot.plot({ { x: "year", y: "capacity", - fill: "prime_mover", + fill: "Prime Mover", order: ["Fossil Turbines", "Recip Engines", "Hydro", "Wind","Storage"], tip: {format: {x: "d"}} } @@ -178,7 +178,7 @@ Plot.plot({ { x: "year", y: "capacity", - fill: "prime_mover", + fill: "Prime Mover", order: ["Hydro", "Wind","Storage"], tip: {format: {x: "d"}} } @@ -232,7 +232,7 @@ Plot.plot({ { x: "year", y: "capacity", - fill: "prime_mover", + fill: "Prime Mover", order: ["Fossil Turbines", "Recip Engines", "Hydro", "Wind","Utility Solar","Rooftop Solar","Storage","Landfill Gas"], tip: {format: {x: "d"}} } @@ -283,7 +283,7 @@ Plot.plot({ { x: "year", y: "capacity", - fill: "prime_mover", + fill: "Prime Mover", order: ["Hydro", "Wind","Utility Solar","Rooftop Solar","Storage","Landfill Gas"], tip: {format: {x: "d"}} } @@ -335,7 +335,7 @@ Plot.plot({ { x: "year", y: "capacity", - fill: "prime_mover", + fill: "Prime Mover", order: ["Fossil Turbines", "Recip Engines", "Hydro", "Wind","Utility Solar","Storage"], tip: {format: {x: "d"}} } @@ -386,7 +386,7 @@ Plot.plot({ { x: "year", y: "capacity", - fill: "prime_mover", + fill: "Prime Mover", order: ["Hydro", "Wind","Utility Solar","Storage"], tip: {format: {x: "d"}} } @@ -405,5 +405,6 @@ Plot.plot({ ```{ojs} -cap_data = FileAttachment("data/working/capacity/capacity_long.csv").csv({ typed: true }) +original_cap_data = FileAttachment("data/working/capacity/capacity_long.csv").csv({ typed: true }) +cap_data = original_cap_data.map((d) => ({...d, "Prime Mover": d.prime_mover})) ``` \ No newline at end of file diff --git a/consumption.qmd b/consumption.qmd index 0e8c8ef..9f3cafb 100644 --- a/consumption.qmd +++ b/consumption.qmd @@ -77,7 +77,7 @@ regional_consumption_data = tidy( customers: sum('customers') }) ]) -) +).map((d) => ({...d, "Customer Class": d.class})).map((d) => ({...d, "ACEP Region": d.acep_region})) // Change in statewide totals statewide_delta = tidy( @@ -104,7 +104,7 @@ statewide_delta = tidy( customers_delta: (d) => (d.customers - d.customers_2011) / d.customers_2011, }), filter((d) => d.year === 2019) -) +).map((d) => ({...d, "Customer Class": d.class})) ``` ```{ojs} @@ -136,8 +136,8 @@ Plot.plot({ Plot.barX(statewide_delta, { x: "sales_delta", - y: "class", - fill: "class", + y: "Customer Class", + fill: "Customer Class", tip: { format: { x: (d) => `${(d).toLocaleString(undefined, {maximumFractionDigits: 2})}%`, @@ -186,8 +186,8 @@ Plot.plot({ Plot.barX(statewide_delta, { x: "customers_delta", - y: "class", - fill: "class", + y: "Customer Class", + fill: "Customer Class", tip: { format: { x: (d) => `${(d).toLocaleString(undefined, {maximumFractionDigits: 2})}%`, @@ -211,7 +211,7 @@ Plot.plot({ ```{ojs} sales_per_capita_data = tidy(regional_consumption_data.filter((d) => d.class === "Residential"), groupBy( - ['acep_region','year'], + ['ACEP Region','year'], [ mutate({ sales_per_capita: (d) => (d.sales / d.customers) * 1000 @@ -253,7 +253,7 @@ Plot.plot({ Plot.line(sales_per_capita_data, { x: "year", y: "sales_per_capita", - stroke: "acep_region", + stroke: "ACEP Region", strokeWidth: 5, tip: {format: {x: "d"}} } @@ -303,7 +303,7 @@ Plot.plot({//| { x: "year", y: "sales", - fill: "class", + fill: "Customer Class", tip: {format: {x: "d"}} } ), @@ -350,7 +350,7 @@ Plot.plot({ { x: "year", y: "customers", - fill: "class", + fill: "Customer Class", tip: {format: {x: "d"}} } ), @@ -399,7 +399,7 @@ Plot.plot({//| { x: "year", y: "sales", - fill: "class", + fill: "Customer Class", tip: {format: {x: "d"}} } ), @@ -446,7 +446,7 @@ Plot.plot({ { x: "year", y: "customers", - fill: "class", + fill: "Customer Class", tip: {format: { x: "d", y: (y) => `${(y).toLocaleString(undefined, {maximumFractionDigits: 2})}` @@ -499,7 +499,7 @@ Plot.plot({ { x: "year", y: "sales", - fill: "class", + fill: "Customer Class", tip: {format: {x: "d"}} } ), @@ -546,7 +546,7 @@ Plot.plot({ { x: "year", y: "customers", - fill: "class", + fill: "Customer Class", tip: {format: { x: "d", y: (y) => `${(y).toLocaleString(undefined, {maximumFractionDigits: 2})}` diff --git a/generation.qmd b/generation.qmd index 928c6b9..8f1e379 100644 --- a/generation.qmd +++ b/generation.qmd @@ -69,7 +69,10 @@ gen_data = FileAttachment("data/working/generation/net_generation_long.csv").csv // Convert MWh to GWh gen_data_gwh = tidy(gen_data, mutate({ generation: (d) => d.generation / 1000 -})); +})).map((d) => ({...d, "Fuel Type": d.fuel_type})).map((d) => ({...d, "ACEP Region": d.acep_region})); + +//gen_data_gwh = gen_data_gwh_.map((d) => ({...d, "ACEP Region": d.acep_region},{...d, "Fuel Type": d.fuel_type})) + ``` ```{ojs} @@ -108,7 +111,7 @@ Plot.plot({ { x: "year", y: "generation", - fill: "acep_region", + fill: "ACEP Region", tip: {format: {x: "d"}} } ) @@ -158,13 +161,13 @@ join = tidy(share_data, fullJoin(total_gen, {by: ['year','acep_region']})) // Creating a column with shares join_shares = tidy(join.filter((d) => d.fuel_type !== "Storage"), mutate({generation_share: (d) => (d.generation / d.total_generation)*100}) -) // join_shares should be used for the 100% area charts +).map((d) => ({...d, "Fuel Type": d.fuel_type})).map((d) => ({...d, "ACEP Region": d.acep_region})) // join_shares should be used for the 100% area charts // Table for just the 2011 and 2021 generation mix comparison gen_mix_diff = tidy( join_shares.filter((d) => d.year === 2011 || d.year === 2021), groupBy( - ['acep_region','fuel_type'], + ['ACEP Region','Fuel Type'], mutateWithSummary({ generation_share_2011: lag('generation_share', {default: 0}) }) @@ -212,13 +215,14 @@ Plot.plot({ Plot.frame(), Plot.barX(gen_mix_diff, { x: "delta", - y: "fuel_type", - fill: "fuel_type", + y: "Fuel Type", + fill: "Fuel Type", order: ["Coal","Oil","Gas","Hydro","Wind","Solar"], tip: { format: { x: (d) => `${(d).toLocaleString(undefined, {maximumFractionDigits: 2})}%`, - y: false + y: false, + fy: false } } } @@ -276,7 +280,7 @@ Plot.plot({ { x:"year", y:"generation_share", - fill: "fuel_type", + fill: "Fuel Type", order: ["Oil","Hydro","Wind"], tip: {format: {x: "d", y: (d) => `${(d).toLocaleString(undefined, {maximumFractionDigits: 2})}%`}} } @@ -331,7 +335,7 @@ Plot.plot({ { x: "year", y: "generation", - fill: "fuel_type", + fill: "Fuel Type", order: ["Oil","Hydro","Wind"], tip: {format: {x: "d"}} } @@ -384,7 +388,7 @@ Plot.plot({//| { x:"year", y:"generation_share", - fill: "fuel_type", + fill: "Fuel Type", order: ["Coal","Oil","Gas","Hydro","Wind","Solar"], tip: {format: {x: "d", y: (d) => `${(d).toLocaleString(undefined, {maximumFractionDigits: 2})}%`}} } @@ -440,7 +444,7 @@ Plot.plot({ { x: "year", y: "generation", - fill: "fuel_type", + fill: "Fuel Type", order: ["Coal","Oil","Gas","Hydro","Wind","Solar"], tip: {format: {x: "d"}} } @@ -494,7 +498,7 @@ Plot.plot({ { x:"year", y:"generation_share", - fill: "fuel_type", + fill: "Fuel Type", order: ["Oil","Gas","Hydro","Wind","Solar","Other"], tip: {format: {x: "d", y: (d) => `${(d).toLocaleString(undefined, {maximumFractionDigits: 2})}%`}} } @@ -549,7 +553,7 @@ Plot.plot({ { x: "year", y: "generation", - fill: "fuel_type", + fill: "Fuel Type", order: ["Oil","Gas","Hydro","Wind","Solar","Other"], tip: {format: {x: "d"}} } diff --git a/prices.qmd b/prices.qmd index 7b8e3af..8ed2140 100644 --- a/prices.qmd +++ b/prices.qmd @@ -42,7 +42,7 @@ region_weighted_prices = tidy(weighted_prices, groupBy(['acep_energy_region', 'year'], [ summarize({ mean_weighted_price: mean('weighted_price')}) ]), - filter((d) => d.year < 2020)) + filter((d) => d.year < 2020)).map((d) => ({...d, "ACEP Region": d.acep_energy_region})) ``` ```{ojs} @@ -77,15 +77,15 @@ Plot.plot({ {x: "year", y: "mean_weighted_price", strokeWidth: 5, - stroke: "acep_energy_region", + stroke: "ACEP Region", tip: {format: {x: "d", stroke: false}} }), Plot.text(region_weighted_prices, Plot.selectLast( {x: "year", y: "mean_weighted_price", - z: "acep_energy_region", - text: "acep_energy_region", + z: "ACEP Region", + text: "ACEP Region", frameAnchor: "bottom", dy: -5, dx: 25 @@ -114,7 +114,7 @@ Residential customers in the Coastal region saw increases in the price of electr coastal_weighted_prices = tidy(weighted_prices, filter((d) => d.acep_energy_region === "Coastal"), filter((d) => d.year < 2020) - ) + ).map((d) => ({...d, "Customer Class": d.sector})) ``` ```{ojs} @@ -150,15 +150,15 @@ Plot.plot({ {x: "year", y: "weighted_price", strokeWidth: 5, - stroke: "sector", + stroke: "Customer Class", tip: {format: {x: "d"}} }), Plot.text(coastal_weighted_prices, Plot.selectLast( {x: "year", y: "weighted_price", - z: "sector", - text: "sector", + z: "Customer Class", + text: "Customer Class", frameAnchor: "bottom", dy: -5, dx: 35 @@ -186,7 +186,7 @@ This region differs significantly from the Coastal and Rural Remote regions in t railbelt_weighted_prices = tidy(weighted_prices, filter((d) => d.acep_energy_region === "Railbelt"), filter((d) => d.year < 2020) - ) + ).map((d) => ({...d, "Customer Class": d.sector})) ``` ```{ojs} @@ -222,15 +222,15 @@ Plot.plot({ {x: "year", y: "weighted_price", strokeWidth: 5, - stroke: "sector", + stroke: "Customer Class", tip: {format: {x: "d"}} }), Plot.text(railbelt_weighted_prices, Plot.selectLast( {x: "year", y: "weighted_price", - z: "sector", - text: "sector", + z: "Customer Class", + text: "Customer Class", frameAnchor: "bottom", dy: -5, dx: 35 @@ -255,7 +255,7 @@ The average price of electricity for the Residential customers in the Rural Remo rural_remote_weighted_prices = tidy(weighted_prices, filter((d) => d.acep_energy_region === "Rural Remote"), filter((d) => d.year < 2020) - ) + ).map((d) => ({...d, "Customer Class": d.sector})) ``` ```{ojs} @@ -291,15 +291,15 @@ Plot.plot({ {x: "year", y: "weighted_price", strokeWidth: 5, - stroke: "sector", + stroke: "Customer Class", tip: {format: {x: "d"}} }), Plot.text(rural_remote_weighted_prices, Plot.selectLast( {x: "year", y: "weighted_price", - z: "sector", - text: "sector", + z: "Customer Class", + text: "Customer Class", frameAnchor: "bottom", dy: -5, dx: 35