Files
chocomae/src/game/lib/chart.js
T

97 lines
2.8 KiB
JavaScript

function Chart() {
this.chartGraphics = game.add.graphics(0, 0);
}
Chart.prototype.printChartBaseLine = function() {
this.chartGraphics.lineStyle(3, 0xffd900, 1);
this.chartGraphics.moveTo(100, Chart.CHART_LINE_Y);
this.chartGraphics.lineTo(game.world.width - 100, Chart.CHART_LINE_Y);
}
Chart.prototype.drawRecordGraph = function(index, date, bestRecord, min, max) {
var reverseIndex = (Chart.CHART_COUNT - 1) - index;
var posX = Chart.CHART_LINE_START_X + Chart.CHART_GRAPH_OFFSET_X + reverseIndex * Chart.CHART_GAP_PX;
var posY = Chart.CHART_LINE_Y;
this.drawText(
posX, posY + Chart.CHART_DATE_OFFSET_Y,
date === "-" ? "-" : DateUtil.printMonthDay(date)
);
if(bestRecord === "")
return;
var recordTextPosY = posY - Chart.CHART_HEIGHT - Chart.CHART_RECORD_OFFSET_Y;
// var absRecordValue = Math.abs(bestRecord);
var absRecordValue = bestRecord < 0 ? -1 * bestRecord : bestRecord;
// var absRecordValue = Math.abs(Math.floor(bestRecord));
var recordWithUnit = RecordUtil.getRecordValueWithUnit(absRecordValue, sessionStorageManager.getPlayingAppID());
if(bestRecord >= 0) {
this.drawText(posX, recordTextPosY, recordWithUnit);
} else {
// recordWithUnit = recordWithUnit + "/실격";
recordWithUnit = "실격/" + recordWithUnit;
this.drawDisqualificationText(posX, recordTextPosY, recordWithUnit);
}
// chart
var chartColor = 0xffffff;
if(bestRecord >= 0)
chartColor = 0xdddddd;
else
chartColor = 0xffaaaa;
if(max < absRecordValue)
max = absRecordValue * 1.1;
this.chartGraphics.lineStyle(50, chartColor, 1);
this.chartGraphics.moveTo(posX, posY);
this.chartGraphics.lineTo(posX, posY - Chart.CHART_HEIGHT * ( (absRecordValue - min) / (max - min) ));
console.log("absRecordValue : " + absRecordValue);
console.log("min : " + min);
console.log("max : " + max);
}
Chart.prototype.drawText = function(posX, posY, text) {
var style = { font: "22px Arial", fill: "#fff", align: "left", boundsAlignH: "center", boundsAlignV: "middle" };
var textObject = game.add.text(
posX, posY,
text, style
);
textObject.anchor.set(0.5);
textObject.stroke = "#333";
textObject.strokeThickness = 3;
return textObject;
}
Chart.prototype.drawDisqualificationText = function(posX, posY, text) {
var style = { font: "22px Arial", fill: "#faa", align: "left", boundsAlignH: "center", boundsAlignV: "middle" };
var textObject = game.add.text(
posX, posY,
text, style
);
textObject.anchor.set(0.5);
textObject.stroke = "#333";
textObject.strokeThickness = 3;
return textObject;
}
Chart.prototype.getFontStyle = function() {
return { font: "32px Arial", fill: "#fff" };
}
Chart.CHART_COUNT = 7;
Chart.CHART_LINE_START_X = 100;
Chart.CHART_LINE_Y = 648;
Chart.CHART_GAP_PX = 120;
Chart.CHART_HEIGHT = 120;
Chart.CHART_GRAPH_OFFSET_X = 50;
Chart.CHART_DATE_OFFSET_Y = 20;
Chart.CHART_RECORD_OFFSET_Y = 30;