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

[ML] Replaces jQuery's $el.width() with element.clientWidth. #180523

Merged
merged 13 commits into from
Apr 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@

export const chartData = [
{
date: 1487899800000,
date: 1709262000000,
entity: '200',
value: 1741.5652200000002,
},
{
date: 1487899800000,
date: 1709262000000,
entity: '404',
value: 494.30564000000004,
},
{
date: 1487899800000,
date: 1709262000000,
entity: '304',
value: 160.93672,
},
{
date: 1487899800000,
date: 1709262000000,
entity: '301',
value: 57.4774,
},
{
date: 1487837700000,
date: 1708668000000,
value: 42,
entity: '303',
anomalyScore: 84.08759,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
]
},
"loading": false,
"plotEarliest": 1487774250000,
"plotLatest": 1487900250000,
"selectedEarliest": 1487836800000,
"selectedLatest": 1487837699999,
"plotEarliest": 1708171200000,
"plotLatest": 1709294400000,
"selectedEarliest": 1708646400000,
"selectedLatest": 1708819200000,
"chartLimits": {
"max": 9294.095580000001,
"min": 5.74774
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import PropTypes from 'prop-types';
import React from 'react';

import d3 from 'd3';
import $ from 'jquery';
import moment from 'moment';

import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -117,14 +116,12 @@ export class ExplorerChartDistribution extends React.Component {
drawRareChart(filteredChartData);

function init({ chartData, functionDescription }) {
const $el = $('.ml-explorer-chart');

// Clear any existing elements from the visualization,
// then build the svg elements for the chart.
const chartElement = d3.select(element).select('.content-wrapper');
chartElement.select('svg').remove();

const svgWidth = $el.width();
const svgWidth = element.clientWidth;
const svgHeight = chartHeight + margin.top + margin.bottom;

const svg = chartElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ describe('ExplorerChart', () => {
const originalGetBBox = SVGElement.prototype.getBBox;
beforeEach(() => (SVGElement.prototype.getBBox = () => mockedGetBBox));
afterEach(() => (SVGElement.prototype.getBBox = originalGetBBox));
// Returning undefined here just for the sake of consistent test results.
// jsdom doesn't have a layout engine so this is hard to test.
// If we pass some real px value here for yet unknown reasons we get different
// results on different environments.
jest.spyOn(Element.prototype, 'clientWidth', 'get').mockImplementation(() => undefined);

test('Initialize', () => {
const mockTooltipService = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import PropTypes from 'prop-types';
import React from 'react';

import d3 from 'd3';
import $ from 'jquery';
import moment from 'moment';

import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -107,14 +106,12 @@ export class ExplorerChartSingleMetric extends React.Component {
drawLineChart(config.chartData);

function init(chartLimits) {
const $el = $('.ml-explorer-chart');

// Clear any existing elements from the visualization,
// then build the svg elements for the chart.
const chartElement = d3.select(element).select(`.${CONTENT_WRAPPER_CLASS}`);
chartElement.select('svg').remove();

const svgWidth = $el.width();
const svgWidth = element.clientWidth;
const svgHeight = chartHeight + margin.top + margin.bottom;

const svg = chartElement
Expand Down