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
dc2b749b
Commit
dc2b749b
authored
Jan 26, 2021
by
Rodrigo Tapia-McClung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve area chart creation
parent
25d53dee
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
193 deletions
+91
-193
cuerpos_charts.js
public/js/cuerpos_charts.js
+59
-160
cuerpos_functions.js
public/js/cuerpos_functions.js
+32
-33
No files found.
public/js/cuerpos_charts.js
View file @
dc2b749b
This diff is collapsed.
Click to expand it.
public/js/cuerpos_functions.js
View file @
dc2b749b
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
* January 2021
* January 2021
*/
*/
/* globals omnivore, Promise, makeBaseMap, am4core, makeRadialChart, makeLineChart */
/* globals omnivore, Promise, makeBaseMap, am4core, makeRadialChart, makeLineChart
, makeAreaChart
*/
/* exported. userFiles, userDates, timeParse, layerControl, yearList */
/* exported. userFiles, userDates, timeParse, layerControl, yearList */
let
timeParse
,
let
timeParse
,
...
@@ -323,7 +323,7 @@ const populateMap = async(mapData) => {
...
@@ -323,7 +323,7 @@ const populateMap = async(mapData) => {
makeRadialChart
(
chartData
,
monthArray
,
yearList
);
makeRadialChart
(
chartData
,
monthArray
,
yearList
);
});
});
//LINE CHART
//
LINE 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 linesChart = am4core.registry.baseSprites.find(c => c.htmlContainer.id === "linesChart");
//let linesChart = am4core.registry.baseSprites.find(c => c.htmlContainer.id === "linesChart");
...
@@ -337,7 +337,6 @@ const populateMap = async(mapData) => {
...
@@ -337,7 +337,6 @@ const populateMap = async(mapData) => {
return
new
Promise
(
resolve
=>
{
return
new
Promise
(
resolve
=>
{
resolve
(
queryData
);
resolve
(
queryData
);
});
});
});
});
// 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_ls
).
then
(
data
=>
{
Promise
.
all
(
queries_ls
).
then
(
data
=>
{
...
@@ -361,45 +360,45 @@ const populateMap = async(mapData) => {
...
@@ -361,45 +360,45 @@ const populateMap = async(mapData) => {
chartData
.
sort
((
a
,
b
)
=>
(
a
.
date
>
b
.
date
)
?
1
:
-
1
);
chartData
.
sort
((
a
,
b
)
=>
(
a
.
date
>
b
.
date
)
?
1
:
-
1
);
makeLineChart
(
chartData
);
makeLineChart
(
chartData
);
});
});
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ STACKED AREAS
CHART
//
STACKED AREA
CHART
let
data_sa
=
[];
// get am chart - may need this to update chart on date change
let
stackedAreaChart
=
am4core
.
registry
.
baseSprites
.
find
(
c
=>
c
.
htmlContainer
.
id
===
"stackedAreaChart"
);
//
let stackedAreaChart = am4core.registry.baseSprites.find(c => c.htmlContainer.id === "stackedAreaChart");
// async queries for each date that has been loaded
// async queries for each date that has been loaded
// TODO: this is the exact same call as in LINE CHART => merge into one
const
queries_sa
=
userFiles
.
map
(
async
(
mes
,
i
)
=>
{
const
queries_sa
=
userFiles
.
map
(
async
(
mes
,
i
)
=>
{
let
query_sa
=
`
${
baseUrl
}
/query/
${
mes
}
?columns=sum(areacpo)/10000 area, descrip&group=descrip`
;
let
query_sa
=
`
${
baseUrl
}
/query/
${
mes
}
?columns=sum(areacpo)/10000 area, descrip&group=descrip`
;
const
queryData
=
await
d3
.
json
(
query_sa
);
const
queryData
=
await
d3
.
json
(
query_sa
);
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_sa
.
push
(
queryData
);
//data_sa.push(queryData);
return
new
Promise
(
resolve
=>
{
});
resolve
(
queryData
);
// wait for all queries to complete
});
const
dataQueries_sa
=
await
Promise
.
all
(
queries_sa
);
});
// and then set chart data
// wait for all queries to complete and then set chart data
//lineStackedChart.data = data_ls;
Promise
.
all
(
queries_sa
).
then
(
data
=>
{
var
merged_1
=
[].
concat
.
apply
([],
data_sa
);
// TODO: maybe make this a function so it can be used to update chart when changing dates
//console.log(data_sa);
let
merged
=
[].
concat
.
apply
([],
data
);
let
aguaPermanente
=
merged
.
filter
(
d
=>
d
.
descrip
==
"Agua permanente"
);
let
aguaPermanente_1
=
merged_1
.
filter
(
function
(
d
)
{
return
d
.
descrip
==
"Agua permanente"
});
let
aguaTemporal
=
merged
.
filter
(
d
=>
d
.
descrip
==
"Áreas temporalmente inundadas"
);
let
aguaTemporal_1
=
merged_1
.
filter
(
function
(
d
)
{
return
d
.
descrip
==
"Áreas temporalmente inundadas"
});
let
aguaVegetacion
=
merged
.
filter
(
d
=>
d
.
descrip
==
"Suelos húmedos-vegetación acuática"
);
let
aguaVegetacion_1
=
merged_1
.
filter
(
function
(
d
)
{
return
d
.
descrip
==
"Suelos húmedos-vegetación acuática"
});
let
chartData
=
[];
let
j
;
aguaPermanente
.
forEach
(
(
wb
,
i
)
=>
{
for
(
j
=
0
;
j
<
aguaPermanente_1
.
length
;
j
++
)
{
let
element
=
{
aguaPermanente_1
[
j
].
permanente
=
aguaPermanente_1
[
j
].
area
;
permanente
:
aguaPermanente
[
i
].
area
,
aguaPermanente_1
[
j
].
temporal
=
aguaTemporal_1
[
j
].
area
;
temporal
:
aguaTemporal
[
i
].
area
,
aguaPermanente_1
[
j
].
vegetacion
=
aguaVegetacion_1
[
j
].
area
;
vegetacion
:
aguaVegetacion
[
i
].
area
,
delete
aguaPermanente_1
[
j
].
descrip
;
date
:
aguaPermanente
[
i
].
date
delete
aguaPermanente_1
[
j
].
area
;
}
}
chartData
.
push
(
element
);
});
let
grijalva_bodies_1
=
aguaPermanente_1
;
chartData
.
sort
((
a
,
b
)
=>
(
a
.
date
>
b
.
date
)
?
1
:
-
1
)
;
grijalva_bodies_1
.
sort
((
a
,
b
)
=>
(
a
.
date
>
b
.
date
)
?
1
:
-
1
)
makeAreaChart
(
chartData
);
stackedAreaChart
.
data
=
grijalva_bodies_1
;
})
;
// populate bars
// populate bars
...
...
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