1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02:00
Maybe/app/javascript/controllers/time_series_chart_controller.js

549 lines
14 KiB
JavaScript
Raw Normal View History

import { Controller } from "@hotwired/stimulus";
import * as d3 from "d3";
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
export default class extends Controller {
static values = {
data: Object,
strokeWidth: { type: Number, default: 2 },
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
useLabels: { type: Boolean, default: true },
useTooltip: { type: Boolean, default: true },
usePercentSign: Boolean,
};
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
2024-10-11 14:40:13 -04:00
_d3SvgMemo = null;
_d3GroupMemo = null;
_d3Tooltip = null;
_d3InitialContainerWidth = 0;
_d3InitialContainerHeight = 0;
_normalDataPoints = [];
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
connect() {
this._install();
document.addEventListener("turbo:load", this._reinstall);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
disconnect() {
this._teardown();
document.removeEventListener("turbo:load", this._reinstall);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_reinstall = () => {
this._teardown();
this._install();
};
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
2024-10-11 14:40:13 -04:00
_teardown() {
this._d3SvgMemo = null;
this._d3GroupMemo = null;
this._d3Tooltip = null;
this._normalDataPoints = [];
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
this._d3Container.selectAll("*").remove();
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_install() {
this._normalizeDataPoints();
this._rememberInitialContainerSize();
this._draw();
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_normalizeDataPoints() {
this._normalDataPoints = (this.dataValue.values || []).map((d) => ({
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
...d,
2024-11-19 16:23:21 -05:00
date: new Date(`${d.date}T00:00:00Z`),
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
value: d.value.amount ? +d.value.amount : +d.value,
currency: d.value.currency,
}));
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_rememberInitialContainerSize() {
this._d3InitialContainerWidth = this._d3Container.node().clientWidth;
this._d3InitialContainerHeight = this._d3Container.node().clientHeight;
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_draw() {
if (this._normalDataPoints.length < 2) {
this._drawEmpty();
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
} else {
this._drawChart();
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
}
2024-10-11 14:40:13 -04:00
_drawEmpty() {
this._d3Svg.selectAll(".tick").remove();
this._d3Svg.selectAll(".domain").remove();
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
this._drawDashedLineEmptyState();
this._drawCenteredCircleEmptyState();
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_drawDashedLineEmptyState() {
this._d3Svg
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.append("line")
2024-10-11 14:40:13 -04:00
.attr("x1", this._d3InitialContainerWidth / 2)
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.attr("y1", 0)
2024-10-11 14:40:13 -04:00
.attr("x2", this._d3InitialContainerWidth / 2)
.attr("y2", this._d3InitialContainerHeight)
.attr("stroke", "var(--color-gray-300)")
.attr("stroke-dasharray", "4, 4");
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_drawCenteredCircleEmptyState() {
this._d3Svg
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.append("circle")
2024-10-11 14:40:13 -04:00
.attr("cx", this._d3InitialContainerWidth / 2)
.attr("cy", this._d3InitialContainerHeight / 2)
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.attr("r", 4)
.style("fill", "var(--color-gray-400)");
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_drawChart() {
this._drawTrendline();
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
if (this.useLabelsValue) {
this._drawXAxisLabels();
this._drawGradientBelowTrendline();
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
if (this.useTooltipValue) {
this._drawTooltip();
this._trackMouseForShowingTooltip();
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
}
2024-10-11 14:40:13 -04:00
_drawTrendline() {
this._installTrendlineSplit();
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
2024-10-11 14:40:13 -04:00
this._d3Group
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.append("path")
2024-10-11 14:40:13 -04:00
.datum(this._normalDataPoints)
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.attr("fill", "none")
.attr("stroke", `url(#${this.element.id}-split-gradient)`)
2024-10-11 14:40:13 -04:00
.attr("d", this._d3Line)
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("stroke-width", this.strokeWidthValue);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_installTrendlineSplit() {
const gradient = this._d3Svg
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.append("defs")
.append("linearGradient")
.attr("id", `${this.element.id}-split-gradient`)
.attr("gradientUnits", "userSpaceOnUse")
2024-10-11 14:40:13 -04:00
.attr("x1", this._d3XScale.range()[0])
.attr("x2", this._d3XScale.range()[1]);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
gradient
.append("stop")
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.attr("class", "start-color")
.attr("offset", "0%")
.attr("stop-color", this._trendColor);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
gradient
.append("stop")
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.attr("class", "middle-color")
.attr("offset", "100%")
.attr("stop-color", this._trendColor);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
gradient
.append("stop")
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.attr("class", "end-color")
.attr("offset", "100%")
.attr("stop-color", "var(--color-gray-300)");
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_setTrendlineSplitAt(percent) {
this._d3Svg
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.select(`#${this.element.id}-split-gradient`)
.select(".middle-color")
.attr("offset", `${percent * 100}%`);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
2024-10-11 14:40:13 -04:00
this._d3Svg
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.select(`#${this.element.id}-split-gradient`)
.select(".end-color")
.attr("offset", `${percent * 100}%`);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
2024-10-11 14:40:13 -04:00
this._d3Svg
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.select(`#${this.element.id}-trendline-gradient-rect`)
.attr("width", this._d3ContainerWidth * percent);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_drawXAxisLabels() {
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
// Add ticks
2024-10-11 14:40:13 -04:00
this._d3Group
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.append("g")
2024-10-11 14:40:13 -04:00
.attr("transform", `translate(0,${this._d3ContainerHeight})`)
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.call(
d3
2024-10-11 14:40:13 -04:00
.axisBottom(this._d3XScale)
.tickValues([
this._normalDataPoints[0].date,
this._normalDataPoints[this._normalDataPoints.length - 1].date,
])
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.tickSize(0)
2024-11-18 11:44:41 -05:00
.tickFormat(d3.utcFormat("%d %b %Y")),
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
)
.select(".domain")
.remove();
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
// Style ticks
this._d3Group
.selectAll(".tick text")
.style("fill", "var(--color-gray-500)")
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.style("font-size", "12px")
.style("font-weight", "500")
.attr("text-anchor", "middle")
.attr("dx", (_d, i) => {
// We know we only have 2 values
return i === 0 ? "5em" : "-5em";
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
})
.attr("dy", "0em");
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_drawGradientBelowTrendline() {
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
// Define gradient
2024-10-11 14:40:13 -04:00
const gradient = this._d3Group
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.append("defs")
.append("linearGradient")
.attr("id", `${this.element.id}-trendline-gradient`)
.attr("gradientUnits", "userSpaceOnUse")
.attr("x1", 0)
.attr("x2", 0)
.attr(
"y1",
this._d3YScale(d3.max(this._normalDataPoints, (d) => d.value)),
)
.attr("y2", this._d3ContainerHeight);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
gradient
.append("stop")
.attr("offset", 0)
2024-10-11 14:40:13 -04:00
.attr("stop-color", this._trendColor)
.attr("stop-opacity", 0.06);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
gradient
.append("stop")
.attr("offset", 0.5)
2024-10-11 14:40:13 -04:00
.attr("stop-color", this._trendColor)
.attr("stop-opacity", 0);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
// Clip path makes gradient start at the trendline
2024-10-11 14:40:13 -04:00
this._d3Group
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.append("clipPath")
.attr("id", `${this.element.id}-clip-below-trendline`)
.append("path")
2024-10-11 14:40:13 -04:00
.datum(this._normalDataPoints)
.attr(
"d",
d3
.area()
.x((d) => this._d3XScale(d.date))
.y0(this._d3ContainerHeight)
.y1((d) => this._d3YScale(d.value)),
);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
// Apply the gradient + clip path
2024-10-11 14:40:13 -04:00
this._d3Group
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.append("rect")
.attr("id", `${this.element.id}-trendline-gradient-rect`)
2024-10-11 14:40:13 -04:00
.attr("width", this._d3ContainerWidth)
.attr("height", this._d3ContainerHeight)
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.attr("clip-path", `url(#${this.element.id}-clip-below-trendline)`)
.style("fill", `url(#${this.element.id}-trendline-gradient)`);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_drawTooltip() {
this._d3Tooltip = d3
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.select(`#${this.element.id}`)
.append("div")
.style("position", "absolute")
.style("padding", "8px")
.style("font", "14px Inter, sans-serif")
.style("background", "var(--color-white)")
.style("border", "1px solid var(--color-alpha-black-100)")
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.style("border-radius", "10px")
.style("pointer-events", "none")
.style("opacity", 0); // Starts as hidden
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_trackMouseForShowingTooltip() {
const bisectDate = d3.bisector((d) => d.date).left;
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
2024-10-11 14:40:13 -04:00
this._d3Group
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.append("rect")
2024-10-11 14:40:13 -04:00
.attr("width", this._d3ContainerWidth)
.attr("height", this._d3ContainerHeight)
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.attr("fill", "none")
.attr("pointer-events", "all")
.on("mousemove", (event) => {
const estimatedTooltipWidth = 250;
const pageWidth = document.body.clientWidth;
const tooltipX = event.pageX + 10;
const overflowX = tooltipX + estimatedTooltipWidth - pageWidth;
const adjustedX =
overflowX > 0 ? event.pageX - overflowX - 20 : tooltipX;
const [xPos] = d3.pointer(event);
const x0 = bisectDate(
this._normalDataPoints,
this._d3XScale.invert(xPos),
1,
);
const d0 = this._normalDataPoints[x0 - 1];
const d1 = this._normalDataPoints[x0];
const d =
xPos - this._d3XScale(d0.date) > this._d3XScale(d1.date) - xPos
? d1
: d0;
const xPercent = this._d3XScale(d.date) / this._d3ContainerWidth;
this._setTrendlineSplitAt(xPercent);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
// Reset
this._d3Group.selectAll(".data-point-circle").remove();
this._d3Group.selectAll(".guideline").remove();
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
// Guideline
2024-10-11 14:40:13 -04:00
this._d3Group
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.append("line")
.attr("class", "guideline")
2024-10-11 14:40:13 -04:00
.attr("x1", this._d3XScale(d.date))
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.attr("y1", 0)
2024-10-11 14:40:13 -04:00
.attr("x2", this._d3XScale(d.date))
.attr("y2", this._d3ContainerHeight)
.attr("stroke", "var(--color-gray-300)")
.attr("stroke-dasharray", "4, 4");
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
// Big circle
2024-10-11 14:40:13 -04:00
this._d3Group
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.append("circle")
.attr("class", "data-point-circle")
2024-10-11 14:40:13 -04:00
.attr("cx", this._d3XScale(d.date))
.attr("cy", this._d3YScale(d.value))
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.attr("r", 8)
2024-10-11 14:40:13 -04:00
.attr("fill", this._trendColor)
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.attr("fill-opacity", "0.1")
.attr("pointer-events", "none");
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
// Small circle
2024-10-11 14:40:13 -04:00
this._d3Group
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.append("circle")
.attr("class", "data-point-circle")
2024-10-11 14:40:13 -04:00
.attr("cx", this._d3XScale(d.date))
.attr("cy", this._d3YScale(d.value))
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.attr("r", 3)
2024-10-11 14:40:13 -04:00
.attr("fill", this._trendColor)
.attr("pointer-events", "none");
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
// Render tooltip
2024-10-11 14:40:13 -04:00
this._d3Tooltip
.html(this._tooltipTemplate(d))
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.style("opacity", 1)
.style("z-index", 999)
.style("left", `${adjustedX}px`)
.style("top", `${event.pageY - 10}px`);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
})
.on("mouseout", (event) => {
const hoveringOnGuideline =
event.toElement?.classList.contains("guideline");
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
if (!hoveringOnGuideline) {
this._d3Group.selectAll(".guideline").remove();
this._d3Group.selectAll(".data-point-circle").remove();
this._d3Tooltip.style("opacity", 0);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
this._setTrendlineSplitAt(1);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
});
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_tooltipTemplate(datum) {
return `
<div style="margin-bottom: 4px; color: var(--color-gray-500);">
2024-11-18 11:44:41 -05:00
${d3.utcFormat("%b %d, %Y")(datum.date)}
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
</div>
<div style="display: flex; align-items: center; gap: 16px;">
<div style="display: flex; align-items: center; gap: 8px;">
<svg width="10" height="10">
<circle
cx="5"
cy="5"
r="4"
2024-10-11 14:40:13 -04:00
stroke="${this._tooltipTrendColor(datum)}"
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
fill="transparent"
stroke-width="1"></circle>
</svg>
2024-10-11 14:40:13 -04:00
${this._tooltipValue(datum)}${this.usePercentSignValue ? "%" : ""}
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
</div>
${
this.usePercentSignValue ||
datum.trend.value === 0 ||
datum.trend.value.amount === 0
? `
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
<span style="width: 80px;"></span>
`
: `
2024-10-11 14:40:13 -04:00
<span style="color: ${this._tooltipTrendColor(datum)};">
${this._tooltipChange(datum)} (${datum.trend.percent}%)
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
</span>
`
}
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
</div>
`;
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_tooltipTrendColor(datum) {
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
return {
2024-11-18 12:01:27 -05:00
up:
datum.trend.favorable_direction === "up"
? "var(--color-success)"
: "var(--color-destructive)",
2024-11-18 12:01:27 -05:00
down:
datum.trend.favorable_direction === "down"
? "var(--color-success)"
: "var(--color-destructive)",
flat: "var(--color-gray-500)",
}[datum.trend.direction];
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_tooltipValue(datum) {
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
if (datum.currency) {
return this._currencyValue(datum);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
return datum.value;
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_tooltipChange(datum) {
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
if (datum.currency) {
return this._currencyChange(datum);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
return this._decimalChange(datum);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_currencyValue(datum) {
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
return Intl.NumberFormat(undefined, {
style: "currency",
currency: datum.currency,
}).format(datum.value);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_currencyChange(datum) {
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
return Intl.NumberFormat(undefined, {
style: "currency",
currency: datum.currency,
signDisplay: "always",
}).format(datum.trend.value.amount);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_decimalChange(datum) {
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
return Intl.NumberFormat(undefined, {
style: "decimal",
signDisplay: "always",
}).format(datum.trend.value);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_createMainSvg() {
return this._d3Container
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.append("svg")
2024-10-11 14:40:13 -04:00
.attr("width", this._d3InitialContainerWidth)
.attr("height", this._d3InitialContainerHeight)
.attr("viewBox", [
0,
0,
this._d3InitialContainerWidth,
this._d3InitialContainerHeight,
]);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
_createMainGroup() {
return this._d3Svg
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
.append("g")
.attr("transform", `translate(${this._margin.left},${this._margin.top})`);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
get _d3Svg() {
if (!this._d3SvgMemo) {
this._d3SvgMemo = this._createMainSvg();
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
return this._d3SvgMemo;
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
get _d3Group() {
if (!this._d3GroupMemo) {
this._d3GroupMemo = this._createMainGroup();
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
return this._d3GroupMemo;
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
get _margin() {
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
if (this.useLabelsValue) {
return { top: 20, right: 0, bottom: 30, left: 0 };
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
return { top: 0, right: 0, bottom: 0, left: 0 };
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
get _d3ContainerWidth() {
return (
this._d3InitialContainerWidth - this._margin.left - this._margin.right
);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
get _d3ContainerHeight() {
return (
this._d3InitialContainerHeight - this._margin.top - this._margin.bottom
);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
get _d3Container() {
return d3.select(this.element);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
get _trendColor() {
if (this._trendDirection === "flat") {
return "var(--color-gray-500)";
}
if (this._trendDirection === this._favorableDirection) {
return "var(--color-green-500)";
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
return "var(--color-destructive)";
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
get _trendDirection() {
return this.dataValue.trend.direction;
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
get _favorableDirection() {
return this.dataValue.trend.favorable_direction;
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
get _d3Line() {
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
return d3
.line()
.x((d) => this._d3XScale(d.date))
.y((d) => this._d3YScale(d.value));
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
get _d3XScale() {
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
return d3
.scaleTime()
2024-10-11 14:40:13 -04:00
.rangeRound([0, this._d3ContainerWidth])
.domain(d3.extent(this._normalDataPoints, (d) => d.date));
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
2024-10-11 14:40:13 -04:00
get _d3YScale() {
const reductionPercent = this.useLabelsValue ? 0.3 : 0.05;
const dataMin = d3.min(this._normalDataPoints, (d) => d.value);
const dataMax = d3.max(this._normalDataPoints, (d) => d.value);
const padding = (dataMax - dataMin) * reductionPercent;
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
return d3
.scaleLinear()
2024-10-11 14:40:13 -04:00
.rangeRound([this._d3ContainerHeight, 0])
.domain([dataMin - padding, dataMax + padding]);
Flesh out D3 time series charts (#657) * Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes * Refactor trendline chart controller into a time series chart controller * Replace trendline controller * Implement empty state * Port line-chart controller into time-series-chart * Split out methods * Group similar time series chart functionality * Fix indicator color * Fix empty state in time series chart * Replace line-chart controller with time-series-chart controller * Draw empty time series chart if less than 2 data points * Fix favorable direction serialization * Handle integers as well as money * Fix favorable direction serialization * Replace chart types with optional elements * Prevent double-renders when displaying turbo caches of time series charts * Remove ambiguities between time series and series data * Improve time series chart property names * Clean up tooltip template * Match tooltip designs * Apply trendline gradient * Implement trendline split behavior * Use same stroke width on all trend lines * Sort time series data by date * Support percentages * Use data color for guideline circles * Revert "Use data color for guideline circles" This reverts commit f239a1e00f84ae28e32f48315d67cf990e541a8a. * Use expected defaults for time series chart * Include day in time-series chart x-axis labels * favorableDirection -> favorable_direction * data -> datum where appropriate * Hide change data in tooltip for percentages
2024-04-22 11:44:26 -06:00
}
}