Skip to content

Commit

Permalink
* added support for labels order (`overrides.chartLegend.legendLabels…
Browse files Browse the repository at this point in the history
…`) for base charts (intersystems-community#383)

* added marker option support for charts (intersystems-community#383)
  • Loading branch information
agnybida committed Jun 1, 2023
1 parent afeb7c1 commit 7c842e3
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 8 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deep-see-web",
"version": "3.1.94",
"version": "3.1.95",
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config=proxy.conf.json --port 4007",
Expand All @@ -9,6 +9,7 @@
"ua": "ng serve --proxy-config=proxy.conf.ua.json --port 4007",
"got": "ng serve --proxy-config=proxy.conf.got.json --port 4007",
"local": "ng serve --proxy-config=proxy.conf.local.json --port 4007",
"samples": "ng serve --proxy-config=proxy.conf.samples.json --port 4007",
"semen": "ng serve --proxy-config=proxy.conf.semen.json --port 4007",
"analytics": "ng serve --proxy-config=proxy.conf.analytics.json --port 4007",
"analytics-pub": "ng serve --proxy-config=proxy.conf.analytics-pub.json --port 4007",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class TypeAndDatasourceComponent implements OnInit, OnDestroy {
WIDGET_TYPES.pieChart,
WIDGET_TYPES.pieChart3D,
WIDGET_TYPES.donutChart,
WIDGET_TYPES.donutChart3d,
WIDGET_TYPES.donutChart3D,
WIDGET_TYPES.treeMapChart,
WIDGET_TYPES.bullseyeChart,
WIDGET_TYPES.timeChart,
Expand Down
8 changes: 7 additions & 1 deletion src/app/components/widgets/base-widget.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export interface IWidgetOverride {
seriesYAxes?: string;
_type: string;
columns?: any[];
legendLabels?: string;
markerShapes?: string;
}

export type IAddonType = 'custom' | 'chart' | 'map';
Expand Down Expand Up @@ -822,7 +824,11 @@ export abstract class BaseWidget implements OnInit, OnDestroy {
if (col.length === 0) {
return;
}
const idx = data.Cols[0].tuples.indexOf(col[0]);
let idx = data.Cols[0].tuples.indexOf(col[0]);
const oIdx = data.Cols[0].tuples[idx].originalIndex;
if (oIdx !== undefined) {
idx = oIdx;
}
let v = data.Data[dataIndex + idx];
if (fmt) {
v = this.formatNumber(v, fmt);
Expand Down
101 changes: 96 additions & 5 deletions src/app/components/widgets/charts/base-chart.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ export class BaseChartClass extends BaseWidget implements OnInit, AfterViewInit,
*/
addSeries(data, chart?: Highcharts.Chart, conf?: Highcharts.Options, redraw = false) {
const c = chart || this.chart;
const index = (this.chart || this.chartConfig).series.length;
if (data && data.data && data.data.length !== 0) {
let isEmpty = true;
let exists = false;
Expand Down Expand Up @@ -525,12 +526,27 @@ export class BaseChartClass extends BaseWidget implements OnInit, AfterViewInit,

// Check series type from widget
if (this.widget?.seriesTypes) {
const st = this.widget?.seriesTypes[(this.chart || this.chartConfig).series.length];
const st = this.widget?.seriesTypes[index];
if (st) {
data.type = st;
}
}

// Check for marker type
if (this.override.markerShapes) {
let marker = this.override.markerShapes.split(',')[index];
if (!marker) {
return;
}
switch (marker) {
case 'up': marker = 'triangle'; break;
case 'down': marker = 'triangle-down'; break;
}
data.marker = {
symbol: marker
};
}

// Check series type from override
const curIdx = (conf || (this.chart || this.chartConfig)).series.length;
if (this.seriesTypes && this.seriesTypes[curIdx]) {
Expand Down Expand Up @@ -747,7 +763,7 @@ export class BaseChartClass extends BaseWidget implements OnInit, AfterViewInit,
if (d && d.Info) {
this.dataInfo = d.Info;
}

this.sortTuplesBasedOnLabels(data);
this.setupAxisMinMax(data.Data);

this.chartConfig.series = [];
Expand All @@ -770,8 +786,12 @@ export class BaseChartClass extends BaseWidget implements OnInit, AfterViewInit,
for (let c = 0; c < len; c++) {
const tempData = [];
for (let g = 0; g < data.Cols[1].tuples.length; g++) {
let oIdx = data.Cols[1].tuples[g].originalIndex;
if (oIdx === undefined) {
oIdx = g;
}
tempData.push({
y: +data.Data[data.Cols[0].tuples.length * len * g + t * len + c],
y: +data.Data[data.Cols[0].tuples.length * len * oIdx + t * len + c],
cube: data.Info.cubeName,
drilldown: true,
path: data.Cols[1].tuples[g].path,
Expand Down Expand Up @@ -806,11 +826,14 @@ export class BaseChartClass extends BaseWidget implements OnInit, AfterViewInit,
continue;
}
}

let oIdx = data.Cols[0].tuples[j].originalIndex;
if (oIdx === undefined) {
oIdx = j;
}
const tempData = [];
for (i = 0; i < data.Cols[1].tuples.length; i++) {
tempData.push({
y: +data.Data[i * data.Cols[0].tuples.length + j],
y: +data.Data[i * data.Cols[0].tuples.length + oIdx],
drilldown: true,
cube: data.Info.cubeName,
path: data.Cols[1].tuples[i].path,
Expand Down Expand Up @@ -1563,4 +1586,72 @@ export class BaseChartClass extends BaseWidget implements OnInit, AfterViewInit,
protected onLegendItemOut(e: any) {

}

/*private sortSeries() {
const legend = this.widget.overrides?.find(o => o._type === 'chartLegend');
if (!legend) {
return;
}
const labels = legend.legendLabels?.split(',');
if (!labels) {
return;
}
if (this.chart?.series?.length) {
// Chart already exists sort series in chart
this.sortSeriesArray(this.chart.series, labels);
//this.char
} else {
// Chart not exists sort series in config
this.sortSeriesArray(this.chartConfig.series, labels);
}
}*/

private sortTuplesArray(tuples: any[], labels: string[]) {
// Create a map to store the indices of each label
const indexMap = new Map();
labels.forEach((title, index) => {
indexMap.set(title, index);
});
tuples.forEach((t, idx) => {
t.originalIndex = idx;
});
tuples.sort((a, b) => {
const indexA = indexMap.get(a.dimension);
const indexB = indexMap.get(b.dimension);

// Check if both elements have corresponding names in the labels array
if (indexA !== undefined && indexB !== undefined) {
return indexA - indexB;
} else if (indexA !== undefined) {
return -1;
} else if (indexB !== undefined) {
return 1;
}

return 0;
});

console.log(tuples.map(s => s.dimension));
}

private sortTuplesBasedOnLabels(data: any) {
if (!data.Cols[0].tuples?.length) {
return;
}

const legend = this.widget.overrides?.find(o => o._type === 'chartLegend');
if (!legend) {
return;
}

const labels = legend.legendLabels?.split(',');
if (!labels) {
return;
}

this.sortTuplesArray(data.Cols[0].tuples, labels);
}
}
4 changes: 4 additions & 0 deletions src/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#### 3.1.95
* added support for labels order (`overrides.chartLegend.legendLabels`) for base charts (#383)
* added marker option support for charts (#383)

#### 3.1.94
* fixed issue with `donutChart3D` type

Expand Down

0 comments on commit 7c842e3

Please sign in to comment.