Skip to content

Commit

Permalink
#88 fixed pdf export with custom time range
Browse files Browse the repository at this point in the history
  • Loading branch information
io53 committed Mar 10, 2024
1 parent 3d4dc9e commit 2e520c5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/states/Sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ class Sensor extends Component {
}
export_PDF() {
this.setState({ ...this.state, graphPDFMode: true });
exportPDF(this.props.sensor, this.state.data, this.getGraphData(), this.state.graphKey, this.state.from, this.chartRef, this.props.t, () => {
let from = this.getFrom()
let to = this.state.to || new Date().getTime()
exportPDF(this.props.sensor, this.state.data, this.getGraphData(), this.state.graphKey, from, to, this.chartRef, this.props.t, () => {
this.setState({ ...this.state, graphPDFMode: false })
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function exportXLSX(dataIn, sensorName, t) {
XLSX.writeFile(wb, exportedFilename);
}

export function exportPDF(sensor, data, graphData, type, from, chartRef, t, done) {
export function exportPDF(sensor, data, graphData, type, from, to, chartRef, t, done) {
let ezdata = [];
for (let i = 0; i < graphData.length; i++) {
if (graphData[i].parsed === null) continue
Expand Down Expand Up @@ -181,7 +181,7 @@ export function exportPDF(sensor, data, graphData, type, from, chartRef, t, done
var d = new Date(ts);
return d.getDate() + "." + (d.getMonth() + 1) + "." + (d.getFullYear())
}
let text_date = t("dates") + `: ${dateToit(new Date().getTime() - from * 60 * 60 * 1000)} - ${dateToit(new Date())}`
let text_date = t("dates") + `: ${dateToit(from)} - ${dateToit(to)}`
doc.text(text_date, width - doc.getTextWidth(text_date) - padding, linePos + lineBottomPadding + doc.getTextDimensions(text_date).h + 1.2)

//doc.text("Note:", padding, linePos + 20)
Expand Down

0 comments on commit 2e520c5

Please sign in to comment.