# Density Contour
Original D3 demo at https://bl.ocks.org/mbostock/7f5f22524bd1d824dd53c535eda0187f
<template>
<d3-cartesian class="demo" :width="860" :height="550" :x="x" :y="y">
<template #default="props">
<d3-contour :data="data" x="carat" y="price" :colorFn="colorFn"
v-bind="props"/>
</template>
<template #south="props">
<d3-axis orientation="Bottom" title="Carats" titleLastTick :config="configX"
v-bind="props"/>
</template>
<template #west="props">
<d3-axis orientation="Left" title="Price (USD)" titleLastTick :config="configY"
v-bind="props"/>
</template>
</d3-cartesian>
</template>
<script>
import * as d3 from 'd3'
export default {
data () {
return {
data: null,
x: { type: 'Log', domain: [2e-1, 5e0] },
y: { type: 'Log', domain: [3e2, 2e4] },
configX: axis => axis.ticks(null, '.1f'),
configY: axis => axis.ticks(null, '.1s'),
colorFn: null
}
},
created () {
d3.tsv('/data/diamonds.tsv', d => {
d.carat = +d.carat
d.price = +d.price
return d
}).then(data => {
this.data = data
const colorScale = d3.scaleSequential(d3.interpolateYlGnBu)
.domain([0, 1.8]) // Points per square pixel
this.colorFn = d => colorScale(d.value)
})
}
}
</script>
<style lang="scss" scoped>
.demo /deep/ {
.domain {
display: none;
}
.axis .label {
font-weight: bold;
}
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
← Choropleth Grid Lines →