-
Notifications
You must be signed in to change notification settings - Fork 2
Create PBCRenderer.js component for Individuals and MR charts together #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import { UIControlsRenderer } from '../UIControlsRenderer.js'; | ||
|
||
export class PBCRenderer extends UIControlsRenderer { | ||
constructor(controlData, movingRangeData, avgMovingRangeFunc, workTicketsURL, chartName = 'pbc') { | ||
super(controlData); | ||
this.controlData = controlData; | ||
this.movingRangeData = movingRangeData; | ||
this.avgMovingRangeFunc = avgMovingRangeFunc; | ||
this.workTicketsURL = workTicketsURL; | ||
this.chartName = chartName; | ||
this.chartType = 'PBC'; | ||
|
||
// Child renderers | ||
this.controlRenderer = null; | ||
this.movingRangeRenderer = null; | ||
} | ||
|
||
/** | ||
* Initialize child renderers with their respective data | ||
*/ | ||
initializeRenderers(ControlRenderer, MovingRangeRenderer) { | ||
this.controlRenderer = new ControlRenderer(this.controlData, this.avgMovingRangeFunc, `${this.chartName}-control`, this.workTicketsURL); | ||
|
||
this.movingRangeRenderer = new MovingRangeRenderer( | ||
this.movingRangeData, // Moving range calculated data | ||
this.avgMovingRangeFunc, | ||
this.workTicketsURL, | ||
`${this.chartName}-moving-range` | ||
); | ||
} | ||
|
||
/** | ||
* Render both charts | ||
*/ | ||
renderGraph(containerSelector) { | ||
this.createContainers(containerSelector); | ||
// Render control chart | ||
this.controlRenderer.renderGraph(`${containerSelector} .control-chart`); | ||
// Render moving range chart | ||
this.movingRangeRenderer.renderGraph(`${containerSelector} .moving-range-chart`); | ||
// Sync baseline dates and time ranges | ||
this.syncChartProperties(); | ||
} | ||
|
||
/** | ||
* Create HTML containers for both charts | ||
*/ | ||
createContainers(containerSelector) { | ||
const container = document.querySelector(containerSelector); | ||
if (!container) return; | ||
|
||
container.innerHTML = ` | ||
<div class="pbc-charts"> | ||
<div class="control-chart"></div> | ||
<div class="moving-range-chart"></div> | ||
</div> | ||
`; | ||
} | ||
|
||
/** | ||
* Setup brush - only from control chart | ||
*/ | ||
setupBrush(brushSelector) { | ||
this.brushSelector = brushSelector; | ||
this.controlRenderer.setupBrush(brushSelector); | ||
this.syncBrushEvents(); | ||
this.updateGraph(this.controlRenderer.selectedTimeRange); | ||
} | ||
|
||
/** | ||
* Sync brush events to update both charts | ||
*/ | ||
syncBrushEvents() { | ||
// Override control renderer's updateGraph to also update moving range | ||
const originalUpdateGraph = this.controlRenderer.updateGraph.bind(this.controlRenderer); | ||
this.controlRenderer.updateGraph = (domain) => { | ||
// Update control chart | ||
originalUpdateGraph(domain); | ||
|
||
// Update moving range chart with the same domain | ||
this.movingRangeRenderer.updateGraph(domain); | ||
}; | ||
} | ||
|
||
setTimeScale(timeScale) { | ||
this.controlRenderer.timeScale = timeScale; | ||
this.movingRangeRenderer.timeScale = timeScale; | ||
} | ||
|
||
/** | ||
* Sync properties between charts | ||
*/ | ||
syncChartProperties() { | ||
if (!this.controlRenderer || !this.movingRangeRenderer) return; | ||
this.movingRangeRenderer.reportingRangeDays = 30; | ||
this.controlRenderer.reportingRangeDays = 30; | ||
this.movingRangeRenderer.timeInterval = 'months'; | ||
this.controlRenderer.timeInterval = 'months'; | ||
this.movingRangeRenderer.timeScale = 'logarithmic'; | ||
this.controlRenderer.timeScale = 'logarithmic'; | ||
} | ||
|
||
/** | ||
* Setup event bus for both charts | ||
*/ | ||
setupEventBus(eventBus, mouseChartsEvents, timeRangeChartsEvents) { | ||
this.controlRenderer?.setupEventBus(eventBus, mouseChartsEvents, timeRangeChartsEvents); | ||
this.movingRangeRenderer?.setupEventBus(eventBus, mouseChartsEvents, timeRangeChartsEvents); | ||
} | ||
|
||
/** | ||
* Setup observations for both charts | ||
*/ | ||
setupObservationLogging(observations) { | ||
this.controlRenderer?.setupObservationLogging(observations); | ||
this.movingRangeRenderer?.setupObservationLogging(observations); | ||
} | ||
|
||
setTimeScaleListener(timeScaleSelector) { | ||
const selectElement = document.querySelector(timeScaleSelector); | ||
if (!selectElement) { | ||
console.warn(`Time scale selector not found: ${timeScaleSelector}`); | ||
return; | ||
} | ||
// Single event listener that updates both charts | ||
selectElement.addEventListener('change', (event) => { | ||
const newTimeScale = event.target.value; | ||
// Update both renderers | ||
if (this.controlRenderer) { | ||
this.controlRenderer.timeScale = newTimeScale; | ||
this.controlRenderer.computeYScale(); | ||
this.controlRenderer.updateGraph(this.controlRenderer.selectedTimeRange); | ||
this.controlRenderer.renderBrush(); // Only control renderer renders brush | ||
} | ||
|
||
if (this.movingRangeRenderer) { | ||
this.movingRangeRenderer.timeScale = newTimeScale; | ||
this.movingRangeRenderer.computeYScale(); | ||
this.movingRangeRenderer.updateGraph(this.controlRenderer.selectedTimeRange); | ||
// No renderBrush() for moving range | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Clear both charts | ||
*/ | ||
clearGraph(containerSelector, brushSelector) { | ||
this.controlRenderer?.clearGraph(`${containerSelector} .control-chart`, brushSelector); | ||
this.movingRangeRenderer?.clearGraph(`${containerSelector} .moving-range-chart`, null); | ||
|
||
const container = document.querySelector(containerSelector); | ||
if (container) container.innerHTML = ''; | ||
} | ||
|
||
/** | ||
* Update both charts | ||
*/ | ||
updateGraph(domain) { | ||
this.controlRenderer?.updateGraph(domain); | ||
this.movingRangeRenderer?.updateGraph(domain); | ||
} | ||
|
||
/** | ||
* Cleanup | ||
*/ | ||
cleanup() { | ||
this.controlRenderer?.cleanupTooltip?.(); | ||
this.movingRangeRenderer?.cleanupTooltip?.(); | ||
} | ||
} |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.