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

64 lines
1.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 === "-" ? "-" : StringUtil.printMonthDay(date)
);
if(bestRecord === "")
return;
this.drawText(
posX, posY - Chart.CHART_HEIGHT - Chart.CHART_RECORD_OFFSET_Y,
StringUtil.getRecordTextWithoutUnit(bestRecord) + StringUtil.getScoreUnit(sessionStorageManager.playingAppID)
);
// chart
this.chartGraphics.lineStyle(50, 0xdddddd, 1);
this.chartGraphics.moveTo(posX, posY);
this.chartGraphics.lineTo(posX, posY - Chart.CHART_HEIGHT * ( (bestRecord - min) / (max - min) ));
}
Chart.prototype.drawText = function(posX, posY, text) {
var style = { font: "24px 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.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;