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

Update dependency @elastic/charts to v37 (master) #113968

Merged
merged 17 commits into from
Oct 12, 2021
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
4 changes: 2 additions & 2 deletions api_docs/charts.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
", xAccessor: string | number | ",
"AccessorFn",
") => ({ x: selectedRange }: ",
"XYBrushArea",
"XYBrushEvent",
") => ",
{
"pluginId": "charts",
Expand Down Expand Up @@ -4266,4 +4266,4 @@
}
]
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"@elastic/apm-generator": "link:bazel-bin/packages/elastic-apm-generator",
"@elastic/apm-rum": "^5.9.1",
"@elastic/apm-rum-react": "^1.3.1",
"@elastic/charts": "34.2.1",
"@elastic/charts": "37.0.0",
"@elastic/datemath": "link:bazel-bin/packages/elastic-datemath",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@^8.0.0-canary.21",
"@elastic/ems-client": "7.15.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import {
XYChartSeriesIdentifier,
GeometryValue,
XYBrushArea,
XYBrushEvent,
Accessor,
AccessorFn,
Datum,
Expand Down Expand Up @@ -261,7 +261,7 @@ export const getFilterFromSeriesFn =
*/
export const getBrushFromChartBrushEventFn =
(table: Datatable, xAccessor: Accessor | AccessorFn) =>
({ x: selectedRange }: XYBrushArea): BrushTriggerEvent => {
({ x: selectedRange }: XYBrushEvent): BrushTriggerEvent => {
const [start, end] = selectedRange ?? [0, 0];
const range: [number, number] = [start, end];
const column = table.columns.findIndex(({ id }) => validateAccessorId(id, xAccessor));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import dateMath from '@elastic/datemath';
import {
Axis,
BrushEndListener,
XYBrushEvent,
Chart,
ElementClickListener,
HistogramBarSeries,
Expand Down Expand Up @@ -65,8 +66,8 @@ export function DiscoverHistogram({
const timeZone = getTimezone(uiSettings);
const { chartData, fetchStatus } = dataState;

const onBrushEnd: BrushEndListener = useCallback(
({ x }) => {
const onBrushEnd = useCallback(
({ x }: XYBrushEvent) => {
if (!x) {
return;
}
Expand Down Expand Up @@ -184,7 +185,7 @@ export function DiscoverHistogram({
<Chart size="100%">
<Settings
xDomain={xDomain}
onBrushEnd={onBrushEnd}
onBrushEnd={onBrushEnd as BrushEndListener}
onElementClick={onElementClick(xInterval)}
tooltip={tooltipProps}
theme={chartTheme}
Expand Down
1 change: 0 additions & 1 deletion src/plugins/vis_types/pie/public/utils/get_layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ export const getLayers = (
syncColors: boolean
): PartitionLayer[] => {
const fillLabel: Partial<PartitionFillLabel> = {
textInvertible: true,
valueFont: {
fontWeight: 700,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const DefaultYAxis = () => (
id="left"
domain={withStaticPadding({
fit: false,
min: NaN,
max: NaN,
})}
position={Position.Left}
groupId={`${MAIN_GROUP_ID}`}
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/vis_types/timelion/public/helpers/panel_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ const adaptYaxisParams = (yaxis: IAxis) => {
tickFormat: y.tickFormatter,
domain: withStaticPadding({
fit: y.min === undefined && y.max === undefined,
min: y.min,
max: y.max,
min: y.min ?? NaN,
max: y.max ?? NaN,
}),
};
};
Expand Down Expand Up @@ -118,6 +118,8 @@ export const extractAllYAxis = (series: Series[]) => {
groupId,
domain: withStaticPadding({
fit: false,
min: NaN,
max: NaN,
}),
id: (yaxis?.position || Position.Left) + index,
position: Position.Left,
Expand Down
1 change: 0 additions & 1 deletion src/plugins/vis_types/xy/public/components/xy_settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ function getValueLabelsStyling() {
return {
displayValue: {
fontSize: { min: VALUE_LABELS_MIN_FONTSIZE, max: VALUE_LABELS_MAX_FONTSIZE },
fill: { textInverted: false, textContrast: true },
alignment: { horizontal: HorizontalAlignment.Center, vertical: VerticalAlignment.Middle },
},
};
Expand Down
16 changes: 2 additions & 14 deletions src/plugins/vis_types/xy/public/config/get_axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { identity, isNil } from 'lodash';
import { identity } from 'lodash';

import { AxisSpec, TickFormatter, YDomainRange, ScaleType as ECScaleType } from '@elastic/charts';

Expand Down Expand Up @@ -171,17 +171,5 @@ function getAxisDomain<S extends XScaleType | YScaleType>(
const fit = defaultYExtents;
const padding = boundsMargin || undefined;

if (!isNil(min) && !isNil(max)) {
return { fit, padding, min, max };
}

if (!isNil(min)) {
return { fit, padding, min };
}

if (!isNil(max)) {
return { fit, padding, max };
}

return { fit, padding };
return { fit, padding, min: min ?? NaN, max: max ?? NaN };
}
12 changes: 7 additions & 5 deletions src/plugins/vis_types/xy/public/utils/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const getXDomain = (params: Aspect['params']): DomainRange => {

return {
minInterval,
min: NaN,
max: NaN,
};
};

Expand Down Expand Up @@ -74,9 +76,9 @@ export const getAdjustedDomain = (
};
}

return 'interval' in params
? {
minInterval: params.interval,
}
: {};
return {
minInterval: 'interval' in params ? params.interval : undefined,
min: NaN,
max: NaN,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ export const getVisConfig = (): VisConfig => {
mode: AxisMode.Normal,
type: 'linear',
},
domain: {},
domain: {
min: NaN,
max: NaN,
},
integersOnly: false,
},
],
Expand Down Expand Up @@ -246,7 +249,10 @@ export const getVisConfigMutipleYaxis = (): VisConfig => {
mode: AxisMode.Normal,
type: 'linear',
},
domain: {},
domain: {
min: NaN,
max: NaN,
},
integersOnly: false,
},
],
Expand Down Expand Up @@ -435,7 +441,10 @@ export const getVisConfigPercentiles = (): VisConfig => {
mode: AxisMode.Normal,
type: 'linear',
},
domain: {},
domain: {
min: NaN,
max: NaN,
},
integersOnly: false,
},
],
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/vis_types/xy/public/vis_component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ScaleType,
AccessorFn,
Accessor,
XYBrushEvent,
} from '@elastic/charts';

import { compact } from 'lodash';
Expand Down Expand Up @@ -131,7 +132,10 @@ const VisComponent = (props: VisComponentProps) => {
): BrushEndListener | undefined => {
if (xAccessor !== null && isInterval) {
return (brushArea) => {
const event = getBrushFromChartBrushEventFn(visData, xAccessor)(brushArea);
const event = getBrushFromChartBrushEventFn(
visData,
xAccessor
)(brushArea as XYBrushEvent);
props.fireEvent(event);
};
}
Expand Down
14 changes: 6 additions & 8 deletions test/functional/apps/dashboard/dashboard_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import expect from '@kbn/expect';
import chroma from 'chroma-js';

import { PIE_CHART_VIS_NAME, AREA_CHART_VIS_NAME } from '../../page_objects/dashboard_page';
import { DEFAULT_PANEL_WIDTH } from '../../../../src/plugins/dashboard/public/application/embeddable/dashboard_constants';
Expand Down Expand Up @@ -264,14 +265,11 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.header.waitUntilLoadingHasFinished();

await retry.try(async () => {
const allPieSlicesColor = await pieChart.getAllPieSliceStyles('80,000');
let whitePieSliceCounts = 0;
allPieSlicesColor.forEach((style) => {
if (style.indexOf('rgb(255, 255, 255)') > -1) {
whitePieSliceCounts++;
}
});

const allPieSlicesColor = await pieChart.getAllPieSliceColor('80,000');
const whitePieSliceCounts = allPieSlicesColor.reduce((count, color) => {
// converting the color to a common format, testing the color, not the string format
return chroma(color).hex().toUpperCase() === '#FFFFFF' ? count + 1 : count;
}, 0);
Comment on lines +268 to +272
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've relaxed this check to verify that the color on the slice is white removing the check of the actual color string format.
getAllPieSliceStyles was also renamed to getAllPieSliceColor because we always return a set of colors, not styles

expect(whitePieSliceCounts).to.be(1);
});
});
Expand Down
12 changes: 6 additions & 6 deletions test/functional/page_objects/visualize_chart_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Position } from '@elastic/charts';
import Color from 'color';
import chroma from 'chroma-js';

import { FtrService } from '../ftr_provider_context';

Expand Down Expand Up @@ -181,17 +181,17 @@ export class VisualizeChartPageObject extends FtrService {
return items.some(({ color: c }) => c === color);
}

public async doesSelectedLegendColorExistForPie(color: string) {
public async doesSelectedLegendColorExistForPie(matchingColor: string) {
if (await this.isNewLibraryChart(pieChartSelector)) {
const hexMatchingColor = chroma(matchingColor).hex().toUpperCase();
const slices =
(await this.getEsChartDebugState(pieChartSelector))?.partition?.[0]?.partitions ?? [];
return slices.some(({ color: c }) => {
const rgbColor = new Color(color).rgb().toString();
return c === rgbColor;
return slices.some(({ color }) => {
return hexMatchingColor === chroma(color).hex().toUpperCase();
});
}

return await this.testSubjects.exists(`legendSelectedColor-${color}`);
return await this.testSubjects.exists(`legendSelectedColor-${matchingColor}`);
}

public async expectError() {
Expand Down
20 changes: 17 additions & 3 deletions test/functional/services/visualizations/pie_chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import expect from '@kbn/expect';
import { isNil } from 'lodash';
import { FtrService } from '../../ftr_provider_context';

const pieChartSelector = 'visTypePieChart';
Expand Down Expand Up @@ -100,8 +101,8 @@ export class PieChartService extends FtrService {
return await pieSlice.getAttribute('style');
}

async getAllPieSliceStyles(name: string) {
this.log.debug(`VisualizePage.getAllPieSliceStyles(${name})`);
async getAllPieSliceColor(name: string) {
this.log.debug(`VisualizePage.getAllPieSliceColor(${name})`);
if (await this.visChart.isNewLibraryChart(pieChartSelector)) {
const slices =
(await this.visChart.getEsChartDebugState(pieChartSelector))?.partition?.[0]?.partitions ??
Expand All @@ -112,9 +113,22 @@ export class PieChartService extends FtrService {
return selectedSlice.map((slice) => slice.color);
}
const pieSlices = await this.getAllPieSlices(name);
return await Promise.all(
const slicesStyles = await Promise.all(
pieSlices.map(async (pieSlice) => await pieSlice.getAttribute('style'))
);
return slicesStyles
.map(
(styles) =>
styles.split(';').reduce<Record<string, string>>((styleAsObj, style) => {
const stylePair = style.split(':');
if (stylePair.length !== 2) {
return styleAsObj;
}
styleAsObj[stylePair[0].trim()] = stylePair[1].trim();
return styleAsObj;
}, {}).fill // in vislib the color is available on the `fill` style prop
)
.filter((d) => !isNil(d));
}

async getPieChartData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function ChartPreview({
position={Position.Left}
tickFormat={yTickFormat}
ticks={5}
domain={{ max: yMax }}
domain={{ max: yMax, min: NaN }}
/>
<BarSeries
color={theme.eui.euiColorVis1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import numeral from '@elastic/numeral';
import {
Axis,
BrushEndListener,
XYBrushEvent,
Chart,
CurveType,
LineSeries,
Expand Down Expand Up @@ -64,7 +65,7 @@ export function PageLoadDistChart({
percentileRange,
}: Props) {
const [breakdownLoading, setBreakdownLoading] = useState(false);
const onBrushEnd: BrushEndListener = ({ x }) => {
const onBrushEnd = ({ x }: XYBrushEvent) => {
if (!x) {
return;
}
Expand Down Expand Up @@ -99,7 +100,7 @@ export function PageLoadDistChart({
<Settings
baseTheme={darkMode ? DARK_THEME : LIGHT_THEME}
theme={euiChartTheme.theme}
onBrushEnd={onBrushEnd}
onBrushEnd={onBrushEnd as BrushEndListener}
tooltip={tooltipProps}
showLegend
/>
Expand Down
Loading