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
e228b024
Commit
e228b024
authored
Aug 23, 2019
by
anneb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add reverse color order checkbox
parent
e1f783a4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
26 deletions
+33
-26
attrinfo.html
public/attrinfo.html
+33
-26
No files found.
public/attrinfo.html
View file @
e228b024
...
...
@@ -79,7 +79,8 @@
document
.
querySelector
(
'#back'
).
innerHTML
=
`<a href="tableinfo.html?table=
${
fullTableName
}
&geom_column=
${
geomColumn
}
">Back to layer info</a>`
;
document
.
querySelectorAll
(
'[name="colorscheme"]'
).
forEach
(
radio
=>
radio
.
onchange
=
updateLegendColorSchemes
);
document
.
querySelectorAll
(
'[name="classtype"]'
).
forEach
(
radio
=>
radio
.
onchange
=
applyLegendToMap
);
document
.
querySelector
(
'#classcount'
).
onchange
=
classCountChanged
;
document
.
querySelector
(
'#classcount'
).
onchange
=
updateLegendColorSchemes
;
document
.
querySelector
(
'input[name="colorsreversed"]'
).
onchange
=
updateLegendColorSchemes
initMap
();
...
...
@@ -372,29 +373,37 @@
// schemeTypes 'div', 'qual', 'seq'
// for diverging, qualitative and sequential legends
function
getColorSchemes
(
numClasses
,
schemeType
)
{
function
getColorSchemes
(
numClasses
,
schemeType
,
reversed
)
{
for
(;
numClasses
>
2
;
numClasses
--
)
{
let
result
=
colorbrewer
.
filter
(
scheme
=>
scheme
.
type
===
schemeType
&&
scheme
.
sets
.
length
>
numClasses
-
3
)
.
map
(
scheme
=>
{
const
result
=
scheme
.
sets
[
numClasses
-
3
]
;
let
result
=
Object
.
assign
({},
scheme
.
sets
[
numClasses
-
3
])
;
result
.
name
=
scheme
.
name
;
result
.
type
=
scheme
.
type
;
return
result
;
});
if
(
result
.
length
)
{
if
(
reversed
)
{
result
.
forEach
(
scheme
=>
scheme
.
colors
=
scheme
.
colors
.
map
(
c
=>
c
).
reverse
())
}
return
result
;
}
}
if
(
numClasses
===
2
)
{
return
colorbrewer
.
filter
(
scheme
=>
scheme
.
type
===
schemeType
)
let
result
=
colorbrewer
.
filter
(
scheme
=>
scheme
.
type
===
schemeType
)
.
map
(
scheme
=>
{
const
result
=
{
colors
:
[
scheme
.
sets
[
0
].
colors
[
0
],
scheme
.
sets
[
0
].
colors
[
2
]]}
result
.
name
=
scheme
.
name
;
result
.
type
=
scheme
.
type
;
return
result
;
})
});
if
(
reversed
)
{
result
.
forEach
(
scheme
=>
scheme
.
colors
=
scheme
.
colors
.
map
(
c
=>
c
).
reverse
());
}
return
result
;
}
return
[];
return
[
{
colors
:[
'#ff0000'
]}
];
}
function
selectColorScheme
(
schemeIndex
)
...
...
@@ -406,17 +415,14 @@
applyLegendToMap
();
}
function
classCountChanged
()
{
updateLegendColorSchemes
();
}
// display the available colorschemes for current scheme type and class number
function
updateLegendColorSchemes
()
{
let
schemeDiv
=
document
.
querySelector
(
'#colorschemes'
);
schemeDiv
.
innerHTML
=
''
;
let
classCount
=
Number
(
document
.
querySelector
(
'#classcount'
).
value
);
let
schemeType
=
document
.
querySelector
(
'input[name="colorscheme"]:checked'
).
value
;
let
schemes
=
getColorSchemes
(
classCount
,
schemeType
);
let
reversed
=
document
.
querySelector
(
'input[name="colorsreversed"]'
).
checked
;
let
schemes
=
getColorSchemes
(
classCount
,
schemeType
,
reversed
);
classCount
=
schemes
[
0
].
colors
.
length
;
if
(
selectedColorScheme
>
schemes
.
length
-
1
)
{
selectedColorScheme
=
schemes
.
length
-
1
;
...
...
@@ -439,25 +445,26 @@
function
applyLegendToMap
()
{
let
classType
=
document
.
querySelector
(
'input[name="classtype"]:checked'
).
value
;
let
reversed
=
document
.
querySelector
(
'input[name="colorsreversed"]'
).
checked
;
if
(
prepareLegend
())
{
let
classCount
=
Number
(
document
.
querySelector
(
'#classcount'
).
value
);
if
(
classCount
===
1
)
{
// special case, single classification
}
else
{
// classCount > 1
cons
t
layerType
=
map
.
getLayer
(
'attrlayer'
).
type
;
cons
t
rowCount
=
globalStats
.
percentiles
.
reduce
((
result
,
percentile
)
=>
result
+
percentile
.
count
,
0
);
le
t
layerType
=
map
.
getLayer
(
'attrlayer'
).
type
;
le
t
rowCount
=
globalStats
.
percentiles
.
reduce
((
result
,
percentile
)
=>
result
+
percentile
.
count
,
0
);
let
mapboxPaint
;
let
schemeType
=
document
.
querySelector
(
'input[name="colorscheme"]:checked'
).
value
;
switch
(
classType
)
{
case
'mostfrequent'
:
const
schemes
=
getColorSchemes
(
classCount
,
schemeType
);
let
schemes
=
getColorSchemes
(
classCount
,
schemeType
,
reversed
);
classCount
=
schemes
[
0
].
colors
.
length
;
let
classValues
=
globalStats
.
values
.
filter
(
value
=>
value
.
value
!==
null
);
cons
t
needsSlice
=
classValues
.
length
>
classCount
;
le
t
needsSlice
=
classValues
.
length
>
classCount
;
if
(
needsSlice
)
{
classValues
=
classValues
.
slice
(
0
,
classCount
-
1
);
cons
t
classValuesRowCount
=
classValues
.
reduce
((
result
,
value
)
=>
result
+
value
.
count
,
0
);
le
t
classValuesRowCount
=
classValues
.
reduce
((
result
,
value
)
=>
result
+
value
.
count
,
0
);
classValues
.
push
({
value
:
"other"
,
count
:
rowCount
-
classValuesRowCount
...
...
@@ -489,7 +496,7 @@
result
.
push
(
Object
.
assign
({},
percentile
));
// spread operator not supported by current Edge
return
result
;
}
if
(
result
[
result
.
length
-
1
].
from
===
percentile
.
from
||
result
[
result
.
length
-
1
].
to
===
percentile
.
to
)
{
if
(
result
[
result
.
length
-
1
].
from
===
percentile
.
from
)
{
result
[
result
.
length
-
1
].
to
=
percentile
.
to
;
result
[
result
.
length
-
1
].
count
+=
percentile
.
count
;
return
result
;
...
...
@@ -497,14 +504,13 @@
result
.
push
(
Object
.
assign
({},
percentile
));
return
result
;
},[]);
//const schemeType = (typeof percentileBreaks[0].from === "string") ? 'qual' : 'seq';
const
seqSchemes
=
getColorSchemes
(
classCount
,
schemeType
);
let
seqSchemes
=
getColorSchemes
(
classCount
,
schemeType
,
reversed
);
classCount
=
seqSchemes
[
selectedColorScheme
].
colors
.
length
;
if
(
classCount
>
percentileBreaks
.
length
)
{
classCount
=
percentileBreaks
.
length
}
else
{
let
totalRowCount
=
percentileBreaks
.
reduce
((
result
,
percentile
)
=>
result
+
percentile
.
count
,
0
);
cons
t
rowCountPerClass
=
totalRowCount
/
classCount
;
le
t
rowCountPerClass
=
totalRowCount
/
classCount
;
let
sumRowCount
=
0
;
let
sumClassCount
=
0
percentileBreaks
=
percentileBreaks
.
reduce
((
result
,
percentile
)
=>
{
...
...
@@ -532,10 +538,10 @@
mapboxPaint
.
push
(
seqSchemes
[
selectedColorScheme
].
colors
[
classCount
-
1
])
break
;
case
'interval'
:
cons
t
min
=
globalStats
.
percentiles
[
0
].
from
;
cons
t
max
=
globalStats
.
percentiles
[
globalStats
.
percentiles
.
length
-
1
].
to
;
le
t
min
=
globalStats
.
percentiles
[
0
].
from
;
le
t
max
=
globalStats
.
percentiles
[
globalStats
.
percentiles
.
length
-
1
].
to
;
if
(
typeof
min
===
"number"
)
{
const
intervalSchemes
=
getColorSchemes
(
classCount
,
schemeType
);
let
intervalSchemes
=
getColorSchemes
(
classCount
,
schemeType
,
reversed
);
classCount
=
intervalSchemes
[
0
].
colors
.
length
;
let
classTicks
=
getIntervalClassTicks
(
min
,
max
,
classCount
);
mapboxPaint
=
[
"case"
];
...
...
@@ -559,14 +565,14 @@
break
;
}
if
(
mapboxPaint
)
{
cons
t
colorprop
=
`
${
layerType
}
-color`
;
le
t
colorprop
=
`
${
layerType
}
-color`
;
map
.
setPaintProperty
(
'attrlayer'
,
colorprop
,
mapboxPaint
);
updateLayerJsonDisplay
();
}
}
cons
t
nullValues
=
globalStats
.
values
.
filter
(
value
=>
value
.
value
===
null
).
reduce
((
result
,
value
)
=>
result
+
value
.
count
,
0
);
cons
t
checkButtonNullValues
=
document
.
querySelector
(
'#hidenulls'
)
le
t
nullValues
=
globalStats
.
values
.
filter
(
value
=>
value
.
value
===
null
).
reduce
((
result
,
value
)
=>
result
+
value
.
count
,
0
);
le
t
checkButtonNullValues
=
document
.
querySelector
(
'#hidenulls'
)
if
(
nullValues
)
{
checkButtonNullValues
.
removeAttribute
(
'disabled'
);
}
else
{
...
...
@@ -618,6 +624,7 @@
<input
type=
"radio"
name=
"colorscheme"
id=
"sequential"
value=
"seq"
><label
for=
"sequential"
>
sequential
</label>
<input
type=
"radio"
name=
"colorscheme"
id=
"diverting"
value=
"div"
><label
for=
"diverting"
>
diverting
</label>
<input
type=
"radio"
name=
"colorscheme"
id=
"qualitative"
value=
"qual"
checked
><label
for=
"qualitative"
>
qualitative
</label><br>
<input
type=
"checkbox"
name=
"colorsreversed"
id=
"colorsreversed"
><label
for=
"colorsreversed"
>
reverse color order
</label><br>
<input
type=
"checkbox"
id=
"hidenulls"
name=
"hidenulls"
checked
><label
for=
"hidenulls"
>
Hide no-data
</label><br>
<div
id=
"colorschemes"
></div>
</div>
...
...
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