Skip to content

Commit 76dfc54

Browse files
authored
Merge branch 'master' into codex/change-itemindaterange-to-local-helper
2 parents b14beb6 + 2c4f87d commit 76dfc54

8 files changed

Lines changed: 56 additions & 58 deletions

File tree

couchdb-setup.sh

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ upsert_doc() {
1818
fi
1919
}
2020

21-
# Function for insert mock data docs
22-
insert_docs() {
23-
DB=$1
24-
DOC_LOC=$2
25-
curl -H 'Content-Type: application/json' -X POST $COUCHURL/$DB/_bulk_docs -d @$DOC_LOC $PROXYHEADER
26-
}
27-
2821
# Function to add databases
2922
insert_dbs() {
3023
DBS=$1
@@ -68,25 +61,6 @@ else
6861
COUCHURL=http://$COUCHUSER:$COUCHPASSWORD@$HOST:$PORT
6962
fi
7063

71-
# Adding attachments to database documents
72-
# To add attachment added two file (resources-mock.json and resources-attachment-mockup.json)
73-
# Ids must match between two files
74-
insert_attachments() {
75-
DB=$1
76-
DOC_LOC=$2
77-
# Use echo $(<$DOC_LOC) to be able to run in Windows
78-
INPUTS=$(echo $(<$DOC_LOC) | jq -c '.[]')
79-
for i in $INPUTS
80-
do
81-
ID=$(echo $i | jq -r '.doc_id' )
82-
FILE_NAME=$(echo $i | jq -r '.file_name')
83-
FILE_LOCATION=$(echo $i | jq -r '.file_location')
84-
FILE_TYPE=$(echo $i | jq -r '.file_type')
85-
REV=$(curl $COUCHURL/$DB/$ID | jq -r '._rev' $PROXYHEADER)
86-
curl -X PUT $COUCHURL/$DB/$ID/$FILE_NAME?rev=$REV --data-binary @$FILE_LOCATION -H Content-Type:$FILE_TYPE $PROXYHEADER
87-
done
88-
}
89-
9064
# Reads one JSON file to update multiple databases
9165
# JSON file needs a 'dbName' field with a string and
9266
# a 'json' field with the JSON to be updated

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"license": "AGPL-3.0",
44
"version": "0.22.68",
55
"myplanet": {
6-
"latest": "v0.54.19",
6+
"latest": "v0.54.54",
77
"min": "v0.52.45"
88
},
99
"scripts": {

src/app/home/home-router.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { NewsListComponent } from '../news/news-list.component';
1414
import { AuthService } from '../shared/auth-guard.service';
1515
import { UnsavedChangesGuard } from '../shared/unsaved-changes.guard';
1616

17-
export function dashboardPath(route): string {
17+
function dashboardPath(route): string {
1818
return `${myDashboardRoute}/${route}`;
1919
}
2020

src/app/manager-dashboard/reports/reports-health.component.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Component, Input, OnChanges, EventEmitter, Output, ViewChild } from '@angular/core';
2-
import { Chart, ChartConfiguration, LineController } from 'chart.js';
2+
import type { ChartConfiguration } from 'chart.js';
3+
import { loadChart } from '../../shared/chart-utils';
34
import { StateService } from '../../shared/state.service';
45
import { HealthService } from '../../health/health.service';
5-
import { generateWeeksArray, filterByDate, weekDataLabels, scaleLabel } from './reports.utils';
6+
import { generateWeeksArray, filterByDate, weekDataLabels } from './reports.utils';
67
import { ReportsService } from './reports.service';
78
import { millisecondsToDay } from '../../meetups/constants';
89
import { dedupeShelfReduce, styleVariables } from '../../shared/utils';
@@ -14,8 +15,6 @@ import { MatSelect } from '@angular/material/select';
1415
import { MatOption } from '@angular/material/autocomplete';
1516
import { ReportsDetailActivitiesComponent } from './reports-detail-activities.component';
1617

17-
Chart.register(LineController);
18-
1918
@Component({
2019
selector: 'planet-reports-health',
2120
templateUrl: './reports-health.component.html',
@@ -130,7 +129,10 @@ export class ReportsHealthComponent implements OnChanges {
130129
});
131130
}
132131

133-
setChart({ data, chartName }) {
132+
async setChart({ data, chartName }) {
133+
const { Chart } = await loadChart([
134+
'LineController', 'LineElement', 'PointElement', 'CategoryScale', 'LinearScale', 'Title', 'Tooltip'
135+
]);
134136
const updateChart = this.charts.find(chart => chart.canvas.id === chartName);
135137
if (updateChart) {
136138
updateChart.data = data;
@@ -141,6 +143,7 @@ export class ReportsHealthComponent implements OnChanges {
141143
setTimeout(() => this.setChart({ data, chartName }));
142144
return;
143145
}
146+
const axisTitleFont = { size: 12, weight: 'bold' as const };
144147
const chartConfig: ChartConfiguration<'line'> = {
145148
type: 'line',
146149
data,
@@ -153,9 +156,13 @@ export class ReportsHealthComponent implements OnChanges {
153156
scales: {
154157
y: {
155158
type: 'linear',
156-
ticks: { precision: 0 }
159+
ticks: { precision: 0 },
160+
title: { display: true, text: $localize`Diagnoses`, font: axisTitleFont }
157161
},
158-
x: { title: { display: true, text: 'Week of' } }
162+
x: {
163+
type: 'category',
164+
title: { display: true, text: $localize`Week of`, font: axisTitleFont }
165+
}
159166
},
160167
}
161168
};

src/app/manager-dashboard/reports/reports.utils.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ export const generateWeeksArray = (dateRange: { startDate: Date, endDate: Date }
124124
return weeks;
125125
};
126126

127-
export const scaleLabel = (labelString: string) => ({
128-
display: true, labelString, fontSize: 12, fontStyle: 'bold'
129-
});
130-
131127
export const sortingOptionsMap = {
132128
'logins': [
133129
{ name: $localize`Login Time Ascending`, value: 'loginTimeAsc' },

src/app/shared/chart-utils.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,17 @@ export async function loadChart(keys: RegisterableKey[] = []): Promise<ChartJsMo
3939
}
4040

4141
export function createChartCanvas(width = 300, height = 400): { canvas: HTMLCanvasElement; ctx: CanvasRenderingContext2D | null } {
42+
const dpr = typeof window !== 'undefined' ? (window.devicePixelRatio || 1) : 1;
4243
const canvas = document.createElement('canvas');
43-
canvas.width = width;
44-
canvas.height = height;
45-
return { canvas, ctx: canvas.getContext('2d') };
44+
canvas.width = width * dpr;
45+
canvas.height = height * dpr;
46+
canvas.style.width = `${width}px`;
47+
canvas.style.height = `${height}px`;
48+
const ctx = canvas.getContext('2d');
49+
if (ctx) {
50+
ctx.scale(dpr, dpr);
51+
}
52+
return { canvas, ctx };
4653
}
4754

4855
export function renderNoDataPlaceholder(ctx: CanvasRenderingContext2D, canvas: HTMLCanvasElement, message = 'No data available'): string {

src/app/submissions/submissions.service.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -588,31 +588,35 @@ export class SubmissionsService {
588588
}
589589

590590
async generateChartImage(data: any): Promise<string> {
591-
const { Chart } = await loadChart([
592-
'BarController', 'DoughnutController', 'BarElement', 'ArcElement', 'LinearScale', 'CategoryScale', 'Legend', 'Tooltip', 'Title'
593-
]);
594-
const { canvas, ctx } = createChartCanvas(300, 400);
595591
const isBar = data.chartType === 'bar';
596592
const isRatingScale = data.isRatingScale || false;
593+
const { Chart } = await loadChart(isBar
594+
? [ 'BarController', 'BarElement', 'LinearScale', 'CategoryScale', 'Legend', 'Tooltip', 'Title' ]
595+
: [ 'DoughnutController', 'ArcElement', 'Legend', 'Tooltip', 'Title' ]
596+
);
597+
const { canvas, ctx } = createChartCanvas(300, 400);
597598

598599
if (!ctx) {
599600
return '';
600601
}
601602
const hasData = Array.isArray(data.data) && data.data.some((value: number) => Number(value) > 0);
602603

603604
if (!hasData) {
604-
renderNoDataPlaceholder(ctx, canvas, 'No data available');
605+
return renderNoDataPlaceholder(ctx, canvas, 'No data available');
605606
}
606607

607608
const maxCount = Math.max(...data.data);
609+
const axisTitleFont = { size: 12, weight: 'bold' as const };
610+
const xAxisText = isRatingScale ? $localize`Rating` : $localize`Choice`;
611+
const yAxisText = isRatingScale ? $localize`Number of responses` : $localize`% of responders`;
612+
const backgroundColor = data.labels.map((_, i) => CHART_COLORS[i % CHART_COLORS.length]);
608613
const chartConfig: ChartConfiguration<'bar' | 'doughnut', number[], string> = {
609614
type: isBar ? 'bar' : 'doughnut',
610615
data: {
611616
labels: data.labels,
612617
datasets: [ {
613618
data: data.data,
614-
label: isRatingScale ? 'selection/choices(1-9)' : (isBar ? '% of responders/selection' : undefined),
615-
backgroundColor: CHART_COLORS
619+
backgroundColor
616620
} ]
617621
},
618622
options: {
@@ -621,19 +625,24 @@ export class SubmissionsService {
621625
indexAxis: 'x',
622626
plugins: {
623627
legend: {
624-
display: true,
628+
display: !isBar,
625629
labels: {
626-
boxWidth: isBar ? 0 : 50,
627-
boxHeight: isBar ? 0 : 20
630+
boxWidth: 50,
631+
boxHeight: 20
628632
}
629633
}
630634
},
631635
scales: isBar ? {
636+
x: {
637+
type: 'category',
638+
title: { display: true, text: xAxisText, font: axisTitleFont }
639+
},
632640
y: {
633641
type: 'linear',
634642
beginAtZero: true,
635643
max: isRatingScale ? maxCount > 0 ? Math.ceil(maxCount / 10) * 10 : 10 : 100,
636-
ticks: { precision: 0, stepSize: 2 }
644+
ticks: { precision: 0 },
645+
title: { display: true, text: yAxisText, font: axisTitleFont }
637646
}
638647
} : {},
639648
animation: false
@@ -644,11 +653,16 @@ export class SubmissionsService {
644653
try {
645654
chart.update();
646655

656+
ctx.fillStyle = '#000000';
657+
ctx.textAlign = 'center';
658+
ctx.textBaseline = 'middle';
659+
ctx.font = '12px sans-serif';
660+
647661
if (isBar && data.userCounts) {
648662
chart.getDatasetMeta(0).data.forEach((bar, index) => {
649663
const count = data.userCounts[index];
650664
if (count > 0) {
651-
ctx.fillText(`${count}`, bar.x - 2.5 , bar.y);
665+
ctx.fillText(`${count}`, bar.x, bar.y - 6);
652666
}
653667
});
654668
} else {
@@ -658,7 +672,7 @@ export class SubmissionsService {
658672
const percentage = total > 0 ? ((count / total) * 100).toFixed(1) : '0';
659673
if (count > 0) {
660674
const pos = element.tooltipPosition();
661-
ctx.fillText(`${count}(${percentage}%)`, pos.x - 15, pos.y);
675+
ctx.fillText(`${count} (${percentage}%)`, pos.x, pos.y);
662676
}
663677
});
664678
}

src/app/teams/teams.utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
export const memberCompare = (member1, member2) => member1.userId === member2.userId && member1.userPlanetCode === member2.userPlanetCode;
2-
3-
export const memberNameCompare = (member1, member2) => {
1+
const memberNameCompare = (member1, member2) => {
42
const memberName = (member) =>
53
(member.userDoc && member.userDoc.doc.lastName) ||
64
(member.userId || '').split(':')[1] ||
@@ -9,6 +7,8 @@ export const memberNameCompare = (member1, member2) => {
97
return memberName(member1).localeCompare(memberName(member2));
108
};
119

10+
export const memberCompare = (member1, member2) => member1.userId === member2.userId && member1.userPlanetCode === member2.userPlanetCode;
11+
1212
export const memberSort = (member1, member2, leader) => memberCompare(member1, leader) ?
1313
-1 :
1414
memberCompare(member2, leader) ?

0 commit comments

Comments
 (0)