Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
fordecyt_2019
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rodrigo Tapia-McClung
fordecyt_2019
Commits
25d53dee
Commit
25d53dee
authored
Jan 22, 2021
by
Rodrigo Tapia-McClung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve line chart creation
parent
4b3219fd
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
207 deletions
+128
-207
cuerpos_charts.js
public/js/cuerpos_charts.js
+91
-167
cuerpos_functions.js
public/js/cuerpos_functions.js
+37
-40
No files found.
public/js/cuerpos_charts.js
View file @
25d53dee
This diff is collapsed.
Click to expand it.
public/js/cuerpos_functions.js
View file @
25d53dee
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
* January 2021
* January 2021
*/
*/
/* globals omnivore, Promise, makeBaseMap, am4core, makeRadialChart */
/* globals omnivore, Promise, makeBaseMap, am4core, makeRadialChart
, makeLineChart
*/
/* exported. userFiles, userDates, timeParse, layerControl, yearList */
/* exported. userFiles, userDates, timeParse, layerControl, yearList */
let
timeParse
,
let
timeParse
,
...
@@ -288,6 +288,10 @@ let barChartData = [],
...
@@ -288,6 +288,10 @@ let barChartData = [],
const
populateMap
=
async
(
mapData
)
=>
{
const
populateMap
=
async
(
mapData
)
=>
{
let
baseUrl
=
new
URL
(
`/data`
,
window
.
location
.
href
).
href
;
let
baseUrl
=
new
URL
(
`/data`
,
window
.
location
.
href
).
href
;
// create sets of unique months and years
yearList
=
[...
new
Set
(
userDates
.
map
(
date
=>
new
Date
(
date
).
getFullYear
()
))];
//let formatter = new Intl.DateTimeFormat('es', { month: 'long' });
// RADIAL CHART
// RADIAL CHART
// get am chart - may need this to update chart on date change
// get am chart - may need this to update chart on date change
//let radialChart = am4core.registry.baseSprites.find(c => c.htmlContainer.id === "radial_chart");
//let radialChart = am4core.registry.baseSprites.find(c => c.htmlContainer.id === "radial_chart");
...
@@ -297,20 +301,15 @@ const populateMap = async(mapData) => {
...
@@ -297,20 +301,15 @@ const populateMap = async(mapData) => {
//let query = `${baseUrl}/query/${mes}?columns=sum(areacpo)/10000 value1,sum(perimcpo) value2, sum(dimfrcpo) value3`;
//let query = `${baseUrl}/query/${mes}?columns=sum(areacpo)/10000 value1,sum(perimcpo) value2, sum(dimfrcpo) value3`;
let
query
=
`
${
baseUrl
}
/query/
${
mes
}
?columns=sum(areacpo)/10000 area`
;
let
query
=
`
${
baseUrl
}
/query/
${
mes
}
?columns=sum(areacpo)/10000 area`
;
const
queryData
=
await
d3
.
json
(
query
);
const
queryData
=
await
d3
.
json
(
query
);
queryData
[
0
].
date
=
new
Date
(
userDates
[
i
])
queryData
[
0
].
date
=
new
Date
(
userDates
[
i
])
;
return
new
Promise
(
resolve
=>
{
return
new
Promise
(
resolve
=>
{
resolve
(
queryData
[
0
]);
resolve
(
queryData
[
0
]);
});
});
});
});
// wait for all queries to complete and then set chart data
// wait for all queries to complete and then set chart data
Promise
.
all
(
queries
).
then
(
data
=>
{
Promise
.
all
(
queries
).
then
(
data
=>
{
// create sets of unique months and years
yearList
=
[...
new
Set
(
userDates
.
map
(
date
=>
new
Date
(
date
).
getFullYear
()
))];
//let formatter = new Intl.DateTimeFormat('es', { month: 'long' });
// TODO: maybe make this a function so it can be used to update chart when changing dates
// TODO: maybe make this a function so it can be used to update chart when changing dates
let
chart
a
Data
=
[];
let
chartData
=
[];
monthArray
.
forEach
(
(
month
,
index
)
=>
{
monthArray
.
forEach
(
(
month
,
index
)
=>
{
let
element
=
{};
let
element
=
{};
yearList
.
forEach
(
year
=>
{
yearList
.
forEach
(
year
=>
{
...
@@ -319,51 +318,49 @@ const populateMap = async(mapData) => {
...
@@ -319,51 +318,49 @@ const populateMap = async(mapData) => {
let
yearData
=
data
.
filter
(
d
=>
new
Date
(
d
.
date
).
getMonth
()
==
index
&&
new
Date
(
d
.
date
).
getFullYear
()
==
year
);
let
yearData
=
data
.
filter
(
d
=>
new
Date
(
d
.
date
).
getMonth
()
==
index
&&
new
Date
(
d
.
date
).
getFullYear
()
==
year
);
element
[
year
]
=
yearData
.
length
>
0
?
yearData
[
0
].
area
:
null
;
element
[
year
]
=
yearData
.
length
>
0
?
yearData
[
0
].
area
:
null
;
});
});
chart
a
Data
.
push
(
element
);
chartData
.
push
(
element
);
});
});
makeRadialChart
(
chart
a
Data
,
monthArray
,
yearList
);
makeRadialChart
(
chartData
,
monthArray
,
yearList
);
});
});
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
LINE CHART
//LINE CHART
let
data_ls
=
[];
// get am chart - may need this to update chart on date change
let
linesChart
=
am4core
.
registry
.
baseSprites
.
find
(
c
=>
c
.
htmlContainer
.
id
===
"linesChart"
);
//
let linesChart = am4core.registry.baseSprites.find(c => c.htmlContainer.id === "linesChart");
// async queries for each date that has been loaded
// async queries for each date that has been loaded
const
queries_ls
=
userFiles
.
map
(
async
(
mes
,
i
)
=>
{
const
queries_ls
=
userFiles
.
map
(
async
(
mes
,
i
)
=>
{
let
query
=
`
${
baseUrl
}
/query/
${
mes
}
?columns=sum(areacpo)/10000 area, descrip&group=descrip`
;
let
query
=
`
${
baseUrl
}
/query/
${
mes
}
?columns=sum(areacpo)/10000 area, descrip&group=descrip`
;
const
queryData
=
await
d3
.
json
(
query
);
const
queryData
=
await
d3
.
json
(
query
);
let
date
=
new
Date
(
dateArray
[
i
]);
//date.setFullYear(2016)
for
(
const
wbody
in
queryData
)
{
for
(
const
wbody
in
queryData
)
{
queryData
[
wbody
].
date
=
date
;
queryData
[
wbody
].
date
=
new
Date
(
userDates
[
i
])
;
}
}
data_ls
.
push
(
queryData
);
return
new
Promise
(
resolve
=>
{
resolve
(
queryData
);
});
});
});
// wait for all queries to complete
// wait for all queries to complete and then set chart data
const
dataQueries_ls
=
await
Promise
.
all
(
queries_ls
);
Promise
.
all
(
queries_ls
).
then
(
data
=>
{
// and then set chart data
// TODO: maybe make this a function so it can be used to update chart when changing dates
//lineStackedChart.data = data_ls;
let
merged
=
[].
concat
.
apply
([],
data
);
var
merged
=
[].
concat
.
apply
([],
data_ls
);
let
aguaPermanente
=
merged
.
filter
(
d
=>
d
.
descrip
==
"Agua permanente"
);
//console.log(merged);
let
aguaTemporal
=
merged
.
filter
(
d
=>
d
.
descrip
==
"Áreas temporalmente inundadas"
);
let
aguaVegetacion
=
merged
.
filter
(
d
=>
d
.
descrip
==
"Suelos húmedos-vegetación acuática"
);
let
aguaPermanente
=
merged
.
filter
(
function
(
d
)
{
return
d
.
descrip
==
"Agua permanente"
});
let
aguaTemporal
=
merged
.
filter
(
function
(
d
)
{
return
d
.
descrip
==
"Áreas temporalmente inundadas"
});
let
chartData
=
[];
let
aguaVegetacion
=
merged
.
filter
(
function
(
d
)
{
return
d
.
descrip
==
"Suelos húmedos-vegetación acuática"
});
aguaPermanente
.
forEach
(
(
wb
,
i
)
=>
{
let
element
=
{
let
i
;
permanente
:
aguaPermanente
[
i
].
area
,
for
(
i
=
0
;
i
<
aguaPermanente
.
length
;
i
++
)
{
temporal
:
aguaTemporal
[
i
].
area
,
aguaPermanente
[
i
].
permanente
=
aguaPermanente
[
i
].
area
;
vegetacion
:
aguaVegetacion
[
i
].
area
,
aguaPermanente
[
i
].
temporal
=
aguaTemporal
[
i
].
area
;
date
:
aguaPermanente
[
i
].
date
aguaPermanente
[
i
].
vegetacion
=
aguaVegetacion
[
i
].
area
;
}
chartData
.
push
(
element
);
delete
aguaPermanente
[
i
].
descrip
;
});
delete
aguaPermanente
[
i
].
area
;
}
let
grijalva_bodies
=
aguaPermanente
;
chartData
.
sort
((
a
,
b
)
=>
(
a
.
date
>
b
.
date
)
?
1
:
-
1
)
;
grijalva_bodies
.
sort
((
a
,
b
)
=>
(
a
.
date
>
b
.
date
)
?
1
:
-
1
);
makeLineChart
(
chartData
);
linesChart
.
data
=
grijalva_bodies
;
})
;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ STACKED AREAS CHART
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ STACKED AREAS CHART
let
data_sa
=
[];
let
data_sa
=
[];
let
stackedAreaChart
=
am4core
.
registry
.
baseSprites
.
find
(
c
=>
c
.
htmlContainer
.
id
===
"stackedAreaChart"
);
let
stackedAreaChart
=
am4core
.
registry
.
baseSprites
.
find
(
c
=>
c
.
htmlContainer
.
id
===
"stackedAreaChart"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment