Make ChartWrapper.getChart() return value nullable (#44927)

This commit is contained in:
Vasily Malykhin 2020-05-27 04:34:26 +03:00 committed by GitHub
parent 6a170bff05
commit df7e6b8b21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 19 deletions

View File

@ -706,3 +706,38 @@ function test_addListeners() {
chart.draw(data, {});
}
}
function test_chartChart() {
var data = google.visualization.arrayToDataTable([
['Year', 'Sales', 'Expenses'],
['2004', 1000, 400],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540]
]);
var options = {
title: 'Company Performance'
};
var container = document.getElementById('chart_div');
if (container) {
var chartWrapper = new google.visualization.ChartWrapper({
chartType: 'LineChart',
container,
options
});
var chart = chartWrapper.getChart();
function isClearable(baseChart: google.visualization.ChartBase): baseChart is google.visualization.ChartBaseClearable {
return 'clearChart' in baseChart;
}
if (chart) {
if (isClearable(chart)) {
chart.clearChart()
}
}
}
}

View File

@ -20,7 +20,7 @@ declare namespace google {
export function dataTableToCsv(data: DataTable | DataView): string;
export function arrayToDataTable(data: any[], firstRowIsData?: boolean): DataTable;
export interface ChartSpecs {
chartType: string;
container?: HTMLElement;
@ -51,7 +51,7 @@ declare namespace google {
getDataTable(): DataTable;
getChartType(): string;
getChartName(): string;
getChart(): any;
getChart(): ChartBase | null;
getContainerId(): string;
getQuery(): string;
getRefreshInterval(): number;
@ -70,7 +70,7 @@ declare namespace google {
setView(view_spec: string): void;
}
//#endregion
//#region data
// https://developers.google.com/chart/interactive/docs/reference#google_visualization_data_group
export interface GroupKeyOptions {
@ -88,11 +88,11 @@ declare namespace google {
label?: string;
id?: string;
}
export class data {
// https://developers.google.com/chart/interactive/docs/reference#data_modifier_functions
static month(value: Date): number;
// https://developers.google.com/chart/interactive/docs/reference#group
static sum(values: number[] | string[] | Date[]): number;
static avg(values: number[] | string[] | Date[]): number;
@ -101,12 +101,12 @@ declare namespace google {
static count(values: any[]): number;
static group(data: DataTable | DataView, keys: (number | GroupKeyOptions)[], columns?: GroupColumnOptions[]): DataTable;
// https://developers.google.com/chart/interactive/docs/reference#join
static join(dataA: DataTable | DataView, dataB: DataTable | DataView, joinMethod: 'full' | 'inner' | 'left' | 'right', keys: number[][], columnsA: number[], columnsB: number[]): DataTable;
}
//#endregion
//#region DataTable
// https://developers.google.com/chart/interactive/docs/reference#DataTable
export class DataTable {
@ -362,7 +362,7 @@ declare namespace google {
}
//#endregion
//#region Common
//#region Common
export interface ChartAnnotations {
boxStyle?: ChartBoxStyle;
textStyle?: ChartTextStyle;
@ -455,9 +455,9 @@ declare namespace google {
export type ChartOrientation = 'vertical' | 'horizontal';
export type ChartAxisTitlesPosition = 'in' | 'out' | 'none';
export type ChartSelectionMode = 'single' | 'multiple';
export type ChartLegendPosition = 'bottom' | 'left' | 'in' | 'none' | 'right' | 'top';
export type ChartLegendAlignment = 'start' | 'center' | 'end';
export interface ChartLegend {
@ -533,9 +533,9 @@ declare namespace google {
colors?: string[];
legend?: ChartLegend;
}
export type ChartPointShape = 'circle' | 'triangle' | 'square' | 'diamond' | 'star' | 'polygon';
export interface ChartLayoutInterface {
getBoundingBox(id: string): ChartBoundingBox;
getChartAreaBoundingBox(): ChartBoundingBox;
@ -559,11 +559,11 @@ declare namespace google {
fallingColor?: ChartStrokeFill;
risingColor?: ChartStrokeFill;
}
export interface ChartSeriesOptionsBase {
color?: string;
}
// https://developers.google.com/chart/interactive/docs/gallery/trendlines
export interface ChartTrendlineOptions {
type?: 'linear' | 'exponential' | 'polynomial';
@ -703,7 +703,7 @@ declare namespace google {
export class LineChart extends CoreChartBase {
draw(data: DataTable | DataView, options: LineChartOptions): void;
}
export interface LineChartSeriesOptions extends ChartSeriesOptionsBase {
annotations?: ChartAnnotations;
curveType?: 'none' | 'function';
@ -716,7 +716,7 @@ declare namespace google {
labelInLegend?: string;
targetAxisIndex?: number;
}
// https://developers.google.com/chart/interactive/docs/gallery/linechart#Configuration_Options
export interface LineChartOptions {
aggregationTarget?: string;
@ -1285,7 +1285,7 @@ declare namespace google {
//#endregion
//#region ControlWrapper
// https://developers.google.com/chart/interactive/docs/gallery/controls#controlwrapperobject
export class ControlWrapper {
constructor(opt_spec?: ControlWrapperOptions)
@ -1307,7 +1307,7 @@ declare namespace google {
setState(state_obj: Object): void;
}
export interface ControlWrapperOptions {
export interface ControlWrapperOptions {
controlType: string;
containerId: string;
options?: Object;
@ -1382,7 +1382,7 @@ declare namespace google {
zoomLevel?: number;
}
//#endregion
//#endregion
//#region Events
namespace events {