From bf73a74dcd07406a246ed746ed84bc42f51bb11f Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sat, 1 Feb 2020 23:11:52 +0200 Subject: [PATCH] feat: add showWeekScale option (#278) --- docs/graph2d/index.html | 6 ++++++ docs/timeline/index.html | 10 ++++++++++ lib/timeline/TimeStep.js | 7 +++---- lib/timeline/component/DataAxis.js | 1 + lib/timeline/component/TimeAxis.js | 3 +++ lib/timeline/optionsGraph2d.js | 4 ++++ lib/timeline/optionsTimeline.js | 1 + types/index.d.ts | 3 +++ 8 files changed, 31 insertions(+), 4 deletions(-) diff --git a/docs/graph2d/index.html b/docs/graph2d/index.html index 4503153958..eebf85b921 100644 --- a/docs/graph2d/index.html +++ b/docs/graph2d/index.html @@ -539,6 +539,12 @@

Graph2d Options

true Toggle the drawing of the major labels on the Y axis. + + dataAxis.showWeekScale + Boolean + false + Toggle the drawing of the week scales on the Y axis. + dataAxis.visible Boolean diff --git a/docs/timeline/index.html b/docs/timeline/index.html index 8b1112e673..34a0a8e954 100644 --- a/docs/timeline/index.html +++ b/docs/timeline/index.html @@ -1124,6 +1124,16 @@

Configuration Options

visible. + + showWeekScale + boolean + false + By default, the timeline doesn't show week number scale in the date labels on the + time axis. + When showWeekScale is true, week number labels + are shown. + + showTooltips boolean diff --git a/lib/timeline/TimeStep.js b/lib/timeline/TimeStep.js index 945d72fdd9..6bee7aca18 100644 --- a/lib/timeline/TimeStep.js +++ b/lib/timeline/TimeStep.js @@ -30,11 +30,12 @@ class TimeStep { * @param {Date} [end] The end date * @param {number} [minimumStep] Optional. Minimum step size in milliseconds * @param {Date|Array.} [hiddenDates] Optional. - * @param {{showMajorLabels: boolean}} [options] Optional. + * @param {{showMajorLabels: boolean, showWeekScale: boolean}} [options] Optional. * @constructor TimeStep */ constructor(start, end, minimumStep, hiddenDates, options) { this.moment = (options && options.moment) || moment; + this.options = options ? options : {}; // variables this.current = this.moment(); @@ -63,8 +64,6 @@ class TimeStep { } this.format = TimeStep.FORMAT; // default formatting - this.options = options ? options : {}; - } /** @@ -319,7 +318,7 @@ class TimeStep { if (stepYear > minimumStep) {this.scale = 'year'; this.step = 1;} if (stepMonth*3 > minimumStep) {this.scale = 'month'; this.step = 3;} if (stepMonth > minimumStep) {this.scale = 'month'; this.step = 1;} - if (stepDay*7 > minimumStep) {this.scale = 'week'; this.step = 1;} + if (stepDay*7 > minimumStep && this.options.showWeekScale) {this.scale = 'week'; this.step = 1;} if (stepDay*2 > minimumStep) {this.scale = 'day'; this.step = 2;} if (stepDay > minimumStep) {this.scale = 'day'; this.step = 1;} if (stepDay/2 > minimumStep) {this.scale = 'weekday'; this.step = 1;} diff --git a/lib/timeline/component/DataAxis.js b/lib/timeline/component/DataAxis.js index a4ee776046..62335628f3 100644 --- a/lib/timeline/component/DataAxis.js +++ b/lib/timeline/component/DataAxis.js @@ -25,6 +25,7 @@ class DataAxis extends Component { orientation: 'left', // supported: 'left', 'right' showMinorLabels: true, showMajorLabels: true, + showWeekScale: false, icons: false, majorLinesOffset: 7, minorLinesOffset: 4, diff --git a/lib/timeline/component/TimeAxis.js b/lib/timeline/component/TimeAxis.js index 8ee58b76a7..88d775f6db 100644 --- a/lib/timeline/component/TimeAxis.js +++ b/lib/timeline/component/TimeAxis.js @@ -43,6 +43,7 @@ class TimeAxis extends Component { }, // axis orientation: 'top' or 'bottom' showMinorLabels: true, showMajorLabels: true, + showWeekScale: false, maxMinorChars: 7, format: TimeStep.FORMAT, moment, @@ -65,6 +66,7 @@ class TimeAxis extends Component { * {string} [orientation.axis] * {boolean} [showMinorLabels] * {boolean} [showMajorLabels] + * {boolean} [showWeekScale] */ setOptions(options) { if (options) { @@ -72,6 +74,7 @@ class TimeAxis extends Component { util.selectiveExtend([ 'showMinorLabels', 'showMajorLabels', + 'showWeekScale', 'maxMinorChars', 'hiddenDates', 'timeAxis', diff --git a/lib/timeline/optionsGraph2d.js b/lib/timeline/optionsGraph2d.js index 99209ac5c3..7ffab7e1ca 100644 --- a/lib/timeline/optionsGraph2d.js +++ b/lib/timeline/optionsGraph2d.js @@ -62,6 +62,7 @@ let allOptions = { dataAxis: { showMinorLabels: {'boolean': bool}, showMajorLabels: {'boolean': bool}, + showWeekScale: {'boolean': bool}, icons: {'boolean': bool}, width: {string, number}, visible: {'boolean': bool}, @@ -157,6 +158,7 @@ let allOptions = { showCurrentTime: {'boolean': bool}, showMajorLabels: {'boolean': bool}, showMinorLabels: {'boolean': bool}, + showWeekScale: {'boolean': bool}, start: {date, number, string, moment}, timeAxis: { scale: {string,'undefined': 'undefined'}, @@ -202,6 +204,7 @@ let configureOptions = { dataAxis: { showMinorLabels: true, showMajorLabels: true, + showWeekScale: false, icons: false, width: [40,0,200,1], visible: true, @@ -272,6 +275,7 @@ let configureOptions = { showCurrentTime: false, showMajorLabels: true, showMinorLabels: true, + showWeekScale: false, start: '', width: '100%', zoomable: true, diff --git a/lib/timeline/optionsTimeline.js b/lib/timeline/optionsTimeline.js index 1a0d0ba934..7646423136 100644 --- a/lib/timeline/optionsTimeline.js +++ b/lib/timeline/optionsTimeline.js @@ -146,6 +146,7 @@ let allOptions = { showCurrentTime: { 'boolean': bool}, showMajorLabels: { 'boolean': bool}, showMinorLabels: { 'boolean': bool}, + showWeekScale: { 'boolean': bool}, stack: { 'boolean': bool}, stackSubgroups: { 'boolean': bool}, cluster: { diff --git a/types/index.d.ts b/types/index.d.ts index 5c32a14ce7..b1e9111d93 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -303,6 +303,7 @@ export interface TimelineOptions { showCurrentTime?: boolean; showMajorLabels?: boolean; showMinorLabels?: boolean; + showWeekScale?: boolean; showTooltips?: boolean; stack?: boolean; stackSubgroups?: boolean; @@ -416,6 +417,7 @@ export interface Graph2dDataAxisOption { orientation?: TimelineOptionsOrientationType; showMinorLabels?: boolean; showMajorLabels?: boolean; + showWeekScale?: boolean; majorLinesOffset?: number; minorLinesOffset?: number; labelOffsetX?: number; @@ -475,6 +477,7 @@ export interface Graph2dOptions { showCurrentTime?: boolean; showMajorLabels?: boolean; showMinorLabels?: boolean; + showWeekScale?: boolean; sort?: boolean; stack?: boolean; start?: DateType;