Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,79 @@
}
};

const canvas = document.getElementById('program-overview-chart');
const ctx = canvas.getContext('2d');

$scope.meterReadingsChart = new Chart(ctx, {
type: 'line',

Check failure on line 140 in seed/static/seed/js/controllers/inventory_detail_meters_controller.js

View workflow job for this annotation

GitHub Actions / formatting (lint)

Expected indentation of 6 spaces but found 10
data: {

Check failure on line 141 in seed/static/seed/js/controllers/inventory_detail_meters_controller.js

View workflow job for this annotation

GitHub Actions / formatting (lint)

Expected indentation of 6 spaces but found 10
labels: [],

Check failure on line 142 in seed/static/seed/js/controllers/inventory_detail_meters_controller.js

View workflow job for this annotation

GitHub Actions / formatting (lint)

Unexpected trailing comma

Check failure on line 142 in seed/static/seed/js/controllers/inventory_detail_meters_controller.js

View workflow job for this annotation

GitHub Actions / formatting (lint)

Expected indentation of 8 spaces but found 12
},

Check failure on line 143 in seed/static/seed/js/controllers/inventory_detail_meters_controller.js

View workflow job for this annotation

GitHub Actions / formatting (lint)

Expected indentation of 6 spaces but found 10
options: {

Check failure on line 144 in seed/static/seed/js/controllers/inventory_detail_meters_controller.js

View workflow job for this annotation

GitHub Actions / formatting (lint)

Expected indentation of 6 spaces but found 10
scales: {},

Check failure on line 145 in seed/static/seed/js/controllers/inventory_detail_meters_controller.js

View workflow job for this annotation

GitHub Actions / formatting (lint)

Expected indentation of 8 spaces but found 12
plugins: {

Check failure on line 146 in seed/static/seed/js/controllers/inventory_detail_meters_controller.js

View workflow job for this annotation

GitHub Actions / formatting (lint)

Expected indentation of 8 spaces but found 12
legend: {

Check failure on line 147 in seed/static/seed/js/controllers/inventory_detail_meters_controller.js

View workflow job for this annotation

GitHub Actions / formatting (lint)

Expected indentation of 10 spaces but found 14
onClick: () => {}

Check failure on line 148 in seed/static/seed/js/controllers/inventory_detail_meters_controller.js

View workflow job for this annotation

GitHub Actions / formatting (lint)

Expected indentation of 12 spaces but found 16
}
}
}
});
$scope.meterReadingsChart.update()

const colors = [
"#a6cee3",
"#1f78b4",
"#b2df8a",
"#33a02c",
"#fb9a99",
"#e31a1c",
"#fdbf6f",
"#ff7f00",
"#cab2d6",
"#6a3d9a",
];

$scope.reloadChart = () => {
if ($scope.interval.selected === "Exact") return

// init empty data obj
const dataForChart = {
labels: $scope.data.map(d => d[$scope.interval.selected.toLowerCase()]),
datasets: $scope.meterReadGridOptions.columnDefs.slice(1).map((c, i) => {
return {
id: c["field"],
label: c["displayName"],
data: [],
yAxisID: c["displayName"].slice(c["field"].length + 2, -1),
backgroundColor: colors[i % colors.length],
borderColor: colors[i % colors.length],
}
}),
};

// fill data object
$scope.data.forEach(readingsForTime => {
dataForChart.datasets.forEach(dataset => {
dataset.data.push(readingsForTime[dataset.id])
})
})
$scope.meterReadingsChart.data = dataForChart;
$scope.meterReadingsChart.update()

// set scale
const yAxisIDs = new Set (dataForChart.datasets.map(d => d.yAxisID))
yAxisIDs.forEach(axis => {
$scope.meterReadingsChart.options.scales[axis].title.text = axis
$scope.meterReadingsChart.options.scales[axis].title.display = true
});
Object.keys($scope.meterReadingsChart.options.scales).forEach(k => {
if (!yAxisIDs.has(k)) {delete $scope.meterReadingsChart.options.scales[k]}
})
$scope.meterReadingsChart.update()
}



$scope.meterReadGridOptions = {
data: 'data',
columnDefs: property_meter_usage.column_defs,
Expand Down Expand Up @@ -245,6 +318,7 @@
$scope.has_meters = meters.length > 0;
$scope.has_readings = $scope.data.length > 0;
$scope.apply_column_settings();
$scope.reloadChart();
};

// refresh_readings make an API call to refresh the base readings data
Expand All @@ -271,6 +345,7 @@

resetSelections();
$scope.applyFilters();
$scope.reloadChart();
spinner_utility.hide();
});
};
Expand Down
4 changes: 4 additions & 0 deletions seed/static/seed/partials/inventory_detail_meters.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ <h4>Meters</h4>
<div class="jumbotron text-center" translate>No Data</div>
</div>

<div class="graph" style="margin-left: 5vw; margin-right: 5vw" ng-hide="interval.selected == 'Exact'">
<canvas id="program-overview-chart"></canvas>
</div>

<h4>Readings</h4>
<div id="meters-readings-grid-container" ng-show="has_readings">
<div
Expand Down
Loading