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

519 lines
14 KiB
JavaScript
Raw Normal View History

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
import { Controller } from "@hotwired/stimulus"
import tailwindColors from "@maybe/tailwindcolors"
import * as d3 from "d3"
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
}
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() {
2024-10-11 14:40:13 -04:00
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() {
2024-10-11 14:40:13 -04:00
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
2024-10-11 14:40:13 -04: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,
date: new Date(d.date),
value: d.value.amount ? +d.value.amount : +d.value,
currency: d.value.currency
}))
}
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 {
2024-10-11 14:40:13 -04:00
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
2024-10-11 14:40:13 -04: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)
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", tailwindColors.gray[300])
.attr("stroke-dasharray", "4, 4")
}
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", tailwindColors.gray[400])
}
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) {
2024-10-11 14:40:13 -04:00
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) {
2024-10-11 14:40:13 -04:00
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")
.attr("class", "start-color")
.attr("offset", "0%")
2024-10-11 14:40:13 -04:00
.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")
.attr("class", "middle-color")
.attr("offset", "100%")
2024-10-11 14:40:13 -04:00
.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")
.attr("class", "end-color")
.attr("offset", "100%")
.attr("stop-color", tailwindColors.gray[300])
}
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}%`)
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}%`)
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`)
2024-10-11 14:40:13 -04:00
.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)
.tickFormat(d3.timeFormat("%d %b %Y"))
)
.select(".domain")
.remove()
// Style ticks
2024-10-11 14:40:13 -04:00
this._d3Group.selectAll(".tick text")
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("fill", tailwindColors.gray[500])
.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"
})
.attr("dy", "0em")
}
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)
2024-10-11 14:40:13 -04:00
.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)
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("stop-opacity", 0.06)
gradient
.append("stop")
.attr("offset", 0.5)
2024-10-11 14:40:13 -04:00
.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
.attr("stop-opacity", 0)
// 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)
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("d", d3.area()
2024-10-11 14:40:13 -04:00
.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)`)
}
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", tailwindColors.white)
.style("border", `1px solid ${tailwindColors["alpha-black"][100]}`)
.style("border-radius", "10px")
.style("pointer-events", "none")
.style("opacity", 0) // Starts as hidden
}
2024-10-11 14:40:13 -04:00
_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
const bisectDate = d3.bisector(d => d.date).left
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)
2024-10-11 14:40:13 -04:00
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
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._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
2024-10-11 14:40:13 -04:00
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)
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", tailwindColors.gray[300])
.attr("stroke-dasharray", "4, 4")
// 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")
// 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)
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("pointer-events", "none")
// 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)
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("left", adjustedX + "px")
.style("top", event.pageY - 10 + "px")
})
.on("mouseout", (event) => {
const hoveringOnGuideline = event.toElement?.classList.contains("guideline")
if (!hoveringOnGuideline) {
2024-10-11 14:40:13 -04:00
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
2024-10-11 14:40:13 -04: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
}
})
}
2024-10-11 14:40:13 -04:00
_tooltipTemplate(datum) {
return (`
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 style="margin-bottom: 4px; color: ${tailwindColors.gray[500]};">
${d3.timeFormat("%b %d, %Y")(datum.date)}
</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 ? `
<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>
`}
</div>
`)
}
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 {
up: tailwindColors.success,
down: tailwindColors.error,
flat: tailwindColors.gray[500],
}[datum.trend.direction]
}
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) {
2024-10-11 14:40:13 -04:00
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
} else {
return datum.value
}
}
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) {
2024-10-11 14:40:13 -04:00
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
} else {
2024-10-11 14:40:13 -04: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)
}
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)
}
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)
}
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")
2024-10-11 14:40:13 -04:00
.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) {
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
} else {
2024-10-11 14:40:13 -04:00
return 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
}
}
2024-10-11 14:40:13 -04:00
get _d3Group() {
if (this._d3GroupMemo) {
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
} else {
2024-10-11 14:40:13 -04:00
return 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
}
}
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 }
} else {
return { top: 0, right: 0, bottom: 0, left: 0 }
}
}
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() {
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.select(this.element)
}
2024-10-11 14:40:13 -04:00
get _trendColor() {
if (this._trendDirection === "flat") {
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 tailwindColors.gray[500]
2024-10-11 14:40:13 -04:00
} else if (this._trendDirection === this._favorableDirection) {
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 tailwindColors.green[500]
} else {
return tailwindColors.error
}
}
2024-10-11 14:40:13 -04:00
get _trendDirection() {
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.dataValue.trend.direction
}
2024-10-11 14:40:13 -04:00
get _favorableDirection() {
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.dataValue.trend.favorable_direction
}
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()
2024-10-11 14:40:13 -04:00
.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() {
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
const reductionPercent = this.useLabelsValue ? 0.15 : 0.05
2024-10-11 14:40:13 -04:00
const dataMin = d3.min(this._normalDataPoints, d => d.value)
const dataMax = d3.max(this._normalDataPoints, d => 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
const padding = (dataMax - dataMin) * reductionPercent
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
}
2024-10-11 14:40:13 -04:00
}