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

fix(scales): bisect correctly on continuous scales #346

Merged
merged 5 commits into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
18 changes: 10 additions & 8 deletions .playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@
<style>
html,
body {
background: darkgrey !important;
background: blanchedalmond !important;
margin: 0;
padding: 0;
}
#root {
background: white;

position: absolute;
top: 100px;
left: 100px;
bottom: 100px;
right: 100px;
top: 10px;
left: 10px;
bottom: 10px;
right: 10px;
}
.chart {
background: white;
position: relative;
width: 100%;
height: 100%;
width: 800px;
height: 150px;
margin: 10px;
}
</style>
</head>
Expand Down
186 changes: 150 additions & 36 deletions .playground/playgroud.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import {
LineAnnotation,
getAnnotationId,
AnnotationDomainTypes,
AreaSeries,
LineSeries,
TooltipType,
RectAnnotation,
HistogramBarSeries,
} from '../src';
import { KIBANA_METRICS } from '../src/utils/data_samples/test_dataset_kibana';
import { CursorEvent } from '../src/specs/settings';
Expand All @@ -23,31 +28,68 @@ export class Playground extends React.Component {
ref1 = React.createRef<Chart>();
ref2 = React.createRef<Chart>();
ref3 = React.createRef<Chart>();
ref4 = React.createRef<Chart>();
ref5 = React.createRef<Chart>();

onCursorUpdate: CursorUpdateListener = (event?: CursorEvent) => {
this.ref1.current!.dispatchExternalCursorEvent(event);
this.ref2.current!.dispatchExternalCursorEvent(event);
this.ref3.current!.dispatchExternalCursorEvent(event);
this.ref4.current!.dispatchExternalCursorEvent(event);
this.ref5.current!.dispatchExternalCursorEvent(event);
};

render() {
return (
<>
{renderChart(
'1',
'1 - top',
this.ref1,
KIBANA_METRICS.metrics.kibana_os_load[0].data.slice(0, 15),
KIBANA_METRICS.metrics.kibana_os_load[1].data.slice(0, 50).filter((d, i) => i !== 1 && i !== 2),
ScaleType.Time,
this.onCursorUpdate,
true,
2,
'line',
)}

{renderChart(
'2',
'2 - middle',
this.ref2,
KIBANA_METRICS.metrics.kibana_os_load[1].data.slice(0, 15),
KIBANA_METRICS.metrics.kibana_os_load[1].data.slice(2, 15).filter((d, i) => i !== 5),
ScaleType.Time,
this.onCursorUpdate,
2,
'line',
)}

{renderChart(
'3 - bottom',
this.ref3,
KIBANA_METRICS.metrics.kibana_os_load[1].data.slice(0, 50),
ScaleType.Time,
this.onCursorUpdate,
2,
'mixed',
)}

{renderChart(
'4 - mixed',
this.ref4,
KIBANA_METRICS.metrics.kibana_os_load[1].data.slice(0, 7),
ScaleType.Time,
this.onCursorUpdate,
1,
'bar',
)}
{renderChart(
'5 - histogram',
this.ref5,
KIBANA_METRICS.metrics.kibana_os_load[1].data.slice(0, 7),
ScaleType.Time,
this.onCursorUpdate,
true,
1,
'histogram',
)}
{renderChart('3', this.ref3, KIBANA_METRICS.metrics.kibana_os_load[1].data.slice(15, 30), this.onCursorUpdate)}
</>
);
}
Expand All @@ -57,60 +99,132 @@ function renderChart(
key: string,
ref: React.RefObject<Chart>,
data: any,
scaleType: 'linear' | 'ordinal' | 'time',
onCursorUpdate?: CursorUpdateListener,
timeSeries: boolean = false,
maxSeries: number = 4,
chartType: 'bar' | 'line' | 'area' | 'mixed' | 'histogram' = 'bar',
) {
const formatter = niceTimeFormatter([data[0][0], data[data.length - 1][0]]);
return (
<div key={key} className="chart">
<Chart ref={ref}>
<Chart ref={ref} id={key}>
<Settings
tooltip={{ type: 'vertical' }}
debug={false}
legendPosition={Position.Right}
showLegend={true}
onCursorUpdate={onCursorUpdate}
rotation={0}
tooltip={{
type: TooltipType.VerticalCursor,
snap: true,
}}
theme={{
lineSeriesStyle: {
point: {
visible: true,
radius: 3,
strokeWidth: 1,
},
},
areaSeriesStyle: {
area: {
opacity: 0.4,
},
},
}}
/>
<Axis
id={getAxisId('timestamp')}
title="timestamp"
position={Position.Bottom}
tickFormat={niceTimeFormatter([1555819200000, 1555905600000])}
/>
<Axis id={getAxisId('timestamp')} title="timestamp" position={Position.Bottom} tickFormat={formatter} />
<Axis id={getAxisId('count')} title="count" position={Position.Left} tickFormat={(d) => d.toFixed(2)} />
<LineAnnotation
annotationId={getAnnotationId('annotation1')}
domainType={AnnotationDomainTypes.XDomain}
dataValues={[
{
dataValue: KIBANA_METRICS.metrics.kibana_os_load[1].data[5][0],
details: 'tooltip 1',
dataValue: KIBANA_METRICS.metrics.kibana_os_load[1].data[2][0],
details: `${formatter(KIBANA_METRICS.metrics.kibana_os_load[1].data[2][0])}`,
},
{
dataValue: KIBANA_METRICS.metrics.kibana_os_load[1].data[9][0],
details: 'tooltip 2',
dataValue: KIBANA_METRICS.metrics.kibana_os_load[1].data[3][0],
details: `${formatter(KIBANA_METRICS.metrics.kibana_os_load[1].data[3][0])}`,
},
]}
hideLinesTooltips={true}
marker={<Icon type="alert" />}
/>
<BarSeries
id={getSpecId('dataset A with long title')}
xScaleType={timeSeries ? ScaleType.Time : ScaleType.Linear}
yScaleType={ScaleType.Linear}
data={data}
xAccessor={0}
yAccessors={[1]}
/>
<BarSeries
id={getSpecId('dataset B')}
xScaleType={ScaleType.Time}
yScaleType={ScaleType.Linear}
data={KIBANA_METRICS.metrics.kibana_os_load[1].data.slice(0, 15)}
xAccessor={0}
yAccessors={[1]}
stackAccessors={[0]}
<RectAnnotation
annotationId={getAnnotationId('rect annotations')}
dataValues={[
{
coordinates: {
x0: KIBANA_METRICS.metrics.kibana_os_load[1].data[2][0],
x1: KIBANA_METRICS.metrics.kibana_os_load[1].data[3][0],
},
details: `from: ${formatter(KIBANA_METRICS.metrics.kibana_os_load[1].data[2][0])} to: ${formatter(
KIBANA_METRICS.metrics.kibana_os_load[1].data[3][0],
)}`,
},
]}
/>
{(chartType === 'mixed' || chartType === 'line') &&
new Array(maxSeries).fill(0).map((d, k) => {
return (
<LineSeries
key={k}
id={getSpecId('dataset line' + k)}
xScaleType={scaleType}
yScaleType={ScaleType.Linear}
data={data.map((d, i) => [d[0], d[1] + 5 + +Math.sin((i * (k + 1)) % data.length) * 10])}
xAccessor={0}
yAccessors={[1]}
/>
);
})}
{(chartType === 'mixed' || chartType === 'bar') &&
new Array(maxSeries).fill(0).map((d, k) => {
return (
<BarSeries
key={k}
id={getSpecId('dataset bar ' + k)}
xScaleType={scaleType}
yScaleType={ScaleType.Linear}
data={data.map((d, i) => [d[0], d[1] + 5 + Math.cos((i * (k + 1)) % data.length) * 5])}
xAccessor={0}
yAccessors={[1]}
sortIndex={-10}
/>
);
})}
{chartType === 'histogram' &&
new Array(maxSeries).fill(0).map((d, k) => {
return (
<HistogramBarSeries
key={k}
id={getSpecId('dataset histogram ' + k)}
xScaleType={scaleType}
yScaleType={ScaleType.Linear}
data={data.map((d, i) => [d[0], d[1] + 5 + Math.cos((i * (k + 1)) % data.length) * 5])}
xAccessor={0}
yAccessors={[1]}
sortIndex={-10}
/>
);
})}
{(chartType === 'mixed' || chartType === 'area') &&
new Array(maxSeries).fill(0).map((d, k) => {
return (
<AreaSeries
key={k}
id={getSpecId('dataset area ' + k)}
xScaleType={scaleType}
yScaleType={ScaleType.Linear}
data={data.map((d, i) => [d[0], d[1] + 5 + Math.cos((i * (k + 1)) % data.length) * 3])}
xAccessor={0}
yAccessors={[1]}
sortIndex={-10}
stackAccessors={[0]}
/>
);
})}
</Chart>
</div>
);
Expand Down
Loading