Skip to content

Commit

Permalink
feat(core): date/time locale support + tick formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
theiliad committed Oct 28, 2019
1 parent 88b6b42 commit bc02012
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"ng-packagr": "4.7.1",
"rxjs": "6.3.3",
"tslint": "5.14.0",
"typescript": "2.8.1",
"typescript": "3.6.4",
"zone.js": "0.8.29"
},
"ngPackage": {
Expand Down
10 changes: 8 additions & 2 deletions packages/core/demo/demo-data/bar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { colors } from "./colors";
import { getTheme } from "./themes";

// Demo turkish locale for simple bar time-series
const turkishLocale = require("d3-time-format/locale/tr-TR.json");

export const groupedBarData = {
labels: ["Qty", "More", "Sold", "Restocking", "Misc"],
datasets: [
Expand Down Expand Up @@ -134,16 +137,19 @@ export const simpleBarTimeSeriesData = {
};

export const simpleBarTimeSeriesOptions = {
title: "Simple bar (time series)",
title: "Simple bar (time series - Turkish)",
axes: {
left: {
primary: true
},
bottom: {
type: "time",
secondary: true,
secondary: true
}
},
locale: {
time: turkishLocale
},
theme: getTheme()
};

Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"tslint": "5.8.0",
"tslint-loader": "3.5.3",
"typedoc": "0.11.1",
"typescript": "2.8.1",
"typescript": "3.6.4",
"url-loader": "0.6.2",
"webpack": "4.41.0",
"webpack-cli": "3.3.9",
Expand Down
12 changes: 11 additions & 1 deletion packages/core/src/components/axes/axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DOMUtils } from "../../services";
import { scaleBand, scaleLinear, scaleTime, scaleLog, scaleOrdinal } from "d3-scale";
import { axisBottom, axisLeft, axisRight, axisTop } from "d3-axis";
import { min, max, extent } from "d3-array";
import { timeFormat, timeFormatDefaultLocale } from "d3-time-format";

export class Axis extends Component {
type = "axes";
Expand Down Expand Up @@ -189,9 +190,18 @@ export class Axis extends Component {
break;
}

// Set the date/time locale
if (this.scaleType === ScaleTypes.TIME) {
const timeLocale = Tools.getProperty(options, "locale", "time");
if (timeLocale) {
timeFormatDefaultLocale(timeLocale);
}
}

// Initialize axis object
const axis = axisFunction(scale)
.tickSizeOuter(0);
.tickSizeOuter(0)
.tickFormat(Tools.getProperty(axisOptions, "ticks", "formatter"));

if (scale.ticks) {
const numberOfTicks = 7;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (typeof window !== "undefined") {
}

CustomEvent.prototype = window["Event"].prototype;
window["CustomEvent"] = CustomEvent;
window["CustomEvent"] = CustomEvent as any;
})();

// Avoid multiple instances of babel-polyfill
Expand Down
1 change: 1 addition & 0 deletions packages/core/tsconfig-demo.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"mapRoot": "./",
"module": "es2015",
"moduleResolution": "node",
"resolveJsonModule": true,
"outDir": "./demo/dist",
"rootDirs": ["./demo", "./src"],
"target": "es5",
Expand Down
1 change: 1 addition & 0 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"mapRoot": "./",
"module": "es2015",
"moduleResolution": "node",
"resolveJsonModule": true,
"outDir": "./dist",
"rootDir": "./src",
"target": "es5",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
},
resolve: {
// Add ".ts" and ".tsx" as a resolvable extension.
extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".json", ".js"]
},
module: {
rules: [
Expand Down
Binary file removed yarn-offline-mirror-cache/typescript-2.8.1.tgz
Binary file not shown.
Binary file added yarn-offline-mirror-cache/typescript-3.6.4.tgz
Binary file not shown.
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19562,16 +19562,16 @@ [email protected]:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.2.tgz#2d615a1ef4aee4f574425cdff7026edf81919836"
integrity sha512-p5TCYZDAO0m4G344hD+wx/LATebLWZNkkh2asWUFqSsD2OrDNhbAHuSjobrmsUmdzjJjEeZVU9g1h3O6vpstnw==

[email protected]:
version "2.8.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.1.tgz#6160e4f8f195d5ba81d4876f9c0cc1fbc0820624"
integrity sha512-Ao/f6d/4EPLq0YwzsQz8iXflezpTkQzqAyenTiw4kCUGr1uPiFLC3+fZ+gMZz6eeI/qdRUqvC+HxIJzUAzEFdg==

[email protected]:
version "2.9.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c"
integrity sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==

[email protected]:
version "3.6.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.4.tgz#b18752bb3792bc1a0281335f7f6ebf1bbfc5b91d"
integrity sha512-unoCll1+l+YK4i4F8f22TaNVPRHcD9PA3yCuZ8g5e0qGqlVlJ/8FSateOLLSagn+Yg5+ZwuPkL8LFUc0Jcvksg==

ua-parser-js@^0.7.18:
version "0.7.20"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.20.tgz#7527178b82f6a62a0f243d1f94fd30e3e3c21098"
Expand Down

0 comments on commit bc02012

Please sign in to comment.