-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/reservoir history chart #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
josemi1189
wants to merge
10
commits into
main
Choose a base branch
from
feature/reservoir-history-chart
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
724c8e6
add the average monthly storage over the last 10 years for each reser…
josemi1189 18c5408
feat: add initial version of reservoir history chart
josemi1189 c07e4f0
fix percentage calculation (max capacity) and style component
josemi1189 e4941aa
feat: implement chart layout with temporary values
josemi1189 5e287d2
refactor chart history component and add current value and average la…
josemi1189 5dea118
refactor: optimize database queries and fix minor bugs
josemi1189 9ea5195
refactor(ui): improve styles and adjust chart layout for responsive s…
josemi1189 5de8023
fix: fetch real reservoir data and limit current percentage to 100%
josemi1189 f35db10
fix: refactor historical gauge code and add unit tests
josemi1189 84a777b
feat: add console runner to fetch and store historical data
josemi1189 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import React from "react"; | ||
| import { monthsNames } from "./chart.constants"; | ||
| import { ReferenceLine } from "./chart.helpers"; | ||
|
|
||
| interface Props { | ||
| currentLevel: number; | ||
| monthOneYearAgo: number; | ||
| yearOneYearAgo: number; | ||
| averageOneYearAgo: number; | ||
| monthTenYearsAgo: number; | ||
| yearTenYearsAgo: number; | ||
| averageTenYearsAgo: number; | ||
| } | ||
| export const ChartLegend: React.FC<Props> = (props) => { | ||
| const { | ||
| currentLevel, | ||
| monthOneYearAgo, | ||
| yearOneYearAgo, | ||
| averageOneYearAgo, | ||
| monthTenYearsAgo, | ||
| yearTenYearsAgo, | ||
| averageTenYearsAgo, | ||
| } = props; | ||
|
|
||
| return ( | ||
| <div className="flex w-full flex-col items-start pt-1"> | ||
| <div className="flex h-8 flex-row items-center gap-2"> | ||
| <div className="h-2 w-9.5 rounded-t-sm bg-(--color-primary)"></div> | ||
| <div> | ||
| <span className="text-base-content text-base">Embalsada:</span> | ||
| <span className="pl-1">{currentLevel} Hm³</span> | ||
| </div> | ||
| </div> | ||
| {averageOneYearAgo && ( | ||
| <div className="flex h-8 flex-row items-center gap-2"> | ||
| <div className="mx-auto h-0.5 w-10 border-t-4 border-dashed border-(--line-average-last-year)" /> | ||
| <div> | ||
| <span> | ||
| {monthsNames[monthOneYearAgo - 1]} de {yearOneYearAgo}: | ||
| </span> | ||
| <span className="pl-1">{averageOneYearAgo} Hm³</span> | ||
| </div> | ||
| </div> | ||
| )} | ||
| {averageTenYearsAgo && ( | ||
| <div className="flex h-8 flex-row items-center gap-2"> | ||
| <div className="mx-auto h-0.5 w-10 border-t-4 border-dotted border-(--line-average-last-ten-years)" /> | ||
| <div> | ||
| <span> | ||
| {monthsNames[monthTenYearsAgo - 1]} de {yearTenYearsAgo}: | ||
| </span> | ||
| <span className="pl-1">{averageTenYearsAgo} Hm³</span> | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
23 changes: 23 additions & 0 deletions
23
front/src/pods/embalse/components/chart/chart.constants.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Declare the chart dimensions and margins. | ||
|
|
||
| export const sizeChart = { | ||
| width: 200, | ||
| height: 180, | ||
| margin: { top: 0, right: 30, bottom: 0, left: 30 }, | ||
| radius: 10, | ||
| }; | ||
|
|
||
| export const monthsNames = [ | ||
| "Enero", | ||
| "Febrero", | ||
| "Marzo", | ||
| "Abril", | ||
| "Mayo", | ||
| "Junio", | ||
| "Julio", | ||
| "Agosto", | ||
| "Septiembre", | ||
| "Octubre", | ||
| "Noviembre", | ||
| "Diciembre", | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import React from "react"; | ||
| import { sizeChart as s } from "./chart.constants"; | ||
|
|
||
| interface barRoundedTopProps { | ||
| x: number; | ||
| y: number; | ||
| width: number; | ||
| height: number; | ||
| fill: string; | ||
| } | ||
| export const BarRoundedTop: React.FC<barRoundedTopProps> = ({ | ||
| x, | ||
| y, | ||
| width, | ||
| height, | ||
| fill, | ||
| }): React.ReactNode => { | ||
| return ( | ||
| <g fill={fill}> | ||
| {/* Barra según porcentaje con esquinas redondeadas */} | ||
| <rect x={x} y={y} width={width} height={height} rx={s.radius} /> | ||
| {/* Barra inferior sin redondeo para aplanar la base */} | ||
| <rect x={x} y={y + height / 2} width={width} height={height / 2} /> | ||
| </g> | ||
| ); | ||
| }; | ||
|
|
||
| export const ReferenceLine: React.FC<{ | ||
| yPos: number; | ||
| x1: number; | ||
| x2: number; | ||
| stroke: string; | ||
| dashArray: string; | ||
| }> = ({ yPos, x1, x2, stroke, dashArray }) => ( | ||
| <line | ||
| y1={yPos} | ||
| y2={yPos} | ||
| x1={x1} | ||
| x2={x2} | ||
| stroke={stroke} | ||
| strokeWidth={5} | ||
| strokeDasharray={dashArray} | ||
| /> | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { | ||
| DataLastYearModel, | ||
| HistoricalAverageReservoir, | ||
| } from "@/pods/embalse/embalse.vm"; | ||
|
|
||
| export interface ChartModel { | ||
| titleChart?: string; | ||
| reservoirName: string; | ||
| currentLevel: number; | ||
| maxCapacity: number; | ||
| dataOneYearAgo?: DataLastYearModel; | ||
| dataTenYearsAgo?: HistoricalAverageReservoir; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass dataTenYearsAgo dataOneYearAgo instead