From b7ba27bc0d69474e7f1c9a336c0db52eaf3f987b Mon Sep 17 00:00:00 2001 From: Irwan Fathurrahman Date: Wed, 4 Dec 2024 13:55:10 +0700 Subject: [PATCH] Make value for measurement from surface or top as positive --- admin/general.py | 9 +++++---- static/gwml2/js/measurement-chart.js | 20 ++++++++++++++++--- templates/groundwater_form/main.html | 2 +- .../plugins/measurements_chart_page.html | 2 +- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/admin/general.py b/admin/general.py index a0fa576a..b8a01ab4 100644 --- a/admin/general.py +++ b/admin/general.py @@ -3,9 +3,6 @@ from gwml2.models.general import ( Unit, UnitConvertion, UnitGroup, Country, Quantity ) -from gwml2.tasks.data_file_cache.country_recache import ( - generate_data_country_cache -) class UnitConvertionInline(admin.TabularInline): @@ -24,4 +21,8 @@ class UnitAdmin(admin.ModelAdmin): admin.site.register(UnitGroup, UnitGroupAdmin) admin.site.register(Unit, UnitAdmin) admin.site.register(Quantity) -admin.site.register(Country) + + +@admin.register(Country) +class CountryAdmin(admin.ModelAdmin): + list_display = ('name', 'code') diff --git a/static/gwml2/js/measurement-chart.js b/static/gwml2/js/measurement-chart.js index 780830e4..9b0c05f9 100644 --- a/static/gwml2/js/measurement-chart.js +++ b/static/gwml2/js/measurement-chart.js @@ -198,12 +198,11 @@ function getTrendlines(chartData, steps) { }); return [data, jumps] } catch (e) { - console.log(e) return [[], []] } } -function renderMeasurementChart(identifier, chart, data, xLabel, yLabel, stepTrenlineData, toggleSeries, onChartClicked, title = '') { +function renderMeasurementChart(identifier, chart, data, xLabel, yLabel, stepTrenlineData, toggleSeries, onChartClicked, title = '', reverse = false, unit = '') { switch (identifier) { case 'WellLevelMeasurement': case 'level_measurement': @@ -236,6 +235,12 @@ function renderMeasurementChart(identifier, chart, data, xLabel, yLabel, stepTre yAxis: { title: { text: yLabel + }, + labels: { + formatter: function () { + const val = reverse ? Math.abs(this.value) : this.value; + return `${val} ${unit}`; + } } }, xAxis: { @@ -280,6 +285,12 @@ function renderMeasurementChart(identifier, chart, data, xLabel, yLabel, stepTre dataGrouping: { groupPixelWidth: 50, units: [['hour', [4]], ['day', [1]], ['week', [1, 2]], ['month', [1]]] } } }, + tooltip: { + pointFormatter: function () { + const val = reverse ? Math.abs(this.y) : this.y; + return ` ${this.series.name}: ${parseFloat(val.toFixed(this.series.tooltipOptions.valueDecimals))} ${unit}
`; + } + }, series: [ { id: 'value', @@ -615,6 +626,7 @@ let MeasurementChartObj = function ( } let title = getParamGroup(this.parameterTo) + const reverse = [FROM_TOP_WELL, FROM_GROUND_LEVEL].includes(this.parameterTo); this.chart = renderMeasurementChart( this.identifier, this.chart, cleanData[this.parameterTo], @@ -625,7 +637,9 @@ let MeasurementChartObj = function ( onNewStep(date.getTime()); } }, - title + title, + reverse, + this.unitTo ) this.$loading.hide(); }; diff --git a/templates/groundwater_form/main.html b/templates/groundwater_form/main.html index db0def1b..5f63acd8 100644 --- a/templates/groundwater_form/main.html +++ b/templates/groundwater_form/main.html @@ -214,7 +214,7 @@
{% trans "Well and Monitoring Data Record" %}
- + diff --git a/templates/plugins/measurements_chart_page.html b/templates/plugins/measurements_chart_page.html index 5154b94e..1f3bbeda 100644 --- a/templates/plugins/measurements_chart_page.html +++ b/templates/plugins/measurements_chart_page.html @@ -21,7 +21,7 @@ - +