Repository navigation
[AGILE-66] Sprint reports: velocity widget #25885
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
Open
EinLama
wants to merge
18
commits into
dev
Choose a base branch
from
feature/agile-66-provide-velocity-charts
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,684
−29
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7af2dfb
[AGILE-66] Sprint reports: velocity widget
EinLama 1b3c276
[AGILE-66] Use correct Ruby copyright header
EinLama 51d7d33
[AGILE-66] Tests for VelocityChart and AverageLine plugin
EinLama 8687a9f
[AGILE-66] Screenreader support for velocity chart
EinLama c7e89ec
[AGILE-66] Velocity chart shows three y-axis ticks
EinLama eed1d02
[AGILE-66] Move Velocity class to Sprints namespace
EinLama 3658a2b
[AGILE-66] Show velocity chart for sprints that are in planning
EinLama ea16405
[AGILE-66] order_by_date will consider started_at over start_date if …
EinLama 88bdcca
[AGILE-66] Use existing getCSSVariable helper
EinLama 989b94f
[AGILE-66] Rework velocity preceding sprints calculation
EinLama df973ec
[AGILE-66] Use journals in velocity spec
EinLama 06755de
[AGILE-66] Fix rebase errors
EinLama 19403fc
[AGILE-66] Change average velocity calculations
EinLama f3c8e63
[AGILE-66] Velocity chart: toggleable average line in legend
EinLama 24e97d3
[AGILE-66] Render average line label in bold
EinLama 6993d7c
[AGILE-66] Velocity chart: padding for average label
EinLama 0f0b40a
[AGILE-66] Velocity chart: pull bar labels up for low values
EinLama f29ae31
[AGILE-66] Refactor WorkPackageBreakdown to use JournalTimeline
EinLama 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
170 changes: 170 additions & 0 deletions
170
frontend/src/app/features/backlogs/plugin.average-line.spec.ts
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,170 @@ | ||
| //-- copyright | ||
| // OpenProject is an open source project management software. | ||
| // Copyright (C) the OpenProject GmbH | ||
| // | ||
| // This program is free software; you can redistribute it and/or | ||
| // modify it under the terms of the GNU General Public License version 3. | ||
| // | ||
| // OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| // Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| // Copyright (C) 2010-2013 the ChiliProject Team | ||
| // | ||
| // This program is free software; you can redistribute it and/or | ||
| // modify it under the terms of the GNU General Public License | ||
| // as published by the Free Software Foundation; either version 2 | ||
| // of the License, or (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| // | ||
| // See COPYRIGHT and LICENSE files for more details. | ||
| //++ | ||
|
|
||
| import type { Chart } from 'chart.js'; | ||
| import AverageLinePlugin, { AverageLinePluginOptions, isAverageLineVisible, toggleAverageLine } from './plugin.average-line'; | ||
|
|
||
| describe('AverageLinePlugin', () => { | ||
| let ctx:Record<string, unknown> & { | ||
| save:ReturnType<typeof vi.fn>; | ||
| restore:ReturnType<typeof vi.fn>; | ||
| beginPath:ReturnType<typeof vi.fn>; | ||
| moveTo:ReturnType<typeof vi.fn>; | ||
| lineTo:ReturnType<typeof vi.fn>; | ||
| stroke:ReturnType<typeof vi.fn>; | ||
| setLineDash:ReturnType<typeof vi.fn>; | ||
| fillText:ReturnType<typeof vi.fn>; | ||
| }; | ||
| let getPixelForValue:ReturnType<typeof vi.fn>; | ||
| let update:ReturnType<typeof vi.fn>; | ||
|
|
||
| beforeEach(() => { | ||
| ctx = { | ||
| save: vi.fn(), | ||
| restore: vi.fn(), | ||
| beginPath: vi.fn(), | ||
| moveTo: vi.fn(), | ||
| lineTo: vi.fn(), | ||
| stroke: vi.fn(), | ||
| setLineDash: vi.fn(), | ||
| fillText: vi.fn(), | ||
| }; | ||
| getPixelForValue = vi.fn().mockReturnValue(120); | ||
| update = vi.fn(); | ||
| }); | ||
|
|
||
| const chartStub = (withYScale = true) => ({ | ||
| ctx, | ||
| chartArea: { left: 40, right: 400, top: 10, bottom: 250 }, | ||
| scales: withYScale ? { y: { getPixelForValue, right: 36 } } : {}, | ||
| options: { font: { family: 'sans-serif', size: 12 } }, | ||
| update, | ||
| } as unknown as Chart); | ||
|
|
||
| const draw = (options:AverageLinePluginOptions, chart = chartStub()) => { | ||
| AverageLinePlugin.beforeDatasetsDraw!(chart, { cancelable: true }, options); | ||
| }; | ||
|
|
||
| it('draws nothing without a value', () => { | ||
| draw({ label: '42', color: 'red' }); | ||
|
|
||
| expect(ctx.save).not.toHaveBeenCalled(); | ||
| expect(ctx.stroke).not.toHaveBeenCalled(); | ||
| expect(ctx.fillText).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('draws nothing without a y scale', () => { | ||
| draw({ value: 42 }, chartStub(false)); | ||
|
|
||
| expect(ctx.stroke).not.toHaveBeenCalled(); | ||
| expect(ctx.fillText).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('draws a dashed line across the full chart area at the value', () => { | ||
| draw({ value: 42.5, color: 'red' }); | ||
|
|
||
| expect(getPixelForValue).toHaveBeenCalledWith(42.5); | ||
| expect(ctx.setLineDash).toHaveBeenCalledWith([4, 4]); | ||
| expect(ctx.moveTo).toHaveBeenCalledWith(40, 120); | ||
| expect(ctx.lineTo).toHaveBeenCalledWith(400, 120); | ||
| expect(ctx.stroke).toHaveBeenCalledTimes(1); | ||
| expect(ctx.strokeStyle).toBe('red'); | ||
| }); | ||
|
|
||
| it('writes the label left-aligned inside the chart area', () => { | ||
| draw({ value: 42.5, label: '42,5', color: 'red' }); | ||
|
|
||
| expect(ctx.fillText).toHaveBeenCalledWith('42,5', 48, 120); | ||
| expect(ctx.textAlign).toBe('left'); | ||
| expect(ctx.textBaseline).toBe('middle'); | ||
| expect(ctx.fillStyle).toBe('red'); | ||
| expect(ctx.font).toContain('sans-serif'); | ||
| expect(ctx.font).toContain('bold'); | ||
| }); | ||
|
|
||
| it('falls back to the raw value and a neutral color', () => { | ||
| draw({ value: 7 }); | ||
|
|
||
| expect(ctx.fillText).toHaveBeenCalledWith('7', 48, 120); | ||
| expect(ctx.strokeStyle).toBe('gray'); | ||
| expect(ctx.fillStyle).toBe('gray'); | ||
| }); | ||
|
|
||
| it('colors the label separately from the line', () => { | ||
| draw({ value: 7, color: 'red', labelColor: 'black' }); | ||
|
|
||
| expect(ctx.strokeStyle).toBe('red'); | ||
| expect(ctx.fillStyle).toBe('black'); | ||
| }); | ||
|
|
||
| describe('toggling', () => { | ||
| it('is visible by default', () => { | ||
| expect(isAverageLineVisible(chartStub())).toBe(true); | ||
| }); | ||
|
|
||
| it('draws nothing once hidden', () => { | ||
| const chart = chartStub(); | ||
| toggleAverageLine(chart); | ||
|
|
||
| draw({ value: 7 }, chart); | ||
|
|
||
| expect(isAverageLineVisible(chart)).toBe(false); | ||
| expect(ctx.stroke).not.toHaveBeenCalled(); | ||
| expect(ctx.fillText).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('draws again when toggled back', () => { | ||
| const chart = chartStub(); | ||
| toggleAverageLine(chart); | ||
| toggleAverageLine(chart); | ||
|
|
||
| draw({ value: 7 }, chart); | ||
|
|
||
| expect(isAverageLineVisible(chart)).toBe(true); | ||
| expect(ctx.stroke).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('redraws the chart', () => { | ||
| toggleAverageLine(chartStub()); | ||
|
|
||
| expect(update).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('hides the line only on the toggled chart', () => { | ||
| toggleAverageLine(chartStub()); | ||
|
|
||
| expect(isAverageLineVisible(chartStub())).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| it('restores the canvas state after drawing', () => { | ||
| draw({ value: 7 }); | ||
|
|
||
| expect(ctx.save).toHaveBeenCalledTimes(1); | ||
| expect(ctx.restore).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
121 changes: 121 additions & 0 deletions
121
frontend/src/app/features/backlogs/plugin.average-line.ts
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,121 @@ | ||
| //-- copyright | ||
| // OpenProject is an open source project management software. | ||
| // Copyright (C) the OpenProject GmbH | ||
| // | ||
| // This program is free software; you can redistribute it and/or | ||
| // modify it under the terms of the GNU General Public License version 3. | ||
| // | ||
| // OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| // Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| // Copyright (C) 2010-2013 the ChiliProject Team | ||
| // | ||
| // This program is free software; you can redistribute it and/or | ||
| // modify it under the terms of the GNU General Public License | ||
| // as published by the Free Software Foundation; either version 2 | ||
| // of the License, or (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| // | ||
| // See COPYRIGHT and LICENSE files for more details. | ||
| //++ | ||
|
|
||
| import { Chart, ChartType, Plugin } from 'chart.js'; | ||
| import { toFont } from 'chart.js/helpers'; | ||
|
|
||
| export interface AverageLinePluginOptions { | ||
| value?:number; | ||
| label?:string; | ||
| color?:string; | ||
| labelColor?:string; | ||
| } | ||
|
|
||
| declare module 'chart.js' { | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| interface PluginOptionsByType<TType extends ChartType> { | ||
| averageLine:AverageLinePluginOptions; | ||
| } | ||
| } | ||
|
|
||
| export const AVERAGE_LINE_DASH = [4, 4]; | ||
| const LABEL_PADDING = 8; | ||
|
|
||
| const chartsWithHiddenLine = new WeakSet<Chart>(); | ||
|
|
||
| export function isAverageLineVisible(chart:Chart):boolean { | ||
| return !chartsWithHiddenLine.has(chart); | ||
| } | ||
|
|
||
| export function toggleAverageLine(chart:Chart):void { | ||
| if (isAverageLineVisible(chart)) { | ||
| chartsWithHiddenLine.add(chart); | ||
| } else { | ||
| chartsWithHiddenLine.delete(chart); | ||
| } | ||
| chart.update(); | ||
| } | ||
|
|
||
| function labelText(options:AverageLinePluginOptions):string { | ||
| return options.label ?? String(options.value); | ||
| } | ||
|
|
||
| function labelFont(chart:Chart):string { | ||
| return toFont({ weight: 'bold' }, chart.options.font).string; | ||
| } | ||
|
|
||
| const AverageLinePlugin:Plugin<ChartType, AverageLinePluginOptions> = { | ||
| id: 'averageLine', | ||
|
|
||
| afterLayout(chart, _args, options) { | ||
| const xScale = chart.scales.x; | ||
| if (options.value === undefined || !xScale) { | ||
| return; | ||
| } | ||
|
|
||
| const { ctx } = chart; | ||
| ctx.save(); | ||
| ctx.font = labelFont(chart); | ||
| const inset = ctx.measureText(labelText(options)).width + (2 * LABEL_PADDING); | ||
| ctx.restore(); | ||
|
|
||
| xScale.left += inset; | ||
| xScale.width -= inset; | ||
| xScale.configure(); | ||
| }, | ||
|
|
||
| beforeDatasetsDraw(chart, _args, options) { | ||
| const yScale = chart.scales.y; | ||
| if (options.value === undefined || !yScale || !isAverageLineVisible(chart)) { | ||
| return; | ||
| } | ||
|
|
||
| const { ctx, chartArea } = chart; | ||
| const y = yScale.getPixelForValue(options.value); | ||
| const color = options.color ?? 'gray'; | ||
|
|
||
| ctx.save(); | ||
|
|
||
| ctx.strokeStyle = color; | ||
| ctx.lineWidth = 1; | ||
| ctx.setLineDash(AVERAGE_LINE_DASH); | ||
| ctx.beginPath(); | ||
| ctx.moveTo(chart.scales.x?.left ?? chartArea.left, y); | ||
| ctx.lineTo(chartArea.right, y); | ||
| ctx.stroke(); | ||
|
|
||
| ctx.fillStyle = options.labelColor ?? color; | ||
| ctx.font = labelFont(chart); | ||
| ctx.textAlign = 'left'; | ||
| ctx.textBaseline = 'middle'; | ||
| ctx.fillText(labelText(options), chartArea.left + LABEL_PADDING, y); | ||
|
|
||
| ctx.restore(); | ||
| }, | ||
| }; | ||
|
|
||
| export default AverageLinePlugin; | ||
33 changes: 33 additions & 0 deletions
33
frontend/src/app/features/backlogs/velocity-chart.component.html
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,33 @@ | ||
| <div class="position-relative" style="height: 320px"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need to extract this hard wired height into a class to then be used by all the charts on the reports page. The Burndown PR does it admittedly with a name that is not generic. Probably to be done after merging both PRs. |
||
| <canvas baseChart | ||
|
EinLama marked this conversation as resolved.
|
||
| role="img" | ||
| [attr.aria-labelledby]="summaryId" | ||
| [attr.aria-describedby]="tableId" | ||
| [data]="barChartData()" | ||
| [options]="barChartOptions()" | ||
| [plugins]="plugins" | ||
| [type]="'bar'"></canvas> | ||
| </div> | ||
|
|
||
| <p [id]="summaryId" class="sr-only">{{ parsedData().summary }}</p> | ||
|
|
||
| <table [id]="tableId" class="sr-only"> | ||
| <thead> | ||
| <tr> | ||
| <th scope="col">{{ parsedData().sprintColumnTitle }}</th> | ||
| @for (dataset of parsedData().datasets; track dataset.label) { | ||
| <th scope="col">{{ dataset.label }}</th> | ||
| } | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| @for (sprint of parsedData().labels; track $index; let sprintIndex = $index) { | ||
| <tr> | ||
| <th scope="row">{{ sprint }}</th> | ||
| @for (dataset of parsedData().datasets; track dataset.label) { | ||
| <td>{{ dataset.data[sprintIndex] }}</td> | ||
| } | ||
| </tr> | ||
| } | ||
| </tbody> | ||
|
EinLama marked this conversation as resolved.
|
||
| </table> | ||
Oops, something went wrong.
Oops, something went wrong.
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.