Skip to content

Commit

Permalink
Version 5.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
martynasma committed Nov 30, 2023
1 parent 62447ae commit a4ec042
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 57 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@amcharts/amcharts5",
"version": "5.6.1",
"version": "5.6.2",
"author": "amCharts <contact@amcharts.com> (https://www.amcharts.com/)",
"description": "amCharts 5",
"homepage": "https://www.amcharts.com/",
Expand Down
15 changes: 15 additions & 0 deletions packages/shared/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
Please note, that this project, while following numbering syntax, it DOES NOT
adhere to [Semantic Versioning](http://semver.org/spec/v2.0.0.html) rules.

## [5.6.2] - 2023-11-30

### Added
- Middle handles added to Parallel channel drawings so that the drawing could be resized vertically.

### Changed
- Clicking on a last or any other bullet when drawing a polyline on a `StockChart` will terminate current polyline. The next click will start a new polyline.
- `extraMax` and `extraMin` settings now work on `GaplessDateAxis`. This allows adding extra space in front (or back) of your data. We recommend setting `maxDeviation` to `0` if you use `extraMax`.

### Fixed
- In some rare cases (with a specific data count and `groupData` set to `true`) the chart was continously switching from monthly to weekly group interval causing the chart to flicker.
- Tick position was not always correct with `minorGridEnabled` set to `true`.
- On a `DateAxis` when `gridInterval` was set to `week`, it still showed minor grid lines even when `baseInterval` was also `week`.


## [5.6.1] - 2023-11-27

### Changed
Expand Down
1 change: 1 addition & 0 deletions src/.internal/charts/stock/drawing/DrawingSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export class DrawingSeries extends LineSeries {
}

const container = this.grips.make();
container.setRaw("userData", "grip");
this.grips.push(container);

const circle = container.children.push(this.circles.make())
Expand Down
87 changes: 87 additions & 0 deletions src/.internal/charts/stock/drawing/ParallelChannelSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export class ParallelChannelSeries extends SimpleLineSeries {
this._addPoint(valueX, valueY, "p2", index);
this._addPoint(valueX, valueY, "p3", index);
this._addPoint(valueX, valueY, "p4", index);

this._addPoint(valueX, valueY, "m1", index);
this._addPoint(valueX, valueY, "m2", index);
}

protected _handlePointerClickReal(event: ISpritePointerEvent) {
Expand Down Expand Up @@ -72,6 +75,9 @@ export class ParallelChannelSeries extends SimpleLineSeries {
const diP3 = this._di[index]["p3"];
const diP4 = this._di[index]["p4"];

const diM1 = this._di[index]["m1"];
const diM2 = this._di[index]["m2"];

if (diP1 && diP2) {
if (this._firstClick) {
this._setContext(diP2, "valueX", valueX);
Expand All @@ -83,10 +89,20 @@ export class ParallelChannelSeries extends SimpleLineSeries {
this._setContext(diP4, "valueX", valueX);
this._setContext(diP4, "valueY", valueY, true);
this._setXLocation(diP4, valueX);

this._setContext(diM1, "valueX", valueX);
this._setContext(diM1, "valueY", valueY, true);
this._setXLocation(diM1, valueX);

this._setContext(diM2, "valueX", valueX);
this._setContext(diM2, "valueY", valueY, true);
this._setXLocation(diM2, valueX);
}
else {
this._setContext(diP4, "valueY", valueY, true);
this._setContext(diP3, "valueY", diP1.get("valueY", 0) + valueY - diP2.get("valueY", 0), true);

this._updateMiddlePoints(index);
}

this._updateSegment(index);
Expand All @@ -96,6 +112,61 @@ export class ParallelChannelSeries extends SimpleLineSeries {
}
}

protected _updateMiddlePoints(index: number) {
const diP1 = this._di[index]["p1"];
const diP2 = this._di[index]["p2"];

const diP3 = this._di[index]["p3"];
const diP4 = this._di[index]["p4"];

const diM1 = this._di[index]["m1"];
const diM2 = this._di[index]["m2"];

const valueX1 = diP1.get("valueX", 0);
const valueX2 = diP2.get("valueX", 0);
const valueX3 = diP3.get("valueX", 0);
const valueX4 = diP4.get("valueX", 0);

const valueY1 = diP1.get("valueY", 0);
const valueY2 = diP2.get("valueY", 0);
const valueY3 = diP3.get("valueY", 0);
const valueY4 = diP4.get("valueY", 0);

const xM1 = Math.round(valueX1 + (valueX2 - valueX1) / 2);

this._setContext(diM1, "valueY", valueY1 + (valueY2 - valueY1) / 2, true);
this._setContext(diM1, "valueX", xM1, true);
this._setXLocation(diM1, xM1);

const xM2 = valueX3 + (valueX4 - valueX3) / 2;
this._setContext(diM2, "valueY", valueY3 + (valueY4 - valueY3) / 2, true);
this._setContext(diM2, "valueX", xM2, true);
this._setXLocation(diM2, xM2);

if (diM1.bullets) {
const mBullet = diM1.bullets[0].get("sprite");
if (mBullet) {
const point1 = diP1.get("point");
const point2 = diP2.get("point");
if (point1 && point2) {
mBullet.set("x", point1.x + (point2.x - point1.x) / 2);
mBullet.set("y", point1.y + (point2.y - point1.y) / 2);
}
}
}
if (diM2.bullets) {
const mBullet = diM2.bullets[0].get("sprite");
if (mBullet) {
const point1 = diP3.get("point");
const point2 = diP4.get("point");
if (point1 && point2) {
mBullet.set("x", point1.x + (point2.x - point1.x) / 2);
mBullet.set("y", point1.y + (point2.y - point1.y) / 2);
}
}
}
}

public _updateChildren() {
super._updateChildren();
const chart = this.chart;
Expand Down Expand Up @@ -167,6 +238,7 @@ export class ParallelChannelSeries extends SimpleLineSeries {
})

this._updateOthers(i, fillGraphics, p1, p2);
this._updateMiddlePoints(i);
}
}
}
Expand All @@ -184,10 +256,14 @@ export class ParallelChannelSeries extends SimpleLineSeries {
const diP2 = this._di[index]["p2"];
const diP3 = this._di[index]["p3"];
const diP4 = this._di[index]["p4"];
const diM1 = this._di[index]["m1"];
const diM2 = this._di[index]["m2"];

if (diP1 && diP2 && diP3 && diP4) {

const dy = diP3.get("valueY", 0) - diP1.get("valueY", 0);
const dy1 = diP2.get("valueY", 0) - diP1.get("valueY", 0);
const dy2 = diP4.get("valueY", 0) - diP3.get("valueY", 0);

const vx = this._getXValue(xAxis.positionToValue(xAxis.coordinateToPosition(point.x)));
const vy = this._getYValue(yAxis.positionToValue(yAxis.coordinateToPosition(point.y)), vx);
Expand Down Expand Up @@ -218,11 +294,22 @@ export class ParallelChannelSeries extends SimpleLineSeries {
this._setContext(diP2, "valueY", vy - dy, true);
this._setXLocation(diP2, vx);
}
else if (corner == "m1") {
this._setContext(diP1, "valueY", vy - dy1 / 2, true);
this._setContext(diP2, "valueY", vy + dy1 / 2, true);
}
else if (corner == "m2") {
this._setContext(diP3, "valueY", vy - dy2 / 2, true);
this._setContext(diP4, "valueY", vy + dy2 / 2, true);
}
this._updateMiddlePoints(index);
}
this._positionBullets(diP1);
this._positionBullets(diP2);
this._positionBullets(diP3);
this._positionBullets(diP4);
this._positionBullets(diM1);
this._positionBullets(diM2);
}

protected _updateOthers(_index: number, _fillGraphics: Graphics, _p1: IPoint, _p2: IPoint) {
Expand Down
82 changes: 41 additions & 41 deletions src/.internal/charts/stock/drawing/PolylineSeries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { ISpritePointerEvent } from "../../../core/render/Sprite";
import type { DataItem } from "../../../core/render/Component";
import type { IPoint } from "../../../core/util/IPoint";
import { Line } from "../../../core/render/Line";

import { DrawingSeries, IDrawingSeriesSettings, IDrawingSeriesPrivate, IDrawingSeriesDataItem } from "./DrawingSeries";
Expand Down Expand Up @@ -32,32 +31,36 @@ export class PolylineSeries extends DrawingSeries {
if (this._drawingEnabled) {
super._handlePointerClick(event);

if (!this._isDragging) {
this._isDrawing = true;
// for consistency with other series
if (this._index == 0) {
this._index = 1;
}
if (event.target.get("userData") == "grip") {
this._endPolyline(event.target.dataItem);
}
else {
if (!this._isDragging) {
this._isDrawing = true;
// for consistency with other series
if (this._index == 0) {
this._index = 1;
}

if (this._pIndex == 0) {
this.data.push({ stroke: this._getStrokeTemplate(), index: this._index, corner: "e" });
if (this._pIndex == 0) {
this.data.push({ stroke: this._getStrokeTemplate(), index: this._index, corner: "e" });
}
this._drawingLine.show();
this._addPoint(event);
}
this._drawingLine.show();
this._addPoint(event);
}

this._drawingLine.set("stroke", this.get("strokeColor"));
this._drawingLine.set("stroke", this.get("strokeColor"));
}
}
}

protected _handleBulletDragStop(event: ISpritePointerEvent) {
super._handleBulletDragStop(event);
this._checkClosing(event);
}

public disableDrawing() {
super.disableDrawing();
this._drawingLine.hide();
this._endPolyline();
}

protected _afterDataChange() {
Expand Down Expand Up @@ -101,38 +104,35 @@ export class PolylineSeries extends DrawingSeries {
this._setXLocation(dataItem, valueX);

this._pIndex++;
this._handleClosing(dataItem, point);
}
}

protected _checkClosing(event: ISpritePointerEvent) {
const dataItem = event.target.dataItem;
if (dataItem) {
const sprite = event.target;
const point = { x: sprite.x(), y: sprite.y() }
this._handleClosing(dataItem, point);
protected _endPolyline(dataItem?: DataItem<this["_dataItemSettings"]>) {
if (!dataItem) {
dataItem = this.dataItems[this.dataItems.length - 1];
}
}

protected _handleClosing(dataItem: DataItem<this["_dataItemSettings"]>, point: IPoint) {
const dataContext = dataItem.dataContext as any;
if (!dataContext.closing) {
if (dataItem) {
this._pIndex = 0;
const dataContext = dataItem.dataContext as any;

const index = dataContext.index;
if (this._di[index]) {
const firstDataItem = this._di[index][0];

if (firstDataItem && firstDataItem != dataItem) {
const dPoint = firstDataItem.get("point");
if (dPoint) {
if (Math.hypot(point.x - dPoint.x, point.y - dPoint.y) < 5) {
dataContext.closing = true;
this._pIndex = 0;
this.data.push({ stroke: this._getStrokeTemplate(), index: index + 1, corner: "e" });
this._drawingLine.hide();
}
}
}

if (dataContext.corner == 0) {
this.data.push({ valueX: dataItem.get("valueX"), valueY: dataItem.get("valueY"), index: index, corner: this._pIndex + 1, closing: true })

const dataItems = this.dataItems;
const len = dataItems.length - 1;

this.setPrivate("startIndex", 0);
this.setPrivate("endIndex", len);

dataItem = dataItems[len];
this._positionBullets(dataItem);
this._setXLocation(dataItem, dataItem.get("valueX", 0));
}
this.data.push({ stroke: this._getStrokeTemplate(), index: index + 1, corner: "e" });
this._drawingLine.hide();
}
}

Expand All @@ -144,7 +144,7 @@ export class PolylineSeries extends DrawingSeries {
if (movePoint) {
const dataItems = this.dataItems;
const len = dataItems.length;
if(len > 0){
if (len > 0) {
const lastItem = dataItems[len - 1];

const point = lastItem.get("point");
Expand Down
27 changes: 17 additions & 10 deletions src/.internal/charts/xy/axes/DateAxis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface IDateAxisSettings<R extends AxisRenderer> extends IValueAxisSet
groupCount?: number;

/**
* Force data item grouping to specific interval.
* Force data item grouping to specific interval. This interval must be within groupIntervals array for this to work.
*
* @see {@link https://www.amcharts.com/docs/v5/charts/xy-chart/axes/date-axis/#Dynamic_data_item_grouping} for more info
*/
Expand Down Expand Up @@ -521,15 +521,20 @@ export class DateAxis<R extends AxisRenderer> extends ValueAxis<R> {
if (this.get("groupData") && !this._groupingCalculated) {
this._groupingCalculated = true;

let modifiedDifference = (selectionMax - selectionMin) + (this.get("startLocation", 0) + (1 - this.get("endLocation", 1)) * this.baseDuration());
let groupInterval = this.get("groupInterval");
let current = this.getPrivate("groupInterval");

let modifiedDifference = (selectionMax - selectionMin) + (this.get("startLocation", 0) + (1 - this.get("endLocation", 1)) * this.baseDuration());

if (current) {
let duration = $time.getIntervalDuration(current);
modifiedDifference = Math.ceil(modifiedDifference / duration) * duration;
}

if (!groupInterval) {
groupInterval = this.getGroupInterval(modifiedDifference);
}

let current = this.getPrivate("groupInterval");

if (groupInterval && (!current || (current.timeUnit !== groupInterval.timeUnit || current.count !== groupInterval.count) || this._seriesDataGrouped)) {
this._seriesDataGrouped = false;
this.setPrivateRaw("groupInterval", groupInterval);
Expand Down Expand Up @@ -641,8 +646,8 @@ export class DateAxis<R extends AxisRenderer> extends ValueAxis<R> {
return 1.01;
}

protected _getMinorInterval(interval:ITimeInterval):ITimeInterval | undefined{
let minorGridInterval:ITimeInterval | undefined;
protected _getMinorInterval(interval: ITimeInterval): ITimeInterval | undefined {
let minorGridInterval: ITimeInterval | undefined;
let count = interval.count;
let timeUnit = interval.timeUnit;
if (count > 1) {
Expand All @@ -654,10 +659,10 @@ export class DateAxis<R extends AxisRenderer> extends ValueAxis<R> {
}
else if (count == 12) {
count = 2;
}
}
else if (count == 6) {
count = 1;
}
}
else if (count == 30) {
count = 10;
}
Expand All @@ -667,7 +672,9 @@ export class DateAxis<R extends AxisRenderer> extends ValueAxis<R> {
minorGridInterval = { timeUnit: timeUnit, count: count };
}
if (timeUnit == "week") {
minorGridInterval = { timeUnit: "day", count: 1 };
if(this.getPrivate("baseInterval")?.timeUnit != "week"){
minorGridInterval = { timeUnit: "day", count: 1 };
}
}
return minorGridInterval;
}
Expand Down Expand Up @@ -820,7 +827,7 @@ export class DateAxis<R extends AxisRenderer> extends ValueAxis<R> {
minorLabel.set("text", this._root.dateFormatter.format(date, format!));
}
else {
minorLabel.setPrivate("visible", false);
minorLabel.setPrivate("visible", false);
}
}

Expand Down
Loading

0 comments on commit a4ec042

Please sign in to comment.