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
4f4e017d
Commit
4f4e017d
authored
Aug 23, 2019
by
anneb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working on graph colors
parent
e228b024
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
23 deletions
+63
-23
README.md
README.md
+1
-1
attrinfo.html
public/attrinfo.html
+62
-22
No files found.
README.md
View file @
4f4e017d
...
...
@@ -24,5 +24,5 @@ If you don't have git, you can donwload [a zip file](https://github.com/anneb/pg
For interactive data browsing, preview, administration and api documentation, head to
[
http://localhost:8090
](
http://localhost:8090
)
.
###
Due credit
###
Attributions
API based on
[
Dirt Simple PostGIS http API
](
https://github.com/tobinbradley/dirt-simple-postgis-http-api
)
\ No newline at end of file
public/attrinfo.html
View file @
4f4e017d
...
...
@@ -24,11 +24,11 @@
display
:
inline-block
;
max-width
:
400px
;
}
#
attrinfo
{
#
graphs
{
display
:
flex
;
flex-wrap
:
wrap
;
}
#
attrinfo
div
{
#
graphs
div
{
margin
:
5px
;
}
#colorschemes
{
...
...
@@ -85,13 +85,13 @@
initMap
();
fetch
(
`data/
${
fullTableName
}
/colstats/
${
attrName
}
?geom_column=
${
geomColumn
}
`
).
then
(
response
=>
{
const
attrInfoElement
=
document
.
querySelector
(
'#attrinfo
'
);
attrInfo
Element
.
innerHTML
=
""
;
const
loadingElement
=
document
.
querySelector
(
'#loader
'
);
loading
Element
.
innerHTML
=
""
;
if
(
!
response
.
ok
)
{
try
{
response
.
json
(
json
=>
attrInfo
Element
.
innerHtml
=
json
.
error
);
response
.
json
(
json
=>
loading
Element
.
innerHtml
=
json
.
error
);
}
catch
(
err
)
{
attrInfo
Element
.
innerHTML
=
err
;
loading
Element
.
innerHTML
=
err
;
}
return
;
}
...
...
@@ -112,7 +112,7 @@
globalStats
=
json
;
})
.
catch
(
err
=>
attrInfo
Element
.
innerHTML
=
`Failed to parse response, message:
${
err
.
message
}
`
loading
Element
.
innerHTML
=
`Failed to parse response, message:
${
err
.
message
}
`
);
})
}
...
...
@@ -223,20 +223,36 @@
document
.
querySelector
(
"#layerjson"
).
innerHTML
=
`<pre>
${
JSON
.
stringify
(
layerjson
,
null
,
2
)}
</pre>`
;
}
function
addCanvas
()
{
const
container
=
document
.
createElement
(
'div'
);
container
.
classList
.
add
(
'canvascontainer'
);
const
canvas
=
document
.
createElement
(
'canvas'
);
container
.
classList
.
add
(
'medium'
);
container
.
appendChild
(
canvas
);
document
.
querySelector
(
'#attrinfo'
).
appendChild
(
container
);
return
canvas
;
function
prepareGraphColors
(
classType
)
{
globalStats
.
graphColors
=
[];
globalStats
.
classType
=
classType
;
}
function
addGraphColors
(
color
,
upperValue
)
{
globalStats
.
graphColors
.
push
({
color
:
color
,
upperValue
:
upperValue
});
}
let
graphNoData
=
null
;
let
graphValues
=
null
;
let
graphMostFrequent
=
null
;
function
destroyGraphs
()
{
if
(
graphNoData
)
{
graphNoData
.
destroy
();
}
if
(
graphValues
)
{
graphValues
.
destroy
();
}
if
(
graphMostFrequent
)
{
graphMostFrequent
.
destroy
();
}
}
function
graphStats
(
stats
)
{
destroyGraphs
();
const
nullValues
=
stats
.
values
.
filter
(
value
=>
value
.
value
===
null
).
reduce
((
result
,
value
)
=>
result
+
value
.
count
,
0
);
const
rowCount
=
stats
.
percentiles
.
reduce
((
result
,
percentile
)
=>
result
+
percentile
.
count
,
0
);
new
Chart
(
addCanvas
(
),
{
graphNoData
=
new
Chart
(
document
.
querySelector
(
'#graphnodata canvas'
),
{
type
:
'doughnut'
,
data
:
{
labels
:
[
'no data'
,
'data'
,],
...
...
@@ -250,13 +266,21 @@
}
});
if
(
stats
.
percentiles
.
length
&&
typeof
(
stats
.
percentiles
[
0
].
from
)
!==
'string'
)
{
new
Chart
(
addCanvas
(
),
{
graphValues
=
new
Chart
(
document
.
querySelector
(
'#graphvalues canvas'
),
{
type
:
'line'
,
data
:
{
labels
:
stats
.
percentiles
.
map
((
percentile
,
index
,
arr
)
=>
Math
.
round
((
index
/
(
arr
.
length
-
1
))
*
100
)),
datasets
:
[{
backgroundColor
:
'red'
,
borderColor
:
'lightred'
,
backgroundColor
:
stats
.
graphColors
?
stats
.
percentiles
.
map
((
percentile
)
=>
{
let
color
=
stats
.
classType
===
'mostfrequent'
?
stats
.
graphColors
.
find
(
graphColor
=>
percentile
.
to
==
graphColor
.
upperValue
)
:
stats
.
graphColors
.
find
(
graphColor
=>
percentile
.
to
<
graphColor
.
upperValue
);
if
(
!
color
)
{
color
=
stats
.
graphColors
[
stats
.
graphColors
.
length
-
1
];
}
return
color
.
color
;
}):
'red'
,
//borderColor: 'lighgray',
data
:
stats
.
percentiles
.
map
((
percentile
,
index
,
arr
)
=>
(
index
===
arr
.
length
-
1
)?
percentile
.
to
:
percentile
.
from
),
fill
:
false
}]
...
...
@@ -299,13 +323,19 @@
count
:
rowCount
-
valuesSummeryRowCount
})
}
new
Chart
(
addCanvas
(
),
{
graphMostFrequent
=
new
Chart
(
document
.
querySelector
(
'#graphmostfrequent canvas'
),
{
type
:
"horizontalBar"
,
data
:
{
labels
:
valuesSummary
.
map
(
value
=>
value
.
value
),
datasets
:
[
{
backgroundColor
:
"red"
,
backgroundColor
:
stats
.
graphColors
?
valuesSummary
.
map
((
value
)
=>
{
let
color
=
stats
.
graphColors
.
find
(
graphColor
=>
value
.
value
===
graphColor
.
upperValue
)
if
(
!
color
)
{
color
=
stats
.
graphColors
[
stats
.
graphColors
.
length
-
1
];
}
return
color
.
color
;
}):
'red'
,
data
:
valuesSummary
.
map
(
value
=>
value
.
count
)
}
]
...
...
@@ -447,6 +477,7 @@
let
classType
=
document
.
querySelector
(
'input[name="classtype"]:checked'
).
value
;
let
reversed
=
document
.
querySelector
(
'input[name="colorsreversed"]'
).
checked
;
if
(
prepareLegend
())
{
prepareGraphColors
(
classType
);
let
classCount
=
Number
(
document
.
querySelector
(
'#classcount'
).
value
);
if
(
classCount
===
1
)
{
// special case, single classification
...
...
@@ -483,6 +514,7 @@
}
classValues
.
forEach
((
value
,
index
)
=>
{
addLegendLine
(
schemes
[
selectedColorScheme
].
colors
[
index
],
value
.
value
,
layerType
);
addGraphColors
(
schemes
[
selectedColorScheme
].
colors
[
index
],
value
.
value
)
if
(
index
<
classValues
.
length
-
1
||
!
needsSlice
)
{
mapboxPaint
.
push
(
value
.
value
);
mapboxPaint
.
push
(
schemes
[
selectedColorScheme
].
colors
[
index
]);
...
...
@@ -529,6 +561,7 @@
mapboxPaint
=
[
"case"
]
percentileBreaks
.
forEach
((
brk
,
index
,
arr
)
=>
{
addLegendLine
(
seqSchemes
[
selectedColorScheme
].
colors
[
index
],
`
${
brk
.
from
}
-
${
brk
.
to
}
`
,
layerType
);
addGraphColors
(
seqSchemes
[
selectedColorScheme
].
colors
[
index
],
brk
.
to
);
if
(
globalStats
.
datatype
===
'numeric'
)
{
mapboxPaint
.
push
([
"<"
,[
"to-number"
,
[
"get"
,
`
${
globalStats
.
column
}
`
],
0
],
brk
.
to
],
seqSchemes
[
selectedColorScheme
].
colors
[
index
]);
}
else
{
...
...
@@ -553,6 +586,7 @@
legendTo
=
Math
.
floor
(
legendTo
);
}
addLegendLine
(
intervalSchemes
[
selectedColorScheme
].
colors
[
index
],
`
${(
legendFrom
)}
-
${
legendTo
}
`
,
layerType
);
addGraphColors
(
intervalSchemes
[
selectedColorScheme
].
colors
[
index
],
legendTo
)
if
(
globalStats
.
datatype
===
'numeric'
)
{
// convert javscript string to number
mapboxPaint
.
push
([
"<"
,
[
"to-number"
,[
"get"
,
globalStats
.
column
],
0
],
legendTo
],
intervalSchemes
[
selectedColorScheme
].
colors
[
index
]);
...
...
@@ -568,6 +602,7 @@
let
colorprop
=
`
${
layerType
}
-color`
;
map
.
setPaintProperty
(
'attrlayer'
,
colorprop
,
mapboxPaint
);
updateLayerJsonDisplay
();
graphStats
(
globalStats
);
}
}
...
...
@@ -589,13 +624,18 @@
<h2
id=
"tablename"
></h2>
<h2
id=
"columnname"
></h2>
<div
id=
"
attrinfo
"
>
<div
id=
"
loader
"
>
<h2>
Loading statistics...
</h2>
<div
class=
"loader"
>
<div
class=
"dot"
></div><div
class=
"dot"
></div><div
class=
"dot"
></div><div
class=
"dot"
></div>
<div
class=
"dot"
></div><div
class=
"dot"
></div><div
class=
"dot"
></div><div
class=
"dot"
></div>
</div>
</div>
<div
id=
"graphs"
>
<div
id=
"graphnodata"
class=
"canvascontainer medium"
><canvas></canvas></div>
<div
id=
"graphvalues"
class=
"canvascontainer medium"
><canvas></canvas></div>
<div
id=
"graphmostfrequent"
class=
"canvascontainer medium"
><canvas></canvas></div>
</div>
<div
id=
"mapcontainer"
>
<div
id=
"map"
></div>
<div
id=
"featurecontainer"
>
...
...
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