Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…to axis-option

* 'master' of https://github.com/JennChao/carbon-charts:
  v0.37.0
  Merge pull request carbon-design-system#780 from natashadecoste/fix-meter-max-val
  feat: enable or disable scatter dot on charts except scatter chart (carbon-design-system#769)
  feat: create options for tick rotation (carbon-design-system#770)

fix: enable zoom in functionality while axis is disabled
  • Loading branch information
JennChao committed Sep 14, 2020
2 parents 98cab37 + 5bdaa57 commit f3cfe15
Show file tree
Hide file tree
Showing 23 changed files with 181 additions and 107 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.37.0](https://github.com/carbon-design-system/carbon-charts/compare/v0.36.4...v0.37.0) (2020-09-11)


### Features

* create options for tick rotation ([#770](https://github.com/carbon-design-system/carbon-charts/issues/770)) ([4063c8a](https://github.com/carbon-design-system/carbon-charts/commit/4063c8a0f4d441589116759b32f2b214fad46154))
* enable or disable scatter dot on charts except scatter chart ([#769](https://github.com/carbon-design-system/carbon-charts/issues/769)) ([3131942](https://github.com/carbon-design-system/carbon-charts/commit/313194217318719152d6a14c2a3cba957b8fc009))





## [0.36.4](https://github.com/carbon-design-system/carbon-charts/compare/v0.36.3...v0.36.4) (2020-09-10)

**Note:** Version bump only for package @carbon/charts-monorepo
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
]
}
},
"version": "0.36.4"
"version": "0.37.0"
}
8 changes: 8 additions & 0 deletions packages/angular/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.37.0](https://github.com/carbon-design-system/carbon-charts/compare/v0.36.4...v0.37.0) (2020-09-11)

**Note:** Version bump only for package @carbon/charts-angular





## [0.36.4](https://github.com/carbon-design-system/carbon-charts/compare/v0.36.3...v0.36.4) (2020-09-10)

**Note:** Version bump only for package @carbon/charts-angular
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@carbon/charts-angular",
"version": "0.36.4",
"version": "0.37.0",
"description": "Carbon charting components for Angular",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -40,7 +40,7 @@
"scss"
],
"dependencies": {
"@carbon/charts": "^0.36.4"
"@carbon/charts": "^0.37.0"
},
"peerDependencies": {
"@angular/common": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0",
Expand Down
12 changes: 12 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.37.0](https://github.com/carbon-design-system/carbon-charts/compare/v0.36.4...v0.37.0) (2020-09-11)


### Features

* create options for tick rotation ([#770](https://github.com/carbon-design-system/carbon-charts/issues/770)) ([4063c8a](https://github.com/carbon-design-system/carbon-charts/commit/4063c8a0f4d441589116759b32f2b214fad46154))
* enable or disable scatter dot on charts except scatter chart ([#769](https://github.com/carbon-design-system/carbon-charts/issues/769)) ([3131942](https://github.com/carbon-design-system/carbon-charts/commit/313194217318719152d6a14c2a3cba957b8fc009))





## [0.36.4](https://github.com/carbon-design-system/carbon-charts/compare/v0.36.3...v0.36.4) (2020-09-10)

**Note:** Version bump only for package @carbon/charts
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@carbon/charts",
"version": "0.36.4",
"version": "0.37.0",
"description": "Carbon charting components",
"main": "./bundle.js",
"module": "./index.js",
Expand Down
119 changes: 50 additions & 69 deletions packages/core/src/components/axes/axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { Tools } from "../../tools";
import { ChartModel } from "../../model";
import { DOMUtils } from "../../services";
import { TickRotations } from "../../interfaces/enums";
import * as Configuration from "../../configuration";
import {
computeTimeIntervalName,
Expand All @@ -29,9 +30,6 @@ export class Axis extends Component {
scale: any;
scaleType: ScaleTypes;

// Track whether zoom domain needs to update in a render
zoomDomainChanging = false;

constructor(model: ChartModel, services: any, configs?: any) {
super(model, services, configs);

Expand All @@ -40,29 +38,6 @@ export class Axis extends Component {
}

this.margins = this.configs.margins;
this.init();
}

init() {
this.services.events.addEventListener(
Events.ZoomBar.SELECTION_START,
this.handleZoomBarSelectionStart
);
this.services.events.addEventListener(
Events.ZoomBar.SELECTION_END,
this.handleZoomBarSelectionEnd
);
}

handleZoomBarSelectionStart = () => {
this.zoomDomainChanging = true;
}

handleZoomBarSelectionEnd = () => {
this.zoomDomainChanging = false;
// need another update after zoom bar selection is completed
// to make sure the tick rotation is calculated correctly
this.services.events.dispatchEvent(Events.Model.UPDATE);
}

render(animate = true) {
Expand Down Expand Up @@ -130,6 +105,7 @@ export class Axis extends Component {
axisRef.attr("role", `${Roles.GRAPHICS_OBJECT} ${Roles.GROUP}`);
axisRef.attr("aria-label", `${axisPosition} ticks`);
}

// We draw the invisible axis because of the async nature of d3 transitions
// To be able to tell the final width & height of the axis when initiaing the transition
// The invisible axis is updated instantly and without a transition
Expand Down Expand Up @@ -445,41 +421,56 @@ export class Axis extends Component {
axisPosition === AxisPositions.BOTTOM ||
axisPosition === AxisPositions.TOP
) {
let rotateTicks = false;

// If we're dealing with a discrete scale type
// We're able to grab the spacing between the ticks
if (scale.step) {
const textNodes = invisibleAxisRef
.selectAll("g.tick text")
.nodes();

// If any ticks are any larger than the scale step size
rotateTicks = textNodes.some(
(textNode) =>
DOMUtils.getSVGElementSize(textNode, { useBBox: true })
.width >= scale.step()
);
} else {
// When dealing with a continuous scale
// We need to calculate an estimated size of the ticks
const minTickSize =
Tools.getProperty(
axisOptions,
"ticks",
"rotateIfSmallerThan"
) || Configuration.axis.ticks.rotateIfSmallerThan;
const ticksNumber = isTimeScaleType
? axis.tickValues().length
: scale.ticks().length;
const estimatedTickSize = width / ticksNumber / 2;
rotateTicks = isTimeScaleType
? estimatedTickSize < minTickSize * 2 // datetime tick could be very long
: estimatedTickSize < minTickSize;
let shouldRotateTicks = false;
// user could decide if tick rotation is required during zoom domain changing
const tickRotation = Tools.getProperty(
axisOptions,
"ticks",
"rotation"
);

if (tickRotation === TickRotations.ALWAYS) {
shouldRotateTicks = true;
} else if (tickRotation === TickRotations.NEVER) {
shouldRotateTicks = false;
} else if (!tickRotation || tickRotation === TickRotations.AUTO) {
// if the option is not set or set to AUTO

// depending on if tick rotation is necessary by calculating space
// If we're dealing with a discrete scale type
// We're able to grab the spacing between the ticks
if (scale.step) {
const textNodes = invisibleAxisRef
.selectAll("g.tick text")
.nodes();

// If any ticks are any larger than the scale step size
shouldRotateTicks = textNodes.some(
(textNode) =>
DOMUtils.getSVGElementSize(textNode, {
useBBox: true
}).width >= scale.step()
);
} else {
// When dealing with a continuous scale
// We need to calculate an estimated size of the ticks
const minTickSize =
Tools.getProperty(
axisOptions,
"ticks",
"rotateIfSmallerThan"
) || Configuration.axis.ticks.rotateIfSmallerThan;
const ticksNumber = isTimeScaleType
? axis.tickValues().length
: scale.ticks().length;
const estimatedTickSize = width / ticksNumber / 2;
shouldRotateTicks = isTimeScaleType
? estimatedTickSize < minTickSize * 2 // datetime tick could be very long
: estimatedTickSize < minTickSize;
}
}

// always rotate ticks if zoomDomain is changing to avoid rotation flips during zoomDomain changing
if (rotateTicks || this.zoomDomainChanging) {
if (shouldRotateTicks) {
if (!isNumberOfTicksProvided) {
axis.ticks(
this.getNumberOfFittingTicks(
Expand Down Expand Up @@ -696,15 +687,5 @@ export class Axis extends Component {
.on("mouseover", null)
.on("mousemove", null)
.on("mouseout", null);

// Remove zoom bar event listeners
this.services.events.removeEventListener(
Events.ZoomBar.SELECTION_START,
this.handleZoomBarSelectionStart
);
this.services.events.removeEventListener(
Events.ZoomBar.SELECTION_END,
this.handleZoomBarSelectionEnd
);
}
}
2 changes: 1 addition & 1 deletion packages/core/src/components/essentials/title-meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class MeterTitle extends Title {

// create a group for the icon/inner path
const statusGroup = DOMUtils.appendOrSelect(svg, `g.status-indicator`)
.classed(`status--${status}`, status !== null)
.attr("class", status !== null ? `status-indicator status--${status}` : "")
.attr("transform", `translate(${containerWidth - radius}, 0)`);

const data = status ? [status] : [];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/graphs/gauge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export class Gauge extends Component {
// Draw the arrow with status
const status = Tools.getProperty(options, "gauge", "status");
DOMUtils.appendOrSelect(deltaArrow, "polygon.gauge-delta-arrow")
.classed(`status--${status}`, status !== null)
.attr("class", status !== null ? `gauge-delta-arrow status--${status}` : "")
.attr("fill", () => (status === null ? "currentColor" : null))
.attr("points", self.getArrow(delta));

Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/components/graphs/meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export class Meter extends Component {
.attr("height", Tools.getProperty(options, "meter", "height"));

// value larger than 100 will display as 100% on meter chart
const dataset = data.value <= 100 ? data : (data["value"] = 100);
const maximumBarWidth = data.value >= 100;

// rect with the value binded
const value = svg.selectAll("rect.value").data([dataset]);
const value = svg.selectAll("rect.value").data([data]);

// if user provided a color for the bar, we dont want to attach a status class
const userProvidedScale = Tools.getProperty(options, "color", "scale");
Expand All @@ -50,14 +50,14 @@ export class Meter extends Component {
.attr("x", 0)
.attr("y", 0)
.attr("height", Tools.getProperty(options, "meter", "height"))
.classed(`status--${status}`, status != null && !userProvidedScale)
.attr("class", status != null && !userProvidedScale ? `value status--${status}` : "")
.transition(
this.services.transitions.getTransition(
"meter-bar-update",
animate
)
)
.attr("width", (d) => xScale(d.value))
.attr("width", (d) => maximumBarWidth ? xScale(100) : xScale(d.value))
.attr("fill", (d) => self.model.getFillColor(d[groupMapsTo]))
// a11y
.attr("role", Roles.GRAPHICS_SYMBOL)
Expand All @@ -69,11 +69,11 @@ export class Meter extends Component {

// update the peak if it is less than the value, it should be equal to the value
const updatedPeak =
peakValue !== null && peakValue < dataset.value
? dataset.value
peakValue !== null && peakValue < data.value
? data.value
: peakValue;
// dont display peak if there isnt one
const peakData = updatedPeak === null ? [] : [updatedPeak];
const peakData = updatedPeak === null || maximumBarWidth ? [] : [updatedPeak];

// if a peak is supplied within the domain, we want to render it
const peak = svg.selectAll("line.peak").data(peakData);
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/components/graphs/scatter-stacked.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
// Internal Imports
import { Scatter } from "./scatter";
import { Roles } from "../../interfaces";
import { Tools } from "../../tools";

export class StackedScatter extends Scatter {
type = "scatter-stacked";

render(animate: boolean) {
const isScatterEnabled = Tools.getProperty(this.model.getOptions(), "scatterDotEnabled");
if (!this.configs.alwaysEnableScatterDot) {
if (!isScatterEnabled) {
return;
}
}
// Grab container SVG
const svg = this.getContainerSVG({ withinChartClip: true });

Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/components/graphs/scatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export class Scatter extends Component {
}

render(animate: boolean) {
const isScatterEnabled = Tools.getProperty(this.model.getOptions(), "points", "enabled") || Tools.getProperty(this.model.getOptions(), "bubble", "enabled");
if (!isScatterEnabled) {
return;
}

// Grab container SVG
const svg = this.getContainerSVG({ withinChartClip: true });

Expand Down
Loading

0 comments on commit f3cfe15

Please sign in to comment.