Skip to content

Commit

Permalink
refactor: remove logging
Browse files Browse the repository at this point in the history
  • Loading branch information
rasulov1337 committed Dec 6, 2024
1 parent d21d7b9 commit 70d8e3a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
1 change: 0 additions & 1 deletion src/components/AuthPopup/AuthPopup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ class AuthPopup {
}

#setFailureMessage(message: string): void {
console.log('???');
const failureMessageElem = document.querySelector(
'.auth-modal__failure-message'
);
Expand Down
3 changes: 0 additions & 3 deletions src/components/ProfileData/ProfileData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,12 @@ class ProfileData {
);

reviews.forEach((reviewData) => {
console.log(reviewData);
reviewData.createdAt = this.#dataToString(reviewData.createdAt);
const review = new ReviewCard(reviewData);
review.render(this.#content);
});
} else {
const noReviews = new NoReviews(this.#isMyProfile, () => {
console.log('there');
clearPage('form');
this.#content.replaceChildren();
this.#renderReviewForm();
Expand Down Expand Up @@ -639,7 +637,6 @@ class ProfileData {
reviewsGraphic.render(this.#content);
} else {
const noReviews = new NoReviews(this.#isMyProfile, () => {
console.log('there');
clearPage('form');
this.#content.replaceChildren();
this.#renderReviewForm();
Expand Down
55 changes: 33 additions & 22 deletions src/components/ReviewsGraphic/ReviewsGraphic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ interface AdditionalInfo {
class ReviewsGraphic {
#data: Array<GraphicPoint>;

constructor(data: Array<GraphicPoint>){
constructor(data: Array<GraphicPoint>) {
this.#data = data;
console.log(this.#data);

this.#registerHelper();
}
Expand All @@ -32,14 +31,22 @@ class ReviewsGraphic {
}

#getAdditionalInfo(): AdditionalInfo {
const sortedData = [...this.#data].sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime());
const sortedData = [...this.#data].sort(
(a, b) => new Date(a.date).getTime() - new Date(b.date).getTime()
);

const addInfo: AdditionalInfo = {
totalRatings: this.#data.length,
firstDate: sortedData[0]?.date || 'Нет данных',
lastDate: sortedData[sortedData.length - 1]?.date || 'Нет данных',
highestRating: Math.max(...this.#data.map(point => point.rating), 0),
lowestRating: Math.min(...this.#data.map(point => point.rating), 5)
highestRating: Math.max(
...this.#data.map((point) => point.rating),
0
),
lowestRating: Math.min(
...this.#data.map((point) => point.rating),
5
),
};

return addInfo;
Expand All @@ -52,28 +59,29 @@ class ReviewsGraphic {
console.error('Canvas context not available');
return;
}

// Размеры графика
const padding = 50; // Отступы от краёв
const canvasWidth = canvas.width = 700; // Ширина холста
const canvasHeight = canvas.height = 400; // Высота холста
const canvasWidth = (canvas.width = 700); // Ширина холста
const canvasHeight = (canvas.height = 400); // Высота холста

const graphWidth = canvasWidth - padding * 2;
const graphHeight = canvasHeight - padding * 2;

// Шаг по X зависит от общего количества точек
const totalPoints = this.#data.length;
const xStep = graphWidth / (totalPoints - 1);

// Границы по Y
const minRating = 1;
const maxRating = 5;
const yStep = graphHeight / (maxRating - minRating);

// Функции для преобразования координат
const toXCoord = (index: number) => padding + index * xStep;
const toYCoord = (rating: number) => canvasHeight - padding - (rating - minRating) * yStep;

const toYCoord = (rating: number) =>
canvasHeight - padding - (rating - minRating) * yStep;

// Сетка
ctx.strokeStyle = '#e0e0e0';
ctx.lineWidth = 1;
Expand All @@ -84,15 +92,15 @@ class ReviewsGraphic {
ctx.lineTo(canvasWidth - padding, y);
ctx.stroke();
}

for (let i = 0; i < totalPoints; i++) {
const x = toXCoord(i);
ctx.beginPath();
ctx.moveTo(x, padding);
ctx.lineTo(x, canvasHeight - padding);
ctx.stroke();
}

// Оси
ctx.strokeStyle = '#000';
ctx.lineWidth = 2;
Expand All @@ -101,22 +109,26 @@ class ReviewsGraphic {
ctx.lineTo(padding, canvasHeight - padding); // Ось Y
ctx.lineTo(canvasWidth - padding, canvasHeight - padding); // Ось X
ctx.stroke();

// Метки по оси Y
ctx.fillStyle = '#000';
ctx.font = '12px Arial';
for (let i = 0; i <= maxRating - minRating; i++) {
const y = toYCoord(i + minRating);
ctx.fillText((i + minRating).toString(), padding - 30, y + 5);
}

// Метки по оси X
ctx.font = '10px Arial';
for (let i = 0; i < totalPoints; i++) {
const x = toXCoord(i);
ctx.fillText(this.#data[i].date, x - 20, canvasHeight - padding + 20);
ctx.fillText(
this.#data[i].date,
x - 20,
canvasHeight - padding + 20
);
}

// Рисуем линии, соединяющие точки
ctx.strokeStyle = '#ffa552';
ctx.lineWidth = 2;
Expand Down Expand Up @@ -165,7 +177,6 @@ class ReviewsGraphic {
}
ctx.stroke(); // Рисуем соединяющую линию среднего значения
}


async render(parent: HTMLDivElement) {
const addInfo = this.#getAdditionalInfo();
Expand All @@ -175,4 +186,4 @@ class ReviewsGraphic {
}
}

export default ReviewsGraphic;
export default ReviewsGraphic;
1 change: 0 additions & 1 deletion src/pages/AdListPage/AdListPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ function AdListPage(data: HorizontalAdCardData[], isHost: boolean) {
router.navigateTo(`/ads/?id=${uuid}`),
onEdit: async (uuid: string) => {
const data = await ApiClient.getAd(uuid);
console.log(data);
const page = new EditAdvertPage({
action: 'edit',
data,
Expand Down
2 changes: 0 additions & 2 deletions src/pages/CityPage/CityPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class CityPage {
const infoResponse = await ApiClient.getCity(name);
if (infoResponse.ok) {
const data = await infoResponse.json();
console.log(data);
this.#name = data.city['title'];
this.#description = data.city['description'];
this.#photo = data.city['image'];
Expand Down Expand Up @@ -69,7 +68,6 @@ class CityPage {
#renderFilter(pageContent: HTMLDivElement): void {
const filter = new Filter(async (filters) => {
filters.location = this.#queryName;
console.log(filters);
const data = await ApiClient.getAds(filters);
this.#places = data;
document.querySelector('.advert')!.remove();
Expand Down

0 comments on commit 70d8e3a

Please sign in to comment.