Last active
January 12, 2021 18:57
-
-
Save surajp/7cd203b3e66207d0f7d7c08dd633de1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LightningElement, api, track, wire } from 'lwc'; | |
import setupChartData from './chartSetup.js'; | |
import getChartData from '@salesforce/apex/MachineActivityCompletionChartController.getTestCompletionDetails'; | |
import getChartOptions from './chartOptions.js'; | |
export default class MachineActivityCompletetionChart extends LightningElement { | |
@api poaId; | |
@api testMethodIds; | |
@api startDate; | |
@api endDate; | |
@api locale; | |
@api fixedHeight; | |
@track chartData; | |
@track chartOptions = {}; | |
connectedCallback(){ | |
this.chartOptions = {...this.chartOptions,...getChartOptions(this.locale)}; | |
} | |
@wire(getChartData, { | |
poaId: '$poaId', | |
testMethods: '$testMethodIds', | |
startDate: '$startDate', | |
endDate: '$endDate' | |
}) | |
getChartData({ error, data }) { | |
if (error) { | |
console.log(error); | |
} else if (data) { | |
try { | |
this.chartData = setupChartData(data, this.startDate, this.endDate); | |
this.chartOptions.animation = { | |
onComplete: () => { | |
this.dispatchEvent( | |
new CustomEvent('rendercomplete', { | |
bubbles: true, | |
composed: true | |
}) | |
); | |
} | |
}; | |
this.chartOptions = {...this.chartOptions}; | |
if (data.length === 0) { | |
this.dispatchEvent( | |
new CustomEvent('nochartdata', { | |
detail: this.poaId, | |
bubbles: true, | |
composed: true | |
}) | |
); | |
} | |
} catch (setupError) { | |
console.warn('Skipping chart', this.poaId); | |
this.dispatchEvent(new CustomEvent('rendercomplete')); | |
this.dispatchEvent(new CustomEvent('invalidchart')); | |
} | |
} | |
} | |
@api getBase64Image() { | |
try { | |
const chart = this.template.querySelector('c-chart-js'); | |
if (chart) { | |
return this.template.querySelector('c-chart-js').getBase64Image(); | |
} | |
} catch (e) { | |
console.error(e); | |
} | |
return undefined; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment