changeset 3380:d83c738e8627

fairway_availability_LNWL: draw chart with MOCKDATA
author Thomas Junk <thomas.junk@intevation.de>
date Wed, 22 May 2019 15:38:21 +0200
parents 4fa3fc4ed987
children 540ef09bd6bc 194feb1a7e37
files client/src/components/fairway/AvailableFairwayDepthLNWL.vue
diffstat 1 files changed, 44 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/fairway/AvailableFairwayDepthLNWL.vue	Wed May 22 15:30:48 2019 +0200
+++ b/client/src/components/fairway/AvailableFairwayDepthLNWL.vue	Wed May 22 15:38:21 2019 +0200
@@ -432,6 +432,48 @@
     },
     drawBars() {
       this.drawLNWL();
+      this.drawAFD();
+    },
+    drawAFD() {
+      let afd = this.diagram
+        .append("g")
+        .attr("transform", `translate(${this.paddingRight + this.barsWidth})`);
+      afd
+        .selectAll("rect")
+        .data(this.fwLNWLData.afd)
+        .enter()
+        .append("rect")
+        .on("mouseover", function() {
+          d3.select(this).attr("opacity", "0.8");
+          d3.select("#tooltip").attr("opacity", 1);
+        })
+        .on("mouseout", function() {
+          d3.select(this).attr("opacity", 1);
+          d3.select("#tooltip").attr("opacity", 0);
+        })
+        .on("mousemove", function(d) {
+          let y = d3.mouse(this)[1];
+          const dy = document
+            .querySelector(".diagram-container")
+            .getBoundingClientRect().left;
+          const value = d.percent;
+          d3.select("#tooltip")
+            .text(value)
+            .attr("y", y - 10)
+            .attr("x", d3.event.pageX - dy);
+          //d3.event.pageX gives coordinates relative to SVG
+          //dy gives offset of svg on page
+        })
+        .attr("height", d => {
+          return this.yScale(0) - this.yScale(d.percent);
+        })
+        .attr("y", d => {
+          return this.yScale(d.translateY);
+        })
+        .attr("width", this.barsWidth)
+        .attr("fill", (d, i) => {
+          return this.$options.AFDCOLORS[i];
+        });
     },
     drawLNWL() {
       let lnwl = this.diagram
@@ -507,6 +549,7 @@
       this.drawDiagram();
     }
   },
-  LEGEND: app.$gettext("Percent")
+  LEGEND: app.$gettext("Percent"),
+  AFDCOLORS: ["#33333", "#666666", "#999999"]
 };
 </script>