Skip to content

Commit

Permalink
Fix boundaries error (zero is falsey on js)
Browse files Browse the repository at this point in the history
  • Loading branch information
voluntadpear committed Feb 7, 2018
1 parent 7294669 commit d12a6b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-choropleth",
"version": "0.1.0",
"version": "0.1.1",
"description": "Choropleth Map for Vue.js",
"homepage": "https://github.com/voluntadpear/ChoroplethMap",
"bugs": "https://github.com/voluntadpear/ChoroplethMap/issues",
Expand Down
7 changes: 3 additions & 4 deletions src/components/ChoroplethLayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</template>
<script>
import Vue2Leaflet from "vue2-leaflet"
import { getMin, getMax, normalizeValue, getColor } from "../util"
import { getMin, getMax, normalizeValue, getColor, validNumber } from "../util"
function mouseover({ target }) {
target.setStyle({
Expand Down Expand Up @@ -80,9 +80,8 @@ export default {
weight: 2
}
}
// let canH = dpto.cantidad_h
let valueParam = item[this.value.key]
if (!Number(valueParam)) {
let valueParam = Number(item[this.value.key])
if (!validNumber(valueParam)) {
return {
color: "white",
weight: 2
Expand Down
12 changes: 8 additions & 4 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import chroma from "chroma-js"

export const validNumber = num => !(isNaN(num) ||
num == null ||
num == undefined)

export const getMin = (array, key) =>
Math.min(...array.filter(x => Number(x[key])).map(x => Number(x[key])))
Math.min(...array.filter(x => validNumber(x[key])).map(x => Number(x[key])))

export const getMax = (array, key) =>
Math.max(...array.filter(x => Number(x[key])).map(x => Number(x[key])))
Math.max(...array.filter(x => validNumber(x[key])).map(x => Number(x[key])))

export const normalizeValue = (value, min, max) => (value - min) / (max - min)

export const getColor = (param, colorScale, min, max) =>
chroma
export const getColor = (param, colorScale, min, max) =>
chroma
.scale(colorScale)
.mode("lch")(normalizeValue(param, min, max))
.hex()

0 comments on commit d12a6b9

Please sign in to comment.