Skip to content

Commit

Permalink
更新googlemap charts
Browse files Browse the repository at this point in the history
  • Loading branch information
estea8968 committed Oct 2, 2023
1 parent 555a516 commit b8ad046
Show file tree
Hide file tree
Showing 7 changed files with 1,758 additions and 427 deletions.
2 changes: 1 addition & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="google" value="notranslate">
<link rel="shortcut icon" href="static/favicon.ico">
<title>OSEP_scratch 1120825</title>
<title>OSEP_scratch 1121002</title>

</head>
<body>
Expand Down
2,025 changes: 1,627 additions & 398 deletions app/lib.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/lib.min.js.map

Large diffs are not rendered by default.

87 changes: 72 additions & 15 deletions source/scratch-vm/src/extensions/scratch3_chart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,26 @@ class chart {
text: msg.showAxisTitle[theLocale]
},
'---',
{
opcode: 'showChart2',
blockType: BlockType.COMMAND,
arguments: {
n: {
type: ArgumentType.STRING,
defaultValue: '2',
},
data: {
type: ArgumentType.STRING,
defaultValue: 'data',
},
chart: {
type: ArgumentType.STRING,
menu: 'chartSelectField',
defaultValue: '1',
},
},
text: msg.showChart2[theLocale]
},
{
opcode: 'showChart',
blockType: BlockType.COMMAND,
Expand Down Expand Up @@ -236,14 +256,35 @@ class chart {
this.showRadarChart();
}

showLineChart() {
showChart2(args) {
var n = args.n;
var chart = args.chart;
this.chartData = args.data;

if (chart == "1")
this.showLineChart(n);
if (chart == "2")
this.showBarChart(n);
if (chart == "3")
this.showPieChart(n);
if (chart == "4")
this.showDoughnutChart(n);
if (chart == "5")
this.showRadarChart(n);
}

showLineChart(n = 1) {
var dataSet = JSON.parse(this.chartData);
var keys = Object.keys(dataSet[0]);
var keysLenght = keys.length;
var dataLength = dataSet.length;
var column = [];

if (n > keysLenght - 1)
return alert("超出試算表的欄位範圍");

for (var i = 0; i < dataLength; i++)
column.push(dataSet[i][keys[0]]);
column.push(dataSet[i][keys[n - 1]]);

var width = screen.width / 2;
var height = screen.height / 2;
Expand All @@ -266,7 +307,7 @@ class chart {
openWindow.document.write(`];`);

openWindow.document.write(`var data = { labels:labels, datasets:[`);
for (var i = 1; i < keys.length; i++) {
for (var i = n; i < keys.length; i++) {
var label = keys[i];
var data = [];
for (var j = 0; j < dataLength; j++)
Expand Down Expand Up @@ -335,14 +376,18 @@ class chart {
openWindow.document.close();
}

showBarChart() {
showBarChart(n = 1) {
var dataSet = JSON.parse(this.chartData);
var keys = Object.keys(dataSet[0]);
var keysLenght = keys.length;
var dataLength = dataSet.length;
var column = [];

if (n > keysLenght)
return alert("超出試算表的欄位範圍");

for (var i = 0; i < dataLength; i++)
column.push(dataSet[i][keys[0]]);
column.push(dataSet[i][keys[n - 1]]);

var width = screen.width / 2;
var height = screen.height / 2;
Expand All @@ -365,7 +410,7 @@ class chart {
openWindow.document.write(`];`);

openWindow.document.write(`var data = { labels:labels, datasets:[`);
for (var i = 1; i < keys.length; i++) {
for (var i = n; i < keys.length; i++) {
var label = keys[i];
var data = [];
for (var j = 0; j < dataLength; j++)
Expand Down Expand Up @@ -434,14 +479,18 @@ class chart {
openWindow.document.close();
}

showPieChart() {
showPieChart(n = 1) {
var dataSet = JSON.parse(this.chartData);
var keys = Object.keys(dataSet[0]);
var keysLenght = keys.length;
var dataLength = dataSet.length;
var column = [];

if (n > keysLenght)
return alert("超出試算表的欄位範圍");

for (var i = 0; i < dataLength; i++)
column.push(dataSet[i][keys[0]]);
column.push(dataSet[i][keys[n - 1]]);

var width = screen.width / 2;
var height = screen.height;
Expand All @@ -468,7 +517,7 @@ class chart {
openWindow.document.write(`];`);

openWindow.document.write(`var data = { labels:label, datasets:[`);
for (var i = 1; i < keys.length; i++) {
for (var i = n; i < keys.length; i++) {
var label = keys[i];
var data = [];
for (var j = 0; j < dataLength; j++)
Expand Down Expand Up @@ -516,14 +565,18 @@ class chart {
openWindow.document.close();
}

showDoughnutChart() {
showDoughnutChart(n = 1) {
var dataSet = JSON.parse(this.chartData);
var keys = Object.keys(dataSet[0]);
var keysLenght = keys.length;
var dataLength = dataSet.length;
var column = [];

if (n > keysLenght)
return alert("超出試算表的欄位範圍");

for (var i = 0; i < dataLength; i++)
column.push(dataSet[i][keys[0]]);
column.push(dataSet[i][keys[n - 1]]);

var width = screen.width / 2;
var height = screen.height;
Expand Down Expand Up @@ -551,7 +604,7 @@ class chart {
openWindow.document.write(`];`);

openWindow.document.write(`var data = { labels:label, datasets:[`);
for (var i = 1; i < keys.length; i++) {
for (var i = n; i < keys.length; i++) {
var label = keys[i];
var data = [];
for (var j = 0; j < dataLength; j++)
Expand Down Expand Up @@ -597,14 +650,18 @@ class chart {
openWindow.document.close();
}

showRadarChart() {
showRadarChart(n = 1) {
var dataSet = JSON.parse(this.chartData);
var keys = Object.keys(dataSet[0]);
var keysLenght = keys.length;
var dataLength = dataSet.length;
var column = [];

if (n > keysLenght)
return alert("超出試算表的欄位範圍");

for (var i = 0; i < dataLength; i++)
column.push(dataSet[i][keys[0]]);
column.push(dataSet[i][keys[n - 1]]);

var width = screen.width / 2;
var height = screen.height;
Expand All @@ -627,7 +684,7 @@ class chart {
openWindow.document.write(`];`);

openWindow.document.write(`var data = { labels:label, datasets:[`);
for (var i = 1; i < keys.length; i++) {
for (var i = n; i < keys.length; i++) {
var label = keys[i];
var data = [];
for (var j = 0; j < dataLength; j++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export const showChart = {
'zh-tw': '讀取資料[data]顯示[chart]'
};

export const showChart2 = {
'en': 'read data [data] from column [n] show [chart]',
'zh-tw': '從第[n]欄讀取資料[data]顯示[chart]'
};

export const lineChart = {
'en': 'line chart ',
'zh-tw': '折線圖'
Expand Down
47 changes: 41 additions & 6 deletions source/scratch-vm/src/extensions/scratch3_googleMap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class googleMap {

this.recordCoordinate = [];

this.name = "location";
this.longitude = "longitude";
this.latitude = "latitude";
this.note = "descriptions";
}

onclose() {
Expand Down Expand Up @@ -117,6 +121,29 @@ class googleMap {
text: msg.showMarker[theLocale]
},
'---',
{
opcode: 'setFieldNames',
blockType: BlockType.COMMAND,
arguments: {
name: {
type: ArgumentType.STRING,
defaultValue: msg.name[theLocale]
},
longitude: {
type: ArgumentType.STRING,
defaultValue: msg.longitude[theLocale]
},
latitude: {
type: ArgumentType.STRING,
defaultValue: msg.latitude[theLocale]
},
note: {
type: ArgumentType.STRING,
defaultValue: msg.note[theLocale]
},
},
text: msg.setFieldNames[theLocale]
},
{
opcode: 'recordMarker2',
blockType: BlockType.COMMAND,
Expand Down Expand Up @@ -156,7 +183,7 @@ class googleMap {
showMarker(args) {
var width = screen.width / 2;
var height = screen.height / 2;
var openGoogleMapWindow = window.open('', 'Google Map 擴充功能', 'width=' + width + ', height=' + height + ', toolbar=no, scrollbars=no, menubar=no, location=no, status=no');
var openGoogleMapWindow = window.open('', 'Google Map 擴充功能', 'width=' + width + ', height=' + height + ', toolbar=no, scrollbars=no, menubar=no, name=no, status=no');

openGoogleMapWindow.document.write(`
<head>
Expand Down Expand Up @@ -307,6 +334,13 @@ class googleMap {
this.recordCoordinate = [];
}

setFieldNames(args){
this.name = args.name;
this.longitude = args.longitude;
this.latitude = args.latitude;
this.note = args.note;
}

recordMarker2(args) {
var data = JSON.parse(args.data);

Expand Down Expand Up @@ -362,11 +396,12 @@ class googleMap {
var lat = data[i]["緯度"];
var remark = data[i]["備註"] == undefined ? "" : data[i]["備註"];
}
if (data[i]["location"]) {
var label = data[i]["location"];
var lng = data[i]["longitude"];
var lat = data[i]["latitude"];
var remark = data[i]["descriptions"] == undefined ? "" : data[i]["descriptions"];

if (data[i][this.name]) {
var label = data[i][this.name];
var lng = data[i][this.longitude];
var lat = data[i][this.latitude];
var remark = data[i][this.note] == undefined ? "" : data[i][this.note];
}
openGoogleMapWindow.document.write('{label:"' + label + '",lat:' + lat + ',lng:' + lng + ',remark:"' + remark + '"},');
}
Expand Down
17 changes: 11 additions & 6 deletions source/scratch-vm/src/extensions/scratch3_googleMap/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,23 @@ export const showMarker ={
'zh-tw': '顯示在 Google 地圖'
}

export const setFieldNames ={
'en': 'set Name [name], Longitude [longitude], Latitude [latitude], and Description [note] fields',
'zh-tw': '設定名稱[name]經度[longitude]緯度[latitude]及備註[note]等欄位名稱'
}

export const recordMarker2 ={
'en': 'import data [data] and show on google maps',
'zh-tw': '從資料[data]標記座標顯示在 Google 地圖'
}

export const tmpData = {
'en': 'location, longitude, latitude, descriptions',
'en': 'name, longitude, latitude, note',
'zh-tw': '名稱,經度,緯度,備註'
}

export const location = {
'en': 'location',
export const name = {
'en': 'name',
'zh-tw': '名稱'
}

Expand All @@ -40,10 +45,10 @@ export const longitude = {

export const latitude = {
'en': 'latitude',
'zh-tw': '緯度,備註'
'zh-tw': '緯度'
}

export const descriptions = {
'en': 'descriptions',
export const note = {
'en': 'note',
'zh-tw': '備註'
}

0 comments on commit b8ad046

Please sign in to comment.