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

Missing rangeBand method #867

Merged
merged 2 commits into from
Mar 7, 2022
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
13 changes: 7 additions & 6 deletions src/client/components/bucket-marks/bucket-marks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

import * as d3 from "d3";
import { PlywoodValue } from "plywood";
import * as React from "react";
import { Stage } from "../../../common/models/stage/stage";
Expand All @@ -26,7 +27,7 @@ const TICK_HEIGHT = 5;
export interface BucketMarksProps {
stage: Stage;
ticks: PlywoodValue[];
scale: any;
scale: d3.ScaleBand<PlywoodValue>;
}

export interface BucketMarksState {
Expand All @@ -36,21 +37,21 @@ export class BucketMarks extends React.Component<BucketMarksProps, BucketMarksSt

render() {
const { stage, ticks, scale } = this.props;
var stageWidth = stage.width;
const stageWidth = stage.width;

var lines: JSX.Element[] = [];
let lines: JSX.Element[] = [];

function addLine(x: number, key: string) {
if (stageWidth < x) return;
lines.push(<line key={key} x1={x} y1={0} x2={x} y2={TICK_HEIGHT} />);
}

for (var tick of ticks) {
var x = roundToHalfPx(scale(tick));
for (let tick of ticks) {
let x = roundToHalfPx(scale(tick));
addLine(x, "_" + tick);
}
if (ticks.length) {
var x = roundToHalfPx(scale(ticks[ticks.length - 1]) + scale.rangeBand());
let x = roundToHalfPx(scale(ticks[ticks.length - 1]) + scale.bandwidth());
addLine(x, "last");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const SingleBar: React.SFC<SingleBarProps> = props => {
const [maxHeight] = yScale.range();
const x = getX(datum);
const xPos = xScale.calculate(x) + SIDE_PADDING;
const width = xScale.rangeBand() - (2 * SIDE_PADDING);
const width = xScale.bandwidth() - (2 * SIDE_PADDING);
const y = series.selectValue(datum);
const yPos = yScale(y);
const height = maxHeight - yPos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const SingleTimeShiftBar: React.SFC<SingleTimeShiftBar> = props => {
const [maxHeight] = yScale.range();
const x = getX(datum);
const xStart = xScale.calculate(x);
const rangeBand = xScale.rangeBand();
const rangeBand = xScale.bandwidth();
const fullWidth = rangeBand - 2 * SIDE_PADDING;
const barWidth = fullWidth * 2 / 3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const StackedBar: React.SFC<StackedBarProps> = props => {

const x = getX(datum);
const xPos = xScale.calculate(x) + SIDE_PADDING;
const width = xScale.rangeBand() - (2 * SIDE_PADDING);
const width = xScale.bandwidth() - (2 * SIDE_PADDING);
const color = (d: Datum) => model.colors.get(String(d[ref]));
return <React.Fragment>
{datums.map(datum => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const StackedTimeShiftBar: React.SFC<StackedTimeShiftBarProps> = props =>
const x = getX(datum);

const xStart = xScale.calculate(x);
const rangeBand = xScale.rangeBand();
const rangeBand = xScale.bandwidth();
const fullWidth = rangeBand - 2 * SIDE_PADDING;
const barWidth = fullWidth * 2 / 3;
const color = (d: Datum) => model.colors.get(String(d[nominalReference]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const HighlightModal: React.SFC<HighlightModalProps> = props => {
series,
xScale } = props;
const xValue = getX(datum);
const x = xScale.calculate(xValue) + (xScale.rangeBand() / 2);
const x = xScale.calculate(xValue) + (xScale.bandwidth() / 2);
const yValue = series.selectValue(datum);
const y = yScale(yValue);
return <BaseHighlightModal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const HighlightOverlay: React.SFC<HighlightOverlayProps> = props => {
const { stage, yScale, series, xScale, showPrevious, interaction: { datum }, getX } = props;
const xValue = getX(datum);
const left = xScale.calculate(xValue);
const right = left + xScale.rangeBand();
const right = left + xScale.bandwidth();
const yValue = getYValue(datum, series, showPrevious);
const top = yScale(yValue) + stage.y - TOP_PADDING;
return <Highlighter left={left} right={right} top={top} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const HoverTooltip: React.SFC<HoverTooltipProps> = props => {
} = props;
const y = yScale(series.selectValue(datum));
const xValue = getX(datum);
const x = xScale.calculate(xValue) + (xScale.rangeBand() / 2);
const x = xScale.calculate(xValue) + (xScale.bandwidth() / 2);
return <SegmentBubble
top={top + y}
left={left + x}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("x-scale", () => {
});

it("should return range band", () => {
expect(scale.rangeBand()).to.be.equal(30);
expect(scale.bandwidth()).to.be.equal(30);
});

it("should apply scale function", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface XScale {
calculate(x: DomainValue): number;
invert(x: number): DomainValue;
domain(): XDomain;
rangeBand(): number;
bandwidth(): number;
}

export function createXScale(domain: XDomain, width: number): XScale {
Expand All @@ -41,7 +41,7 @@ export function createXScale(domain: XDomain, width: number): XScale {
calculate: (value: DomainValue) => ordinalScale(formatDomainValue(value)),
domain: () => domain,
invert: (x: number) => quantizedScale(x),
rangeBand: () => ordinalScale.bandwidth()
bandwidth: () => ordinalScale.bandwidth()
};
}

Expand Down