Mercurial > gemma
comparison client/src/components/Pdftool.vue @ 2258:24cafd6b1a55
client: pdf-gen: width of bottleneck info box is calculated based on its content now
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Thu, 14 Feb 2019 10:00:11 +0100 |
parents | ce6fd3d4a3a2 |
children | 7e378b38d302 |
comparison
equal
deleted
inserted
replaced
2257:ce6fd3d4a3a2 | 2258:24cafd6b1a55 |
---|---|
671 addBottleneckInfo(position, offset, rounding, color) { | 671 addBottleneckInfo(position, offset, rounding, color) { |
672 if ( | 672 if ( |
673 this.selectedBottleneck && | 673 this.selectedBottleneck && |
674 this.getLayerByName("Bottleneck isolines").isVisible | 674 this.getLayerByName("Bottleneck isolines").isVisible |
675 ) { | 675 ) { |
676 let width = 54; | 676 let survey = this.selectedSurvey; |
677 let height = 17; | 677 |
678 // determine text dimensions | |
679 // this is a little bit cumbersome but we need to separate width | |
680 // calculations and writing | |
681 this.pdf.doc.setFontSize(10); | |
682 this.pdf.doc.setTextColor(color); | |
683 let textOptions = { baseline: "hanging" }; | |
684 let str1_1 = this.$gettext("Bottleneck") + ": "; | |
685 let str1_2 = this.selectedBottleneck; | |
686 let str2_1 = this.$gettext("Survey date") + ": "; | |
687 let str2_2 = survey.date_info; | |
688 let str3_1 = this.$gettext("Ref gauge") + ": "; | |
689 let str3_2 = survey.gauge_objname; | |
690 let str4_1 = this.$gettext("Depth relativ to") + ": "; | |
691 let str4_2 = | |
692 survey.depth_reference + | |
693 " = " + | |
694 survey.hasOwnProperty("waterlevel_value") | |
695 ? survey.waterlevel_value + " cm" | |
696 : "?"; | |
697 | |
698 this.pdf.doc.setFontStyle("italic"); | |
699 let w1_1 = this.pdf.doc.getTextWidth(str1_1); | |
700 this.pdf.doc.setFontStyle("bold"); | |
701 let w1_2 = this.pdf.doc.getTextWidth(str1_2); | |
702 this.pdf.doc.setFontStyle("italic"); | |
703 let w2_1 = this.pdf.doc.getTextWidth(str2_1); | |
704 this.pdf.doc.setFontStyle("normal"); | |
705 let w2_2 = this.pdf.doc.getTextWidth(str2_2); | |
706 this.pdf.doc.setFontStyle("italic"); | |
707 let w3_1 = this.pdf.doc.getTextWidth(str3_1); | |
708 this.pdf.doc.setFontStyle("normal"); | |
709 let w3_2 = this.pdf.doc.getTextWidth(str3_2); | |
710 this.pdf.doc.setFontStyle("italic"); | |
711 let w4_1 = this.pdf.doc.getTextWidth(str4_1); | |
712 this.pdf.doc.setFontStyle("normal"); | |
713 let w4_2 = this.pdf.doc.getTextWidth(str4_2); | |
714 | |
715 let height = 21; | |
678 let padding = 3; | 716 let padding = 3; |
717 let width = | |
718 Math.max(w1_1 + w1_2, w2_1 + w2_2, w3_1 + w3_2, w4_1 + w4_2) + | |
719 2 * padding; | |
679 | 720 |
680 // x/y defaults to offset for topleft corner (normal x/y coordinates) | 721 // x/y defaults to offset for topleft corner (normal x/y coordinates) |
681 let x = offset.x; | 722 let x = offset.x; |
682 let y = offset.y; | 723 let y = offset.y; |
683 | 724 |
688 } | 729 } |
689 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { | 730 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { |
690 y = this.pdf.height - offset.y - height; | 731 y = this.pdf.height - offset.y - height; |
691 } | 732 } |
692 | 733 |
734 // white background box | |
693 this.addRoundedBox(x, y, width, height, "white", rounding); | 735 this.addRoundedBox(x, y, width, height, "white", rounding); |
694 | 736 |
695 this.pdf.doc.setFontSize(10); | 737 // bottleneck |
696 this.pdf.doc.setTextColor(color); | |
697 | |
698 let str, w; | |
699 | |
700 str = this.$gettext("Bottleneck") + ": "; | |
701 w = this.pdf.doc.getTextWidth(str); | |
702 this.pdf.doc.setFontStyle("italic"); | 738 this.pdf.doc.setFontStyle("italic"); |
703 this.pdf.doc.text(x + padding, y + padding, str); | 739 this.pdf.doc.text(x + padding, y + padding, str1_1, textOptions); |
704 str = this.selectedBottleneck; | |
705 this.pdf.doc.setFontStyle("bold"); | 740 this.pdf.doc.setFontStyle("bold"); |
706 this.pdf.doc.text(x + padding + w, y + padding, str); | 741 this.pdf.doc.text(x + padding + w1_1, y + padding, str1_2, textOptions); |
707 | 742 |
708 let survey = this.selectedSurvey; | 743 // survey date |
709 | |
710 str = this.$gettext("Survey date") + ": "; | |
711 w = this.pdf.doc.getTextWidth(str); | |
712 this.pdf.doc.setFontStyle("italic"); | 744 this.pdf.doc.setFontStyle("italic"); |
713 this.pdf.doc.text(x + padding, y + padding + 3, str); | 745 this.pdf.doc.text(x + padding, y + padding + 4, str2_1, textOptions); |
714 str = survey.date_info; | |
715 this.pdf.doc.setFontStyle("normal"); | 746 this.pdf.doc.setFontStyle("normal"); |
716 this.pdf.doc.text(x + padding + w, y + padding + 3, str); | 747 this.pdf.doc.text( |
717 | 748 x + padding + w2_1, |
718 str = this.$gettext("Ref gauge") + ": "; | 749 y + padding + 4, |
719 w = this.pdf.doc.getTextWidth(str); | 750 str2_2, |
751 textOptions | |
752 ); | |
753 | |
754 // ref gauge | |
720 this.pdf.doc.setFontStyle("italic"); | 755 this.pdf.doc.setFontStyle("italic"); |
721 this.pdf.doc.text(x + padding, y + padding + 6, str); | 756 this.pdf.doc.text(x + padding, y + padding + 8, str3_1, textOptions); |
722 str = survey.gauge_objname; | |
723 this.pdf.doc.setFontStyle("normal"); | 757 this.pdf.doc.setFontStyle("normal"); |
724 this.pdf.doc.text(x + padding + w, y + padding + 6, str); | 758 this.pdf.doc.text( |
725 | 759 x + padding + w3_1, |
726 str = this.$gettext("Depth relativ to") + ": "; | 760 y + padding + 8, |
727 w = this.pdf.doc.getTextWidth(str); | 761 str3_2, |
762 textOptions | |
763 ); | |
764 | |
765 // depth relative to | |
728 this.pdf.doc.setFontStyle("italic"); | 766 this.pdf.doc.setFontStyle("italic"); |
729 this.pdf.doc.text(x + padding, y + padding + 9, str); | 767 this.pdf.doc.text(x + padding, y + padding + 12, str4_1, textOptions); |
730 this.pdf.doc.setFontStyle("normal"); | 768 this.pdf.doc.setFontStyle("normal"); |
731 str = survey.depth_reference + " = "; | 769 this.pdf.doc.text( |
732 if (survey.hasOwnProperty("waterlevel_value")) { | 770 x + padding + w4_1, |
733 str += survey.waterlevel_value + " cm"; | 771 y + padding + 12, |
734 } else { | 772 str4_2, |
735 str += "?"; | 773 textOptions |
736 } | 774 ); |
737 this.pdf.doc.text(x + padding + w, y + padding + 9, str); | |
738 } | 775 } |
739 }, | 776 }, |
740 replacePlaceholders(text) { | 777 replacePlaceholders(text) { |
741 if (text.includes("{date}")) { | 778 if (text.includes("{date}")) { |
742 text = text.replace("{date}", new Date().toLocaleString(locale2)); | 779 text = text.replace("{date}", new Date().toLocaleString(locale2)); |