Skip to content

Commit ef4d82d

Browse files
committed
combine multiple data sources in code-viewer
1 parent ee79b4b commit ef4d82d

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

browser/tasks/Transformer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,23 +806,23 @@ class PackageDependency {
806806
}
807807

808808
class CodeViewer {
809-
public path: string;
810809
public hasRelativeAssetsUrls: boolean;
811-
public content: string;
812810
public isMain: boolean;
811+
public path: string;
813812
public fileExtension: string;
814813
public fileHeader: string;
814+
public content: string;
815815

816816
constructor(filePath: string, content: string, fileExtension: string, fileHeader: string, isMain: boolean) {
817817

818818
let jsonContent = content;
819819
// jsonContent = jsonContent.replace(/\/\//g, "/");
820820

821821
this.hasRelativeAssetsUrls = false;
822-
this.path = filePath;
823-
this.content = jsonContent;
824822
this.isMain = isMain;
825823
this.fileExtension = fileExtension;
826824
this.fileHeader = fileHeader;
825+
this.path = filePath;
826+
this.content = jsonContent;
827827
}
828828
}

browser/tasks/gulp-samples.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var sampleSource = [
4040
// igConfig.SampleCopyPath + '/charts/data-chart/chart-performance/package.json',
4141
// igConfig.SampleCopyPath + '/charts/financial-chart/high-frequency/package.json',
4242
// igConfig.SampleCopyPath + '/charts/financial-chart/high-volume/package.json',
43+
// igConfig.SampleCopyPath + '/charts/data-chart/data-annotation-multiple-with-stocks/package.json',
4344

4445
// including samples for specific components:
4546
// igConfig.SampleCopyPath + '/charts/category-chart/**/package.json',
@@ -636,6 +637,7 @@ function updateCodeViewer(cb) {
636637

637638
var content = "{\r\n \"sampleFiles\":\r\n";
638639

640+
var dataFiles = [];
639641
var contentItems = [];
640642
var tsxItem = new CodeViewer(sample.SampleFilePath, sample.SampleFileSourceCode, "tsx", "tsx", true);
641643

@@ -650,10 +652,26 @@ function updateCodeViewer(cb) {
650652
else if (file.indexOf(".ts") > 0 && file.indexOf("index.tsx") === -1) {
651653
var tsContent = fs.readFileSync(file, "utf8");
652654
var tsItem = new CodeViewer(file, tsContent, "ts", "DATA", true);
653-
contentItems.push(tsItem);
655+
dataFiles.push(tsItem);
654656
}
655657
}
656658

659+
if (dataFiles.length === 1) {
660+
contentItems.push(dataFiles[0]);
661+
} else if (dataFiles.length > 1) {
662+
// combining multiple data files into one data source
663+
var dataPath = dataFiles[0].path;
664+
var dataFolder = dataPath.substring(0, dataPath.lastIndexOf("/"));
665+
var dataContent = "// NOTE this file contains multiple data sources:\r\n";
666+
for (let i = 0; i < dataFiles.length; i++) {
667+
const data = dataFiles[i];
668+
dataContent += "\r\n\r\n" + "// Data Source #" + (i+1) + "\r\n";
669+
dataContent += data.content + "\r\n";
670+
}
671+
var dataItem = new CodeViewer(dataFolder + "/DataSources.ts", dataContent, "ts", "DATA", true);
672+
contentItems.push(dataItem);
673+
}
674+
657675
content += JSON.stringify(contentItems, null, ' ');
658676
content += "\r\n}";
659677

0 commit comments

Comments
 (0)