Skip to content
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

d3 implementation of progress pie chart #7485

Merged
merged 31 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f7cfa3e
d3 implementation of progress pie chart
shefalijoshi Feb 7, 2024
cf64869
Handle 0% and 100% cases
shefalijoshi Feb 12, 2024
77a3692
PR #7485
charlesh88 Feb 12, 2024
42f45af
add in-progress class for compact view
shefalijoshi Feb 12, 2024
b1f1cf3
Merge branch 'redo-pie-chart' of https://github.com/nasa/openmct into…
shefalijoshi Feb 12, 2024
6cbcf7a
Merge branch 'master' into redo-pie-chart
shefalijoshi Feb 13, 2024
729e2b4
Merge branch 'master' into redo-pie-chart
ozyx Feb 21, 2024
5f8aaab
Merge branch 'master' of https://github.com/nasa/openmct into redo-pi…
shefalijoshi Feb 29, 2024
557f8f9
Fix issue where updating progress for pie chart wasn't working till a…
shefalijoshi Mar 1, 2024
651665f
update documentation for clock annotation
unlikelyzero Mar 4, 2024
3acd37c
Update clock annotation in tests
unlikelyzero Mar 4, 2024
a96fbbe
split long testfile
unlikelyzero Mar 4, 2024
c8944dc
driveby missing test
unlikelyzero Mar 4, 2024
8682974
driveby fix flake
unlikelyzero Mar 4, 2024
b68a35a
temp: fix flake and prep for visual test
unlikelyzero Mar 4, 2024
1b4e368
Merge branch 'redo-pie-chart' of https://github.com/nasa/openmct into…
unlikelyzero Mar 4, 2024
20e0973
Fix linting errors
shefalijoshi Mar 4, 2024
08dd7c1
Merge branch 'master' into redo-pie-chart
akhenry Mar 4, 2024
6129034
this should be resolved
unlikelyzero Mar 4, 2024
f516a76
Merge branch 'redo-pie-chart' of https://github.com/nasa/openmct into…
unlikelyzero Mar 4, 2024
4107a9b
these keep popping up
unlikelyzero Mar 4, 2024
998279c
moving some of this around
unlikelyzero Mar 4, 2024
b326577
moving this around
unlikelyzero Mar 4, 2024
217b430
the test
unlikelyzero Mar 4, 2024
7284c47
Merge branch 'master' of https://github.com/nasa/openmct into redo-pi…
shefalijoshi Mar 5, 2024
f891c23
Merge branch 'master' of https://github.com/nasa/openmct into redo-pi…
shefalijoshi Mar 5, 2024
ead0127
Fix imports for tests
shefalijoshi Mar 5, 2024
289465d
no longer need constant
unlikelyzero Mar 5, 2024
3853d17
move to front
unlikelyzero Mar 5, 2024
910b683
Stabalize name
unlikelyzero Mar 5, 2024
b7628e7
test(missionStatus): fix visual test
ozyx Mar 5, 2024
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@percy/playwright": "1.0.4",
"@playwright/test": "1.39.0",
"@types/d3-axis": "3.0.6",
"@types/d3-shape": "3.0.0",
"@types/d3-scale": "4.0.8",
"@types/d3-selection": "3.0.10",
"@types/eventemitter3": "1.2.0",
Expand All @@ -26,6 +27,7 @@
"cspell": "7.3.8",
"css-loader": "6.8.1",
"d3-axis": "3.0.0",
"d3-shape": "3.0.0",
"d3-scale": "4.0.2",
"d3-selection": "3.0.0",
"eslint": "8.56.0",
Expand Down
17 changes: 17 additions & 0 deletions src/plugins/timelist/ExpandedViewItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@
</div>
<div class="c-tli__graphic">
<svg viewBox="0 0 100 100">
<g aria-label="Activity in progress" class="c-tli__graphic__pie">
<circle class="c-svg-progress__bg" r="50" cx="50" cy="50"></circle>
<path ref="progressElement" class="c-svg-progress__progress"></path>
<circle
class="c-svg-progress__ticks"
r="40"
cx="50"
cy="50"
stroke-dasharray="3 7.472"
></circle>
<rect class="c-svg-progress__sweep-hand" x="48" y="18" width="4" height="27"></rect>
</g>
<path
aria-label="Activity complete"
class="c-tli__graphic__check"
Expand Down Expand Up @@ -80,6 +92,7 @@ import _ from 'lodash';

import { TIME_CONTEXT_EVENTS } from '../../api/time/constants.js';
import { CURRENT_CSS_SUFFIX, FUTURE_CSS_SUFFIX, PAST_CSS_SUFFIX } from './constants.js';
import { updateProgress } from './svg-progress.js';

const ITEM_COLORS = {
[CURRENT_CSS_SUFFIX]: '#ffcc00',
Expand Down Expand Up @@ -220,6 +233,10 @@ export default {
},
updateTimestamp(time) {
this.timestamp = time;
const progressElement = this.$refs.progressElement;
if (this.isInProgress && progressElement) {
updateProgress(this.start, this.end, this.timestamp, progressElement);
}
this.formatItemLabel();
},
formatItemLabel() {
Expand Down
55 changes: 55 additions & 0 deletions src/plugins/timelist/svg-progress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const PI = Math.PI; // Use the built-in constant directly
const DEGREES_TO_RADIANS = PI / 180; // Calculate the conversion factor

import { arc } from 'd3-shape';

const SVG_VB_SIZE = 100;
const UPDATE_RATE_MS = 1000; // 1 Hz

function progToDegrees(progVal) {
return (progVal / 100) * 360;

Check warning on line 10 in src/plugins/timelist/svg-progress.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/timelist/svg-progress.js#L10

Added line #L10 was not covered by tests
}

function renderProgress(progressPercent, element) {
let startAngleInDegrees = 0;
let endAngleInDegrees = progToDegrees(progressPercent);

Check warning on line 15 in src/plugins/timelist/svg-progress.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/timelist/svg-progress.js#L14-L15

Added lines #L14 - L15 were not covered by tests
// Check if the arc forms a full circle
const isFullCircle = Math.abs(endAngleInDegrees - startAngleInDegrees) === 360;

Check warning on line 17 in src/plugins/timelist/svg-progress.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/timelist/svg-progress.js#L17

Added line #L17 was not covered by tests

if (isFullCircle) {
endAngleInDegrees--;

Check warning on line 20 in src/plugins/timelist/svg-progress.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/timelist/svg-progress.js#L19-L20

Added lines #L19 - L20 were not covered by tests
}

// Convert angles to radians for calculations
const startAngleInRadians = startAngleInDegrees * DEGREES_TO_RADIANS;
const endAngleInRadians = endAngleInDegrees * DEGREES_TO_RADIANS;

Check warning on line 25 in src/plugins/timelist/svg-progress.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/timelist/svg-progress.js#L24-L25

Added lines #L24 - L25 were not covered by tests

// d3's arc API does the work for us
const progressArc = arc();
progressArc.innerRadius(0);
progressArc.outerRadius(SVG_VB_SIZE / 2);
progressArc.startAngle(startAngleInRadians);
progressArc.endAngle(endAngleInRadians);
element.setAttribute('d', progressArc());

Check warning on line 33 in src/plugins/timelist/svg-progress.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/timelist/svg-progress.js#L28-L33

Added lines #L28 - L33 were not covered by tests
}

export function updateProgress(start, end, timestamp, element) {
const duration = end - start;
const update_per_cycle = 100 / (duration / UPDATE_RATE_MS);
let progressPercent = 0;
if (timestamp > start) {

Check warning on line 40 in src/plugins/timelist/svg-progress.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/timelist/svg-progress.js#L37-L40

Added lines #L37 - L40 were not covered by tests
// Now is after activity start datetime
if (timestamp > end) {
progressPercent = 100;

Check warning on line 43 in src/plugins/timelist/svg-progress.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/timelist/svg-progress.js#L42-L43

Added lines #L42 - L43 were not covered by tests
} else {
progressPercent = (1 - (end - timestamp) / duration) * 100;

Check warning on line 45 in src/plugins/timelist/svg-progress.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/timelist/svg-progress.js#L45

Added line #L45 was not covered by tests
}
}
if (progressPercent < 100) {

Check warning on line 48 in src/plugins/timelist/svg-progress.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/timelist/svg-progress.js#L48

Added line #L48 was not covered by tests
// If the remaining percent is less than update_per_cycle, round up to 100%.
// Otherwise, increment by update_per_cycle.
progressPercent =

Check warning on line 51 in src/plugins/timelist/svg-progress.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/timelist/svg-progress.js#L51

Added line #L51 was not covered by tests
100 - progressPercent < update_per_cycle ? 100 : (progressPercent += update_per_cycle);
}
renderProgress(progressPercent, element);

Check warning on line 54 in src/plugins/timelist/svg-progress.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/timelist/svg-progress.js#L54

Added line #L54 was not covered by tests
}
1 change: 1 addition & 0 deletions src/plugins/timelist/timelist.scss
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@

&__progress {
fill: $colorInProgressFgEm;
transform: translateX(50%) translateY(50%);
}

&__sweep-hand {
Expand Down
Loading