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
4b3219fd
Commit
4b3219fd
authored
Jan 22, 2021
by
Rodrigo Tapia-McClung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve radar chart ceation
parent
4643d048
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
201 deletions
+80
-201
cuerpos_charts.js
public/js/cuerpos_charts.js
+47
-143
cuerpos_functions.js
public/js/cuerpos_functions.js
+33
-58
No files found.
public/js/cuerpos_charts.js
View file @
4b3219fd
This diff is collapsed.
Click to expand it.
public/js/cuerpos_functions.js
View file @
4b3219fd
...
@@ -5,8 +5,8 @@
...
@@ -5,8 +5,8 @@
* January 2021
* January 2021
*/
*/
/* globals omnivore, Promise, makeBaseMap, am4core */
/* globals omnivore, Promise, makeBaseMap, am4core
, makeRadialChart
*/
/* exported. userFiles, userDates, timeParse, layerControl */
/* exported. userFiles, userDates, timeParse, layerControl
, yearList
*/
let
timeParse
,
let
timeParse
,
timeFormat
,
timeFormat
,
...
@@ -282,72 +282,47 @@ const setupMap = (dates) => {
...
@@ -282,72 +282,47 @@ const setupMap = (dates) => {
});
});
}
}
let
barChartData
=
[];
let
barChartData
=
[],
yearList
;
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
;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ RADIAL CHART
// RADIAL CHART
let
data
=
[];
// empty array to hold chart data
// get am chart - may need this to update chart on date change
// get am chart
//let radialChart = am4core.registry.baseSprites.find(c => c.htmlContainer.id === "radial_chart");
let
radialChart
=
am4core
.
registry
.
baseSprites
.
find
(
c
=>
c
.
htmlContainer
.
id
===
"radial_chart"
);
// async queries for each date that has been loaded
// async queries for each date that has been loaded
const
queries
=
userFiles
.
map
(
async
(
mes
,
i
)
=>
{
const
queries
=
userFiles
.
map
(
async
(
mes
,
i
)
=>
{
//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
value1
`
;
let
query
=
`
${
baseUrl
}
/query/
${
mes
}
?columns=sum(areacpo)/10000
area
`
;
const
queryData
=
await
d3
.
json
(
query
);
const
queryData
=
await
d3
.
json
(
query
);
let
date
=
new
Date
(
dateArray
[
i
]);
queryData
[
0
].
date
=
new
Date
(
userDates
[
i
])
queryData
[
0
].
date
=
date
;
return
new
Promise
(
resolve
=>
{
data
.
push
(
queryData
[
0
]);
resolve
(
queryData
[
0
]);
});
});
// wait for all queries to complete
});
const
dataQueries
=
await
Promise
.
all
(
queries
);
// wait for all queries to complete and then set chart data
// and then set chart data
Promise
.
all
(
queries
).
then
(
data
=>
{
let
data_1
=
data
;
data_1
.
sort
((
a
,
b
)
=>
(
a
.
date
>
b
.
date
)
?
1
:
-
1
)
var
month
=
new
Array
();
month
[
0
]
=
"January"
;
month
[
1
]
=
"February"
;
month
[
2
]
=
"March"
;
month
[
3
]
=
"April"
;
month
[
4
]
=
"May"
;
month
[
5
]
=
"June"
;
month
[
6
]
=
"July"
;
month
[
7
]
=
"August"
;
month
[
8
]
=
"September"
;
month
[
9
]
=
"October"
;
month
[
10
]
=
"November"
;
month
[
11
]
=
"December"
;
var
year
=
new
Array
();
year
[
116
]
=
"2016"
;
year
[
117
]
=
"2017"
;
year
[
118
]
=
"2018"
;
let
cc
;
for
(
cc
=
0
;
cc
<
data_1
.
length
;
cc
++
)
{
data_1
[
cc
].
mm
=
month
[(
data_1
[
cc
].
date
).
getMonth
()];
data_1
[
cc
].
yy
=
year
[(
data_1
[
cc
].
date
).
getYear
()];
}
// TODO: check this for loop to use selected months and years
// create sets of unique months and years
yearList
=
[...
new
Set
(
userDates
.
map
(
date
=>
new
Date
(
date
).
getFullYear
()
))];
var
element
=
{},
//let formatter = new Intl.DateTimeFormat('es', { month: 'long' });
cart
=
[],
cntr
;
for
(
cntr
=
0
;
cntr
<
12
;
cntr
++
)
{
//console.log(month[cntr]);
element
=
{};
element
.
month
=
(
month
[
cntr
]).
toString
();
element
.
value1
=
(
data_1
.
filter
(
function
(
d
)
{
return
d
.
mm
==
month
[
cntr
]
&&
d
.
yy
==
2016
}))[
0
].
value1
;
element
.
value2
=
(
data_1
.
filter
(
function
(
d
)
{
return
d
.
mm
==
month
[
cntr
]
&&
d
.
yy
==
2017
}))[
0
].
value1
;
element
.
value3
=
(
data_1
.
filter
(
function
(
d
)
{
return
d
.
mm
==
month
[
cntr
]
&&
d
.
yy
==
2018
}))[
0
].
value1
;
cart
.
push
(
element
);
}
radialChart
.
data
=
cart
;
// TODO: maybe make this a function so it can be used to update chart when changing dates
let
chartaData
=
[];
monthArray
.
forEach
(
(
month
,
index
)
=>
{
let
element
=
{};
yearList
.
forEach
(
year
=>
{
//element.month = formatter.format(new Date(year, month, 1, 0, 0, 0));
element
.
month
=
month
.
toLowerCase
();
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
;
});
chartaData
.
push
(
element
);
});
makeRadialChart
(
chartaData
,
monthArray
,
yearList
);
});
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ LINE CHART
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ LINE CHART
let
data_ls
=
[];
let
data_ls
=
[];
...
...
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