Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCAL-229147 Dynamic Measure Name/Values #81

Merged
merged 5 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions example/custom-bar-chart/custom-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,16 @@ import { ChartConfigEditorDefinition } from '@thoughtspot/ts-chart-sdk/src';
import Chart from 'chart.js/auto';
import ChartDataLabels from 'chartjs-plugin-datalabels';
import _ from 'lodash';
import { availableColor, getBackgroundColor, getPlotLinesAndBandsFromConditionalFormatting, visualPropKeyMap } from './custom-chart.utils';
import { createPlotbandPlugin, createPlotlinePlugin } from './custom-chart-plugins';
import {
availableColor,
getBackgroundColor,
getPlotLinesAndBandsFromConditionalFormatting,
visualPropKeyMap,
} from './custom-chart.utils';
import {
createPlotbandPlugin,
createPlotlinePlugin,
} from './custom-chart-plugins';

Chart.register(ChartDataLabels);

Expand Down Expand Up @@ -487,6 +495,16 @@ const renderChart = async (ctx: CustomChartContext): Promise<void> => {
},
allowedConfigurations: {
allowColumnConditionalFormatting: true,
allowMeasureNamesAndValues: true,
},
chartConfigParameters: {
measureNameValueColumns: {
enableMeasureNameColumn: true,
enableMeasureValueColumn: true,
measureNameColumnAlias: 'Name',
measureValueColumnAlias: 'Value',
},
batchSizeLimit: 20000,
},
});

Expand Down
4 changes: 2 additions & 2 deletions example/custom-bar-chart/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/custom-bar-chart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"vite": "^4.3.5"
},
"dependencies": {
"@thoughtspot/ts-chart-sdk": "0.0.2-alpha.14",
"@thoughtspot/ts-chart-sdk": "0.0.2-alpha.20",
"chart.js": "^4.3.0",
"chartjs-plugin-datalabels": "^2.2.0",
"lodash": "^4.17.21"
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@thoughtspot/ts-chart-sdk",
"private": false,
"version": "0.0.2-alpha.19",
"version": "0.0.2-alpha.20",
"module": "lib/index",
"main": "lib/index",
"types": "lib/index",
Expand Down
9 changes: 9 additions & 0 deletions src/main/custom-chart-context.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ describe('CustomChartContext', () => {
allowColumnConditionalFormatting: false,
allowMeasureNamesAndValues: false,
},
chartConfigParameters: {
measureNameValueColumns: {
enableMeasureNameColumn: false,
enableMeasureValueColumn: false,
measureNameColumnAlias: 'Measure Name',
measureValueColumnAlias: 'Measure Values',
},
batchSizeLimit: 20000,
},
});
});

Expand Down
121 changes: 118 additions & 3 deletions src/main/custom-chart-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,105 @@
postMessageToHostApp,
} from './post-message-event-bridge';

/**
* Configuration for allowing or disallowing specific TS UI features.
*
* @fileoverview
* This configuration defines the ability to toggle specific features such as
* column number formatting, conditional formatting, and measure names/values.
*
* @version SDK: 0.1 | ThoughtSpot:
*/
export type AllowedConfigurations = {
/**
* Allows column-level number formatting.
*
* @default false
* @version SDK: 0.1 | ThoughtSpot:
*/
allowColumnNumberFormatting?: boolean;

/**
* Allows conditional formatting at the column level.
* This allows users to apply rules that visually highlight or differentiate data.
*
* @default false
* @version SDK: 0.1 | ThoughtSpot:
*/
allowColumnConditionalFormatting?: boolean;

/**
* Enables measure_name and measure_values in the chart configuration.
*
* @default false
* @version SDK: 0.1 | ThoughtSpot:
*/
allowMeasureNamesAndValues?: boolean;
};

/**
* Configuration parameters for setting chart-specific options.
*
* @fileoverview
* This configuration includes settings for controlling measure name/value columns
* and batch size limits for data processing.
*
* @version SDK: 0.1 | ThoughtSpot:
*/
export type ChartConfigParameters = {
/**
* Configurations related to measure name and value columns.
* These parameters allow for enabling/disabling and aliasing the columns
* used to represent measure names and values.
*
* @version SDK: 0.1 | ThoughtSpot:
*/
measureNameValueColumns?: {
/**
* Enables or disables the measure_name column.
*
* @default false
* @version SDK: 0.1 | ThoughtSpot:
*/
enableMeasureNameColumn?: boolean;

/**
* Enables or disables the measure_value column.
*
* @default false
* @version SDK: 0.1 | ThoughtSpot:
*/
enableMeasureValueColumn?: boolean;

/**
* Alias for the measure_name column.
* This allows users to define a custom name for the measure_name column.
*
* @default 'Measure Name'
* @version SDK: 0.1 | ThoughtSpot:
*/
measureNameColumnAlias?: string;

/**
* Alias for the measure_value column.
* This allows users to define a custom name for the measure_value column.
*
* @default 'Measure Value'
* @version SDK: 0.1 | ThoughtSpot:
*/
measureValueColumnAlias?: string;
};

/**
* Limit on the batch size for data processing.
* This sets an upper limit on how much data can be processed in a single batch.
*
* @default 20000
* @version SDK: 0.1 | ThoughtSpot:
*/
batchSizeLimit?: number;
};

export type CustomChartContextProps = {
/**
* Generate the default axis configuration for rendering the chart on first load.
Expand Down Expand Up @@ -142,10 +235,21 @@
| VisualEditorDefinitionSetter
| VisualPropEditorDefinition;

// Whether user wants thoughtspot default number and conditional formatting
/**
* Optional configuration to toggle native TS UI configurations, such as column number formatting

Check warning on line 239 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Comments may not exceed 100 characters
* and conditional formatting.
*
* @type {AllowedConfigurations}
* @version SDK: 0.1 | ThoughtSpot:
*/
allowedConfigurations?: AllowedConfigurations;
// TODO: needs to implement this on TS side
batchSizeLimit?: number;
/**
* Optional parameters for configuring specific chart-related features, such as measure name and value columns.

Check warning on line 247 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Comments may not exceed 100 characters

Check warning on line 247 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Comments may not exceed 100 characters
*
* @type {ChartConfigParameters}
* @version SDK: 0.1 | ThoughtSpot:
*/
chartConfigParameters?: ChartConfigParameters;
};

export type ValidationFunctions =
Expand All @@ -164,6 +268,15 @@
allowColumnConditionalFormatting: false,
allowMeasureNamesAndValues: false,
},
chartConfigParameters: {
measureNameValueColumns: {
enableMeasureNameColumn: false,
enableMeasureValueColumn: false,
measureNameColumnAlias: 'Measure Name',
measureValueColumnAlias: 'Measure Values',
},
batchSizeLimit: 20000,
},
};

export class CustomChartContext {
Expand Down Expand Up @@ -285,7 +398,7 @@
* @version SDK: 0.1 | ThoughtSpot:
*/
public initialize = (): Promise<void> => {
console.log('Chart Context: initialization start');

Check warning on line 401 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
return this.hasInitializedPromise;
};

Expand Down Expand Up @@ -317,7 +430,7 @@
*/
public off<T extends keyof TSToChartEventsPayloadMap>(eventType: T): void {
if (_.isNil(this.eventListeners[eventType])) {
console.log('No event listener found to remove');

Check warning on line 433 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
this.eventListeners[eventType] = [];
return;
}
Expand Down Expand Up @@ -538,7 +651,7 @@
...eventPayload: ChartToTSEventsPayloadMap[T]
): Promise<any> {
if (!globalThis.isInitialized) {
console.log(

Check warning on line 654 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
'Chart Context: not initialized the context, something went wrong',
);
return Promise.reject(new Error('Context not initialized'));
Expand All @@ -561,7 +674,7 @@
*/
private registerEventProcessor = () => {
if (globalThis.isInitialized) {
console.error(

Check warning on line 677 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
'The context is already initialized. you cannot have multiple contexts',
);
throw new Error(ErrorType.MultipleContextsNotSupported);
Expand All @@ -577,7 +690,7 @@
* @param event : Message Event Object
*/
private eventProcessor = (data: any) => {
console.log('Chart Context: message received:', data.eventType, data);

Check warning on line 693 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

const messageResponse = this.executeEventListenerCBs(data);

Expand Down Expand Up @@ -740,7 +853,7 @@
isValid: true,
};
} catch (error: unknown) {
console.log(

Check warning on line 856 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
'ContextMenuCustomAction: payload recieved:',
payload,
'CustomActionCallbackStore:',
Expand Down Expand Up @@ -783,7 +896,7 @@
isValid: true,
};
} catch (error: unknown) {
console.log(

Check warning on line 899 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
'AxisMenuCustomAction: payload recieved:',
payload,
'CustomActionCallbackStore:',
Expand Down Expand Up @@ -913,6 +1026,8 @@
this.getVisualPropEditorDefinition(),
allowedConfigurations:
this.chartContextProps.allowedConfigurations,
chartConfigParameters:
this.chartContextProps.chartConfigParameters,
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/types/configurator.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Copyright: ThoughtSpot Inc. 2023
*/

import { CustomChartContext } from '../main/custom-chart-context';
import type { CustomChartContext } from '../main/custom-chart-context';
import { ChartModel } from './common.types';
/**
*
Expand Down
18 changes: 14 additions & 4 deletions src/types/ts-to-chart-event.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { AllowedConfigurations } from '../main/custom-chart-context';
import type {
AllowedConfigurations,
ChartConfigParameters,
} from '../main/custom-chart-context';
import { ChartColumn } from './answer-column.types';
import { Point } from './chart-to-ts-event.types';
import type { Point } from './chart-to-ts-event.types';
import {
AppConfig,
ChartConfig,
Expand All @@ -9,8 +12,8 @@ import {
ValidationResponse,
VisualProps,
} from './common.types';
import { ChartConfigEditorDefinition } from './configurator.types';
import { VisualPropEditorDefinition } from './visual-prop.types';
import type { ChartConfigEditorDefinition } from './configurator.types';
import type { VisualPropEditorDefinition } from './visual-prop.types';

/**
* All the events sent from the ThoughtSpot application to Custom Chart App
Expand Down Expand Up @@ -206,6 +209,13 @@ export interface InitializeEventResponsePayload {
* @version SDK: 0.1 | ThoughtSpot:
*/
allowedConfigurations?: AllowedConfigurations;
/**
* Additional chart configuration parameters supported by TS UI. Ex: show/hide Measure Name/
* Value columns.
*
* @version SDK: 0.1 | ThoughtSpot:
*/
chartConfigParameters?: ChartConfigParameters;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/types/visual-prop.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Copyright: ThoughtSpot Inc. 2023
*/

import { CustomChartContext } from '../main/custom-chart-context';
import type { CustomChartContext } from '../main/custom-chart-context';
import { ColumnType } from './answer-column.types';
import { ChartModel } from './common.types';
/**
Expand Down
Loading