Skip to content

Commit

Permalink
Merge pull request #436 from Pewillia/356-line-chart-yyyy-date-format-b
Browse files Browse the repository at this point in the history
fix(356) add  dates in YYYY format
  • Loading branch information
jolevesq authored Jul 29, 2022
2 parents c84ecad + aa8da50 commit 06f3907
Show file tree
Hide file tree
Showing 5 changed files with 1,823 additions and 7 deletions.
14 changes: 8 additions & 6 deletions chart/src/chart-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,14 @@ export class ChartLoader {
} else if (data.type === 'combine') {
let parseCombValues = parse.replace(new RegExp(data.regex, 'g'), '*').split('*').filter(Boolean);
let numberPattern = /\d+/g;
parsed.isDateTimeObjForXAxis = (parseCombValues.filter(q=>{
let time: any = parseInt(q.split('T')[1].split(data.split)[0].match(numberPattern).join(''));
if (time > 0) {
return true;
}
})).length > 0;
if (parseCombValues.includes("T")) {
parsed.isDateTimeObjForXAxis = (parseCombValues.filter(q => {
let time: any = parseInt(q.split('T')[1].split(data.split)[0].match(numberPattern).join(''));
if (time > 0) {
return true;
}
})).length > 0;
}
for (let val of parseCombValues) {
let splitVal = val.split(data.split);

Expand Down
8 changes: 7 additions & 1 deletion chart/src/chart-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@ export class ChartParser {

data.features.forEach((feat: any) => {
if (typeof attrValue === 'undefined' || attrValue === feat.attributes[layerConfig.data[index].values]) {
values.push(`(${new Date(feat.attributes[layerConfig.data[index].date]).toJSON()},${feat.attributes[layerConfig.data[index].measure]})`);
if (String(feat.attributes[layerConfig.data[index].date]).length === 4) {
feat.attributes[layerConfig.data[index].date] = Number(feat.attributes[layerConfig.data[index].date]);
}
if (String(feat.attributes[layerConfig.data[index].date]).length === 4)
values.push(`(${(feat.attributes[layerConfig.data[index].date])},${feat.attributes[layerConfig.data[index].measure]})`)
else
values.push(`(${new Date(feat.attributes[layerConfig.data[index].date]).toJSON()},${feat.attributes[layerConfig.data[index].measure]})`);
}
});

Expand Down
2 changes: 2 additions & 0 deletions chart/src/samples/chart-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<option value="Bar-chart-link.json">11. Substance Selector</option>
<option value="Environmental_dosimetry_linechart_en.json">12. Environmental dosimetry linechart.json</option>
<option value="fpsn_chart_en.json">13. Real-time Environmental Radioactivity Monitoring in Canada</option>
<option value="v6-1_line_date_chart.json">14. YYYY date x axis Environmental Radioactivity Monitoring in Canada</option>
<option value="v6-1_line_linear_chart.json">15. YYYY linear x axis Environmental Radioactivity Monitoring in Canada</option>
</select>
</div>
</section>
Expand Down
Loading

0 comments on commit 06f3907

Please sign in to comment.