UNPKG

@apptane/react-ui-charts

Version:
45 lines (39 loc) 2.46 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; const _excluded = ["scale", "format", "tickValues"]; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } import { useMemo } from "react"; import { timeDay, timeHour, timeMinute, timeMonth, timeWeek, timeYear } from "d3-time"; import { timeFormat } from "d3-time-format"; import { ChartAxis } from "./ChartAxis.js"; import { jsx as _jsx } from "@emotion/react/jsx-runtime"; const FormatSecond = timeFormat(":%S"); const FormatMinute = timeFormat("%H:%M"); const FormatHour = timeFormat("%I %p"); const FormatDay = timeFormat("%a %d"); const FormatWeek = timeFormat("%b %d"); const FormatMonth = timeFormat("%b"); const FormatYear = timeFormat("%Y"); /** * Formats tick labels for time-based axis. */ function formatTime(v) { return (timeMinute(v) < v ? FormatSecond : timeHour(v) < v ? FormatMinute : timeDay(v) < v ? FormatHour : timeMonth(v) < v ? timeWeek(v) < v ? FormatDay : FormatWeek : timeYear(v) < v ? FormatMonth : FormatYear)(v); } export function ChartTimeAxis(_ref) { let { scale, format, tickValues } = _ref, other = _objectWithoutProperties(_ref, _excluded); const ticks = useMemo(() => tickValues != null && Array.isArray(tickValues) ? tickValues : scale.ticks(tickValues), [scale, tickValues]); return _jsx(ChartAxis, _objectSpread(_objectSpread({}, other), {}, { extent: scale.range()[1], ticks: ticks, tickPosition: scale, format: format !== null && format !== void 0 ? format : formatTime })); } //# sourceMappingURL=ChartTimeAxis.js.map