# HG changeset patch # User Thomas Junk # Date 1563365923 -7200 # Node ID 06096a7ce1c522852d86d3dec3525f002d920ae4 # Parent beaa75082c09f9c3f082c20587784a5f911002eb# Parent d76321bc22d8958c1ae4edd87ec00111be3e1af1 merge with diagram-cleanup diff -r beaa75082c09 -r 06096a7ce1c5 client/src/components/fairway/AvailableFairwayDepth.vue --- a/client/src/components/fairway/AvailableFairwayDepth.vue Wed Jul 17 14:13:51 2019 +0200 +++ b/client/src/components/fairway/AvailableFairwayDepth.vue Wed Jul 17 14:18:43 2019 +0200 @@ -1,7 +1,6 @@ - - diff -r beaa75082c09 -r 06096a7ce1c5 client/src/components/fairway/AvailableFairwayDepthLNWL.vue --- a/client/src/components/fairway/AvailableFairwayDepthLNWL.vue Wed Jul 17 14:13:51 2019 +0200 +++ b/client/src/components/fairway/AvailableFairwayDepthLNWL.vue Wed Jul 17 14:18:43 2019 +0200 @@ -1,7 +1,6 @@ - - diff -r beaa75082c09 -r 06096a7ce1c5 client/src/components/fairway/Fairwayprofile.vue --- a/client/src/components/fairway/Fairwayprofile.vue Wed Jul 17 14:13:51 2019 +0200 +++ b/client/src/components/fairway/Fairwayprofile.vue Wed Jul 17 14:18:43 2019 +0200 @@ -93,12 +93,11 @@
-
+
No data available.
@@ -148,37 +147,16 @@ */ import * as d3 from "d3"; import { mapState, mapGetters } from "vuex"; -import debounce from "debounce"; import { diagram, pdfgen, templateLoader } from "@/lib/mixins"; -import { HTTP } from "@/lib/http"; -import { displayError } from "@/lib/errors"; -import { defaultDiagramTemplate } from "@/lib/DefaultDiagramTemplate"; const GROUND_COLOR = "#4A2F06"; const WATER_COLOR = "#005DFF"; export default { mixins: [diagram, pdfgen, templateLoader], - name: "fairwayprofile", - components: { - DiagramLegend: () => import("@/components/DiagramLegend") - }, data() { return { - resizeListenerFunction: null, - width: null, - height: null, - form: { - template: null - }, - templates: [], - defaultTemplate: defaultDiagramTemplate, - pdf: { - doc: null, - width: 32, - height: 297 - }, - templateData: null + containerId: "fairwayprofile-diagram-container" }; }, computed: { @@ -293,46 +271,6 @@ return { fillColor, fillOpacity, strokeColor, strokeOpacity, strokeDash }; }, - applyChange() { - if (this.form.template.hasOwnProperty("properties")) { - this.templateData = this.defaultTemplate; - return; - } - if (this.form.template) { - this.loadTemplates("/templates/diagram/" + this.form.template.name) - .then(response => { - this.prepareImages(response.data.template_data.elements).then( - values => { - values.forEach(v => { - response.data.template_data.elements[v.index].url = v.url; - }); - this.templateData = response.data.template_data; - } - ); - }) - .catch(e => { - const { status, data } = e.response; - displayError({ - title: this.$gettext("Backend Error"), - message: `${status}: ${data.message || data}` - }); - }); - } - }, - downloadPDF() { - let fairwayInfo = - this.selectedBottleneck + " (" + this.selectedSurvey.date_info + ")"; - - this.generatePDF({ - templateData: this.templateData, - diagramTitle: fairwayInfo - }); - - this.pdf.doc.save( - this.title.replace(/\s/g, "_").replace(/[():,]/g, "") + ".pdf" - ); - }, - // Diagram legend addDiagramLegend(position, offset, color) { let x = offset.x, @@ -383,24 +321,21 @@ }, getPrintLayout() { return { - main: { - top: 20, - right: 80, - bottom: 60, - left: 80 - } + main: { top: 20, right: 80, bottom: 60, left: 80 } }; }, drawDiagram() { - d3.select(".diagram-container svg").remove(); - this.scaleFairwayProfile(); - if (!this.height || !this.width) return; // do not try to render when height and width are unknown - const layout = this.getPrintLayout(this.height); + // remove old diagram and exit if necessary data is missing + d3.select("#" + this.containerId + " svg").remove(); + const elem = document.querySelector("#" + this.containerId); + const svgWidth = elem.clientWidth; + const svgHeight = elem.clientHeight; + const layout = this.getPrintLayout(); this.renderTo({ - element: ".diagram-container", + element: "#" + this.containerId, dimensions: this.getDimensions({ - svgWidth: this.width, - svgHeight: this.height, + svgWidth: svgWidth, + svgHeight: svgHeight, ...layout }) }); @@ -672,62 +607,7 @@ .attr("fill-opacity", 0) .attr("d", profileLine); } - }, - scaleFairwayProfile() { - if (!document.querySelector(".diagram-container")) return; - const clientHeight = document.querySelector(".diagram-container") - .clientHeight; - const clientWidth = document.querySelector(".diagram-container") - .clientWidth; - if (!clientHeight || !clientWidth) return; - this.height = clientHeight; - this.width = clientWidth; } - }, - created() { - this.resizeListenerFunction = debounce(this.drawDiagram, 100); - window.addEventListener("resize", this.resizeListenerFunction); - }, - mounted() { - // Nasty but necessary if we don't want to use the updated hook to re-draw - // the diagram because this would re-draw it also for irrelevant reasons. - // In this case we need to wait for the child component (DiagramLegend) to - // render. According to the docs (https://vuejs.org/v2/api/#mounted) this - // should be possible with $nextTick() but it doesn't work because it does - // not guarantee that the DOM is not only updated but also re-painted on the - // screen. - setTimeout(this.drawDiagram, 150); - - this.templates[0] = this.defaultTemplate; - this.form.template = this.templates[0]; - this.templateData = this.form.template; - HTTP.get("/templates/diagram", { - headers: { - "X-Gemma-Auth": localStorage.getItem("token"), - "Content-type": "text/xml; charset=UTF-8" - } - }) - .then(response => { - if (response.data.length) { - this.templates = response.data; - this.form.template = this.templates[0]; - this.templates[this.templates.length] = this.defaultTemplate; - this.applyChange(); - } - }) - .catch(e => { - const { status, data } = e.response; - displayError({ - title: this.$gettext("Backend Error"), - message: `${status}: ${data.message || data}` - }); - }); - }, - updated() { - this.drawDiagram(); - }, - destroyed() { - window.removeEventListener("resize", this.resizeListenerFunction); } }; diff -r beaa75082c09 -r 06096a7ce1c5 client/src/components/gauge/HydrologicalConditions.vue --- a/client/src/components/gauge/HydrologicalConditions.vue Wed Jul 17 14:13:51 2019 +0200 +++ b/client/src/components/gauge/HydrologicalConditions.vue Wed Jul 17 14:18:43 2019 +0200 @@ -1,13 +1,8 @@